Open
Description
I tried this code:
trait Trait {}
// Make sure casts between thin-pointer <-> fat pointer obey RFC401
fn main() {
let a: *mut (dyn Trait + 'static) = 0 as *mut _; //~ ERROR casting
let x: *mut (dyn Trait + 'static) = std::ptr::null_mut();
}
When I ran this on rustc 1.32.0, I got this error message:
error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
--> src/lib.rs:6:41
|
6 | let x: *mut (dyn Trait + 'static) = std::ptr::null_mut();
| ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `(dyn Trait + 'static)`
= note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: required by `std::ptr::null_mut`
error[E0606]: casting `usize` as `*mut (dyn Trait + 'static)` is invalid
--> src/lib.rs:5:41
|
5 | let a: *mut (dyn Trait + 'static) = 0 as *mut _; //~ ERROR casting
| ^^^^^^^^^^^
error: aborting due to 2 previous errors
Some errors occurred: E0277, E0606.
For more information about an error, try `rustc --explain E0277`.
But when I ran this on rustc nightly, I got this error message:
error[E0606]: casting `usize` as `*mut (dyn Trait + 'static)` is invalid
--> src/lib.rs:5:41
|
5 | let a: *mut (dyn Trait + 'static) = 0 as *mut _; //~ ERROR casting
| ^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0606`.
Meta
% rustc +1.32.0 -Vv
rustc 1.32.0 (9fda7c223 2019-01-16)
binary: rustc
commit-hash: 9fda7c2237db910e41d6a712e9a2139b352e558b
commit-date: 2019-01-16
host: x86_64-unknown-linux-gnu
release: 1.32.0
LLVM version: 8.0
% rustc +nightly -Vv
rustc 1.37.0-nightly (0e4a56b4b 2019-06-13)
binary: rustc
commit-hash: 0e4a56b4b04ea98bb16caada30cb2418dd06e250
commit-date: 2019-06-13
host: x86_64-unknown-linux-gnu
release: 1.37.0-nightly
LLVM version: 8.0