Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix the ICE described in #83693 #86438

Merged
merged 1 commit into from
Jul 25, 2021
Merged

Conversation

FabianWolff
Copy link
Contributor

@FabianWolff FabianWolff commented Jun 18, 2021

This pull request fixes #83693 and fixes #84768.

@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(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 Jun 18, 2021
@petrochenkov
Copy link
Contributor

I'm sufficiently sure that this patch treats symptoms rather than the root cause.

The minimized self-contained reproduction for this case is

#![feature(associated_type_defaults)]
#![feature(unboxed_closures)]

#[rustc_paren_sugar]
trait Tr<T> {
    type Output = u8;
    fn method() {}
}

impl<T> Tr<T> for u8 {}

fn main() {
    <u8 as Tr(&u8)>::method; // Sugared, ICE
    <u8 as Tr<(), Output = &u8>>::method; // Desugared, no ICE
}

What is the difference between the sugared and desugared cases?
Can we reproduce the ICE in desugared form?
Can we produce a desugaring not causing the ICE?

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 20, 2021
@FabianWolff
Copy link
Contributor Author

I'm sufficiently sure that this patch treats symptoms rather than the root cause.

It seems that you are right; the issue is more complex than I thought at first.

Thanks for the example that you've provided; however, I think your desugaring is wrong and should look like this:

    <u8 as Tr(&u8)>::method; // ICE
    <u8 as Tr(&u8) -> ()>::method; // equivalent, ICE
    <u8 as Tr<(&u8,), Output = ()>>::method; // desugared, no ICE

Neither of the following cause an ICE:

    <u8 as Tr<(), Output = &u8>>::method;
    <u8 as Tr() -> &u8>::method;

The ICE thus probably has to do with the special treatment of lifetime elision for parenthesized generic trait arguments:

if generic_args.parenthesized {
let was_in_fn_syntax = self.is_in_fn_syntax;
self.is_in_fn_syntax = true;
self.visit_fn_like_elision(generic_args.inputs(), Some(generic_args.bindings[0].ty()));
self.is_in_fn_syntax = was_in_fn_syntax;
return;
}

So probably visit_fn_like_elision() should create a binder somewhere but doesn't. However, I know too little about this function to figure out where or how to fix this; do you happen to have an idea?

@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 21, 2021
@petrochenkov
Copy link
Contributor

do you happen to have an idea?

No (perhaps @jackh726 may know something right away).
I can investigate, but I won't get to it soon, so I suggest to dig into the code yourself, there's no rocket science in those parts of the compiler.

@jackh726
Copy link
Member

I do know, not quite off of my head. On mobile so will followup next time I get on my computer.

If I remember correctly, visit_fn_like_elision doesn't create the binders, but instead uses the closest binders in scope.

@petrochenkov
Copy link
Contributor

r? @jackh726
(I'd taken two PRs from your queue instead.)

@jackh726
Copy link
Member

So, we probably should be bailing out of visit_fn_like_elision sooner, but we aren't.

https://github.com/rust-lang/rust/blob/master/compiler/rustc_resolve/src/late/lifetimes.rs#L2686-L2707

We actually should probably be bailing on Scope::Body too. I'm not sure if we also need to manually set any lifetimes to 'static. I think that should be the default. And that'll prevent an escaping bound var. (This is another place where a ReError would be nice)

@jackh726 jackh726 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 30, 2021
@FabianWolff
Copy link
Contributor Author

We actually should probably be bailing on Scope::Body too.

Sorry for not getting around to implementing this sooner @jackh726. But yes, this seems to fix the problem; thanks for your help! I've also added a test case for #84768, which was caused by the same problem.

@JohnCSimon
Copy link
Member

Ping from triage:
@FabianWolff is this ready for review?
If so - remove the S-waiting-on-author label and add S-waiting-on-review

@FabianWolff
Copy link
Contributor Author

@FabianWolff is this ready for review?

Yes, it is.

@rustbot label: +S-waiting-on-review -S-waiting-on-author

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 25, 2021
@jackh726
Copy link
Member

Sorry it's taken a bit to get back to this.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jul 25, 2021

📌 Commit 6f0fe9b has been approved by jackh726

@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 Jul 25, 2021
@FabianWolff
Copy link
Contributor Author

Sorry it's taken a bit to get back to this.

No problem, thanks for the review!

@bors
Copy link
Contributor

bors commented Jul 25, 2021

⌛ Testing commit 6f0fe9b with merge 478126c...

@bors
Copy link
Contributor

bors commented Jul 25, 2021

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing 478126c to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 25, 2021
@bors bors merged commit 478126c into rust-lang:master Jul 25, 2021
@rustbot rustbot added this to the 1.56.0 milestone Jul 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
7 participants