diff options
| author | David Wood <david@davidtw.co> | 2018-12-07 11:16:13 +0100 |
|---|---|---|
| committer | David Wood <david@davidtw.co> | 2018-12-07 12:02:41 +0100 |
| commit | 7fcf31b181433cc67b17af550d87fca1e3394f90 (patch) | |
| tree | 97fdb66344f8c7ce96902dadeec4a9bf997a7f83 | |
| parent | e4dc15a96905217dbdf857159f67bfd79d5e4d7c (diff) | |
| download | rust-7fcf31b181433cc67b17af550d87fca1e3394f90.tar.gz rust-7fcf31b181433cc67b17af550d87fca1e3394f90.zip | |
Add suggestion for underscore binding fix.
This commit emits a suggestion for adding an underscore binding to arguments in trait methods that previously did not have a argument name specified.
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/anon-params-denied-2018.stderr | 8 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index af63314b154..560078136eb 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1850,6 +1850,15 @@ impl<'a> Parser<'a> { Applicability::HasPlaceholders, ); } else if require_name && is_trait_item { + if let PatKind::Ident(_, ident, _) = pat.node { + err.span_suggestion_with_applicability( + pat.span, + "explicitly ignore parameter", + format!("_: {}", ident), + Applicability::MachineApplicable, + ); + } + err.note("anonymous parameters are removed in the 2018 edition (see RFC 1685)"); } diff --git a/src/test/ui/anon-params-denied-2018.stderr b/src/test/ui/anon-params-denied-2018.stderr index e1aa65981f6..dd9e933542f 100644 --- a/src/test/ui/anon-params-denied-2018.stderr +++ b/src/test/ui/anon-params-denied-2018.stderr @@ -2,7 +2,9 @@ error: expected one of `:` or `@`, found `)` --> $DIR/anon-params-denied-2018.rs:6:15 | LL | fn foo(i32); //~ expected one of `:` or `@`, found `)` - | ^ expected one of `:` or `@` here + | ---^ expected one of `:` or `@` here + | | + | help: explicitly ignore parameter: `_: i32` | = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) @@ -10,7 +12,9 @@ error: expected one of `:` or `@`, found `,` --> $DIR/anon-params-denied-2018.rs:8:36 | LL | fn bar_with_default_impl(String, String) {} - | ^ expected one of `:` or `@` here + | ------^ expected one of `:` or `@` here + | | + | help: explicitly ignore parameter: `_: String` | = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) |
