stop to strip 'impl' from impl trait type alias (#3816)

This commit is contained in:
rChaser53 2019-10-04 11:25:17 +09:00 committed by Seiichi Uchida
parent e28ae8b4a3
commit 7926851bb0
4 changed files with 36 additions and 3 deletions

View file

@ -1118,6 +1118,18 @@ pub(crate) fn format_trait(
}
}
struct OpaqueTypeBounds<'a> {
generic_bounds: &'a ast::GenericBounds,
}
impl<'a> Rewrite for OpaqueTypeBounds<'a> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
self.generic_bounds
.rewrite(context, shape)
.map(|s| format!("impl {}", s))
}
}
pub(crate) struct TraitAliasBounds<'a> {
generic_bounds: &'a ast::GenericBounds,
generics: &'a ast::Generics,
@ -1524,13 +1536,14 @@ pub(crate) fn rewrite_opaque_type(
generics: &ast::Generics,
vis: &ast::Visibility,
) -> Option<String> {
let opaque_type_bounds = OpaqueTypeBounds { generic_bounds };
rewrite_type_item(
context,
indent,
"type",
" =",
ident,
generic_bounds,
&opaque_type_bounds,
generics,
vis,
)

View file

@ -13,3 +13,11 @@ pub type Adderrr<T> = impl Fn( T ) -> T;
impl Foo for Bar {
type E = impl Trait;
}
pub type Adder_without_impl<F, T>
where
T: Clone,
F: Copy
= Fn(T) -> T;
pub type Adderrr_without_impl<T> = Fn( T ) -> T;

View file

@ -6,10 +6,18 @@ pub type Adder<F, T>
where
T: Clone,
F: Copy,
= Fn(T) -> T;
= impl Fn(T) -> T;
pub type Adderrr<T> = Fn(T) -> T;
pub type Adderrr<T> = impl Fn(T) -> T;
impl Foo for Bar {
type E = impl Trait;
}
pub type Adder_without_impl<F, T>
where
T: Clone,
F: Copy,
= Fn(T) -> T;
pub type Adderrr_without_impl<T> = Fn(T) -> T;

View file

@ -0,0 +1,4 @@
pub type Type = impl Deref<Target = i8>;
pub type Type =
impl VeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeryLongType<Target = i8>;