Skip to content

Commit e4dc15a

Browse files
committed
Add context for RFC 1685 change in 2018 edition.
This commit adds a note providing context for the change to argument names being required in the 2018 edition for trait methods.
1 parent a2fb99b commit e4dc15a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/libsyntax/parse/parser.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ impl<'a> Parser<'a> {
14041404
// definition...
14051405

14061406
// We don't allow argument names to be left off in edition 2018.
1407-
p.parse_arg_general(p.span.rust_2018())
1407+
p.parse_arg_general(p.span.rust_2018(), true)
14081408
})?;
14091409
generics.where_clause = self.parse_where_clause()?;
14101410

@@ -1817,7 +1817,7 @@ impl<'a> Parser<'a> {
18171817

18181818
/// This version of parse arg doesn't necessarily require
18191819
/// identifier names.
1820-
fn parse_arg_general(&mut self, require_name: bool) -> PResult<'a, Arg> {
1820+
fn parse_arg_general(&mut self, require_name: bool, is_trait_item: bool) -> PResult<'a, Arg> {
18211821
maybe_whole!(self, NtArg, |x| x);
18221822

18231823
if let Ok(Some(_)) = self.parse_self_arg() {
@@ -1849,6 +1849,8 @@ impl<'a> Parser<'a> {
18491849
String::from("<identifier>: <type>"),
18501850
Applicability::HasPlaceholders,
18511851
);
1852+
} else if require_name && is_trait_item {
1853+
err.note("anonymous parameters are removed in the 2018 edition (see RFC 1685)");
18521854
}
18531855

18541856
return Err(err);
@@ -1914,7 +1916,7 @@ impl<'a> Parser<'a> {
19141916

19151917
/// Parse a single function argument
19161918
crate fn parse_arg(&mut self) -> PResult<'a, Arg> {
1917-
self.parse_arg_general(true)
1919+
self.parse_arg_general(true, false)
19181920
}
19191921

19201922
/// Parse an argument in a lambda header e.g. |arg, arg|
@@ -5469,7 +5471,7 @@ impl<'a> Parser<'a> {
54695471
}
54705472
}
54715473
} else {
5472-
match p.parse_arg_general(named_args) {
5474+
match p.parse_arg_general(named_args, false) {
54735475
Ok(arg) => Ok(Some(arg)),
54745476
Err(mut e) => {
54755477
e.emit();

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

+4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ error: expected one of `:` or `@`, found `)`
33
|
44
LL | fn foo(i32); //~ expected one of `:` or `@`, found `)`
55
| ^ expected one of `:` or `@` here
6+
|
7+
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
68

79
error: expected one of `:` or `@`, found `,`
810
--> $DIR/anon-params-denied-2018.rs:8:36
911
|
1012
LL | fn bar_with_default_impl(String, String) {}
1113
| ^ expected one of `:` or `@` here
14+
|
15+
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
1216

1317
error: aborting due to 2 previous errors
1418

0 commit comments

Comments
 (0)