diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2021-03-05 14:52:45 +0900 |
|---|---|---|
| committer | Yuki Okushi <huyuumi.dev@gmail.com> | 2021-03-17 07:45:19 +0900 |
| commit | 8240f1a3d3f0ff3e36c19836ea4d783f29752b0b (patch) | |
| tree | b08b0815612310d8db30a3e6cf48fe7a6565e521 | |
| parent | ea355bc6be34f7c3c1da0342ade39593a7f5e494 (diff) | |
| download | rust-8240f1a3d3f0ff3e36c19836ea4d783f29752b0b.tar.gz rust-8240f1a3d3f0ff3e36c19836ea4d783f29752b0b.zip | |
Fix bad diagnostics for anon params with qualified paths
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 30 | ||||
| -rw-r--r-- | src/test/ui/anon-params/anon-params-denied-2018.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/anon-params/anon-params-denied-2018.stderr | 24 |
3 files changed, 46 insertions, 14 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index f214b11d5f0..975b9cc15bd 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1627,18 +1627,28 @@ impl<'a> Parser<'a> { ), // Also catches `fn foo(&a)`. PatKind::Ref(ref pat, mutab) => { - if let PatKind::Ident(_, ident, _) = pat.clone().into_inner().kind { - let mutab = mutab.prefix_str(); - ( - ident, - format!("self: &{}{}", mutab, ident), - format!("{}: &{}TypeName", ident, mutab), - format!("_: &{}{}", mutab, ident), - ) - } else { - return None; + match pat.clone().into_inner().kind { + PatKind::Ident(_, ident, _) => { + let mutab = mutab.prefix_str(); + ( + ident, + format!("self: &{}{}", mutab, ident), + format!("{}: &{}TypeName", ident, mutab), + format!("_: &{}{}", mutab, ident), + ) + } + PatKind::Path(..) => { + err.note("anonymous parameters are removed in the 2018 edition (see RFC 1685)"); + return None; + } + _ => return None, } } + // Also catches `fn foo(<Bar as T>::Baz)` + PatKind::Path(..) => { + err.note("anonymous parameters are removed in the 2018 edition (see RFC 1685)"); + return None; + } // Ignore other `PatKind`. _ => return None, }; diff --git a/src/test/ui/anon-params/anon-params-denied-2018.rs b/src/test/ui/anon-params/anon-params-denied-2018.rs index a7dfdc83732..5487d5c9b03 100644 --- a/src/test/ui/anon-params/anon-params-denied-2018.rs +++ b/src/test/ui/anon-params/anon-params-denied-2018.rs @@ -9,6 +9,12 @@ trait T { fn foo_with_ref(&mut i32); //~^ ERROR expected one of `:`, `@`, or `|`, found `)` + fn foo_with_qualified_path(<Bar as T>::Baz); + //~^ ERROR expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)` + + fn foo_with_qualified_path_and_ref(&<Bar as T>::Baz); + //~^ ERROR expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)` + fn bar_with_default_impl(String, String) {} //~^ ERROR expected one of `:` //~| ERROR expected one of `:` diff --git a/src/test/ui/anon-params/anon-params-denied-2018.stderr b/src/test/ui/anon-params/anon-params-denied-2018.stderr index 0efb7d424e6..f57578f0174 100644 --- a/src/test/ui/anon-params/anon-params-denied-2018.stderr +++ b/src/test/ui/anon-params/anon-params-denied-2018.stderr @@ -38,8 +38,24 @@ help: if this is a type, explicitly ignore the parameter name LL | fn foo_with_ref(_: &mut i32); | ^^^^^^^^^^^ +error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)` + --> $DIR/anon-params-denied-2018.rs:12:47 + | +LL | fn foo_with_qualified_path(<Bar as T>::Baz); + | ^ expected one of 8 possible tokens + | + = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) + +error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)` + --> $DIR/anon-params-denied-2018.rs:15:56 + | +LL | fn foo_with_qualified_path_and_ref(&<Bar as T>::Baz); + | ^ expected one of 8 possible tokens + | + = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) + error: expected one of `:`, `@`, or `|`, found `,` - --> $DIR/anon-params-denied-2018.rs:12:36 + --> $DIR/anon-params-denied-2018.rs:18:36 | LL | fn bar_with_default_impl(String, String) {} | ^ expected one of `:`, `@`, or `|` @@ -59,7 +75,7 @@ LL | fn bar_with_default_impl(_: String, String) {} | ^^^^^^^^^ error: expected one of `:`, `@`, or `|`, found `)` - --> $DIR/anon-params-denied-2018.rs:12:44 + --> $DIR/anon-params-denied-2018.rs:18:44 | LL | fn bar_with_default_impl(String, String) {} | ^ expected one of `:`, `@`, or `|` @@ -75,7 +91,7 @@ LL | fn bar_with_default_impl(String, _: String) {} | ^^^^^^^^^ error: expected one of `:`, `@`, or `|`, found `,` - --> $DIR/anon-params-denied-2018.rs:17:22 + --> $DIR/anon-params-denied-2018.rs:23:22 | LL | fn baz(a:usize, b, c: usize) -> usize { | ^ expected one of `:`, `@`, or `|` @@ -90,5 +106,5 @@ help: if this is a type, explicitly ignore the parameter name LL | fn baz(a:usize, _: b, c: usize) -> usize { | ^^^^ -error: aborting due to 5 previous errors +error: aborting due to 7 previous errors |
