Recover from typo where == is used in place of =#101515
Recover from typo where == is used in place of =#101515bors merged 1 commit intorust-lang:masterfrom
Conversation
|
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.
f9fd237 to
f3e9893
Compare
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.
| 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) |
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: `=`
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)]
pub struct ErrorGuaranteed(());But fn parse_let_expr(&mut self) -> PResult<'a, P<Expr>> {
...
self.expect(&token::Eq)?;
...
Ok(self.mk_expr(span, ExprKind::Let(pat, expr, span)))
} |
|
Got it: let mut err = self.sess.create_err(UseEqInstead { span: self.token.span });
err.emit();
return Err(err); |
f3e9893 to
04ef874
Compare
|
cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki |
04ef874 to
ddb225f
Compare
|
@bors r+ |
Recover from typo where == is used in place of = Fixes rust-lang#101477
Recover from typo where == is used in place of = Fixes rust-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