Skip to content

Commit 7926851

Browse files
rchaser53topecongiro
authored andcommitted
stop to strip 'impl' from impl trait type alias (#3816)
1 parent e28ae8b commit 7926851

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

src/items.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,18 @@ pub(crate) fn format_trait(
11181118
}
11191119
}
11201120

1121+
struct OpaqueTypeBounds<'a> {
1122+
generic_bounds: &'a ast::GenericBounds,
1123+
}
1124+
1125+
impl<'a> Rewrite for OpaqueTypeBounds<'a> {
1126+
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
1127+
self.generic_bounds
1128+
.rewrite(context, shape)
1129+
.map(|s| format!("impl {}", s))
1130+
}
1131+
}
1132+
11211133
pub(crate) struct TraitAliasBounds<'a> {
11221134
generic_bounds: &'a ast::GenericBounds,
11231135
generics: &'a ast::Generics,
@@ -1524,13 +1536,14 @@ pub(crate) fn rewrite_opaque_type(
15241536
generics: &ast::Generics,
15251537
vis: &ast::Visibility,
15261538
) -> Option<String> {
1539+
let opaque_type_bounds = OpaqueTypeBounds { generic_bounds };
15271540
rewrite_type_item(
15281541
context,
15291542
indent,
15301543
"type",
15311544
" =",
15321545
ident,
1533-
generic_bounds,
1546+
&opaque_type_bounds,
15341547
generics,
15351548
vis,
15361549
)

tests/source/existential_type.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@ pub type Adderrr<T> = impl Fn( T ) -> T;
1313
impl Foo for Bar {
1414
type E = impl Trait;
1515
}
16+
17+
pub type Adder_without_impl<F, T>
18+
where
19+
T: Clone,
20+
F: Copy
21+
= Fn(T) -> T;
22+
23+
pub type Adderrr_without_impl<T> = Fn( T ) -> T;

tests/target/existential_type.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ pub type Adder<F, T>
66
where
77
T: Clone,
88
F: Copy,
9-
= Fn(T) -> T;
9+
= impl Fn(T) -> T;
1010

11-
pub type Adderrr<T> = Fn(T) -> T;
11+
pub type Adderrr<T> = impl Fn(T) -> T;
1212

1313
impl Foo for Bar {
1414
type E = impl Trait;
1515
}
16+
17+
pub type Adder_without_impl<F, T>
18+
where
19+
T: Clone,
20+
F: Copy,
21+
= Fn(T) -> T;
22+
23+
pub type Adderrr_without_impl<T> = Fn(T) -> T;

tests/target/issue-3815.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub type Type = impl Deref<Target = i8>;
2+
3+
pub type Type =
4+
impl VeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeryLongType<Target = i8>;

0 commit comments

Comments
 (0)