diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-09-20 19:46:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-20 19:46:38 +0200 |
| commit | fe5f734e6a0b9afe43fc98e0529ec667393f918b (patch) | |
| tree | 9ebd10f748950f7c83e5deb9c50b541a09054e93 /compiler/rustc_middle/src | |
| parent | bf6389f077ca62b4695231ea381255487e6097ed (diff) | |
| parent | a18800f8078f3fb7b986183b53c34a6a1b921d63 (diff) | |
| download | rust-fe5f734e6a0b9afe43fc98e0529ec667393f918b.tar.gz rust-fe5f734e6a0b9afe43fc98e0529ec667393f918b.zip | |
Rollup merge of #130526 - eholk:pin-reborrow, r=compiler-errors
Begin experimental support for pin reborrowing
This commit adds basic support for reborrowing `Pin` types in argument position. At the moment it only supports reborrowing `Pin<&mut T>` as `Pin<&mut T>` by inserting a call to `Pin::as_mut()`, and only in argument position (not as the receiver in a method call).
This PR makes the following example compile:
```rust
#![feature(pin_ergonomics)]
fn foo(_: Pin<&mut Foo>) {
}
fn bar(mut x: Pin<&mut Foo>) {
foo(x);
foo(x);
}
```
Previously, you would have had to write `bar` as:
```rust
fn bar(mut x: Pin<&mut Foo>) {
foo(x.as_mut());
foo(x);
}
```
Tracking:
- #130494
r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/ty/adjustment.rs | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/adjustment.rs b/compiler/rustc_middle/src/ty/adjustment.rs index 1236c9efb41..5a32078760e 100644 --- a/compiler/rustc_middle/src/ty/adjustment.rs +++ b/compiler/rustc_middle/src/ty/adjustment.rs @@ -104,6 +104,9 @@ pub enum Adjust<'tcx> { /// Cast into a dyn* object. DynStar, + + /// Take a pinned reference and reborrow as a `Pin<&mut T>` or `Pin<&T>`. + ReborrowPin(ty::Region<'tcx>, hir::Mutability), } /// An overloaded autoderef step, representing a `Deref(Mut)::deref(_mut)` |
