Skip to content

Commit a478cd4

Browse files
committed
Improve diagnostics
1 parent 235905c commit a478cd4

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

src/librustc_passes/ast_validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
348348
let mut err = struct_span_err!(self.session, span, E0642,
349349
"patterns aren't allowed in trait methods");
350350
let suggestion = "give this argument a name or use an \
351-
underscore to ignore it, instead of a \
351+
underscore to ignore it instead of using a \
352352
tuple pattern";
353353
err.span_suggestion(span, suggestion, "_".to_owned());
354354
err.emit();

src/librustc_passes/diagnostics.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,15 @@ Example of erroneous code:
269269
```compile_fail,E0642
270270
trait Foo {
271271
fn foo((x, y): (i32, i32)); // error: patterns aren't allowed
272-
// in methods without bodies
272+
// in trait methods
273+
}
274+
```
275+
276+
You can instead use a single name for the argument:
277+
278+
```
279+
trait Foo {
280+
fn foo(x_and_y: (i32, i32)); // ok!
273281
}
274282
```
275283
"##,

src/libsyntax/parse/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ impl<'a> Parser<'a> {
17441744
fn parse_arg_general(&mut self, require_name: bool) -> PResult<'a, Arg> {
17451745
maybe_whole!(self, NtArg, |x| x);
17461746

1747-
// If we see `ident :`, then we know that the argument is just of the
1747+
// If we see `ident :`, then we know that the argument is not just of the
17481748
// form `type`, which means we won't need to recover from parsing a
17491749
// pattern and so we don't need to store a parser snapshot.
17501750
let parser_snapshot_before_pat = if

src/test/ui/E0642.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ error[E0642]: patterns aren't allowed in trait methods
33
|
44
LL | fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in trait methods
55
| ^^^^^^
6-
help: give this argument a name or use an underscore to ignore it, instead of a tuple pattern
6+
help: give this argument a name or use an underscore to ignore it instead of using a tuple pattern
77
|
88
LL | fn foo(_: (i32, i32)); //~ ERROR patterns aren't allowed in trait methods
99
| ^
@@ -13,7 +13,7 @@ error[E0642]: patterns aren't allowed in trait methods
1313
|
1414
LL | fn bar((x, y): (i32, i32)) {} //~ ERROR patterns aren't allowed in trait methods
1515
| ^^^^^^
16-
help: give this argument a name or use an underscore to ignore it, instead of a tuple pattern
16+
help: give this argument a name or use an underscore to ignore it instead of using a tuple pattern
1717
|
1818
LL | fn bar(_: (i32, i32)) {} //~ ERROR patterns aren't allowed in trait methods
1919
| ^

0 commit comments

Comments
 (0)