diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index f18c95a61d4..b8ee2b994b1 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -16,6 +16,7 @@ use rustc_span::symbol::{kw, Ident, Symbol}; use rustc_target::abi::Size; use rustc_target::spec::abi::Abi; +use smallvec::SmallVec; use std::cell::Cell; use std::char; @@ -794,6 +795,7 @@ fn pretty_print_opaque_impl_type( let mut traits = FxIndexMap::default(); let mut fn_traits = FxIndexMap::default(); let mut is_sized = false; + let mut lifetimes = SmallVec::<[ty::Region<'tcx>; 1]>::new(); for (predicate, _) in bounds.subst_iter_copied(tcx, substs) { let bound_predicate = predicate.kind(); @@ -824,6 +826,9 @@ fn pretty_print_opaque_impl_type( &mut fn_traits, ); } + ty::PredicateKind::TypeOutlives(outlives) => { + lifetimes.push(outlives.1); + } _ => {} } } @@ -977,6 +982,11 @@ fn pretty_print_opaque_impl_type( write!(self, "Sized")?; } + for re in lifetimes { + write!(self, " + ")?; + self = self.print_region(re)?; + } + Ok(self) } diff --git a/src/test/ui/associated-type-bounds/inside-adt.rs b/src/test/ui/associated-type-bounds/inside-adt.rs index f26037f0707..8eb8c44bb42 100644 --- a/src/test/ui/associated-type-bounds/inside-adt.rs +++ b/src/test/ui/associated-type-bounds/inside-adt.rs @@ -16,7 +16,7 @@ enum E2 { V(Box>) } //~^ ERROR associated type bounds are not allowed within structs, enums, or unions enum E3 { V(dyn Iterator) } //~^ ERROR associated type bounds are not allowed within structs, enums, or unions -//~| ERROR the size for values of type `(dyn Iterator + 'static)` +//~| ERROR the size for values of type `(dyn Iterator + 'static)` union U1 { f: ManuallyDrop> } //~^ ERROR associated type bounds are not allowed within structs, enums, or unions @@ -25,6 +25,6 @@ union U2 { f: ManuallyDrop>> } //~^ ERROR associated type bounds are not allowed within structs, enums, or unions union U3 { f: ManuallyDrop> } //~^ ERROR associated type bounds are not allowed within structs, enums, or unions -//~| ERROR the size for values of type `(dyn Iterator + 'static)` +//~| ERROR the size for values of type `(dyn Iterator + 'static)` fn main() {} diff --git a/src/test/ui/associated-type-bounds/inside-adt.stderr b/src/test/ui/associated-type-bounds/inside-adt.stderr index 978390fa712..dbfcfa58063 100644 --- a/src/test/ui/associated-type-bounds/inside-adt.stderr +++ b/src/test/ui/associated-type-bounds/inside-adt.stderr @@ -70,13 +70,13 @@ help: the `Box` type always has a statically known size and allocates its conten LL | enum E1 { V(Box>) } | ++++ + -error[E0277]: the size for values of type `(dyn Iterator + 'static)` cannot be known at compilation time +error[E0277]: the size for values of type `(dyn Iterator + 'static)` cannot be known at compilation time --> $DIR/inside-adt.rs:17:13 | LL | enum E3 { V(dyn Iterator) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | - = help: the trait `Sized` is not implemented for `(dyn Iterator + 'static)` + = help: the trait `Sized` is not implemented for `(dyn Iterator + 'static)` = note: no field of an enum variant may have a dynamically sized type = help: change the field's type to have a statically known size help: borrowed types always have a statically known size @@ -107,14 +107,14 @@ help: the `Box` type always has a statically known size and allocates its conten LL | union U1 { f: Box>> } | ++++ + -error[E0277]: the size for values of type `(dyn Iterator + 'static)` cannot be known at compilation time +error[E0277]: the size for values of type `(dyn Iterator + 'static)` cannot be known at compilation time --> $DIR/inside-adt.rs:26:15 | LL | union U3 { f: ManuallyDrop> } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | - = help: within `ManuallyDrop<(dyn Iterator + 'static)>`, the trait `Sized` is not implemented for `(dyn Iterator + 'static)` - = note: required because it appears within the type `ManuallyDrop<(dyn Iterator + 'static)>` + = help: within `ManuallyDrop<(dyn Iterator + 'static)>`, the trait `Sized` is not implemented for `(dyn Iterator + 'static)` + = note: required because it appears within the type `ManuallyDrop<(dyn Iterator + 'static)>` = note: no field of a union may have a dynamically sized type = help: change the field's type to have a statically known size help: borrowed types always have a statically known size diff --git a/src/test/ui/associated-types/issue-87261.rs b/src/test/ui/associated-types/issue-87261.rs index 384561f8ccd..e8548d402fa 100644 --- a/src/test/ui/associated-types/issue-87261.rs +++ b/src/test/ui/associated-types/issue-87261.rs @@ -77,10 +77,10 @@ fn check_generics(a: A, b: B, c: C, d: D, e: E, f: F, g: G) fn main() { accepts_trait(returns_opaque()); - //~^ ERROR type mismatch resolving `::Associated == ()` + //~^ ERROR type mismatch resolving `::Associated == ()` accepts_trait(returns_opaque_derived()); - //~^ ERROR type mismatch resolving `::Associated == ()` + //~^ ERROR type mismatch resolving `::Associated == ()` accepts_trait(returns_opaque_foo()); //~^ ERROR type mismatch resolving `::Associated == ()` @@ -89,7 +89,7 @@ fn main() { //~^ ERROR type mismatch resolving `::Associated == ()` accepts_generic_trait(returns_opaque_generic()); - //~^ ERROR type mismatch resolving ` as GenericTrait<()>>::Associated == ()` + //~^ ERROR type mismatch resolving ` + 'static as GenericTrait<()>>::Associated == ()` accepts_generic_trait(returns_opaque_generic_foo()); //~^ ERROR type mismatch resolving ` + Foo as GenericTrait<()>>::Associated == ()` diff --git a/src/test/ui/associated-types/issue-87261.stderr b/src/test/ui/associated-types/issue-87261.stderr index f24423dd106..2cce6b94702 100644 --- a/src/test/ui/associated-types/issue-87261.stderr +++ b/src/test/ui/associated-types/issue-87261.stderr @@ -132,7 +132,7 @@ note: required by a bound in `accepts_generic_trait` LL | fn accepts_generic_trait>(_: T) {} | ^^^^^^^^^^^^^^^ required by this bound in `accepts_generic_trait` -error[E0271]: type mismatch resolving `::Associated == ()` +error[E0271]: type mismatch resolving `::Associated == ()` --> $DIR/issue-87261.rs:79:19 | LL | fn returns_opaque() -> impl Trait + 'static { @@ -144,18 +144,18 @@ LL | accepts_trait(returns_opaque()); | required by a bound introduced by this call | = note: expected unit type `()` - found associated type `::Associated` + found associated type `::Associated` note: required by a bound in `accepts_trait` --> $DIR/issue-87261.rs:43:27 | LL | fn accepts_trait>(_: T) {} | ^^^^^^^^^^^^^^^ required by this bound in `accepts_trait` -help: consider constraining the associated type `::Associated` to `()` +help: consider constraining the associated type `::Associated` to `()` | LL | fn returns_opaque() -> impl Trait + 'static { | +++++++++++++++++ -error[E0271]: type mismatch resolving `::Associated == ()` +error[E0271]: type mismatch resolving `::Associated == ()` --> $DIR/issue-87261.rs:82:19 | LL | fn returns_opaque_derived() -> impl DerivedTrait + 'static { @@ -167,13 +167,13 @@ LL | accepts_trait(returns_opaque_derived()); | required by a bound introduced by this call | = note: expected unit type `()` - found associated type `::Associated` + found associated type `::Associated` note: required by a bound in `accepts_trait` --> $DIR/issue-87261.rs:43:27 | LL | fn accepts_trait>(_: T) {} | ^^^^^^^^^^^^^^^ required by this bound in `accepts_trait` -help: consider constraining the associated type `::Associated` to `()` +help: consider constraining the associated type `::Associated` to `()` | LL | fn returns_opaque_derived() -> impl DerivedTrait + 'static { | +++++++++++++++++ @@ -222,7 +222,7 @@ note: required by a bound in `accepts_trait` LL | fn accepts_trait>(_: T) {} | ^^^^^^^^^^^^^^^ required by this bound in `accepts_trait` -error[E0271]: type mismatch resolving ` as GenericTrait<()>>::Associated == ()` +error[E0271]: type mismatch resolving ` + 'static as GenericTrait<()>>::Associated == ()` --> $DIR/issue-87261.rs:91:27 | LL | fn returns_opaque_generic() -> impl GenericTrait<()> + 'static { @@ -234,13 +234,13 @@ LL | accepts_generic_trait(returns_opaque_generic()); | required by a bound introduced by this call | = note: expected unit type `()` - found associated type ` as GenericTrait<()>>::Associated` + found associated type ` + 'static as GenericTrait<()>>::Associated` note: required by a bound in `accepts_generic_trait` --> $DIR/issue-87261.rs:44:46 | LL | fn accepts_generic_trait>(_: T) {} | ^^^^^^^^^^^^^^^ required by this bound in `accepts_generic_trait` -help: consider constraining the associated type ` as GenericTrait<()>>::Associated` to `()` +help: consider constraining the associated type ` + 'static as GenericTrait<()>>::Associated` to `()` | LL | fn returns_opaque_generic() -> impl GenericTrait<(), Associated = ()> + 'static { | +++++++++++++++++ diff --git a/src/test/ui/impl-trait/hidden-lifetimes.stderr b/src/test/ui/impl-trait/hidden-lifetimes.stderr index efc228de58b..de06ded7acd 100644 --- a/src/test/ui/impl-trait/hidden-lifetimes.stderr +++ b/src/test/ui/impl-trait/hidden-lifetimes.stderr @@ -1,4 +1,4 @@ -error[E0700]: hidden type for `impl Swap` captures lifetime that does not appear in bounds +error[E0700]: hidden type for `impl Swap + 'a` captures lifetime that does not appear in bounds --> $DIR/hidden-lifetimes.rs:29:5 | LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { @@ -11,7 +11,7 @@ help: to declare that the `impl Trait` captures `'b`, you can add an explicit `' LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a + 'b { | ++++ -error[E0700]: hidden type for `impl Swap` captures lifetime that does not appear in bounds +error[E0700]: hidden type for `impl Swap + 'a` captures lifetime that does not appear in bounds --> $DIR/hidden-lifetimes.rs:46:5 | LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl Swap + 'a {