Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 5 commits into from
Aug 30, 2022

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Aug 13, 2022

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:

trait Foo { type Bar; }

impl<T> Foo for T {
    type Bar = i32;
}

fn foo<T>(_: <T as Foo>::Bar) {}

fn needs_i32_ref_fn(f: fn(&'static i32)) {}

fn main() {
    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::<()>}`

@rustbot rustbot 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
Contributor

r? @michaelwoerister

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

@rust-highfive rust-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
Member Author

r? diagnostics

(or maybe @rust-lang/types?)

@compiler-errors compiler-errors force-pushed the normalize-the-fn-def-sig-plz branch from 3a5a285 to 818de76 Compare August 13, 2022 02:31
@jyn514
Copy link
Member

jyn514 commented Aug 13, 2022

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

@estebank
Copy link
Contributor

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

r? rust-lang/types

@rust-highfive rust-highfive assigned lcnr and unassigned estebank Aug 15, 2022
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

nits, then r=me

@compiler-errors compiler-errors force-pushed the normalize-the-fn-def-sig-plz branch from 7292a63 to e5602cb Compare August 26, 2022 00:10
@compiler-errors
Copy link
Member Author

Added ObligationCtxt::new_in_snapshot and addressed other nits.

@bors r=lcnr

@bors
Copy link
Collaborator

bors commented Aug 26, 2022

📌 Commit e5602cb has been approved by lcnr

It is now in the queue for this repository.

@bors bors 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
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:master Aug 30, 2022
@rustbot rustbot 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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant 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