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

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

Merged
merged 1 commit into from
Sep 8, 2022

Conversation

chenyukang
Copy link
Member

@chenyukang chenyukang commented Sep 7, 2022

Fixes #101477

@rust-highfive
Copy link
Collaborator

r? @fee1-dead

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

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 7, 2022
@rust-highfive rust-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.

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.

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

Comment on lines 965 to 966
let mut err = self.struct_span_err(self.token.span, "expect `=`, found `==`");
err.span_suggestion_short(self.token.span, "write `=` instead of `==`", "=", appl)
Copy link
Member

Choose a reason for hiding this comment

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

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

Copy link
Member Author

@chenyukang chenyukang Sep 8, 2022

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
Member Author

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

chenyukang commented Sep 7, 2022

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

chenyukang commented Sep 7, 2022

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)]
pub struct ErrorGuaranteed(());

But parse_let_expr is:

 fn parse_let_expr(&mut self) -> PResult<'a, P<Expr>> {
        ...

        self.expect(&token::Eq)?;
        
        ...
        Ok(self.mk_expr(span, ExprKind::Let(pat, expr, span)))
    }

@chenyukang
Copy link
Member Author

chenyukang commented Sep 8, 2022

Got it:

  let mut err = self.sess.create_err(UseEqInstead { span: self.token.span });
  err.emit();
  return Err(err);

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

rustbot commented Sep 8, 2022

rustc_error_messages was changed

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

@fee1-dead
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Sep 8, 2022

📌 Commit ddb225f 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 Sep 8, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Sep 8, 2022
Recover from typo where == is used in place of =

Fixes rust-lang#101477
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Sep 8, 2022
Recover from typo where == is used in place of =

Fixes rust-lang#101477
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:master Sep 8, 2022
@rustbot rustbot 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 free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic 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.

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