Skip to content

Commit e0d0aac

Browse files
authored
Rollup merge of #130635 - eholk:pin-reborrow-sugar, r=compiler-errors
Add `&pin (mut|const) T` type position sugar This adds parser support for `&pin mut T` and `&pin const T` references. These are desugared to `Pin<&mut T>` and `Pin<&T>` in the AST lowering phases. This PR currently includes #130526 since that one is in the commit queue. Only the most recent commits (bd450027eb4a94b814a7dd9c0fa29102e6361149 and following) are new. Tracking: - #130494 r? `@compiler-errors`
2 parents ab5afca + 44788b8 commit e0d0aac

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/types.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,8 @@ impl Rewrite for ast::Ty {
827827

828828
rewrite_unary_prefix(context, prefix, &*mt.ty, shape)
829829
}
830-
ast::TyKind::Ref(ref lifetime, ref mt) => {
830+
ast::TyKind::Ref(ref lifetime, ref mt)
831+
| ast::TyKind::PinnedRef(ref lifetime, ref mt) => {
831832
let mut_str = format_mutability(mt.mutbl);
832833
let mut_len = mut_str.len();
833834
let mut result = String::with_capacity(128);
@@ -861,6 +862,13 @@ impl Rewrite for ast::Ty {
861862
cmnt_lo = lifetime.ident.span.hi();
862863
}
863864

865+
if let ast::TyKind::PinnedRef(..) = self.kind {
866+
result.push_str("pin ");
867+
if ast::Mutability::Not == mt.mutbl {
868+
result.push_str("const ");
869+
}
870+
}
871+
864872
if ast::Mutability::Mut == mt.mutbl {
865873
let mut_hi = context.snippet_provider.span_after(self.span(), "mut");
866874
let before_mut_span = mk_sp(cmnt_lo, mut_hi - BytePos::from_usize(3));
@@ -1260,9 +1268,9 @@ pub(crate) fn can_be_overflowed_type(
12601268
) -> bool {
12611269
match ty.kind {
12621270
ast::TyKind::Tup(..) => context.use_block_indent() && len == 1,
1263-
ast::TyKind::Ref(_, ref mutty) | ast::TyKind::Ptr(ref mutty) => {
1264-
can_be_overflowed_type(context, &*mutty.ty, len)
1265-
}
1271+
ast::TyKind::Ref(_, ref mutty)
1272+
| ast::TyKind::PinnedRef(_, ref mutty)
1273+
| ast::TyKind::Ptr(ref mutty) => can_be_overflowed_type(context, &*mutty.ty, len),
12661274
_ => false,
12671275
}
12681276
}

tests/source/pin_sugar.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// See #130494
2+
3+
#![feature(pin_ergonomics)]
4+
#![allow(incomplete_features)]
5+
6+
fn f(x: &pin const i32) {}
7+
fn g<'a>(x: & 'a pin const i32) {}
8+
fn h<'a>(x: & 'a pin
9+
mut i32) {}
10+
fn i(x: &pin mut i32) {}

tests/target/pin_sugar.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// See #130494
2+
3+
#![feature(pin_ergonomics)]
4+
#![allow(incomplete_features)]
5+
6+
fn f(x: &pin const i32) {}
7+
fn g<'a>(x: &'a pin const i32) {}
8+
fn h<'a>(x: &'a pin mut i32) {}
9+
fn i(x: &pin mut i32) {}

0 commit comments

Comments
 (0)