about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2020-12-01 00:40:28 -0800
committerEsteban Küber <esteban@kuber.com.ar>2021-01-26 15:59:43 -0800
commit2e846d6f618332ef80e5333f0d7922527373e517 (patch)
tree3c7db937699e1e6eba5f66572a112b157d9fe518
parent7907345e58b4f4d2c95e5ea9b8e0b3bff8946523 (diff)
downloadrust-2e846d6f618332ef80e5333f0d7922527373e517.tar.gz
rust-2e846d6f618332ef80e5333f0d7922527373e517.zip
Point only at generic arguments when they are unexpected
-rw-r--r--compiler/rustc_parse/src/parser/path.rs10
-rw-r--r--src/test/ui/issues/issue-43424.stderr4
-rw-r--r--src/test/ui/span/import-ty-params.rs3
-rw-r--r--src/test/ui/span/import-ty-params.stderr16
-rw-r--r--src/test/ui/span/visibility-ty-params.stderr8
5 files changed, 29 insertions, 12 deletions
diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs
index 4234740b2b1..6b7059eecf4 100644
--- a/compiler/rustc_parse/src/parser/path.rs
+++ b/compiler/rustc_parse/src/parser/path.rs
@@ -133,7 +133,15 @@ impl<'a> Parser<'a> {
         maybe_whole!(self, NtPath, |path| {
             if style == PathStyle::Mod && path.segments.iter().any(|segment| segment.args.is_some())
             {
-                self.struct_span_err(path.span, "unexpected generic arguments in path").emit();
+                self.struct_span_err(
+                    path.segments
+                        .iter()
+                        .filter_map(|segment| segment.args.as_ref())
+                        .map(|arg| arg.span())
+                        .collect::<Vec<_>>(),
+                    "unexpected generic arguments in path",
+                )
+                .emit();
             }
             path
         });
diff --git a/src/test/ui/issues/issue-43424.stderr b/src/test/ui/issues/issue-43424.stderr
index 6274a7928ba..8f59d7cc3aa 100644
--- a/src/test/ui/issues/issue-43424.stderr
+++ b/src/test/ui/issues/issue-43424.stderr
@@ -1,8 +1,8 @@
 error: unexpected generic arguments in path
-  --> $DIR/issue-43424.rs:10:4
+  --> $DIR/issue-43424.rs:10:10
    |
 LL | m!(inline<u8>);
-   |    ^^^^^^^^^^
+   |          ^^^^
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/span/import-ty-params.rs b/src/test/ui/span/import-ty-params.rs
index 850bbd857ff..313cd227b7c 100644
--- a/src/test/ui/span/import-ty-params.rs
+++ b/src/test/ui/span/import-ty-params.rs
@@ -16,5 +16,8 @@ fn f1() {
 fn f2() {
     import! { a::b::c::S<> } //~ ERROR unexpected generic arguments in path
 }
+fn f3() {
+    import! { a::b<>::c<u8>::S<> } //~ ERROR unexpected generic arguments in path
+}
 
 fn main() {}
diff --git a/src/test/ui/span/import-ty-params.stderr b/src/test/ui/span/import-ty-params.stderr
index a02a1edc134..701cd0c04bd 100644
--- a/src/test/ui/span/import-ty-params.stderr
+++ b/src/test/ui/span/import-ty-params.stderr
@@ -1,14 +1,20 @@
 error: unexpected generic arguments in path
-  --> $DIR/import-ty-params.rs:14:15
+  --> $DIR/import-ty-params.rs:14:25
    |
 LL |     import! { a::b::c::S<u8> }
-   |               ^^^^^^^^^^^^^^
+   |                         ^^^^
 
 error: unexpected generic arguments in path
-  --> $DIR/import-ty-params.rs:17:15
+  --> $DIR/import-ty-params.rs:17:25
    |
 LL |     import! { a::b::c::S<> }
-   |               ^^^^^^^^^^^^
+   |                         ^^
 
-error: aborting due to 2 previous errors
+error: unexpected generic arguments in path
+  --> $DIR/import-ty-params.rs:20:19
+   |
+LL |     import! { a::b<>::c<u8>::S<> }
+   |                   ^^   ^^^^   ^^
+
+error: aborting due to 3 previous errors
 
diff --git a/src/test/ui/span/visibility-ty-params.stderr b/src/test/ui/span/visibility-ty-params.stderr
index d3fa1d7732e..067893fd22d 100644
--- a/src/test/ui/span/visibility-ty-params.stderr
+++ b/src/test/ui/span/visibility-ty-params.stderr
@@ -1,8 +1,8 @@
 error: unexpected generic arguments in path
-  --> $DIR/visibility-ty-params.rs:6:5
+  --> $DIR/visibility-ty-params.rs:6:6
    |
 LL | m!{ S<u8> }
-   |     ^^^^^
+   |      ^^^^
 
 error[E0577]: expected module, found struct `S`
   --> $DIR/visibility-ty-params.rs:6:5
@@ -11,10 +11,10 @@ LL | m!{ S<u8> }
    |     ^^^^^ not a module
 
 error: unexpected generic arguments in path
-  --> $DIR/visibility-ty-params.rs:10:9
+  --> $DIR/visibility-ty-params.rs:10:10
    |
 LL |     m!{ m<> }
-   |         ^^^
+   |          ^^
 
 error: aborting due to 3 previous errors