]> git.lizzy.rs Git - rust.git/commitdiff
Add context for RFC 1685 change in 2018 edition.
authorDavid Wood <david@davidtw.co>
Fri, 7 Dec 2018 09:54:14 +0000 (10:54 +0100)
committerDavid Wood <david@davidtw.co>
Fri, 7 Dec 2018 10:56:56 +0000 (11:56 +0100)
This commit adds a note providing context for the change to argument
names being required in the 2018 edition for trait methods.

src/libsyntax/parse/parser.rs
src/test/ui/anon-params-denied-2018.stderr

index c7eaf4d1eeeb7af8d3f3281d2cd5414329e013e5..af63314b154476d799367983806d305028d8552b 100644 (file)
@@ -1404,7 +1404,7 @@ fn parse_trait_item_(&mut self,
                 // definition...
 
                 // We don't allow argument names to be left off in edition 2018.
-                p.parse_arg_general(p.span.rust_2018())
+                p.parse_arg_general(p.span.rust_2018(), true)
             })?;
             generics.where_clause = self.parse_where_clause()?;
 
@@ -1817,7 +1817,7 @@ fn eat_incorrect_doc_comment(&mut self, applied_to: &str) {
 
     /// This version of parse arg doesn't necessarily require
     /// identifier names.
-    fn parse_arg_general(&mut self, require_name: bool) -> PResult<'a, Arg> {
+    fn parse_arg_general(&mut self, require_name: bool, is_trait_item: bool) -> PResult<'a, Arg> {
         maybe_whole!(self, NtArg, |x| x);
 
         if let Ok(Some(_)) = self.parse_self_arg() {
@@ -1849,6 +1849,8 @@ fn parse_arg_general(&mut self, require_name: bool) -> PResult<'a, Arg> {
                         String::from("<identifier>: <type>"),
                         Applicability::HasPlaceholders,
                     );
+                } else if require_name && is_trait_item {
+                    err.note("anonymous parameters are removed in the 2018 edition (see RFC 1685)");
                 }
 
                 return Err(err);
@@ -1914,7 +1916,7 @@ fn parse_arg_general(&mut self, require_name: bool) -> PResult<'a, Arg> {
 
     /// Parse a single function argument
     crate fn parse_arg(&mut self) -> PResult<'a, Arg> {
-        self.parse_arg_general(true)
+        self.parse_arg_general(true, false)
     }
 
     /// Parse an argument in a lambda header e.g. |arg, arg|
@@ -5469,7 +5471,7 @@ fn parse_fn_args(&mut self, named_args: bool, allow_variadic: bool)
                             }
                         }
                     } else {
-                        match p.parse_arg_general(named_args) {
+                        match p.parse_arg_general(named_args, false) {
                             Ok(arg) => Ok(Some(arg)),
                             Err(mut e) => {
                                 e.emit();
index 24a1e6ecd932c75dbb940187a96f45b04a5487de..e1aa65981f6fd8db10d23971a8b22a8d4203fc12 100644 (file)
@@ -3,12 +3,16 @@ error: expected one of `:` or `@`, found `)`
    |
 LL |     fn foo(i32); //~ expected one of `:` or `@`, found `)`
    |               ^ expected one of `:` or `@` here
+   |
+   = 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
+   |
+   = note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
 
 error: aborting due to 2 previous errors