Add basic pin sugar support to rustfmt

This commit is contained in:
Eric Holk 2024-09-23 16:07:31 -07:00
parent b490bf56b7
commit 3aabe1e4a3
No known key found for this signature in database
GPG Key ID: F1A772BB658A63E1
3 changed files with 26 additions and 1 deletions

View File

@ -829,7 +829,6 @@ impl Rewrite for ast::Ty {
}
ast::TyKind::Ref(ref lifetime, ref mt)
| ast::TyKind::PinnedRef(ref lifetime, ref mt) => {
// FIXME(pin_ergonomics): correctly format pinned reference syntax
let mut_str = format_mutability(mt.mutbl);
let mut_len = mut_str.len();
let mut result = String::with_capacity(128);
@ -863,6 +862,13 @@ impl Rewrite for ast::Ty {
cmnt_lo = lifetime.ident.span.hi();
}
if let ast::TyKind::PinnedRef(..) = self.kind {
result.push_str("pin ");
if ast::Mutability::Not == mt.mutbl {
result.push_str("const ");
}
}
if ast::Mutability::Mut == mt.mutbl {
let mut_hi = context.snippet_provider.span_after(self.span(), "mut");
let before_mut_span = mk_sp(cmnt_lo, mut_hi - BytePos::from_usize(3));

View File

@ -0,0 +1,10 @@
// See #130494
#![feature(pin_ergonomics)]
#![allow(incomplete_features)]
fn f(x: &pin const i32) {}
fn g<'a>(x: & 'a pin const i32) {}
fn h<'a>(x: & 'a pin
mut i32) {}
fn i(x: &pin mut i32) {}

View File

@ -0,0 +1,9 @@
// See #130494
#![feature(pin_ergonomics)]
#![allow(incomplete_features)]
fn f(x: &pin const i32) {}
fn g<'a>(x: &'a pin const i32) {}
fn h<'a>(x: &'a pin mut i32) {}
fn i(x: &pin mut i32) {}