-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Recover upon mistyped error on typo'd const
in const param def
#112029
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
r? @cjgillot (rustbot has picked a reviewer for you, use r? to override) |
84a5120
to
be66fca
Compare
if let Some(last) = params.last() | ||
&& last.ident.as_str().to_ascii_lowercase() == kw::Const.as_str() | ||
{ | ||
// We might have a typo'd `Const` that was parsed as a type parameter. | ||
let span = last.ident.span; | ||
let mut err = self.struct_span_err( | ||
span, | ||
format!("`const` keyword was mistyped as `{}`", last.ident.as_str()), | ||
); | ||
err.span_suggestion_verbose( | ||
span, | ||
"use the `const` keyword", | ||
kw::Const.as_str(), | ||
Applicability::MachineApplicable, | ||
); | ||
err.emit(); | ||
return Err(err); | ||
} else { | ||
self.expect_gt()?; | ||
} |
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.
Should this suggestion happen inside parse_generic_params
or parse_ty_param
?
Can it be made an actual recovery = if self.may_recover()
, find a way to return Ok
with a sensible AST?
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.
I think I got the recovery as GenericParam
working
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.
Had to attrs.clone()
a few places, not sure if I can avoid it
302052c
to
e98650c
Compare
const
in const param defconst
in const param def
e98650c
to
41f5a30
Compare
Thanks! |
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#112029 (Recover upon mistyped error on typo'd `const` in const param def) - rust-lang#112037 (Add details about `unsafe_op_in_unsafe_fn` to E0133) - rust-lang#112039 (compiler: update solaris/illumos to enable tsan support.) - rust-lang#112042 (Migrate GUI colors test to original CSS color format) - rust-lang#112045 (Followup to rust-lang#111973) r? `@ghost` `@rustbot` modify labels: rollup
And add machine-applicable fix for the typo'd
const
keyword.Before
After This PR
Fixes #111941.