about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2023-12-09 18:00:37 +0100
committerGitHub <noreply@github.com>2023-12-09 18:00:37 +0100
commit034d73d6d7b1cbc654fea336ccc3e4170f7af043 (patch)
tree25bbd5d4301e8714f5b72e73ea78ed88b2db72cf
parent5b9e917b64307c6fcc71ee5a74c8182144a58913 (diff)
parentcb6984217f12acd1da6eb7f244effe2c9f9f11f8 (diff)
downloadrust-034d73d6d7b1cbc654fea336ccc3e4170f7af043.tar.gz
rust-034d73d6d7b1cbc654fea336ccc3e4170f7af043.zip
Rollup merge of #118775 - Young-Flash:fix, r=compiler-errors
chore: add test case for type with generic

follow up https://github.com/rust-lang/rust/pull/118502
-rw-r--r--tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.fixed14
-rw-r--r--tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.rs14
-rw-r--r--tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.stderr44
3 files changed, 69 insertions, 3 deletions
diff --git a/tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.fixed b/tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.fixed
index 6e679134d63..61f06d802b6 100644
--- a/tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.fixed
+++ b/tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.fixed
@@ -7,10 +7,24 @@ impl A {
     fn test(_a: Self, _b: i32) {}
 }
 
+struct B<T> {
+    _b: T
+}
+impl<T> B<T> {
+    fn hello(_a: i32) {}
+    fn test(_a: Self, _b: i32) {}
+}
+
 fn main() {
     let _a = A {};
     A::hello(1);
     //~^ ERROR no method named `hello` found
     A::test(_a, 1);
     //~^ ERROR no method named `test` found
+
+    let _b = B {_b: ""};
+    B::<&str>::hello(1);
+    //~^ ERROR no method named `hello` found
+    B::<&str>::test(_b, 1);
+    //~^ ERROR no method named `test` found
 }
diff --git a/tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.rs b/tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.rs
index 67c2cc1bed5..07e614f0c15 100644
--- a/tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.rs
+++ b/tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.rs
@@ -7,10 +7,24 @@ impl A {
     fn test(_a: Self, _b: i32) {}
 }
 
+struct B<T> {
+    _b: T
+}
+impl<T> B<T> {
+    fn hello(_a: i32) {}
+    fn test(_a: Self, _b: i32) {}
+}
+
 fn main() {
     let _a = A {};
     _a.hello(1);
     //~^ ERROR no method named `hello` found
     _a.test(1);
     //~^ ERROR no method named `test` found
+
+    let _b = B {_b: ""};
+    _b.hello(1);
+    //~^ ERROR no method named `hello` found
+    _b.test(1);
+    //~^ ERROR no method named `test` found
 }
diff --git a/tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.stderr b/tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.stderr
index ed227cbab39..793595784d9 100644
--- a/tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.stderr
+++ b/tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.stderr
@@ -1,5 +1,5 @@
 error[E0599]: no method named `hello` found for struct `A` in the current scope
-  --> $DIR/suggest-assoc-fn-call-without-receiver.rs:12:8
+  --> $DIR/suggest-assoc-fn-call-without-receiver.rs:20:8
    |
 LL | struct A {}
    | -------- method `hello` not found for this struct
@@ -18,7 +18,7 @@ LL |     fn hello(_a: i32) {}
    |     ^^^^^^^^^^^^^^^^^
 
 error[E0599]: no method named `test` found for struct `A` in the current scope
-  --> $DIR/suggest-assoc-fn-call-without-receiver.rs:14:8
+  --> $DIR/suggest-assoc-fn-call-without-receiver.rs:22:8
    |
 LL | struct A {}
    | -------- method `test` not found for this struct
@@ -36,6 +36,44 @@ note: the candidate is defined in an impl for the type `A`
 LL |     fn test(_a: Self, _b: i32) {}
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to 2 previous errors
+error[E0599]: no method named `hello` found for struct `B<&str>` in the current scope
+  --> $DIR/suggest-assoc-fn-call-without-receiver.rs:26:8
+   |
+LL | struct B<T> {
+   | ----------- method `hello` not found for this struct
+...
+LL |     _b.hello(1);
+   |     ---^^^^^---
+   |     |  |
+   |     |  this is an associated function, not a method
+   |     help: use associated function syntax instead: `B::<&str>::hello(1)`
+   |
+   = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
+note: the candidate is defined in an impl for the type `B<T>`
+  --> $DIR/suggest-assoc-fn-call-without-receiver.rs:14:5
+   |
+LL |     fn hello(_a: i32) {}
+   |     ^^^^^^^^^^^^^^^^^
+
+error[E0599]: no method named `test` found for struct `B<&str>` in the current scope
+  --> $DIR/suggest-assoc-fn-call-without-receiver.rs:28:8
+   |
+LL | struct B<T> {
+   | ----------- method `test` not found for this struct
+...
+LL |     _b.test(1);
+   |     ---^^^^---
+   |     |  |
+   |     |  this is an associated function, not a method
+   |     help: use associated function syntax instead: `B::<&str>::test(_b, 1)`
+   |
+   = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
+note: the candidate is defined in an impl for the type `B<T>`
+  --> $DIR/suggest-assoc-fn-call-without-receiver.rs:15:5
+   |
+LL |     fn test(_a: Self, _b: i32) {}
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0599`.