diff --git a/src/librustc_parse/parser/stmt.rs b/src/librustc_parse/parser/stmt.rs index abee24e2b09..42d85e96aef 100644 --- a/src/librustc_parse/parser/stmt.rs +++ b/src/librustc_parse/parser/stmt.rs @@ -42,16 +42,16 @@ impl<'a> Parser<'a> { return self.parse_local_mk(lo, attrs.into()).map(Some) } if self.is_kw_followed_by_ident(kw::Mut) { - return self.recover_stmt_local(lo, attrs.into(), "missing `let`", "let mut"); + return self.recover_stmt_local(lo, attrs.into(), "missing keyword", "let mut"); } if self.is_kw_followed_by_ident(kw::Auto) { self.bump(); // `auto` - let msg = "to introduce a variable, write `let` instead of `auto`"; + let msg = "write `let` instead of `auto` to introduce a new variable"; return self.recover_stmt_local(lo, attrs.into(), msg, "let"); } if self.is_kw_followed_by_ident(sym::var) { self.bump(); // `var` - let msg = "to introduce a variable, write `let` instead of `var`"; + let msg = "write `let` instead of `var` to introduce a new variable"; return self.recover_stmt_local(lo, attrs.into(), msg, "let"); } @@ -208,14 +208,14 @@ impl<'a> Parser<'a> { fn recover_stmt_local( &mut self, - span: Span, + lo: Span, attrs: AttrVec, msg: &str, sugg: &str, ) -> PResult<'a, Option> { - let stmt = self.parse_local_mk(span, attrs)?; - self.struct_span_err(stmt.span, "invalid variable declaration") - .span_suggestion_short(span, msg, sugg.to_string(), Applicability::MachineApplicable) + let stmt = self.parse_local_mk(lo, attrs)?; + self.struct_span_err(lo, "invalid variable declaration") + .span_suggestion(lo, msg, sugg.to_string(), Applicability::MachineApplicable) .emit(); Ok(Some(stmt)) } diff --git a/src/test/ui/parser/issue-65257-invalid-var-decl-recovery.rs b/src/test/ui/parser/issue-65257-invalid-var-decl-recovery.rs index 7efc4174874..c1826f8caae 100644 --- a/src/test/ui/parser/issue-65257-invalid-var-decl-recovery.rs +++ b/src/test/ui/parser/issue-65257-invalid-var-decl-recovery.rs @@ -1,20 +1,20 @@ fn main() { auto n = 0;//~ ERROR invalid variable declaration - //~^ HELP to introduce a variable, write `let` instead of `auto` + //~^ HELP write `let` instead of `auto` to introduce a new variable auto m;//~ ERROR invalid variable declaration - //~^ HELP to introduce a variable, write `let` instead of `auto` + //~^ HELP write `let` instead of `auto` to introduce a new variable m = 0; var n = 0;//~ ERROR invalid variable declaration - //~^ HELP to introduce a variable, write `let` instead of `var` + //~^ HELP write `let` instead of `var` to introduce a new variable var m;//~ ERROR invalid variable declaration - //~^ HELP to introduce a variable, write `let` instead of `var` + //~^ HELP write `let` instead of `var` to introduce a new variable m = 0; mut n = 0;//~ ERROR invalid variable declaration - //~^ HELP missing `let` + //~^ HELP missing keyword mut var;//~ ERROR invalid variable declaration - //~^ HELP missing `let` + //~^ HELP missing keyword var = 0; let _recovery_witness: () = 0; //~ ERROR mismatched types diff --git a/src/test/ui/parser/issue-65257-invalid-var-decl-recovery.stderr b/src/test/ui/parser/issue-65257-invalid-var-decl-recovery.stderr index 429c12265bd..ad72dd30542 100644 --- a/src/test/ui/parser/issue-65257-invalid-var-decl-recovery.stderr +++ b/src/test/ui/parser/issue-65257-invalid-var-decl-recovery.stderr @@ -2,49 +2,57 @@ error: invalid variable declaration --> $DIR/issue-65257-invalid-var-decl-recovery.rs:2:5 | LL | auto n = 0; - | ----^^^^^^ - | | - | help: to introduce a variable, write `let` instead of `auto` + | ^^^^ + | +help: write `let` instead of `auto` to introduce a new variable + | +LL | let n = 0; + | ^^^ error: invalid variable declaration --> $DIR/issue-65257-invalid-var-decl-recovery.rs:4:5 | LL | auto m; - | ----^^ - | | - | help: to introduce a variable, write `let` instead of `auto` + | ^^^^ + | +help: write `let` instead of `auto` to introduce a new variable + | +LL | let m; + | ^^^ error: invalid variable declaration --> $DIR/issue-65257-invalid-var-decl-recovery.rs:8:5 | LL | var n = 0; - | ---^^^^^^ - | | - | help: to introduce a variable, write `let` instead of `var` + | ^^^ + | +help: write `let` instead of `var` to introduce a new variable + | +LL | let n = 0; + | ^^^ error: invalid variable declaration --> $DIR/issue-65257-invalid-var-decl-recovery.rs:10:5 | LL | var m; - | ---^^ - | | - | help: to introduce a variable, write `let` instead of `var` + | ^^^ + | +help: write `let` instead of `var` to introduce a new variable + | +LL | let m; + | ^^^ error: invalid variable declaration --> $DIR/issue-65257-invalid-var-decl-recovery.rs:14:5 | LL | mut n = 0; - | ---^^^^^^ - | | - | help: missing `let` + | ^^^ help: missing keyword: `let mut` error: invalid variable declaration --> $DIR/issue-65257-invalid-var-decl-recovery.rs:16:5 | LL | mut var; - | ---^^^^ - | | - | help: missing `let` + | ^^^ help: missing keyword: `let mut` error[E0308]: mismatched types --> $DIR/issue-65257-invalid-var-decl-recovery.rs:20:33