forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
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#135733 - frank-king:feature/pin-self-receiv…
…er, r=oli-obk Implement `&pin const self` and `&pin mut self` sugars This PR implements part of rust-lang#130494. It introduces the sugars `&pin const self` and `&pin mut self` for `self: Pin<&Self>` and `self: Pin<&mut Self>`.
- Loading branch information
Showing
10 changed files
with
308 additions
and
76 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,24 @@ | ||
//@ pp-exact | ||
|
||
#![feature(pin_ergonomics)] | ||
#![allow(dead_code, incomplete_features)] | ||
|
||
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_lt<'a>(_: &'a pin mut Foo) {} | ||
|
||
fn foo_const(_: &pin const Foo) {} | ||
fn foo_const_lt(_: &'_ pin const Foo) {} | ||
|
||
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,46 @@ | ||
//@ 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(_: &pin const Foo) {} | ||
|
||
fn bar(x: &pin mut Foo) { | ||
// For the calls below to work we need to automatically reborrow, | ||
// as if the user had written `foo(x.as_mut())`. | ||
foo(x); | ||
foo(x); | ||
|
||
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() {} |
Oops, something went wrong.