-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add suggestions for possible missing fn
, struct
, or enum
keywords
#127419
Conversation
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
@rustbot ready |
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.
Thanks for addressing the comments! The approach looks a lot better now. Had a couple more nits.
if self.look_ahead(1, |t| *t == token::CloseDelim(Delimiter::Brace)) | ||
|| self.look_ahead(2, |t| *t == token::Colon) | ||
|| self.look_ahead(3, |t| *t == token::Colon) |
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.
Comment here justifying the lookaheads. Otherwise this is a bit confusing.
// possible public struct definition where `struct` was forgotten | ||
Some(errors::MissingKeywordForItemDefinition::Struct { span: sp, ident }) | ||
// possible struct or enum definition where `struct` or `enum` was forgotten | ||
if self.look_ahead(1, |t| *t == token::CloseDelim(Delimiter::Brace)) |
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.
It could be either struct
or enum
when the brace closes without anything inside, so we shouldn't just suggest struct
let full_sp = self.prev_token.span.to(self.token.span); | ||
let is_pub = self.prev_token.is_keyword(kw::Pub); | ||
let is_const = self.prev_token.is_keyword(kw::Const); | ||
let sp = self.token.span.shrink_to_lo(); |
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.
The span here is a bit suboptimal here. If there was a pub
, we should use the span for pub foo
(both tokens) in pub foo() {}
. If there is no pub
, I think it makes sense for us to just use the span for the identifier instead of shrinking.
As for the suggestion, I'm pretty sure you can use a separate (shrunk) span for the suggested snippet to replace.
@rustbot ready |
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.
LGTM, thanks!
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (0c81f94): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)Results (primary -3.9%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary -6.9%, secondary -3.1%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 704.203s -> 704.958s (0.11%) |
Closes #125446
Closes #65381