Uh oh!
There was an error while loading. Please reload this page.
Recover from typo where == is used in place of = - #101515
Conversation
rust-highfive
commented
Sep 7, 2022
r? @fee1-dead (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
fee1-dead
left a comment
There was a problem hiding this comment.
Nice work! LGTM pending error message improvements. Also, could this be using SessionDiagnostics instead? cc @davidtwco
There was a problem hiding this comment.
| 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) |
There was a problem hiding this comment.
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: `=`davidtwco
commented
Sep 7, 2022
This could absolutely use |
@davidtwco How can I keep returning an - 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 |
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 fnparse_let_expr(&mutself) -> PResult<'a,P<Expr>>{
...self.expect(&token::Eq)?;
...Ok(self.mk_expr(span,ExprKind::Let(pat, expr, span)))} |
Got it: letmut err = self.sess.create_err(UseEqInstead{span:self.token.span});
err.emit();returnErr(err); |
rustbot
commented
Sep 8, 2022
cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
fee1-dead
commented
Sep 8, 2022
@bors r+ |
bors
commented
Sep 8, 2022
Recover from typo where == is used in place of = Fixesrust-lang#101477
Recover from typo where == is used in place of = Fixesrust-lang#101477
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
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
Fixes#101477