diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 7022136f2398..2195331f465b 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -348,7 +348,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { let mut err = struct_span_err!(self.session, span, E0642, "patterns aren't allowed in trait methods"); let suggestion = "give this argument a name or use an \ - underscore to ignore it, instead of a \ + underscore to ignore it instead of using a \ tuple pattern"; err.span_suggestion(span, suggestion, "_".to_owned()); err.emit(); diff --git a/src/librustc_passes/diagnostics.rs b/src/librustc_passes/diagnostics.rs index b78f2ca676d2..f1d0a4fee341 100644 --- a/src/librustc_passes/diagnostics.rs +++ b/src/librustc_passes/diagnostics.rs @@ -269,7 +269,15 @@ Example of erroneous code: ```compile_fail,E0642 trait Foo { fn foo((x, y): (i32, i32)); // error: patterns aren't allowed - // in methods without bodies + // in trait methods +} +``` + +You can instead use a single name for the argument: + +``` +trait Foo { + fn foo(x_and_y: (i32, i32)); // ok! } ``` "##, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 57eb1f52fb70..a1dbe93fdfe3 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1744,7 +1744,7 @@ impl<'a> Parser<'a> { fn parse_arg_general(&mut self, require_name: bool) -> PResult<'a, Arg> { maybe_whole!(self, NtArg, |x| x); - // If we see `ident :`, then we know that the argument is just of the + // If we see `ident :`, then we know that the argument is not just of the // form `type`, which means we won't need to recover from parsing a // pattern and so we don't need to store a parser snapshot. let parser_snapshot_before_pat = if diff --git a/src/test/ui/E0642.stderr b/src/test/ui/E0642.stderr index 07ec8b4cc2c8..8c16b8b30cd5 100644 --- a/src/test/ui/E0642.stderr +++ b/src/test/ui/E0642.stderr @@ -3,7 +3,7 @@ error[E0642]: patterns aren't allowed in trait methods | LL | fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in trait methods | ^^^^^^ -help: give this argument a name or use an underscore to ignore it, instead of a tuple pattern +help: give this argument a name or use an underscore to ignore it instead of using a tuple pattern | LL | fn foo(_: (i32, i32)); //~ ERROR patterns aren't allowed in trait methods | ^ @@ -13,7 +13,7 @@ error[E0642]: patterns aren't allowed in trait methods | LL | fn bar((x, y): (i32, i32)) {} //~ ERROR patterns aren't allowed in trait methods | ^^^^^^ -help: give this argument a name or use an underscore to ignore it, instead of a tuple pattern +help: give this argument a name or use an underscore to ignore it instead of using a tuple pattern | LL | fn bar(_: (i32, i32)) {} //~ ERROR patterns aren't allowed in trait methods | ^