Skip to content

Commit

Permalink
Improve diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Aug 11, 2018
1 parent 235905c commit a478cd4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/librustc_passes/ast_validation.rs
Expand Up @@ -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();
Expand Down
10 changes: 9 additions & 1 deletion src/librustc_passes/diagnostics.rs
Expand Up @@ -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!
}
```
"##,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/parser.rs
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/E0642.stderr
Expand Up @@ -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
| ^
Expand All @@ -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
| ^
Expand Down

0 comments on commit a478cd4

Please sign in to comment.