Add suggestions for possible missing fn, struct, or enum keywords#127419
Add suggestions for possible missing fn, struct, or enum keywords#127419bors merged 1 commit intorust-lang:masterfrom
fn, struct, or enum keywords#127419Conversation
|
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
|
@rustbot ready |
fee1-dead
left a comment
There was a problem hiding this comment.
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.
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.
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.
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 |
|
@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