Skip to content

Commit 3aabe1e

Browse files
committed
Add basic pin sugar support to rustfmt
1 parent b490bf5 commit 3aabe1e

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

Diff for: src/tools/rustfmt/src/types.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,6 @@ impl Rewrite for ast::Ty {
829829
}
830830
ast::TyKind::Ref(ref lifetime, ref mt)
831831
| ast::TyKind::PinnedRef(ref lifetime, ref mt) => {
832-
// FIXME(pin_ergonomics): correctly format pinned reference syntax
833832
let mut_str = format_mutability(mt.mutbl);
834833
let mut_len = mut_str.len();
835834
let mut result = String::with_capacity(128);
@@ -863,6 +862,13 @@ impl Rewrite for ast::Ty {
863862
cmnt_lo = lifetime.ident.span.hi();
864863
}
865864

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+
866872
if ast::Mutability::Mut == mt.mutbl {
867873
let mut_hi = context.snippet_provider.span_after(self.span(), "mut");
868874
let before_mut_span = mk_sp(cmnt_lo, mut_hi - BytePos::from_usize(3));

Diff for: src/tools/rustfmt/tests/source/pin_sugar.rs

+10
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) {}

Diff for: src/tools/rustfmt/tests/target/pin_sugar.rs

+9
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)