mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-15 05:26:47 +00:00
Add test for WF check of implied unsizing in struct fields
Note that the test output is currently *incorrect*. We should be emitting an error at the use site too, not just at the definition. This is partly for UI reasons, but mainly to fix a related ICE where a const generic body is not tainted with an error since no usage error is reported.
This commit is contained in:
parent
e57f3090ae
commit
18906754cc
10
tests/ui/structs/field-implied-unsizing-wfcheck.rs
Normal file
10
tests/ui/structs/field-implied-unsizing-wfcheck.rs
Normal file
@ -0,0 +1,10 @@
|
||||
struct Foo {
|
||||
nested: &'static Bar<dyn std::fmt::Debug>,
|
||||
//~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
|
||||
}
|
||||
|
||||
struct Bar<T>(T);
|
||||
|
||||
fn main() {
|
||||
let x = Foo { nested: &Bar(4) };
|
||||
}
|
23
tests/ui/structs/field-implied-unsizing-wfcheck.stderr
Normal file
23
tests/ui/structs/field-implied-unsizing-wfcheck.stderr
Normal file
@ -0,0 +1,23 @@
|
||||
error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
|
||||
--> $DIR/field-implied-unsizing-wfcheck.rs:2:13
|
||||
|
|
||||
LL | nested: &'static Bar<dyn std::fmt::Debug>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: the trait `Sized` is not implemented for `(dyn Debug + 'static)`
|
||||
note: required by an implicit `Sized` bound in `Bar`
|
||||
--> $DIR/field-implied-unsizing-wfcheck.rs:6:12
|
||||
|
|
||||
LL | struct Bar<T>(T);
|
||||
| ^ required by the implicit `Sized` requirement on this type parameter in `Bar`
|
||||
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
|
||||
--> $DIR/field-implied-unsizing-wfcheck.rs:6:12
|
||||
|
|
||||
LL | struct Bar<T>(T);
|
||||
| ^ - ...if indirection were used here: `Box<T>`
|
||||
| |
|
||||
| this could be changed to `T: ?Sized`...
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
Loading…
Reference in New Issue
Block a user