Skip to content

Commit

Permalink
Add suggestion for underscore binding fix.
Browse files Browse the repository at this point in the history
This commit emits a suggestion for adding an underscore binding to
arguments in trait methods that previously did not have a argument name
specified.
  • Loading branch information
davidtwco committed Dec 7, 2018
1 parent e4dc15a commit 7fcf31b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/libsyntax/parse/parser.rs
Expand Up @@ -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)");
}

Expand Down
8 changes: 6 additions & 2 deletions src/test/ui/anon-params-denied-2018.stderr
Expand Up @@ -2,15 +2,19 @@ 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)

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)

Expand Down

0 comments on commit 7fcf31b

Please sign in to comment.