Skip to content

Commit 2f4603b

Browse files
committed
Test more cases of WF-checking for fields
1 parent 9479792 commit 2f4603b

File tree

2 files changed

+151
-10
lines changed

2 files changed

+151
-10
lines changed

Diff for: tests/ui/structs/field-implied-unsizing-wfcheck.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1-
struct Foo {
1+
struct FooStruct {
22
nested: &'static Bar<dyn std::fmt::Debug>,
33
//~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
44
}
55

6+
struct FooTuple(&'static Bar<dyn std::fmt::Debug>);
7+
//~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
8+
9+
enum FooEnum1 {
10+
Struct { nested: &'static Bar<dyn std::fmt::Debug> },
11+
//~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
12+
}
13+
14+
enum FooEnum2 {
15+
Tuple(&'static Bar<dyn std::fmt::Debug>),
16+
//~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
17+
}
18+
619
struct Bar<T>(T);
720

821
fn main() {
9-
let x = Foo { nested: &Bar(4) };
22+
// Ensure there's an error at the construction site, for error tainting purposes.
23+
24+
FooStruct { nested: &Bar(4) };
25+
//~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
26+
FooTuple(&Bar(4));
27+
//~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
28+
FooEnum1::Struct { nested: &Bar(4) };
29+
//~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
30+
FooEnum2::Tuple(&Bar(4));
1031
//~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
1132
}

Diff for: tests/ui/structs/field-implied-unsizing-wfcheck.stderr

+128-8
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,158 @@ LL | nested: &'static Bar<dyn std::fmt::Debug>,
66
|
77
= help: the trait `Sized` is not implemented for `(dyn Debug + 'static)`
88
note: required by an implicit `Sized` bound in `Bar`
9-
--> $DIR/field-implied-unsizing-wfcheck.rs:6:12
9+
--> $DIR/field-implied-unsizing-wfcheck.rs:19:12
1010
|
1111
LL | struct Bar<T>(T);
1212
| ^ required by the implicit `Sized` requirement on this type parameter in `Bar`
1313
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
14-
--> $DIR/field-implied-unsizing-wfcheck.rs:6:12
14+
--> $DIR/field-implied-unsizing-wfcheck.rs:19:12
1515
|
1616
LL | struct Bar<T>(T);
1717
| ^ - ...if indirection were used here: `Box<T>`
1818
| |
1919
| this could be changed to `T: ?Sized`...
2020

2121
error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
22-
--> $DIR/field-implied-unsizing-wfcheck.rs:9:27
22+
--> $DIR/field-implied-unsizing-wfcheck.rs:6:17
2323
|
24-
LL | let x = Foo { nested: &Bar(4) };
25-
| ^^^^^^^ doesn't have a size known at compile-time
24+
LL | struct FooTuple(&'static Bar<dyn std::fmt::Debug>);
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
2626
|
2727
= help: the trait `Sized` is not implemented for `(dyn Debug + 'static)`
2828
note: required by an implicit `Sized` bound in `Bar`
29-
--> $DIR/field-implied-unsizing-wfcheck.rs:6:12
29+
--> $DIR/field-implied-unsizing-wfcheck.rs:19:12
3030
|
3131
LL | struct Bar<T>(T);
3232
| ^ required by the implicit `Sized` requirement on this type parameter in `Bar`
3333
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
34-
--> $DIR/field-implied-unsizing-wfcheck.rs:6:12
34+
--> $DIR/field-implied-unsizing-wfcheck.rs:19:12
3535
|
3636
LL | struct Bar<T>(T);
3737
| ^ - ...if indirection were used here: `Box<T>`
3838
| |
3939
| this could be changed to `T: ?Sized`...
4040

41-
error: aborting due to 2 previous errors
41+
error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
42+
--> $DIR/field-implied-unsizing-wfcheck.rs:10:22
43+
|
44+
LL | Struct { nested: &'static Bar<dyn std::fmt::Debug> },
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
46+
|
47+
= help: the trait `Sized` is not implemented for `(dyn Debug + 'static)`
48+
note: required by an implicit `Sized` bound in `Bar`
49+
--> $DIR/field-implied-unsizing-wfcheck.rs:19:12
50+
|
51+
LL | struct Bar<T>(T);
52+
| ^ required by the implicit `Sized` requirement on this type parameter in `Bar`
53+
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
54+
--> $DIR/field-implied-unsizing-wfcheck.rs:19:12
55+
|
56+
LL | struct Bar<T>(T);
57+
| ^ - ...if indirection were used here: `Box<T>`
58+
| |
59+
| this could be changed to `T: ?Sized`...
60+
61+
error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
62+
--> $DIR/field-implied-unsizing-wfcheck.rs:15:11
63+
|
64+
LL | Tuple(&'static Bar<dyn std::fmt::Debug>),
65+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
66+
|
67+
= help: the trait `Sized` is not implemented for `(dyn Debug + 'static)`
68+
note: required by an implicit `Sized` bound in `Bar`
69+
--> $DIR/field-implied-unsizing-wfcheck.rs:19:12
70+
|
71+
LL | struct Bar<T>(T);
72+
| ^ required by the implicit `Sized` requirement on this type parameter in `Bar`
73+
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
74+
--> $DIR/field-implied-unsizing-wfcheck.rs:19:12
75+
|
76+
LL | struct Bar<T>(T);
77+
| ^ - ...if indirection were used here: `Box<T>`
78+
| |
79+
| this could be changed to `T: ?Sized`...
80+
81+
error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
82+
--> $DIR/field-implied-unsizing-wfcheck.rs:24:25
83+
|
84+
LL | FooStruct { nested: &Bar(4) };
85+
| ^^^^^^^ doesn't have a size known at compile-time
86+
|
87+
= help: the trait `Sized` is not implemented for `(dyn Debug + 'static)`
88+
note: required by an implicit `Sized` bound in `Bar`
89+
--> $DIR/field-implied-unsizing-wfcheck.rs:19:12
90+
|
91+
LL | struct Bar<T>(T);
92+
| ^ required by the implicit `Sized` requirement on this type parameter in `Bar`
93+
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
94+
--> $DIR/field-implied-unsizing-wfcheck.rs:19:12
95+
|
96+
LL | struct Bar<T>(T);
97+
| ^ - ...if indirection were used here: `Box<T>`
98+
| |
99+
| this could be changed to `T: ?Sized`...
100+
101+
error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
102+
--> $DIR/field-implied-unsizing-wfcheck.rs:26:14
103+
|
104+
LL | FooTuple(&Bar(4));
105+
| ^^^^^^^ doesn't have a size known at compile-time
106+
|
107+
= help: the trait `Sized` is not implemented for `(dyn Debug + 'static)`
108+
note: required by an implicit `Sized` bound in `Bar`
109+
--> $DIR/field-implied-unsizing-wfcheck.rs:19:12
110+
|
111+
LL | struct Bar<T>(T);
112+
| ^ required by the implicit `Sized` requirement on this type parameter in `Bar`
113+
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
114+
--> $DIR/field-implied-unsizing-wfcheck.rs:19:12
115+
|
116+
LL | struct Bar<T>(T);
117+
| ^ - ...if indirection were used here: `Box<T>`
118+
| |
119+
| this could be changed to `T: ?Sized`...
120+
121+
error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
122+
--> $DIR/field-implied-unsizing-wfcheck.rs:28:32
123+
|
124+
LL | FooEnum1::Struct { nested: &Bar(4) };
125+
| ^^^^^^^ doesn't have a size known at compile-time
126+
|
127+
= help: the trait `Sized` is not implemented for `(dyn Debug + 'static)`
128+
note: required by an implicit `Sized` bound in `Bar`
129+
--> $DIR/field-implied-unsizing-wfcheck.rs:19:12
130+
|
131+
LL | struct Bar<T>(T);
132+
| ^ required by the implicit `Sized` requirement on this type parameter in `Bar`
133+
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
134+
--> $DIR/field-implied-unsizing-wfcheck.rs:19:12
135+
|
136+
LL | struct Bar<T>(T);
137+
| ^ - ...if indirection were used here: `Box<T>`
138+
| |
139+
| this could be changed to `T: ?Sized`...
140+
141+
error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
142+
--> $DIR/field-implied-unsizing-wfcheck.rs:30:21
143+
|
144+
LL | FooEnum2::Tuple(&Bar(4));
145+
| ^^^^^^^ doesn't have a size known at compile-time
146+
|
147+
= help: the trait `Sized` is not implemented for `(dyn Debug + 'static)`
148+
note: required by an implicit `Sized` bound in `Bar`
149+
--> $DIR/field-implied-unsizing-wfcheck.rs:19:12
150+
|
151+
LL | struct Bar<T>(T);
152+
| ^ required by the implicit `Sized` requirement on this type parameter in `Bar`
153+
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
154+
--> $DIR/field-implied-unsizing-wfcheck.rs:19:12
155+
|
156+
LL | struct Bar<T>(T);
157+
| ^ - ...if indirection were used here: `Box<T>`
158+
| |
159+
| this could be changed to `T: ?Sized`...
160+
161+
error: aborting due to 8 previous errors
42162

43163
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)