-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Give correct suggestion for a typo in raw pointers #145903
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
base: master
Are you sure you want to change the base?
Conversation
|
||
return Ok(self.mk_ty(kw_span.to(star_span), TyKind::Err(guar))); | ||
} | ||
} |
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.
} | |
} | |
) | ||
.emit(); | ||
|
||
return Ok(self.mk_ty(kw_span.to(star_span), TyKind::Err(guar))); |
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.
Why not recover this like a TyKind::RawPtr
? Recovering like TyKind::Err
seems to be strictly worse.
let kw_span = self.token.span; | ||
self.bump(); | ||
|
||
if self.eat(exp!(Star)) { |
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 should try to parse a subsequent type via a snapshot. Or at least check that lookahead(2)
can begin a type
let kw_span = self.token.span; | ||
self.bump(); | ||
|
||
if self.eat(exp!(Star)) { |
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 eat is always true, since we checked the lookahead above
.dcx() | ||
.struct_span_err( | ||
kw_span, | ||
"raw pointer type must have a star before the mutability keyword", |
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.
"raw pointer type must have a star before the mutability keyword", | |
"raw pointer types are written like `*{...} T`", |
I find the phrasing kind of awkward -- "must have a star before the mutability keyword" doesn't really point to the fact that there is a star, and it's just misplaced. And also I wouldn't call "const
" to be a mutability keyword.
I'm not sure if what I suggested is any better, but I wonder if there's a way to suggest the change here that sounds more descriptive.
@@ -276,6 +276,34 @@ impl<'a> Parser<'a> { | |||
) -> PResult<'a, Box<Ty>> { | |||
let allow_qpath_recovery = recover_qpath == RecoverQPath::Yes; | |||
maybe_recover_from_interpolated_ty_qpath!(self, allow_qpath_recovery); | |||
|
|||
if (self.token.is_keyword(kw::Const) || self.token.is_keyword(kw::Mut)) |
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.
if (self.token.is_keyword(kw::Const) || self.token.is_keyword(kw::Mut)) | |
// Comment that describes what we're trying to do here. | |
if (self.token.is_keyword(kw::Const) || self.token.is_keyword(kw::Mut)) |
@@ -276,6 +276,34 @@ impl<'a> Parser<'a> { | |||
) -> PResult<'a, Box<Ty>> { | |||
let allow_qpath_recovery = recover_qpath == RecoverQPath::Yes; | |||
maybe_recover_from_interpolated_ty_qpath!(self, allow_qpath_recovery); | |||
|
|||
if (self.token.is_keyword(kw::Const) || self.token.is_keyword(kw::Mut)) |
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 probably should also be moved into a separate function and also moved way down into the actually if else
chain below rather than being hit first on every call to parse_ty_common
This adds a check for when user wrote
const* T
instead of*const T
, I just saw how a C-person made this typo and compiler suggests thiswhich is very incorrect
in my current approach we don't recover from this because otherwise we will get a wall from errors which is very verbose and 0 helpful
also fixes #136602
r? compiler