diff --git a/src/items.rs b/src/items.rs index cdf9fa06eef..053e856b9f1 100644 --- a/src/items.rs +++ b/src/items.rs @@ -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 { + 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 { + let opaque_type_bounds = OpaqueTypeBounds { generic_bounds }; rewrite_type_item( context, indent, "type", " =", ident, - generic_bounds, + &opaque_type_bounds, generics, vis, ) diff --git a/tests/source/existential_type.rs b/tests/source/existential_type.rs index 92412fca879..33bb9a95159 100644 --- a/tests/source/existential_type.rs +++ b/tests/source/existential_type.rs @@ -13,3 +13,11 @@ pub type Adderrr = impl Fn( T ) -> T; impl Foo for Bar { type E = impl Trait; } + +pub type Adder_without_impl +where + T: Clone, + F: Copy + = Fn(T) -> T; + +pub type Adderrr_without_impl = Fn( T ) -> T; diff --git a/tests/target/existential_type.rs b/tests/target/existential_type.rs index 869ffda2378..ffc206875b5 100644 --- a/tests/target/existential_type.rs +++ b/tests/target/existential_type.rs @@ -6,10 +6,18 @@ pub type Adder where T: Clone, F: Copy, -= Fn(T) -> T; += impl Fn(T) -> T; -pub type Adderrr = Fn(T) -> T; +pub type Adderrr = impl Fn(T) -> T; impl Foo for Bar { type E = impl Trait; } + +pub type Adder_without_impl +where + T: Clone, + F: Copy, += Fn(T) -> T; + +pub type Adderrr_without_impl = Fn(T) -> T; diff --git a/tests/target/issue-3815.rs b/tests/target/issue-3815.rs new file mode 100644 index 00000000000..eff27e2de3c --- /dev/null +++ b/tests/target/issue-3815.rs @@ -0,0 +1,4 @@ +pub type Type = impl Deref; + +pub type Type = + impl VeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeryLongType;