Skip to content

Commit cb69842

Browse files
committed
chore: add test case for type with generic
1 parent e4cfe03 commit cb69842

3 files changed

+69
-3
lines changed

tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.fixed

+14
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,24 @@ impl A {
77
fn test(_a: Self, _b: i32) {}
88
}
99

10+
struct B<T> {
11+
_b: T
12+
}
13+
impl<T> B<T> {
14+
fn hello(_a: i32) {}
15+
fn test(_a: Self, _b: i32) {}
16+
}
17+
1018
fn main() {
1119
let _a = A {};
1220
A::hello(1);
1321
//~^ ERROR no method named `hello` found
1422
A::test(_a, 1);
1523
//~^ ERROR no method named `test` found
24+
25+
let _b = B {_b: ""};
26+
B::<&str>::hello(1);
27+
//~^ ERROR no method named `hello` found
28+
B::<&str>::test(_b, 1);
29+
//~^ ERROR no method named `test` found
1630
}

tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.rs

+14
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,24 @@ impl A {
77
fn test(_a: Self, _b: i32) {}
88
}
99

10+
struct B<T> {
11+
_b: T
12+
}
13+
impl<T> B<T> {
14+
fn hello(_a: i32) {}
15+
fn test(_a: Self, _b: i32) {}
16+
}
17+
1018
fn main() {
1119
let _a = A {};
1220
_a.hello(1);
1321
//~^ ERROR no method named `hello` found
1422
_a.test(1);
1523
//~^ ERROR no method named `test` found
24+
25+
let _b = B {_b: ""};
26+
_b.hello(1);
27+
//~^ ERROR no method named `hello` found
28+
_b.test(1);
29+
//~^ ERROR no method named `test` found
1630
}

tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.stderr

+41-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0599]: no method named `hello` found for struct `A` in the current scope
2-
--> $DIR/suggest-assoc-fn-call-without-receiver.rs:12:8
2+
--> $DIR/suggest-assoc-fn-call-without-receiver.rs:20:8
33
|
44
LL | struct A {}
55
| -------- method `hello` not found for this struct
@@ -18,7 +18,7 @@ LL | fn hello(_a: i32) {}
1818
| ^^^^^^^^^^^^^^^^^
1919

2020
error[E0599]: no method named `test` found for struct `A` in the current scope
21-
--> $DIR/suggest-assoc-fn-call-without-receiver.rs:14:8
21+
--> $DIR/suggest-assoc-fn-call-without-receiver.rs:22:8
2222
|
2323
LL | struct A {}
2424
| -------- method `test` not found for this struct
@@ -36,6 +36,44 @@ note: the candidate is defined in an impl for the type `A`
3636
LL | fn test(_a: Self, _b: i32) {}
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
3838

39-
error: aborting due to 2 previous errors
39+
error[E0599]: no method named `hello` found for struct `B<&str>` in the current scope
40+
--> $DIR/suggest-assoc-fn-call-without-receiver.rs:26:8
41+
|
42+
LL | struct B<T> {
43+
| ----------- method `hello` not found for this struct
44+
...
45+
LL | _b.hello(1);
46+
| ---^^^^^---
47+
| | |
48+
| | this is an associated function, not a method
49+
| help: use associated function syntax instead: `B::<&str>::hello(1)`
50+
|
51+
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
52+
note: the candidate is defined in an impl for the type `B<T>`
53+
--> $DIR/suggest-assoc-fn-call-without-receiver.rs:14:5
54+
|
55+
LL | fn hello(_a: i32) {}
56+
| ^^^^^^^^^^^^^^^^^
57+
58+
error[E0599]: no method named `test` found for struct `B<&str>` in the current scope
59+
--> $DIR/suggest-assoc-fn-call-without-receiver.rs:28:8
60+
|
61+
LL | struct B<T> {
62+
| ----------- method `test` not found for this struct
63+
...
64+
LL | _b.test(1);
65+
| ---^^^^---
66+
| | |
67+
| | this is an associated function, not a method
68+
| help: use associated function syntax instead: `B::<&str>::test(_b, 1)`
69+
|
70+
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
71+
note: the candidate is defined in an impl for the type `B<T>`
72+
--> $DIR/suggest-assoc-fn-call-without-receiver.rs:15:5
73+
|
74+
LL | fn test(_a: Self, _b: i32) {}
75+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
76+
77+
error: aborting due to 4 previous errors
4078

4179
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)