Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add test case for type with generic #118775

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
14 changes: 14 additions & 0 deletions tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
44 changes: 41 additions & 3 deletions tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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`.