Skip to content

Commit 8240f1a

Browse files
committed
Fix bad diagnostics for anon params with qualified paths
1 parent ea355bc commit 8240f1a

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -1627,18 +1627,28 @@ impl<'a> Parser<'a> {
16271627
),
16281628
// Also catches `fn foo(&a)`.
16291629
PatKind::Ref(ref pat, mutab) => {
1630-
if let PatKind::Ident(_, ident, _) = pat.clone().into_inner().kind {
1631-
let mutab = mutab.prefix_str();
1632-
(
1633-
ident,
1634-
format!("self: &{}{}", mutab, ident),
1635-
format!("{}: &{}TypeName", ident, mutab),
1636-
format!("_: &{}{}", mutab, ident),
1637-
)
1638-
} else {
1639-
return None;
1630+
match pat.clone().into_inner().kind {
1631+
PatKind::Ident(_, ident, _) => {
1632+
let mutab = mutab.prefix_str();
1633+
(
1634+
ident,
1635+
format!("self: &{}{}", mutab, ident),
1636+
format!("{}: &{}TypeName", ident, mutab),
1637+
format!("_: &{}{}", mutab, ident),
1638+
)
1639+
}
1640+
PatKind::Path(..) => {
1641+
err.note("anonymous parameters are removed in the 2018 edition (see RFC 1685)");
1642+
return None;
1643+
}
1644+
_ => return None,
16401645
}
16411646
}
1647+
// Also catches `fn foo(<Bar as T>::Baz)`
1648+
PatKind::Path(..) => {
1649+
err.note("anonymous parameters are removed in the 2018 edition (see RFC 1685)");
1650+
return None;
1651+
}
16421652
// Ignore other `PatKind`.
16431653
_ => return None,
16441654
};

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

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ trait T {
99
fn foo_with_ref(&mut i32);
1010
//~^ ERROR expected one of `:`, `@`, or `|`, found `)`
1111

12+
fn foo_with_qualified_path(<Bar as T>::Baz);
13+
//~^ ERROR expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)`
14+
15+
fn foo_with_qualified_path_and_ref(&<Bar as T>::Baz);
16+
//~^ ERROR expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)`
17+
1218
fn bar_with_default_impl(String, String) {}
1319
//~^ ERROR expected one of `:`
1420
//~| ERROR expected one of `:`

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

+20-4
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,24 @@ help: if this is a type, explicitly ignore the parameter name
3838
LL | fn foo_with_ref(_: &mut i32);
3939
| ^^^^^^^^^^^
4040

41+
error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)`
42+
--> $DIR/anon-params-denied-2018.rs:12:47
43+
|
44+
LL | fn foo_with_qualified_path(<Bar as T>::Baz);
45+
| ^ expected one of 8 possible tokens
46+
|
47+
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
48+
49+
error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)`
50+
--> $DIR/anon-params-denied-2018.rs:15:56
51+
|
52+
LL | fn foo_with_qualified_path_and_ref(&<Bar as T>::Baz);
53+
| ^ expected one of 8 possible tokens
54+
|
55+
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
56+
4157
error: expected one of `:`, `@`, or `|`, found `,`
42-
--> $DIR/anon-params-denied-2018.rs:12:36
58+
--> $DIR/anon-params-denied-2018.rs:18:36
4359
|
4460
LL | fn bar_with_default_impl(String, String) {}
4561
| ^ expected one of `:`, `@`, or `|`
@@ -59,7 +75,7 @@ LL | fn bar_with_default_impl(_: String, String) {}
5975
| ^^^^^^^^^
6076

6177
error: expected one of `:`, `@`, or `|`, found `)`
62-
--> $DIR/anon-params-denied-2018.rs:12:44
78+
--> $DIR/anon-params-denied-2018.rs:18:44
6379
|
6480
LL | fn bar_with_default_impl(String, String) {}
6581
| ^ expected one of `:`, `@`, or `|`
@@ -75,7 +91,7 @@ LL | fn bar_with_default_impl(String, _: String) {}
7591
| ^^^^^^^^^
7692

7793
error: expected one of `:`, `@`, or `|`, found `,`
78-
--> $DIR/anon-params-denied-2018.rs:17:22
94+
--> $DIR/anon-params-denied-2018.rs:23:22
7995
|
8096
LL | fn baz(a:usize, b, c: usize) -> usize {
8197
| ^ expected one of `:`, `@`, or `|`
@@ -90,5 +106,5 @@ help: if this is a type, explicitly ignore the parameter name
90106
LL | fn baz(a:usize, _: b, c: usize) -> usize {
91107
| ^^^^
92108

93-
error: aborting due to 5 previous errors
109+
error: aborting due to 7 previous errors
94110

0 commit comments

Comments
 (0)