Skip to content

Commit 0ae8340

Browse files
committed
Implement &pin const self and &pin mut self sugars
1 parent a28a422 commit 0ae8340

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

src/items.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,6 +2395,33 @@ fn rewrite_explicit_self(
23952395
)?),
23962396
}
23972397
}
2398+
ast::SelfKind::Pinned(lt, m) => {
2399+
let mut_str = m.ptr_str();
2400+
match lt {
2401+
Some(ref l) => {
2402+
let lifetime_str = l.rewrite_result(
2403+
context,
2404+
Shape::legacy(context.config.max_width(), Indent::empty()),
2405+
)?;
2406+
Ok(combine_strs_with_missing_comments(
2407+
context,
2408+
param_attrs,
2409+
&format!("&{lifetime_str} pin {mut_str} self"),
2410+
span,
2411+
shape,
2412+
!has_multiple_attr_lines,
2413+
)?)
2414+
}
2415+
None => Ok(combine_strs_with_missing_comments(
2416+
context,
2417+
param_attrs,
2418+
&format!("&pin {mut_str} self"),
2419+
span,
2420+
shape,
2421+
!has_multiple_attr_lines,
2422+
)?),
2423+
}
2424+
}
23982425
ast::SelfKind::Explicit(ref ty, mutability) => {
23992426
let type_str = ty.rewrite_result(
24002427
context,

tests/source/pin_sugar.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,13 @@ fn g<'a>(x: & 'a pin const i32) {}
88
fn h<'a>(x: & 'a pin
99
mut i32) {}
1010
fn i(x: &pin mut i32) {}
11+
12+
struct Foo;
13+
14+
impl Foo {
15+
fn f(&pin const self) {}
16+
fn g<'a>(& 'a pin const self) {}
17+
fn h<'a>(& 'a pin
18+
mut self) {}
19+
fn i(&pin mut self) {}
20+
}

tests/target/pin_sugar.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@ fn f(x: &pin const i32) {}
77
fn g<'a>(x: &'a pin const i32) {}
88
fn h<'a>(x: &'a pin mut i32) {}
99
fn i(x: &pin mut i32) {}
10+
11+
struct Foo;
12+
13+
impl Foo {
14+
fn f(&pin const self) {}
15+
fn g<'a>(&'a pin const self) {}
16+
fn h<'a>(&'a pin mut self) {}
17+
fn i(&pin mut self) {}
18+
}

0 commit comments

Comments
 (0)