-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Arbitrary self types v2: Weak, NonNull hints
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.
- Loading branch information
Showing
7 changed files
with
104 additions
and
2 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
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`; 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`; 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`; 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`; 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`. |