-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Use deref target in Pin trait implementations #67039
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 4 commits into
rust-lang:master
from
LunaBorowska:manually-implement-pin-traits
Dec 10, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1cf0db1
Use deref target in Pin trait implementations
LunaBorowska dfcf764
Document why Pin implementations aren't derived
LunaBorowska 6996ae1
Add UI test for Pin PartialEq unsoundness
LunaBorowska 61d9c00
Explicitly refer to operator methods in Pin impls
LunaBorowska 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Pin's PartialEq implementation allowed to access the pointer allowing for | ||
// unsoundness by using Rc::get_mut to move value within Rc. | ||
// See https://internals.rust-lang.org/t/unsoundness-in-pin/11311/73 for more details. | ||
|
||
use std::ops::Deref; | ||
use std::pin::Pin; | ||
use std::rc::Rc; | ||
|
||
struct Apple; | ||
|
||
impl Deref for Apple { | ||
type Target = Apple; | ||
fn deref(&self) -> &Apple { | ||
&Apple | ||
} | ||
} | ||
|
||
impl PartialEq<Rc<Apple>> for Apple { | ||
fn eq(&self, _rc: &Rc<Apple>) -> bool { | ||
unreachable!() | ||
} | ||
} | ||
|
||
fn main() { | ||
let _ = Pin::new(Apple) == Rc::pin(Apple); | ||
//~^ ERROR type mismatch resolving | ||
} |
13 changes: 13 additions & 0 deletions
13
src/test/ui/issues/issue-67039-unsound-pin-partialeq.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,13 @@ | ||
error[E0271]: type mismatch resolving `<std::rc::Rc<Apple> as std::ops::Deref>::Target == std::rc::Rc<Apple>` | ||
--> $DIR/issue-67039-unsound-pin-partialeq.rs:25:29 | ||
| | ||
LL | let _ = Pin::new(Apple) == Rc::pin(Apple); | ||
| ^^ expected struct `Apple`, found struct `std::rc::Rc` | ||
| | ||
= note: expected type `Apple` | ||
found struct `std::rc::Rc<Apple>` | ||
= note: required because of the requirements on the impl of `std::cmp::PartialEq<std::pin::Pin<std::rc::Rc<Apple>>>` for `std::pin::Pin<Apple>` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0271`. |
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.