Skip to content

Commit 7fcf31b

Browse files
committed
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.
1 parent e4dc15a commit 7fcf31b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/libsyntax/parse/parser.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,15 @@ impl<'a> Parser<'a> {
18501850
Applicability::HasPlaceholders,
18511851
);
18521852
} else if require_name && is_trait_item {
1853+
if let PatKind::Ident(_, ident, _) = pat.node {
1854+
err.span_suggestion_with_applicability(
1855+
pat.span,
1856+
"explicitly ignore parameter",
1857+
format!("_: {}", ident),
1858+
Applicability::MachineApplicable,
1859+
);
1860+
}
1861+
18531862
err.note("anonymous parameters are removed in the 2018 edition (see RFC 1685)");
18541863
}
18551864

src/test/ui/anon-params-denied-2018.stderr

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ error: expected one of `:` or `@`, found `)`
22
--> $DIR/anon-params-denied-2018.rs:6:15
33
|
44
LL | fn foo(i32); //~ expected one of `:` or `@`, found `)`
5-
| ^ expected one of `:` or `@` here
5+
| ---^ expected one of `:` or `@` here
6+
| |
7+
| help: explicitly ignore parameter: `_: i32`
68
|
79
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
810

911
error: expected one of `:` or `@`, found `,`
1012
--> $DIR/anon-params-denied-2018.rs:8:36
1113
|
1214
LL | fn bar_with_default_impl(String, String) {}
13-
| ^ expected one of `:` or `@` here
15+
| ------^ expected one of `:` or `@` here
16+
| |
17+
| help: explicitly ignore parameter: `_: String`
1418
|
1519
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
1620

0 commit comments

Comments
 (0)