about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorHirochika Matsumoto <git@hkmatsumoto.com>2022-08-21 16:59:09 +0900
committerHirochika Matsumoto <git@hkmatsumoto.com>2022-08-21 17:00:18 +0900
commitbafa89bc467a2b5862c409fc6cae9c01fdf25c6e (patch)
treedeba6f9b635573d2a038632865920866e509a38b /src/test/ui
parent908fc5b26d15fc96d630ab921e70b2db77a532c4 (diff)
downloadrust-bafa89bc467a2b5862c409fc6cae9c01fdf25c6e.tar.gz
rust-bafa89bc467a2b5862c409fc6cae9c01fdf25c6e.zip
Suggest moving redundant generic args of an assoc fn to its trait
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/suggestions/issue-89064.rs32
-rw-r--r--src/test/ui/suggestions/issue-89064.stderr69
2 files changed, 101 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/issue-89064.rs b/src/test/ui/suggestions/issue-89064.rs
new file mode 100644
index 00000000000..c0fcad4236e
--- /dev/null
+++ b/src/test/ui/suggestions/issue-89064.rs
@@ -0,0 +1,32 @@
+use std::convert::TryInto;
+
+trait A<T> {
+    fn foo() {}
+}
+
+trait B<T, U> {
+    fn bar() {}
+}
+
+struct S;
+
+impl<T> A<T> for S {}
+impl<T, U> B<T, U> for S {}
+
+fn main() {
+    let _ = A::foo::<S>();
+    //~^ ERROR
+    //~| HELP remove these generics
+    //~| HELP consider moving this generic argument
+
+    let _ = B::bar::<S, S>();
+    //~^ ERROR
+    //~| HELP remove these generics
+    //~| HELP consider moving these generic arguments
+
+    // bad suggestion
+    let _ = A::<S>::foo::<S>();
+    //~^ ERROR
+    //~| HELP remove these generics
+    //~| HELP consider moving this generic argument
+}
diff --git a/src/test/ui/suggestions/issue-89064.stderr b/src/test/ui/suggestions/issue-89064.stderr
new file mode 100644
index 00000000000..11d652b4c60
--- /dev/null
+++ b/src/test/ui/suggestions/issue-89064.stderr
@@ -0,0 +1,69 @@
+error[E0107]: this associated function takes 0 generic arguments but 1 generic argument was supplied
+  --> $DIR/issue-89064.rs:17:16
+   |
+LL |     let _ = A::foo::<S>();
+   |                ^^^ expected 0 generic arguments
+   |
+note: associated function defined here, with 0 generic parameters
+  --> $DIR/issue-89064.rs:4:8
+   |
+LL |     fn foo() {}
+   |        ^^^
+help: remove these generics
+   |
+LL -     let _ = A::foo::<S>();
+LL +     let _ = A::foo();
+   |
+help: consider moving this generic argument to the `A` trait, which takes up to 1 argument
+   |
+LL -     let _ = A::foo::<S>();
+LL +     let _ = A::<S>::foo();
+   |
+
+error[E0107]: this associated function takes 0 generic arguments but 2 generic arguments were supplied
+  --> $DIR/issue-89064.rs:22:16
+   |
+LL |     let _ = B::bar::<S, S>();
+   |                ^^^ expected 0 generic arguments
+   |
+note: associated function defined here, with 0 generic parameters
+  --> $DIR/issue-89064.rs:8:8
+   |
+LL |     fn bar() {}
+   |        ^^^
+help: remove these generics
+   |
+LL -     let _ = B::bar::<S, S>();
+LL +     let _ = B::bar();
+   |
+help: consider moving these generic arguments to the `B` trait, which takes up to 2 arguments
+   |
+LL -     let _ = B::bar::<S, S>();
+LL +     let _ = B::<S, S>::bar();
+   |
+
+error[E0107]: this associated function takes 0 generic arguments but 1 generic argument was supplied
+  --> $DIR/issue-89064.rs:28:21
+   |
+LL |     let _ = A::<S>::foo::<S>();
+   |                     ^^^ expected 0 generic arguments
+   |
+note: associated function defined here, with 0 generic parameters
+  --> $DIR/issue-89064.rs:4:8
+   |
+LL |     fn foo() {}
+   |        ^^^
+help: remove these generics
+   |
+LL -     let _ = A::<S>::foo::<S>();
+LL +     let _ = A::<S>::foo();
+   |
+help: consider moving this generic argument to the `A` trait, which takes up to 1 argument
+   |
+LL -     let _ = A::<S>::foo::<S>();
+LL +     let _ = A::<S>::<S>::foo();
+   |
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0107`.