-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct the arg for 'suggest to use associated function syntax' …
…diagnostic
- Loading branch information
1 parent
c9c760f
commit e4cfe03
Showing
4 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// run-rustfix | ||
|
||
struct A {} | ||
|
||
impl A { | ||
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 | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// run-rustfix | ||
|
||
struct A {} | ||
|
||
impl A { | ||
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 | ||
} |
41 changes: 41 additions & 0 deletions
41
tests/ui/suggestions/suggest-assoc-fn-call-without-receiver.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
error[E0599]: no method named `hello` found for struct `A` in the current scope | ||
--> $DIR/suggest-assoc-fn-call-without-receiver.rs:12:8 | ||
| | ||
LL | struct A {} | ||
| -------- method `hello` not found for this struct | ||
... | ||
LL | _a.hello(1); | ||
| ---^^^^^--- | ||
| | | | ||
| | this is an associated function, not a method | ||
| help: use associated function syntax instead: `A::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 `A` | ||
--> $DIR/suggest-assoc-fn-call-without-receiver.rs:6:5 | ||
| | ||
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 | ||
| | ||
LL | struct A {} | ||
| -------- method `test` not found for this struct | ||
... | ||
LL | _a.test(1); | ||
| ---^^^^--- | ||
| | | | ||
| | this is an associated function, not a method | ||
| help: use associated function syntax instead: `A::test(_a, 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 `A` | ||
--> $DIR/suggest-assoc-fn-call-without-receiver.rs:7:5 | ||
| | ||
LL | fn test(_a: Self, _b: i32) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0599`. |