-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Detect method not found on arbitrary self type with different mutability #114469
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
Merged
bors
merged 3 commits into
rust-lang:master
from
estebank:arbitrary-self-types-mut-diff
Aug 10, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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`. |
17 changes: 17 additions & 0 deletions
17
tests/ui/self/arbitrary_self_types_needing_box_or_arc_wrapping.fixed
This file contains hidden or 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,17 @@ | ||
// run-rustfix | ||
#![allow(dead_code)] | ||
mod first { | ||
trait Foo { fn m(self: Box<Self>); } | ||
fn foo<T: Foo>(a: T) { | ||
Box::new(a).m(); //~ ERROR no method named `m` found | ||
} | ||
} | ||
mod second { | ||
use std::sync::Arc; | ||
trait Bar { fn m(self: Arc<Self>); } | ||
fn bar(b: impl Bar) { | ||
Arc::new(b).m(); //~ ERROR no method named `m` found | ||
} | ||
} | ||
|
||
fn main() {} |
17 changes: 17 additions & 0 deletions
17
tests/ui/self/arbitrary_self_types_needing_box_or_arc_wrapping.rs
This file contains hidden or 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,17 @@ | ||
// run-rustfix | ||
#![allow(dead_code)] | ||
mod first { | ||
trait Foo { fn m(self: Box<Self>); } | ||
fn foo<T: Foo>(a: T) { | ||
a.m(); //~ ERROR no method named `m` found | ||
} | ||
} | ||
mod second { | ||
use std::sync::Arc; | ||
trait Bar { fn m(self: Arc<Self>); } | ||
fn bar(b: impl Bar) { | ||
b.m(); //~ ERROR no method named `m` found | ||
} | ||
} | ||
|
||
fn main() {} |
43 changes: 43 additions & 0 deletions
43
tests/ui/self/arbitrary_self_types_needing_box_or_arc_wrapping.stderr
This file contains hidden or 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,43 @@ | ||
error[E0599]: no method named `m` found for type parameter `T` in the current scope | ||
--> $DIR/arbitrary_self_types_needing_box_or_arc_wrapping.rs:6:11 | ||
| | ||
LL | trait Foo { fn m(self: Box<Self>); } | ||
| - --------- the method might not be found because of this arbitrary self type | ||
| | | ||
| the method is available for `Box<T>` here | ||
LL | fn foo<T: Foo>(a: T) { | ||
| - method `m` not found for this type parameter | ||
LL | a.m(); | ||
| ^ method not found in `T` | ||
... | ||
LL | trait Bar { fn m(self: Arc<Self>); } | ||
| --------- the method might not be found because of this arbitrary self type | ||
| | ||
help: consider wrapping the receiver expression with the appropriate type | ||
| | ||
LL | Box::new(a).m(); | ||
| +++++++++ + | ||
|
||
error[E0599]: no method named `m` found for type parameter `impl Bar` in the current scope | ||
--> $DIR/arbitrary_self_types_needing_box_or_arc_wrapping.rs:13:11 | ||
| | ||
LL | trait Foo { fn m(self: Box<Self>); } | ||
| --------- the method might not be found because of this arbitrary self type | ||
... | ||
LL | trait Bar { fn m(self: Arc<Self>); } | ||
| - --------- the method might not be found because of this arbitrary self type | ||
| | | ||
| the method is available for `Arc<impl Bar>` here | ||
LL | fn bar(b: impl Bar) { | ||
| -------- method `m` not found for this type parameter | ||
LL | b.m(); | ||
| ^ method not found in `impl Bar` | ||
| | ||
help: consider wrapping the receiver expression with the appropriate type | ||
| | ||
LL | Arc::new(b).m(); | ||
| +++++++++ + | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0599`. |
This file contains hidden or 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,12 @@ | ||
// run-rustfix | ||
use std::pin::Pin; | ||
struct S; | ||
|
||
impl S { | ||
fn x(self: Pin<&mut Self>) { | ||
} | ||
} | ||
|
||
fn main() { | ||
Pin::new(&mut S).x(); //~ ERROR no method named `x` found | ||
} |
This file contains hidden or 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,12 @@ | ||
// run-rustfix | ||
use std::pin::Pin; | ||
struct S; | ||
|
||
impl S { | ||
fn x(self: Pin<&mut Self>) { | ||
} | ||
} | ||
|
||
fn main() { | ||
S.x(); //~ ERROR no method named `x` found | ||
} |
This file contains hidden or 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,20 @@ | ||
error[E0599]: no method named `x` found for struct `S` in the current scope | ||
--> $DIR/arbitrary_self_types_needing_mut_pin.rs:11:7 | ||
| | ||
LL | struct S; | ||
| -------- method `x` not found for this struct | ||
... | ||
LL | fn x(self: Pin<&mut Self>) { | ||
| - the method is available for `Pin<&mut S>` here | ||
... | ||
LL | S.x(); | ||
| ^ method not found in `S` | ||
| | ||
help: consider wrapping the receiver expression with the appropriate type | ||
| | ||
LL | Pin::new(&mut S).x(); | ||
| +++++++++++++ + | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0599`. |
This file contains hidden or 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 @@ | ||
use std::pin::Pin; | ||
struct S; | ||
|
||
impl S { | ||
fn x(self: Pin<&mut Self>) { | ||
} | ||
} | ||
|
||
fn main() { | ||
Pin::new(S).x(); | ||
//~^ ERROR the trait bound `S: Deref` is not satisfied | ||
//~| ERROR no method named `x` found for struct `Pin` in the current scope | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.