Enforce that dyn* casts are actually pointer-sized
This commit is contained in:
parent
fd3bfb3551
commit
da3c5397a6
10 changed files with 131 additions and 8 deletions
15
src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.rs
Normal file
15
src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#![feature(dyn_star)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
fn dyn_debug(_: (dyn* Debug + '_)) {
|
||||
|
||||
}
|
||||
|
||||
fn polymorphic<T: Debug + ?Sized>(t: &T) {
|
||||
dyn_debug(t);
|
||||
//~^ ERROR `&T` needs to be a pointer-sized type
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
error[E0277]: `&T` needs to be a pointer-sized type
|
||||
--> $DIR/check-size-at-cast-polymorphic-bad.rs:11:15
|
||||
|
|
||||
LL | dyn_debug(t);
|
||||
| ^ `&T` needs to be a pointer-sized type
|
||||
|
|
||||
= help: the trait `PointerSized` is not implemented for `&T`
|
||||
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
||||
|
|
||||
LL | fn polymorphic<T: Debug + ?Sized>(t: &T) where &T: PointerSized {
|
||||
| ++++++++++++++++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
16
src/test/ui/dyn-star/check-size-at-cast-polymorphic.rs
Normal file
16
src/test/ui/dyn-star/check-size-at-cast-polymorphic.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// check-pass
|
||||
|
||||
#![feature(dyn_star)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
fn dyn_debug(_: (dyn* Debug + '_)) {
|
||||
|
||||
}
|
||||
|
||||
fn polymorphic<T: Debug>(t: &T) {
|
||||
dyn_debug(t);
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
10
src/test/ui/dyn-star/check-size-at-cast.rs
Normal file
10
src/test/ui/dyn-star/check-size-at-cast.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#![feature(dyn_star)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
fn main() {
|
||||
let i = [1, 2, 3, 4] as dyn* Debug;
|
||||
//~^ ERROR `[i32; 4]` needs to be a pointer-sized type
|
||||
dbg!(i);
|
||||
}
|
||||
11
src/test/ui/dyn-star/check-size-at-cast.stderr
Normal file
11
src/test/ui/dyn-star/check-size-at-cast.stderr
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
error[E0277]: `[i32; 4]` needs to be a pointer-sized type
|
||||
--> $DIR/check-size-at-cast.rs:7:13
|
||||
|
|
||||
LL | let i = [1, 2, 3, 4] as dyn* Debug;
|
||||
| ^^^^^^^^^^^^ `[i32; 4]` needs to be a pointer-sized type
|
||||
|
|
||||
= help: the trait `PointerSized` is not implemented for `[i32; 4]`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue