diff options
| author | varkor <github@varkor.com> | 2018-08-07 00:03:26 +0100 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2018-08-11 21:08:24 +0100 |
| commit | a478cd41e3f203ec531bfce7efb8fc602aad5c7d (patch) | |
| tree | 9d281c05e049256d4ee313eac0ff25fc96afacc0 | |
| parent | 235905c080bf953a522ff86d4fec6134ac4fb371 (diff) | |
| download | rust-a478cd41e3f203ec531bfce7efb8fc602aad5c7d.tar.gz rust-a478cd41e3f203ec531bfce7efb8fc602aad5c7d.zip | |
Improve diagnostics
| -rw-r--r-- | src/librustc_passes/ast_validation.rs | 2 | ||||
| -rw-r--r-- | src/librustc_passes/diagnostics.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/E0642.stderr | 4 |
4 files changed, 13 insertions, 5 deletions
diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 7022136f239..2195331f465 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 b78f2ca676d..f1d0a4fee34 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 57eb1f52fb7..a1dbe93fdfe 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 07ec8b4cc2c..8c16b8b30cd 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 | ^ |
