-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 an ICE on an invalid binding @ ...
in a tuple struct pattern
#74557
Conversation
r? @oli-obk (rust_highfive has picked a reviewer for you, use r? to override) |
@JohnTitor, oh, I see in #74539 (comment) that you have a better idea than this? 🙂
What do you mean by “not losing diags”? The thing is that AST lowering runs after name resolution. 🤔 How else could it “poison” that particular invalid binding? Sorry, I don't know the compiler very well, it's been years. 🙂 |
@bors r+ |
📌 Commit db77a9e516ad37a730c19e3c008c7279b5767aa7 has been approved by |
let e = E::A(2, 3); | ||
match e { | ||
E::A(x @ ..) => { //~ ERROR `x @` is not allowed in a tuple | ||
x //~ ERROR cannot find value `x` in this scope |
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.
Hmm, x
should be found here?
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.
@JohnTitor, this is a consequence of the nature of the fix. But I think you're right, this should be done differently.
@JohnTitor, okay, I have now pushed a second commit with an alternate, simpler approach. But it leads to diagnostics that are, in my opinion, degraded compared to the status quo.
We end up with two extra diagnostics that do not contribute anything new. Which solution seems better in your opinion? |
@jakubadamw Thanks for investigating more! I like the later diagnostics but let's hear opinion from @nagisa or someone from T-compiler. |
I personally like the former slightly more because its not as redundant (and In the end the decision on diagnostics is something that @rust-lang/wg-diagnostics is responsible for and the diagnostics themselves can be iterated further in a separate PR that does not target a backport to beta or stable. If we want this to be backportable it needs to be as simple and obviously correct as it can possibly get. |
@nagisa, thank you. Looks like I stepped on your toes by pushing after your r+, sorry! 🙂 Yeah, I agree the first solution gives nicer results (although implementation wise it's not as simple as the second one). Should we await input from @rust-lang/wg-diagnostics or go ahead with the first approach? If the latter, then I can take back the redundant commits. |
@nagisa, okay, I brought back the initial version. 🙂 |
@bors r+ |
📌 Commit 77a2fbb86e9a0cddc18722390d939e9bcd874c64 has been approved by |
@nagisa, pardon, this will need one more r+, as I had to tidy up the style per the failed build. 🙂 |
@bors r=nagisa |
📌 Commit f5e5eb6 has been approved by |
// In tuple struct patterns ignore the invalid `ident @ ...`. | ||
// It will be handled as an error by the AST lowering. | ||
PatKind::Ident(bmode, ident, ref sub) | ||
if !(is_tuple_struct_pat && sub.as_ref().filter(|p| p.is_rest()).is_some()) => | ||
{ |
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 PR can be merged as is, but I think we could also add another branch that detects the case with PatKind::Ident(..)
where ..
is present and record it with a PartialRes::new(Res::Err)
, which should eliminate the second unnecessary error that complains about x
not being defined. (Haven't looked at this deeply enough to be sure.)
…arth Rollup of 13 pull requests Successful merges: - rust-lang#72714 (Fix debug assertion in typeck) - rust-lang#73197 (Impl Default for ranges) - rust-lang#73323 (wf: check foreign fn decls for well-formedness) - rust-lang#74051 (disallow non-static lifetimes in const generics) - rust-lang#74376 (test caching opt_const_param_of on disc) - rust-lang#74501 (Ayu theme: Use different background color for Run button) - rust-lang#74505 (Fix search input focus in ayu theme) - rust-lang#74522 (Update sanitizer docs) - rust-lang#74546 (Fix duplicate maybe_uninit_extra attribute) - rust-lang#74552 (Stabilize TAU constant.) - rust-lang#74555 (Improve "important traits" popup display on mobile) - rust-lang#74557 (Fix an ICE on an invalid `binding @ ...` in a tuple struct pattern) - rust-lang#74561 (update backtrace-rs) Failed merges: r? @ghost
The beta nomination was discussed at weekly T-compiler meeting. The stable nomination was also discussed at that same meeting. At the end of both discussions, I noted (and @Mark-Simulacrum agreed) that we'd be more comfortable backporting this if it guarded against the scenario where this guard fires but the AST-lowering code, for whatever reason, doesn't signal an error. In particular, we think that should be implementable via a Having said that, adding a Having said that: beta backport approved, and stable backport approved. |
delay_span_bug instead of silent ignore This is a follow-up to rust-lang#74557. r? @pnkfelix
delay_span_bug instead of silent ignore This is a follow-up to rust-lang#74557. r? @pnkfelix
Fix ICEs with `@ ..` binding This reverts rust-lang#74557 and introduces an alternative fix while ensuring that rust-lang#74954 is not broken. The diagnostics are verbose though, it fixes three related issues. cc rust-lang#74954, rust-lang#74539, and rust-lang#74702
Fixes #74539.