Recover missing turbofish for lifetime arguments in expression position - #162749
raushan728 wants to merge 4 commits into
Conversation
…eywordLabel emission in eat_label
|
The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease |
|
r? @chenyukang rustbot has assigned @chenyukang. Use Why was this reviewer chosen?The reviewer was selected based on:
|
There was a problem hiding this comment.
I need to do a more in-depth review, as I have some mild concerns about increasing the size of the parser, but the results look reasonable so far. I'll look at this again later this week if the assigned reviewer doesn't manage to get the time before then.
| if let Some((op_span, ident)) = self.expected_turbofish_context.take() { | ||
| err.help(format!( | ||
| "if you meant to specify lifetime parameters for `{ident}`, use the `::<>` turbofish" | ||
| )); | ||
| err.span_suggestion( | ||
| op_span.shrink_to_lo(), | ||
| "use the `::<>` turbofish", | ||
| "::", | ||
| Applicability::MachineApplicable, | ||
| ); | ||
| } else { | ||
| err.help("if you meant to specify lifetime parameters, use the `::<>` turbofish"); | ||
| if let Some(lt_sp) = lt_span { | ||
| err.span_suggestion( | ||
| lt_sp.shrink_to_lo(), | ||
| "use the `::<>` turbofish", | ||
| "::", | ||
| Applicability::MachineApplicable, | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
Mild nitpicks (the help text can be the one used for the suggestion message, making the suggestion verbose and using the wording from the existing diagnostics)
| if let Some((op_span, ident)) = self.expected_turbofish_context.take() { | |
| err.help(format!( | |
| "if you meant to specify lifetime parameters for `{ident}`, use the `::<>` turbofish" | |
| )); | |
| err.span_suggestion( | |
| op_span.shrink_to_lo(), | |
| "use the `::<>` turbofish", | |
| "::", | |
| Applicability::MachineApplicable, | |
| ); | |
| } else { | |
| err.help("if you meant to specify lifetime parameters, use the `::<>` turbofish"); | |
| if let Some(lt_sp) = lt_span { | |
| err.span_suggestion( | |
| lt_sp.shrink_to_lo(), | |
| "use the `::<>` turbofish", | |
| "::", | |
| Applicability::MachineApplicable, | |
| ); | |
| } | |
| } | |
| if let Some((op_span, ident)) = self.expected_turbofish_context.take() { | |
| err.span_suggestion( | |
| op_span.shrink_to_lo(), | |
| format!( | |
| "use `::<...>` instead of `<...>` to specify lifetime arguments for `{ident}`", | |
| ), | |
| "::", | |
| Applicability::MachineApplicable, | |
| ); | |
| } else if let Some(lt_sp) = lt_span { | |
| err.span_suggestion( | |
| lt_sp.shrink_to_lo(), | |
| "use `::<...>` instead of `<...>` to specify lifetime arguments", | |
| "::", | |
| Applicability::MachineApplicable, | |
| ); | |
| } else { | |
| err.help("use `::<...>` instead of `<...>` to specify lifetime arguments"); | |
| } |
|
Reminder, once the PR becomes ready for a review, use |
Fixes #162656.
rustc already suggests
::<>when a type/const generic argument is missing its turbofish (foo<Bar>()), but not for lifetime arguments -Struct<'a> { .. }previously misfired through label/char-literal recovery, producing a confusing cascade of unrelated errors instead of one actionable turbofish suggestion.cc @estebank