Skip to content

Recover from typo where == is used in place of = - #101515

Merged
bors merged 1 commit into
rust-lang:masterfrom
chenyukang:fix-101477
Sep 8, 2022
Merged

Recover from typo where == is used in place of =#101515
bors merged 1 commit into
rust-lang:masterfrom
chenyukang:fix-101477

Conversation

@chenyukang

@chenyukangchenyukang commented Sep 7, 2022

Copy link
Copy Markdown
Member

Fixes#101477

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @fee1-dead

(rust-highfive has picked a reviewer for you, use r? to override)

@rustbotrustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 7, 2022
@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 7, 2022
@rust-log-analyzer

This comment has been minimized.

@fee1-deadfee1-dead left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work! LGTM pending error message improvements. Also, could this be using SessionDiagnostics instead? cc @davidtwco

Comment on lines 965 to 966

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
letmut err = self.struct_span_err(self.token.span,"expect `=`, found `==`");
err.span_suggestion_short(self.token.span,"write `=` instead of `==`","=", appl)
letmut err = self.struct_span_err(self.token.span,"unexpected `==`");
err.span_suggestion_short(self.token.span,"try using `=` instead","=", appl)

@chenyukangchenyukangSep 8, 2022

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

SessionDiagnostic will print the suggestion in the same line, so it will print like this:

error: unexpected `==` --> src/test/ui/parser/issue-101477-enum.rs:6:7 |6 | B == 2 //~ ERROR unexpected `==` | ^^ help: try using `=` instead `==`: `=`

I think it's better in this format?

error: unexpected `==` --> src/test/ui/parser/issue-101477-enum.rs:6:7 |6 | B == 2 //~ ERROR unexpected `==` | ^^ help: replace `==` with a equal symbol: `=`

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Resolved with @compiler-errors with advices.

@davidtwco

Copy link
Copy Markdown
Member

Also, could this be using SessionDiagnostics instead? cc @davidtwco

This could absolutely use SessionDiagnostic, I'd appreciate it if it did - see #100717.

@chenyukang

chenyukang commented Sep 7, 2022

Copy link
Copy Markdown
MemberAuthor

Also, could this be using SessionDiagnostics instead? cc @davidtwco

This could absolutely use SessionDiagnostic, I'd appreciate it if it did - see #100717.

@davidtwco
I'm fixing it to use SessionDiagnostic, I have a question when using it:

How can I keep returning an Err to avoid extra useless diagnostics?

- let mut err = self.struct_span_err(self.token.span, "unexpected `==`");- err.span_suggestion_short(self.token.span, "try using `=` instead `==`", "=", appl)- .emit();- return Err(err);+ self.sess.emit_err(UseEqInstead { span: self.token.span });+ return Ok(true);

I use return Ok now and there will be a extra diagnostics which I want to remove.

--- a/src/test/ui/parser/issue-101477-let.stderr+++ b/src/test/ui/parser/issue-101477-let.stderr@@ -2,7 +2,13 @@ error: unexpected `==`
--> $DIR/issue-101477-let.rs:4:11
|
LL | let x == 2;
- | ^^ help: try using `=` instead `==`+ | ^^ help: replace `==` with a equal symbol: `=`-error: aborting due to previous error+error: expected expression, found `==`+ --> $DIR/issue-101477-let.rs:4:11+ |+LL | let x == 2;+ | ^^ expected expression++error: aborting due to 2 previous errors

@chenyukang

chenyukang commented Sep 7, 2022

Copy link
Copy Markdown
MemberAuthor

Seems we use this struct to avoid later errors:

/// Useful type to use with `Result<>` indicate that an error has already/// been reported to the user, so no need to continue checking.#[derive(Clone,Copy,Debug,Encodable,Decodable,Hash,PartialEq,Eq,PartialOrd,Ord)]#[derive(HashStable_Generic)]pubstructErrorGuaranteed(());

But parse_let_expr is:

fnparse_let_expr(&mutself) -> PResult<'a,P<Expr>>{
...self.expect(&token::Eq)?;
...Ok(self.mk_expr(span,ExprKind::Let(pat, expr, span)))}

@chenyukang

chenyukang commented Sep 8, 2022

Copy link
Copy Markdown
MemberAuthor

Got it:

letmut err = self.sess.create_err(UseEqInstead{span:self.token.span});
err.emit();returnErr(err);

@rustbotrustbot added the A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic label Sep 8, 2022
@rustbot

Copy link
Copy Markdown
Collaborator

rustc_error_messages was changed

cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki

Comment threadcompiler/rustc_parse/src/parser/diagnostics.rs Outdated
Comment threadcompiler/rustc_parse/src/parser/diagnostics.rs Outdated
Comment threadcompiler/rustc_error_messages/locales/en-US/parser.ftl Outdated
@fee1-dead

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented Sep 8, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit ddb225f has been approved by fee1-dead

It is now in the queue for this repository.

@borsbors 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 Sep 8, 2022
@Dylan-DPCDylan-DPC mentioned this pull request Sep 8, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Sep 8, 2022
@Dylan-DPCDylan-DPC mentioned this pull request Sep 8, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Sep 8, 2022
@Dylan-DPCDylan-DPC mentioned this pull request Sep 8, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 8, 2022
Rollup of 7 pull requests
Successful merges:
- rust-lang#98933 (Opaque types' generic params do not imply anything about their hidden type's lifetimes)
- rust-lang#101041 (translations(rustc_session): migrates rustc_session to use SessionDiagnostic - Pt. 2)
- rust-lang#101424 (Adjust and slightly generalize operator error suggestion)
- rust-lang#101496 (Allow lower_lifetime_binder receive a closure)
- rust-lang#101501 (Allow lint passes to be bound by `TyCtxt`)
- rust-lang#101515 (Recover from typo where == is used in place of =)
- rust-lang#101545 (Remove unnecessary `PartialOrd` and `Ord`)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 8d2a492 into rust-lang:masterSep 8, 2022
@rustbotrustbot added this to the 1.65.0 milestone Sep 8, 2022
flip1995 pushed a commit to flip1995/rust that referenced this pull request Oct 6, 2022
Rollup of 7 pull requests
Successful merges:
- rust-lang#98933 (Opaque types' generic params do not imply anything about their hidden type's lifetimes)
- rust-lang#101041 (translations(rustc_session): migrates rustc_session to use SessionDiagnostic - Pt. 2)
- rust-lang#101424 (Adjust and slightly generalize operator error suggestion)
- rust-lang#101496 (Allow lower_lifetime_binder receive a closure)
- rust-lang#101501 (Allow lint passes to be bound by `TyCtxt`)
- rust-lang#101515 (Recover from typo where == is used in place of =)
- rust-lang#101545 (Remove unnecessary `PartialOrd` and `Ord`)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-translationArea: Translation infrastructure, and migrating existing diagnostics to SessionDiagnosticS-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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.

Recover from typo where == is used in place of =

8 participants

@chenyukang@rust-highfive@rust-log-analyzer@davidtwco@rustbot@fee1-dead@bors@compiler-errors