diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 8482824ec4be4..bbf914368e661 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -137,6 +137,32 @@ impl<'a> Parser<'a> { self.bump(); Ok(self.mk_expr(self.prev_token.span, ExprKind::Err)) } + None if self.may_recover() + && self.prev_token.is_ident() + && self.token.kind == token::Colon => + { + err.span_suggestion_verbose( + self.prev_token.span.until(self.look_ahead(1, |t| t.span)), + "if this is a parameter, remove the name for the parameter", + "", + Applicability::MaybeIncorrect, + ); + + let snapshot = self.create_snapshot_for_diagnostic(); + self.bump(); + match self.parse_expr() { + Ok(expr) => { + err.emit(); + Ok(expr) + } + + Err(expr_err) => { + expr_err.cancel(); + self.restore_snapshot(snapshot); + Err(err) + } + } + } _ => Err(err), }, } diff --git a/tests/ui/parser/issues/issue-111416.rs b/tests/ui/parser/issues/issue-111416.rs index cfd1b6b99ba76..f89e7a1b841bf 100644 --- a/tests/ui/parser/issues/issue-111416.rs +++ b/tests/ui/parser/issues/issue-111416.rs @@ -1,3 +1,7 @@ fn main() { - let my = monad_bind(mx, T: Try); //~ ERROR invalid `struct` delimiters or `fn` call arguments + let my = monad_bind(mx, T: Try); + //~^ ERROR expected identifier, found `:` + //~| ERROR cannot find value `mx` + //~| ERROR cannot find value `Try` + //~| ERROR cannot find function `monad_bind` } diff --git a/tests/ui/parser/issues/issue-111416.stderr b/tests/ui/parser/issues/issue-111416.stderr index 36f6c5b018fe8..1d6faa41d148a 100644 --- a/tests/ui/parser/issues/issue-111416.stderr +++ b/tests/ui/parser/issues/issue-111416.stderr @@ -1,18 +1,33 @@ -error: invalid `struct` delimiters or `fn` call arguments - --> $DIR/issue-111416.rs:2:14 +error: expected identifier, found `:` + --> $DIR/issue-111416.rs:2:30 | LL | let my = monad_bind(mx, T: Try); - | ^^^^^^^^^^^^^^^^^^^^^^ - | -help: if `monad_bind` is a struct, use braces as delimiters + | ^ expected identifier | -LL | let my = monad_bind { mx, T: Try }; - | ~ ~ -help: if `monad_bind` is a function, use the arguments directly +help: if this is a parameter, remove the name for the parameter | LL - let my = monad_bind(mx, T: Try); LL + let my = monad_bind(mx, Try); | -error: aborting due to 1 previous error +error[E0425]: cannot find value `mx` in this scope + --> $DIR/issue-111416.rs:2:25 + | +LL | let my = monad_bind(mx, T: Try); + | ^^ not found in this scope + +error[E0425]: cannot find value `Try` in this scope + --> $DIR/issue-111416.rs:2:32 + | +LL | let my = monad_bind(mx, T: Try); + | ^^^ not found in this scope + +error[E0425]: cannot find function `monad_bind` in this scope + --> $DIR/issue-111416.rs:2:14 + | +LL | let my = monad_bind(mx, T: Try); + | ^^^^^^^^^^ not found in this scope + +error: aborting due to 4 previous errors +For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/parser/issues/issue-34255-1.stderr b/tests/ui/parser/issues/issue-34255-1.stderr index 1e72f040b0366..c881ab6f2c735 100644 --- a/tests/ui/parser/issues/issue-34255-1.stderr +++ b/tests/ui/parser/issues/issue-34255-1.stderr @@ -1,18 +1,37 @@ -error: invalid `struct` delimiters or `fn` call arguments - --> $DIR/issue-34255-1.rs:8:5 +error: expected expression, found `:` + --> $DIR/issue-34255-1.rs:8:22 | LL | Test::Drill(field: 42); - | ^^^^^^^^^^^^^^^^^^^^^^ - | -help: if `Test::Drill` is a struct, use braces as delimiters + | ^ expected expression | -LL | Test::Drill { field: 42 }; - | ~ ~ -help: if `Test::Drill` is a function, use the arguments directly +help: if this is a parameter, remove the name for the parameter | LL - Test::Drill(field: 42); LL + Test::Drill(42); | -error: aborting due to 1 previous error +error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `:` + --> $DIR/issue-34255-1.rs:8:22 + | +LL | Test::Drill(field: 42); + | ^ + | | + | expected one of 8 possible tokens + | help: missing `,` + +error[E0425]: cannot find value `field` in this scope + --> $DIR/issue-34255-1.rs:8:17 + | +LL | Test::Drill(field: 42); + | ^^^^^ not found in this scope + +error[E0533]: expected value, found struct variant `Test::Drill` + --> $DIR/issue-34255-1.rs:8:5 + | +LL | Test::Drill(field: 42); + | ^^^^^^^^^^^ not a value + +error: aborting due to 4 previous errors +Some errors have detailed explanations: E0425, E0533. +For more information about an error, try `rustc --explain E0425`. diff --git a/tests/ui/parser/issues/issue-44406.stderr b/tests/ui/parser/issues/issue-44406.stderr index d005f116e124b..7eaf573275d08 100644 --- a/tests/ui/parser/issues/issue-44406.stderr +++ b/tests/ui/parser/issues/issue-44406.stderr @@ -1,22 +1,55 @@ -error: invalid `struct` delimiters or `fn` call arguments - --> $DIR/issue-44406.rs:3:9 +error: expected expression, found `:` + --> $DIR/issue-44406.rs:3:16 | LL | bar(baz: $rest) - | ^^^^^^^^^^^^^^^ + | ^ expected expression ... LL | foo!(true); | ---------- in this macro invocation | = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) -help: if `bar` is a struct, use braces as delimiters - | -LL | bar { baz: $rest } - | ~ ~ -help: if `bar` is a function, use the arguments directly +help: if this is a parameter, remove the name for the parameter | LL - bar(baz: $rest) LL + bar(: $rest) | -error: aborting due to 1 previous error +error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `:` + --> $DIR/issue-44406.rs:3:16 + | +LL | bar(baz: $rest) + | ^ + | | + | expected one of 8 possible tokens + | help: missing `,` +... +LL | foo!(true); + | ---------- in this macro invocation + | + = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0425]: cannot find value `baz` in this scope + --> $DIR/issue-44406.rs:3:13 + | +LL | bar(baz: $rest) + | ^^^ not found in this scope +... +LL | foo!(true); + | ---------- in this macro invocation + | + = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0425]: cannot find function `bar` in this scope + --> $DIR/issue-44406.rs:3:9 + | +LL | bar(baz: $rest) + | ^^^ not found in this scope +... +LL | foo!(true); + | ---------- in this macro invocation + | + = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 4 previous errors +For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/parser/issues/issue-91461.stderr b/tests/ui/parser/issues/issue-91461.stderr index 27e1b5cdc177f..8268ad92cd54b 100644 --- a/tests/ui/parser/issues/issue-91461.stderr +++ b/tests/ui/parser/issues/issue-91461.stderr @@ -1,14 +1,35 @@ +error: expected expression, found `:` + --> $DIR/issue-91461.rs:2:8 + | +LL | a(_:b:,) + | ^ expected expression + | +help: if this is a parameter, remove the name for the parameter + | +LL - a(_:b:,) +LL + a(b:,) + | + +error: expected one of `)`, `,`, `.`, `?`, or an operator, found `:` + --> $DIR/issue-91461.rs:2:8 + | +LL | a(_:b:,) + | ^ + | | + | expected one of `)`, `,`, `.`, `?`, or an operator + | help: missing `,` + error: expected identifier, found reserved identifier `_` --> $DIR/issue-91461.rs:2:7 | LL | a(_:b:,) | ^ expected identifier, found reserved identifier -error: expected one of `)`, `,`, `.`, `?`, or an operator, found `:` - --> $DIR/issue-91461.rs:2:8 +error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `:` + --> $DIR/issue-91461.rs:2:10 | LL | a(_:b:,) - | ^ expected one of `)`, `,`, `.`, `?`, or an operator + | ^ expected one of 8 possible tokens -error: aborting due to 2 previous errors +error: aborting due to 4 previous errors diff --git a/tests/ui/parser/recover/recover-from-bad-variant.stderr b/tests/ui/parser/recover/recover-from-bad-variant.stderr index 04968bbdf999d..ff9a9e79363c8 100644 --- a/tests/ui/parser/recover/recover-from-bad-variant.stderr +++ b/tests/ui/parser/recover/recover-from-bad-variant.stderr @@ -1,18 +1,62 @@ -error: invalid `struct` delimiters or `fn` call arguments - --> $DIR/recover-from-bad-variant.rs:7:13 +error: expected expression, found `:` + --> $DIR/recover-from-bad-variant.rs:7:24 + | +LL | let x = Enum::Foo(a: 3, b: 4); + | ^ expected expression + | +help: if this is a parameter, remove the name for the parameter + | +LL - let x = Enum::Foo(a: 3, b: 4); +LL + let x = Enum::Foo(3, b: 4); + | + +error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `:` + --> $DIR/recover-from-bad-variant.rs:7:24 | LL | let x = Enum::Foo(a: 3, b: 4); - | ^^^^^^^^^^^^^^^^^^^^^ + | ^ + | | + | expected one of 8 possible tokens + | help: missing `,` + +error: expected expression, found `:` + --> $DIR/recover-from-bad-variant.rs:7:30 | -help: if `Enum::Foo` is a struct, use braces as delimiters +LL | let x = Enum::Foo(a: 3, b: 4); + | ^ expected expression | -LL | let x = Enum::Foo { a: 3, b: 4 }; - | ~ ~ -help: if `Enum::Foo` is a function, use the arguments directly +help: if this is a parameter, remove the name for the parameter | LL - let x = Enum::Foo(a: 3, b: 4); -LL + let x = Enum::Foo(3, 4); +LL + let x = Enum::Foo(a: 3, 4); + | + +error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `:` + --> $DIR/recover-from-bad-variant.rs:7:30 | +LL | let x = Enum::Foo(a: 3, b: 4); + | ^ + | | + | expected one of 8 possible tokens + | help: missing `,` + +error[E0425]: cannot find value `a` in this scope + --> $DIR/recover-from-bad-variant.rs:7:23 + | +LL | let x = Enum::Foo(a: 3, b: 4); + | ^ not found in this scope + +error[E0425]: cannot find value `b` in this scope + --> $DIR/recover-from-bad-variant.rs:7:29 + | +LL | let x = Enum::Foo(a: 3, b: 4); + | ^ not found in this scope + +error[E0533]: expected value, found struct variant `Enum::Foo` + --> $DIR/recover-from-bad-variant.rs:7:13 + | +LL | let x = Enum::Foo(a: 3, b: 4); + | ^^^^^^^^^ not a value error[E0164]: expected tuple struct or tuple variant, found struct variant `Enum::Foo` --> $DIR/recover-from-bad-variant.rs:10:9 @@ -31,7 +75,7 @@ help: use the tuple variant pattern syntax instead LL | Enum::Bar(a, b) => {} | ~~~~~~ -error: aborting due to 3 previous errors +error: aborting due to 9 previous errors -Some errors have detailed explanations: E0164, E0769. +Some errors have detailed explanations: E0164, E0425, E0533, E0769. For more information about an error, try `rustc --explain E0164`. diff --git a/tests/ui/type/type-ascription-precedence.stderr b/tests/ui/type/type-ascription-precedence.stderr index 09cdc370309dc..7dadbdb19104f 100644 --- a/tests/ui/type/type-ascription-precedence.stderr +++ b/tests/ui/type/type-ascription-precedence.stderr @@ -9,12 +9,24 @@ error: expected identifier, found `:` | LL | *(S: Z); | ^ expected identifier + | +help: if this is a parameter, remove the name for the parameter + | +LL - *(S: Z); +LL + *(Z); + | error: expected identifier, found `:` --> $DIR/type-ascription-precedence.rs:37:8 | LL | -(S: Z); | ^ expected identifier + | +help: if this is a parameter, remove the name for the parameter + | +LL - -(S: Z); +LL + -(Z); + | error: expected one of `.`, `;`, `?`, `}`, or an operator, found `:` --> $DIR/type-ascription-precedence.rs:41:12 @@ -42,5 +54,27 @@ error: expected one of `.`, `;`, `?`, `}`, or an operator, found `:` LL | (S .. S): S; | ^ expected one of `.`, `;`, `?`, `}`, or an operator -error: aborting due to 7 previous errors +error[E0614]: type `Z` cannot be dereferenced + --> $DIR/type-ascription-precedence.rs:33:5 + | +LL | *(S: Z); + | ^^^^^^^ + +error[E0600]: cannot apply unary operator `-` to type `Z` + --> $DIR/type-ascription-precedence.rs:37:5 + | +LL | -(S: Z); + | ^^^^^^^ cannot apply unary operator `-` + | +note: an implementation of `std::ops::Neg` might be missing for `Z` + --> $DIR/type-ascription-precedence.rs:7:1 + | +LL | struct Z; + | ^^^^^^^^ must implement `std::ops::Neg` +note: the trait `std::ops::Neg` must be implemented + --> $SRC_DIR/core/src/ops/arith.rs:LL:COL + +error: aborting due to 9 previous errors +Some errors have detailed explanations: E0600, E0614. +For more information about an error, try `rustc --explain E0600`.