Skip to content

Commit 742c972

Browse files
committed
Auto merge of #79591 - estebank:unexpected-generics, r=oli-obk
Point only at generic arguments when they are unexpected
2 parents 78e2206 + 2e846d6 commit 742c972

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

compiler/rustc_parse/src/parser/path.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,15 @@ impl<'a> Parser<'a> {
133133
maybe_whole!(self, NtPath, |path| {
134134
if style == PathStyle::Mod && path.segments.iter().any(|segment| segment.args.is_some())
135135
{
136-
self.struct_span_err(path.span, "unexpected generic arguments in path").emit();
136+
self.struct_span_err(
137+
path.segments
138+
.iter()
139+
.filter_map(|segment| segment.args.as_ref())
140+
.map(|arg| arg.span())
141+
.collect::<Vec<_>>(),
142+
"unexpected generic arguments in path",
143+
)
144+
.emit();
137145
}
138146
path
139147
});

src/test/ui/issues/issue-43424.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: unexpected generic arguments in path
2-
--> $DIR/issue-43424.rs:10:4
2+
--> $DIR/issue-43424.rs:10:10
33
|
44
LL | m!(inline<u8>);
5-
| ^^^^^^^^^^
5+
| ^^^^
66

77
error: aborting due to previous error
88

src/test/ui/span/import-ty-params.rs

+3
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@ fn f1() {
1616
fn f2() {
1717
import! { a::b::c::S<> } //~ ERROR unexpected generic arguments in path
1818
}
19+
fn f3() {
20+
import! { a::b<>::c<u8>::S<> } //~ ERROR unexpected generic arguments in path
21+
}
1922

2023
fn main() {}
+11-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
error: unexpected generic arguments in path
2-
--> $DIR/import-ty-params.rs:14:15
2+
--> $DIR/import-ty-params.rs:14:25
33
|
44
LL | import! { a::b::c::S<u8> }
5-
| ^^^^^^^^^^^^^^
5+
| ^^^^
66

77
error: unexpected generic arguments in path
8-
--> $DIR/import-ty-params.rs:17:15
8+
--> $DIR/import-ty-params.rs:17:25
99
|
1010
LL | import! { a::b::c::S<> }
11-
| ^^^^^^^^^^^^
11+
| ^^
1212

13-
error: aborting due to 2 previous errors
13+
error: unexpected generic arguments in path
14+
--> $DIR/import-ty-params.rs:20:19
15+
|
16+
LL | import! { a::b<>::c<u8>::S<> }
17+
| ^^ ^^^^ ^^
18+
19+
error: aborting due to 3 previous errors
1420

src/test/ui/span/visibility-ty-params.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: unexpected generic arguments in path
2-
--> $DIR/visibility-ty-params.rs:6:5
2+
--> $DIR/visibility-ty-params.rs:6:6
33
|
44
LL | m!{ S<u8> }
5-
| ^^^^^
5+
| ^^^^
66

77
error[E0577]: expected module, found struct `S`
88
--> $DIR/visibility-ty-params.rs:6:5
@@ -11,10 +11,10 @@ LL | m!{ S<u8> }
1111
| ^^^^^ not a module
1212

1313
error: unexpected generic arguments in path
14-
--> $DIR/visibility-ty-params.rs:10:9
14+
--> $DIR/visibility-ty-params.rs:10:10
1515
|
1616
LL | m!{ m<> }
17-
| ^^^
17+
| ^^
1818

1919
error: aborting due to 3 previous errors
2020

0 commit comments

Comments
 (0)