Skip to content

Commit c5df620

Browse files
Annotate static lifetimes too
1 parent c0cda2b commit c5df620

File tree

5 files changed

+22
-28
lines changed

5 files changed

+22
-28
lines changed

compiler/rustc_middle/src/ty/print/pretty.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -983,15 +983,9 @@ pub trait PrettyPrinter<'tcx>:
983983
write!(self, "Sized")?;
984984
}
985985

986-
if let [re] = lifetimes.as_slice()
987-
&& re.is_static()
988-
{
989-
// Don't print a single static lifetime
990-
} else {
991-
for re in lifetimes {
992-
write!(self, " + ")?;
993-
self = self.print_region(re)?;
994-
}
986+
for re in lifetimes {
987+
write!(self, " + ")?;
988+
self = self.print_region(re)?;
995989
}
996990

997991
Ok(self)

src/test/ui/associated-type-bounds/inside-adt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ enum E2 { V(Box<dyn Iterator<Item: Copy>>) }
1616
//~^ ERROR associated type bounds are not allowed within structs, enums, or unions
1717
enum E3 { V(dyn Iterator<Item: 'static>) }
1818
//~^ ERROR associated type bounds are not allowed within structs, enums, or unions
19-
//~| ERROR the size for values of type `(dyn Iterator<Item = impl Sized> + 'static)`
19+
//~| ERROR the size for values of type `(dyn Iterator<Item = impl Sized + 'static> + 'static)`
2020

2121
union U1 { f: ManuallyDrop<dyn Iterator<Item: Copy>> }
2222
//~^ ERROR associated type bounds are not allowed within structs, enums, or unions
@@ -25,6 +25,6 @@ union U2 { f: ManuallyDrop<Box<dyn Iterator<Item: Copy>>> }
2525
//~^ ERROR associated type bounds are not allowed within structs, enums, or unions
2626
union U3 { f: ManuallyDrop<dyn Iterator<Item: 'static>> }
2727
//~^ ERROR associated type bounds are not allowed within structs, enums, or unions
28-
//~| ERROR the size for values of type `(dyn Iterator<Item = impl Sized> + 'static)`
28+
//~| ERROR the size for values of type `(dyn Iterator<Item = impl Sized + 'static> + 'static)`
2929

3030
fn main() {}

src/test/ui/associated-type-bounds/inside-adt.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ help: the `Box` type always has a statically known size and allocates its conten
7070
LL | enum E1 { V(Box<dyn Iterator<Item: Copy>>) }
7171
| ++++ +
7272

73-
error[E0277]: the size for values of type `(dyn Iterator<Item = impl Sized> + 'static)` cannot be known at compilation time
73+
error[E0277]: the size for values of type `(dyn Iterator<Item = impl Sized + 'static> + 'static)` cannot be known at compilation time
7474
--> $DIR/inside-adt.rs:17:13
7575
|
7676
LL | enum E3 { V(dyn Iterator<Item: 'static>) }
7777
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
7878
|
79-
= help: the trait `Sized` is not implemented for `(dyn Iterator<Item = impl Sized> + 'static)`
79+
= help: the trait `Sized` is not implemented for `(dyn Iterator<Item = impl Sized + 'static> + 'static)`
8080
= note: no field of an enum variant may have a dynamically sized type
8181
= help: change the field's type to have a statically known size
8282
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
107107
LL | union U1 { f: Box<ManuallyDrop<dyn Iterator<Item: Copy>>> }
108108
| ++++ +
109109

110-
error[E0277]: the size for values of type `(dyn Iterator<Item = impl Sized> + 'static)` cannot be known at compilation time
110+
error[E0277]: the size for values of type `(dyn Iterator<Item = impl Sized + 'static> + 'static)` cannot be known at compilation time
111111
--> $DIR/inside-adt.rs:26:15
112112
|
113113
LL | union U3 { f: ManuallyDrop<dyn Iterator<Item: 'static>> }
114114
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
115115
|
116-
= help: within `ManuallyDrop<(dyn Iterator<Item = impl Sized> + 'static)>`, the trait `Sized` is not implemented for `(dyn Iterator<Item = impl Sized> + 'static)`
117-
= note: required because it appears within the type `ManuallyDrop<(dyn Iterator<Item = impl Sized> + 'static)>`
116+
= help: within `ManuallyDrop<(dyn Iterator<Item = impl Sized + 'static> + 'static)>`, the trait `Sized` is not implemented for `(dyn Iterator<Item = impl Sized + 'static> + 'static)`
117+
= note: required because it appears within the type `ManuallyDrop<(dyn Iterator<Item = impl Sized + 'static> + 'static)>`
118118
= note: no field of a union may have a dynamically sized type
119119
= help: change the field's type to have a statically known size
120120
help: borrowed types always have a statically known size

src/test/ui/associated-types/issue-87261.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ where
7777

7878
fn main() {
7979
accepts_trait(returns_opaque());
80-
//~^ ERROR type mismatch resolving `<impl Trait as Trait>::Associated == ()`
80+
//~^ ERROR type mismatch resolving `<impl Trait + 'static as Trait>::Associated == ()`
8181

8282
accepts_trait(returns_opaque_derived());
83-
//~^ ERROR type mismatch resolving `<impl DerivedTrait as Trait>::Associated == ()`
83+
//~^ ERROR type mismatch resolving `<impl DerivedTrait + 'static as Trait>::Associated == ()`
8484

8585
accepts_trait(returns_opaque_foo());
8686
//~^ ERROR type mismatch resolving `<impl Trait + Foo as Trait>::Associated == ()`
@@ -89,7 +89,7 @@ fn main() {
8989
//~^ ERROR type mismatch resolving `<impl DerivedTrait + Foo as Trait>::Associated == ()`
9090

9191
accepts_generic_trait(returns_opaque_generic());
92-
//~^ ERROR type mismatch resolving `<impl GenericTrait<()> as GenericTrait<()>>::Associated == ()`
92+
//~^ ERROR type mismatch resolving `<impl GenericTrait<()> + 'static as GenericTrait<()>>::Associated == ()`
9393

9494
accepts_generic_trait(returns_opaque_generic_foo());
9595
//~^ ERROR type mismatch resolving `<impl GenericTrait<()> + Foo as GenericTrait<()>>::Associated == ()`

src/test/ui/associated-types/issue-87261.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ note: required by a bound in `accepts_generic_trait`
132132
LL | fn accepts_generic_trait<T: GenericTrait<(), Associated = ()>>(_: T) {}
133133
| ^^^^^^^^^^^^^^^ required by this bound in `accepts_generic_trait`
134134

135-
error[E0271]: type mismatch resolving `<impl Trait as Trait>::Associated == ()`
135+
error[E0271]: type mismatch resolving `<impl Trait + 'static as Trait>::Associated == ()`
136136
--> $DIR/issue-87261.rs:79:19
137137
|
138138
LL | fn returns_opaque() -> impl Trait + 'static {
@@ -144,18 +144,18 @@ LL | accepts_trait(returns_opaque());
144144
| required by a bound introduced by this call
145145
|
146146
= note: expected unit type `()`
147-
found associated type `<impl Trait as Trait>::Associated`
147+
found associated type `<impl Trait + 'static as Trait>::Associated`
148148
note: required by a bound in `accepts_trait`
149149
--> $DIR/issue-87261.rs:43:27
150150
|
151151
LL | fn accepts_trait<T: Trait<Associated = ()>>(_: T) {}
152152
| ^^^^^^^^^^^^^^^ required by this bound in `accepts_trait`
153-
help: consider constraining the associated type `<impl Trait as Trait>::Associated` to `()`
153+
help: consider constraining the associated type `<impl Trait + 'static as Trait>::Associated` to `()`
154154
|
155155
LL | fn returns_opaque() -> impl Trait<Associated = ()> + 'static {
156156
| +++++++++++++++++
157157

158-
error[E0271]: type mismatch resolving `<impl DerivedTrait as Trait>::Associated == ()`
158+
error[E0271]: type mismatch resolving `<impl DerivedTrait + 'static as Trait>::Associated == ()`
159159
--> $DIR/issue-87261.rs:82:19
160160
|
161161
LL | fn returns_opaque_derived() -> impl DerivedTrait + 'static {
@@ -167,13 +167,13 @@ LL | accepts_trait(returns_opaque_derived());
167167
| required by a bound introduced by this call
168168
|
169169
= note: expected unit type `()`
170-
found associated type `<impl DerivedTrait as Trait>::Associated`
170+
found associated type `<impl DerivedTrait + 'static as Trait>::Associated`
171171
note: required by a bound in `accepts_trait`
172172
--> $DIR/issue-87261.rs:43:27
173173
|
174174
LL | fn accepts_trait<T: Trait<Associated = ()>>(_: T) {}
175175
| ^^^^^^^^^^^^^^^ required by this bound in `accepts_trait`
176-
help: consider constraining the associated type `<impl DerivedTrait as Trait>::Associated` to `()`
176+
help: consider constraining the associated type `<impl DerivedTrait + 'static as Trait>::Associated` to `()`
177177
|
178178
LL | fn returns_opaque_derived() -> impl DerivedTrait<Associated = ()> + 'static {
179179
| +++++++++++++++++
@@ -222,7 +222,7 @@ note: required by a bound in `accepts_trait`
222222
LL | fn accepts_trait<T: Trait<Associated = ()>>(_: T) {}
223223
| ^^^^^^^^^^^^^^^ required by this bound in `accepts_trait`
224224

225-
error[E0271]: type mismatch resolving `<impl GenericTrait<()> as GenericTrait<()>>::Associated == ()`
225+
error[E0271]: type mismatch resolving `<impl GenericTrait<()> + 'static as GenericTrait<()>>::Associated == ()`
226226
--> $DIR/issue-87261.rs:91:27
227227
|
228228
LL | fn returns_opaque_generic() -> impl GenericTrait<()> + 'static {
@@ -234,13 +234,13 @@ LL | accepts_generic_trait(returns_opaque_generic());
234234
| required by a bound introduced by this call
235235
|
236236
= note: expected unit type `()`
237-
found associated type `<impl GenericTrait<()> as GenericTrait<()>>::Associated`
237+
found associated type `<impl GenericTrait<()> + 'static as GenericTrait<()>>::Associated`
238238
note: required by a bound in `accepts_generic_trait`
239239
--> $DIR/issue-87261.rs:44:46
240240
|
241241
LL | fn accepts_generic_trait<T: GenericTrait<(), Associated = ()>>(_: T) {}
242242
| ^^^^^^^^^^^^^^^ required by this bound in `accepts_generic_trait`
243-
help: consider constraining the associated type `<impl GenericTrait<()> as GenericTrait<()>>::Associated` to `()`
243+
help: consider constraining the associated type `<impl GenericTrait<()> + 'static as GenericTrait<()>>::Associated` to `()`
244244
|
245245
LL | fn returns_opaque_generic() -> impl GenericTrait<(), Associated = ()> + 'static {
246246
| +++++++++++++++++

0 commit comments

Comments
 (0)