Skip to content
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

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

trevyn
Copy link
Contributor

@trevyn trevyn commented Jul 6, 2024

Closes #125446
Closes #65381

@rustbot
Copy link
Collaborator

rustbot commented Jul 6, 2024

r? @fee1-dead

rustbot has assigned @fee1-dead.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 6, 2024
compiler/rustc_parse/src/parser/diagnostics.rs Outdated Show resolved Hide resolved
compiler/rustc_parse/src/parser/diagnostics.rs Outdated Show resolved Hide resolved
compiler/rustc_parse/src/parser/diagnostics.rs Outdated Show resolved Hide resolved
compiler/rustc_parse/src/parser/diagnostics.rs Outdated Show resolved Hide resolved
compiler/rustc_parse/src/parser/diagnostics.rs Outdated Show resolved Hide resolved
compiler/rustc_parse/src/parser/diagnostics.rs Outdated Show resolved Hide resolved
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 7, 2024
@fee1-dead fee1-dead removed the request for review from compiler-errors July 7, 2024 11:05
@trevyn
Copy link
Contributor Author

trevyn commented Jul 7, 2024

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 7, 2024
Copy link
Member

@fee1-dead fee1-dead left a 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.

Comment on lines 413 to 418
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)
Copy link
Member

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))
Copy link
Member

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();
Copy link
Member

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 rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 7, 2024
@trevyn
Copy link
Contributor Author

trevyn commented Jul 8, 2024

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 8, 2024
Copy link
Member

@fee1-dead fee1-dead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@fee1-dead
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jul 10, 2024

📌 Commit b40adc9 has been approved by fee1-dead

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 10, 2024
@bors
Copy link
Contributor

bors commented Jul 10, 2024

⌛ Testing commit b40adc9 with merge 0c81f94...

@bors
Copy link
Contributor

bors commented Jul 10, 2024

☀️ Test successful - checks-actions
Approved by: fee1-dead
Pushing 0c81f94 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 10, 2024
@bors bors merged commit 0c81f94 into rust-lang:master Jul 10, 2024
7 checks passed
@rustbot rustbot added this to the 1.81.0 milestone Jul 10, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0c81f94): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.5% [-2.8%, -0.3%] 2
All ❌✅ (primary) - - 0

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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.9% [-3.9%, -3.9%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -3.9% [-3.9%, -3.9%] 1

Cycles

Results (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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-6.9% [-6.9%, -6.9%] 1
Improvements ✅
(secondary)
-3.1% [-3.4%, -2.8%] 3
All ❌✅ (primary) -6.9% [-6.9%, -6.9%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 704.203s -> 704.958s (0.11%)
Artifact size: 328.70 MiB -> 328.69 MiB (-0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when fn keyword is missing could be more explicit missing fn before main() -- error could be improved
6 participants