-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect method not found on arbitrary self type with different mutability
``` error[E0599]: no method named `x` found for struct `Pin<&S>` in the current scope --> $DIR/arbitrary_self_type_mut_difference.rs:11:18 | LL | Pin::new(&S).x(); | ^ help: there is a method with a similar name: `y` | note: method is available for `Pin<&mut S>` --> $DIR/arbitrary_self_type_mut_difference.rs:6:5 | LL | fn x(self: Pin<&mut Self>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` Related to #57994, as one of the presented cases can lead to code like this.
- Loading branch information
Showing
4 changed files
with
77 additions
and
10 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
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
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,13 @@ | ||
// Related to #57994. | ||
use std::pin::Pin; | ||
struct S; | ||
|
||
impl S { | ||
fn x(self: Pin<&mut Self>) {} //~ NOTE method is available for `Pin<&mut S>` | ||
fn y(self: Pin<&Self>) {} //~ NOTE method is available for `Pin<&S>` | ||
} | ||
|
||
fn main() { | ||
Pin::new(&S).x(); //~ ERROR no method named `x` found for struct `Pin<&S>` in the current scope | ||
Pin::new(&mut S).y(); //~ ERROR no method named `y` found for struct `Pin<&mut S>` in the current scope | ||
} |
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,27 @@ | ||
error[E0599]: no method named `x` found for struct `Pin<&S>` in the current scope | ||
--> $DIR/arbitrary_self_type_mut_difference.rs:11:18 | ||
| | ||
LL | Pin::new(&S).x(); | ||
| ^ help: there is a method with a similar name: `y` | ||
| | ||
note: method is available for `Pin<&mut S>` | ||
--> $DIR/arbitrary_self_type_mut_difference.rs:6:5 | ||
| | ||
LL | fn x(self: Pin<&mut Self>) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0599]: no method named `y` found for struct `Pin<&mut S>` in the current scope | ||
--> $DIR/arbitrary_self_type_mut_difference.rs:12:22 | ||
| | ||
LL | Pin::new(&mut S).y(); | ||
| ^ help: there is a method with a similar name: `x` | ||
| | ||
note: method is available for `Pin<&S>` | ||
--> $DIR/arbitrary_self_type_mut_difference.rs:7:5 | ||
| | ||
LL | fn y(self: Pin<&Self>) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0599`. |