Improve diagnostics
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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!
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
| ^
|
||||
|
||||
Reference in New Issue
Block a user