From c5df62041950b2279191804841a51077826df9a0 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 23 Oct 2022 17:21:43 +0000 Subject: [PATCH] Annotate static lifetimes too --- compiler/rustc_middle/src/ty/print/pretty.rs | 12 +++--------- .../ui/associated-type-bounds/inside-adt.rs | 4 ++-- .../associated-type-bounds/inside-adt.stderr | 10 +++++----- src/test/ui/associated-types/issue-87261.rs | 6 +++--- .../ui/associated-types/issue-87261.stderr | 18 +++++++++--------- 5 files changed, 22 insertions(+), 28 deletions(-) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 2a229e04743..b1523068799 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -983,15 +983,9 @@ pub trait PrettyPrinter<'tcx>: write!(self, "Sized")?; } - if let [re] = lifetimes.as_slice() - && re.is_static() - { - // Don't print a single static lifetime - } else { - for re in lifetimes { - write!(self, " + ")?; - self = self.print_region(re)?; - } + 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 @@ where 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 { | +++++++++++++++++