Enforce that dyn* casts are actually pointer-sized

This commit is contained in:
Michael Goulet 2022-11-12 22:27:18 +00:00
parent fd3bfb3551
commit da3c5397a6
10 changed files with 131 additions and 8 deletions

View 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() {}

View file

@ -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`.

View 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() {}

View 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);
}

View 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`.