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 ICE with explicit late-bound lifetimes #72441

Merged
merged 1 commit into from
May 30, 2020
Merged

Fix ICE with explicit late-bound lifetimes #72441

merged 1 commit into from
May 30, 2020

Conversation

doctorn
Copy link
Contributor

@doctorn doctorn commented May 21, 2020

Rather than returning an explicit late-bound lifetime as a generic argument count mismatch (which is not necessarily true), this PR propagates the presence of explicit late-bound lifetimes.

This avoids an ICE that can occur due to the presence of explicit late-bound lifetimes when building generic substitutions by explicitly ignoring them.

r? @varkor

cc @davidtwco (this removes a check you introduced in #60892)

Resolves #72278

Comment on lines +149 to +164
/// Decorates the result of a generic argument count mismatch
/// check with whether explicit late bounds were provided.
#[derive(Clone)]
pub struct GenericArgCountResult {
pub explicit_late_bound: ExplicitLateBound,
pub correct: Result<(), GenericArgCountMismatch>,
}
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't this information go into the GenericArgCountMismatch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is we want to warn not error at the moment (introducing an error would be a breaking change - see #42868), so basically we end up with situations where we might not have a generic arg count mismatch but we still have explicit late bounds. That's part of what's causing the ICE. (If you #[deny(warnings)] the ICE disappears.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we consider trying to close #42868? I guess we still need to make some expressiveness improvements to do so?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So #42868 lists two future PRs, one to make the lint deny-by-default, and the other to turn the warning into a hard error. Making the lint deny-by-default would still require this patch, but if we jumped straight to a hard error, then none of this work is necessary. It doesn't resolve the issue that this is still a breaking change though, but I guess that might not matter so much seeing as it's already broken?

@eddyb
Copy link
Member

eddyb commented May 22, 2020

r? @nikomatsakis (maybe we should discuss how to get rid of the early/late-bound lifetime split...)

@rust-highfive rust-highfive assigned nikomatsakis and unassigned varkor May 22, 2020
@doctorn
Copy link
Contributor Author

doctorn commented May 22, 2020

Reading, I think @nikomatsakis's suggestion here is probably close to the right answer, but we'd definitely have to wait for a new edition before it could be integrated.

src/librustc_typeck/astconv.rs Show resolved Hide resolved
Comment on lines +149 to +164
/// Decorates the result of a generic argument count mismatch
/// check with whether explicit late bounds were provided.
#[derive(Clone)]
pub struct GenericArgCountResult {
pub explicit_late_bound: ExplicitLateBound,
pub correct: Result<(), GenericArgCountMismatch>,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we consider trying to close #42868? I guess we still need to make some expressiveness improvements to do so?

S.func::<'a, U>()
//~^ WARN cannot specify lifetime arguments explicitly
//~| WARN this was previously accepted
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have tests for all the other random scenarios that can occur? It seems like we should try to test them all -- in particular the case of "got a lifetime but expected something else"...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was under the impression that

cover pretty much everything but I could be wrong

Copy link
Contributor

Choose a reason for hiding this comment

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

Those tests look pretty good. I guess they don't cover lifetimes + types intermixed. But I'm satisfied.

@nikomatsakis
Copy link
Contributor

nikomatsakis commented May 28, 2020

So I guess r=me with comment applied

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 28, 2020

📌 Commit fa351ee has been approved by nikomatsakis

@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 May 28, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request May 30, 2020
Rollup of 9 pull requests

Successful merges:

 - rust-lang#72299 (more `LocalDefId`s)
 - rust-lang#72368 (Resolve overflow behavior for RangeFrom)
 - rust-lang#72441 (Fix ICE with explicit late-bound lifetimes)
 - rust-lang#72499 (Override Box::<[T]>::clone_from)
 - rust-lang#72521 (Properly handle InlineAsmOperand::SymFn when collecting monomorphized items)
 - rust-lang#72540 (mir: adjust conditional in recursion limit check)
 - rust-lang#72563 (multiple Return terminators are possible)
 - rust-lang#72585 (Only capture tokens for items with outer attributes)
 - rust-lang#72607 (Eagerly lower asm sub-expressions to HIR even if there is an error)

Failed merges:

r? @ghost
@bors bors merged commit 49ca99d into rust-lang:master May 30, 2020
@doctorn doctorn deleted the late-bound-lifetime-ice branch May 30, 2020 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE when using lifetime arguments explicitly in late bound lifetime parameters
6 participants