-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 when parsing lifetime as function argument #93595
Conversation
r? @jackh726 (rust-highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't quite seem right :)
I would have expected that the "recovery" here is just to fall back to generics with a lifetime.
@jackh726, this fix is actually for when we parse lifetimes in the expression position. This happens when we have a lifetime token as the first token when parsing a loop expression. So the deal is that we delayed a bug in the code, but none of the paths that I've previously added which do recovery for bad generics apply to something like: fn main() {
function('a,
// ^^- here |
Not sure how to fix this other than emitting a sometimes-unhelpful error. This error existed in the past, before I added the delay-span-bug that I reverted here. For context: #92876 (specifically this) |
"let ".to_string(), | ||
Applicability::MachineApplicable, | ||
); | ||
// Check if our lhs is a child of the condition of a while loop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this definitely got included from another PR of mine. I'll revert this!
Revert spurious changes included in PR
For the function arg case, I could see this as acceptable (given that you actually can use a labeled expr as an argument - or at least I would expect that to work). For the generics though, I'm a bit surprised we get to |
Well in the case we have an expr We can't just raise a It's just because the recovery is split over too many layers, since that |
I think that explanation of mine is a bit complicated. To put it in a different way: We don't start recovering a bad turbofish until after we have parsed the bad label expression. If we continue to delay a bug in the label parsing code like we're doing now, we must be absolutely certain we're going to emit another bug later on all codepaths we took to get here, in order to prevent an ICE (sorry, you definitely know this already, just want to spell out my thought process clearly). It turns out this doesn't always work out, since we cannot bubble up the information that we've parsed a naked lifetime label token through the various layers of parse_expr, since we just return an expression (and doing so would be a very heavy change). We can't bubble down the expectation that we might be currently parsing something that looks like a bad turbofish either, because we already parsed the This example, which ICEs, might help demonstrate something that locally looks like a bad turbofish, but which parses (incorrectly) today, since we only delay a bug when we parse that bad lifetime fn f(_a1: bool, _a2: bool) {
let a = 1i32;
let b = 1i32;
f(a < 'a, b > (1))
} This PR just adds emitting an error back to the label parsing code, which I supressed in previous PR. I'd rather us possibly emit two errors, where one is redundant, and emit zero and ICE on certain pathological cases. |
@bors r+ rollup |
📌 Commit 5be9e79 has been approved by |
…, r=jackh726 fix ICE when parsing lifetime as function argument I don't really like this, but we basically need to emit an error instead of just delaying an bug, because there are too many places in the AST that aren't covered by my previous PRs... cc: rust-lang#93282 (comment)
…askrgr Rollup of 7 pull requests Successful merges: - rust-lang#91908 (Add 2 tests) - rust-lang#93595 (fix ICE when parsing lifetime as function argument) - rust-lang#93757 (Add some known GAT bugs as tests) - rust-lang#93759 (Pretty print ItemKind::Use in rustfmt style) - rust-lang#93897 (linkchecker: fix panic on directory symlinks) - rust-lang#93898 (tidy: Extend error code check) - rust-lang#93928 (Add missing release notes for rust-lang#85200) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
I don't really like this, but we basically need to emit an error instead of just delaying an bug, because there are too many places in the AST that aren't covered by my previous PRs...
cc: #93282 (comment)