forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#134264 - adetaylor:weak-and-nonnull, r=compiler-errors Arbitrary self types v2: Weak & NonNull diagnostics This builds on top of rust-lang#134262 which is more urgent to review and merge first. I'll likely rebase this PR once that lands. This is the first part of the diagnostic enhancements planned for Arbitrary Self Types v2. Various types can be used as method receivers, such as `Rc<>`, `Box<>` and `Arc<>`. The arbitrary self types v2 work allows further types to be made method receivers by implementing the Receiver trait. With that in mind, it may come as a surprise to people when certain common types do not implement Receiver and thus cannot be used as a method receiver. The RFC for arbitrary self types v2 therefore proposes emitting specific lint hints for these cases: * `NonNull` * `Weak` * Raw pointers The code already emits a hint for this third case, in that it advises folks that the `arbitrary_self_types_pointers` feature may meet their need. This PR adds diagnostic hints for the `Weak` and `NonNull` cases. Tracking issue rust-lang#44874 r? `@wesleywiser`
- Loading branch information
Showing
7 changed files
with
101 additions
and
1 deletion.
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
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 @@ | ||
#![feature(arbitrary_self_types)] | ||
|
||
struct A; | ||
|
||
impl A { | ||
fn m(self: std::ptr::NonNull<Self>) {} | ||
//~^ ERROR: invalid `self` parameter type | ||
fn n(self: &std::ptr::NonNull<Self>) {} | ||
//~^ ERROR: invalid `self` parameter type | ||
} | ||
|
||
fn main() { | ||
} |
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,23 @@ | ||
error[E0307]: invalid `self` parameter type: `NonNull<A>` | ||
--> $DIR/arbitrary_self_types_nonnull.rs:6:16 | ||
| | ||
LL | fn m(self: std::ptr::NonNull<Self>) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: type of `self` must be `Self` or some type implementing `Receiver` | ||
= help: consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box<Self>`, `self: Rc<Self>`, or `self: Arc<Self>` | ||
= note: `NonNull` does not implement `Receiver` because it has methods that may shadow the referent; consider wrapping your `NonNull` in a newtype wrapper for which you implement `Receiver` | ||
|
||
error[E0307]: invalid `self` parameter type: `&NonNull<A>` | ||
--> $DIR/arbitrary_self_types_nonnull.rs:8:16 | ||
| | ||
LL | fn n(self: &std::ptr::NonNull<Self>) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: type of `self` must be `Self` or some type implementing `Receiver` | ||
= help: consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box<Self>`, `self: Rc<Self>`, or `self: Arc<Self>` | ||
= note: `NonNull` does not implement `Receiver` because it has methods that may shadow the referent; consider wrapping your `NonNull` in a newtype wrapper for which you implement `Receiver` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0307`. |
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 @@ | ||
#![feature(arbitrary_self_types)] | ||
|
||
struct A; | ||
|
||
impl A { | ||
fn m(self: std::rc::Weak<Self>) {} | ||
//~^ ERROR: invalid `self` parameter type | ||
fn n(self: std::sync::Weak<Self>) {} | ||
//~^ ERROR: invalid `self` parameter type | ||
} | ||
|
||
fn main() { | ||
} |
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,23 @@ | ||
error[E0307]: invalid `self` parameter type: `std::rc::Weak<A>` | ||
--> $DIR/arbitrary_self_types_weak.rs:6:16 | ||
| | ||
LL | fn m(self: std::rc::Weak<Self>) {} | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: type of `self` must be `Self` or some type implementing `Receiver` | ||
= help: consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box<Self>`, `self: Rc<Self>`, or `self: Arc<Self>` | ||
= note: `Weak` does not implement `Receiver` because it has methods that may shadow the referent; consider wrapping your `Weak` in a newtype wrapper for which you implement `Receiver` | ||
|
||
error[E0307]: invalid `self` parameter type: `std::sync::Weak<A>` | ||
--> $DIR/arbitrary_self_types_weak.rs:8:16 | ||
| | ||
LL | fn n(self: std::sync::Weak<Self>) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: type of `self` must be `Self` or some type implementing `Receiver` | ||
= help: consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box<Self>`, `self: Rc<Self>`, or `self: Arc<Self>` | ||
= note: `Weak` does not implement `Receiver` because it has methods that may shadow the referent; consider wrapping your `Weak` in a newtype wrapper for which you implement `Receiver` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0307`. |