Skip to content

Attempt to normalize FnDef signature in InferCtxt::cmp - #100473

Merged
bors merged 5 commits into
rust-lang:masterfrom
compiler-errors:normalize-the-fn-def-sig-plz
Aug 30, 2022
Merged

Attempt to normalize FnDef signature in InferCtxt::cmp#100473
bors merged 5 commits into
rust-lang:masterfrom
compiler-errors:normalize-the-fn-def-sig-plz

Conversation

@compiler-errors

@compiler-errorscompiler-errors commented Aug 13, 2022

Copy link
Copy Markdown
Contributor

Stashes a normalization callback in InferCtxt so that the signature we get from tcx.fn_sig(..).subst(..) in InferCtxt::cmp can be properly normalized, since we cannot expect for it to have normalized types since it comes straight from astconv.

This is kind of a hack, but I will say that @jyn514 found the fact that we present unnormalized types to be very confusing in real life code, and I agree with that feeling. Though altogether I am still a bit unsure about whether this PR is worth the effort, so I'm open to alternatives and/or just closing it outright.

On the other hand, this isn't a ridiculously heavy implementation anyways -- it's less than a hundred lines of changes, and half of that is just miscellaneous cleanup.

This is stacked onto #100471 which is basically unrelated, and it can be rebased off of that when that lands or if needed.


The code:

traitFoo{typeBar;}impl<T>FooforT{typeBar = i32;}fnfoo<T>(_: <TasFoo>::Bar){}fnneeds_i32_ref_fn(f:fn(&'statici32)){}fnmain(){needs_i32_ref_fn(foo::<()>);}

Before:

 = note: expected fn pointer `fn(&'static i32)`
found fn item `fn(<() as Foo>::Bar) {foo::<()>}`

After:

 = note: expected fn pointer `fn(&'static i32)`
found fn item `fn(i32) {foo::<()>}`

@rustbotrustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 13, 2022
@rust-highfive

Copy link
Copy Markdown
Contributor

r? @michaelwoerister

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 13, 2022
@compiler-errors

Copy link
Copy Markdown
ContributorAuthor

r? diagnostics

(or maybe @rust-lang/types?)

@jyn514

Copy link
Copy Markdown
Member

Here is a real world use case where this would have been enormously helpful: https://mobile.twitter.com/joshuayn514/status/1557913836337786880

Comment threadcompiler/rustc_typeck/src/check/inherited.rs Outdated
Comment threadcompiler/rustc_infer/src/infer/mod.rs Outdated
@estebank

Copy link
Copy Markdown
Contributor

I'm r+ on this, but want to make sure another pair of eyes looks at this

r? rust-lang/types

@rust-highfiverust-highfive assigned lcnr and unassigned estebankAug 15, 2022

@lcnrlcnr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits, then r=me

Comment threadcompiler/rustc_infer/src/infer/mod.rs Outdated
Comment threadcompiler/rustc_typeck/src/check/inherited.rs Outdated
Comment threadcompiler/rustc_typeck/src/check/inherited.rs Outdated
@compiler-errors
compiler-errorsforce-pushed the normalize-the-fn-def-sig-plz branch from 7292a63 to e5602cbCompareAugust 26, 2022 00:10
@compiler-errors

Copy link
Copy Markdown
ContributorAuthor

Added ObligationCtxt::new_in_snapshot and addressed other nits.

@bors r=lcnr

@bors

bors commented Aug 26, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit e5602cb has been approved by lcnr

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 26, 2022
@Dylan-DPCDylan-DPC mentioned this pull request Aug 30, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 30, 2022
Rollup of 5 pull requests
Successful merges:
- rust-lang#99517 (Display raw pointer as *{mut,const} T instead of *-ptr in errors)
- rust-lang#99928 (Do not leak type variables from opaque type relation)
- rust-lang#100473 (Attempt to normalize `FnDef` signature in `InferCtxt::cmp`)
- rust-lang#100653 (Move the cast_float_to_int fallback code to GCC)
- rust-lang#100941 (Point at the string inside literal and mention if we need string inte…)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 15e2e51 into rust-lang:masterAug 30, 2022
@rustbotrustbot added this to the 1.65.0 milestone Aug 30, 2022
@compiler-errors
compiler-errors deleted the normalize-the-fn-def-sig-plz branch August 11, 2023 20:12
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@compiler-errors@rust-highfive@jyn514@estebank@bors@lcnr@michaelwoerister@rustbot