-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
&pin const self
and &pin mut self
sugars
- Loading branch information
1 parent
73c0ae6
commit 07f960b
Showing
7 changed files
with
156 additions
and
0 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
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,45 @@ | ||
//@ check-pass | ||
|
||
#![feature(pin_ergonomics)] | ||
#![allow(dead_code, incomplete_features)] | ||
|
||
// Makes sure we can handle `&pin mut self` and `&pin const self` as sugar for | ||
// `self: Pin<&mut Self>` and `self: Pin<&Self>`. | ||
|
||
use std::pin::Pin; | ||
|
||
struct Foo; | ||
|
||
impl Foo { | ||
fn baz(&pin mut self) {} | ||
|
||
fn baz_const(&pin const self) {} | ||
|
||
fn baz_lt<'a>(&'a pin mut self) {} | ||
|
||
fn baz_const_lt(&'_ pin const self) {} | ||
} | ||
|
||
fn foo(_: &pin mut Foo) {} | ||
|
||
fn foo_const(x: &pin const Foo) {} | ||
|
||
fn bar(x: &pin mut Foo) { | ||
foo(x); | ||
foo(x); // for this to work we need to automatically reborrow, | ||
// as if the user had written `foo(x.as_mut())`. | ||
|
||
Foo::baz(x); | ||
Foo::baz(x); | ||
|
||
// make sure we can reborrow &mut as &. | ||
foo_const(x); | ||
Foo::baz_const(x); | ||
|
||
let x: &pin const _ = Pin::new(&Foo); | ||
|
||
foo_const(x); // make sure reborrowing from & to & works. | ||
foo_const(x); | ||
} | ||
|
||
fn main() {} |