diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 7fa8202e5d60a..866cd5ec535d2 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -255,7 +255,6 @@ pub mod option; pub mod panic; pub mod panicking; pub mod pin; -pub mod raw; pub mod result; #[unstable(feature = "async_stream", issue = "79024")] pub mod stream; diff --git a/library/core/src/raw.rs b/library/core/src/raw.rs deleted file mode 100644 index 6d1e28f4cd7d7..0000000000000 --- a/library/core/src/raw.rs +++ /dev/null @@ -1,90 +0,0 @@ -#![allow(missing_docs)] -#![unstable(feature = "raw", issue = "27751")] -#![rustc_deprecated( - since = "1.53.0", - reason = "use pointer metadata APIs instead https://github.com/rust-lang/rust/issues/81513" -)] - -//! Contains struct definitions for the layout of compiler built-in types. -//! -//! They can be used as targets of transmutes in unsafe code for manipulating -//! the raw representations directly. -//! -//! Their definition should always match the ABI defined in -//! `rustc_middle::ty::layout`. - -/// The representation of a trait object like `&dyn SomeTrait`. -/// -/// This struct has the same layout as types like `&dyn SomeTrait` and -/// `Box`. -/// -/// `TraitObject` is guaranteed to match layouts, but it is not the -/// type of trait objects (e.g., the fields are not directly accessible -/// on a `&dyn SomeTrait`) nor does it control that layout (changing the -/// definition will not change the layout of a `&dyn SomeTrait`). It is -/// only designed to be used by unsafe code that needs to manipulate -/// the low-level details. -/// -/// There is no way to refer to all trait objects generically, so the only -/// way to create values of this type is with functions like -/// [`std::mem::transmute`][transmute]. Similarly, the only way to create a true -/// trait object from a `TraitObject` value is with `transmute`. -/// -/// [transmute]: crate::intrinsics::transmute -/// -/// Synthesizing a trait object with mismatched types—one where the -/// vtable does not correspond to the type of the value to which the -/// data pointer points—is highly likely to lead to undefined -/// behavior. -/// -/// # Examples -/// -/// ``` -/// #![feature(raw)] -/// -/// use std::{mem, raw}; -/// -/// // an example trait -/// trait Foo { -/// fn bar(&self) -> i32; -/// } -/// -/// impl Foo for i32 { -/// fn bar(&self) -> i32 { -/// *self + 1 -/// } -/// } -/// -/// let value: i32 = 123; -/// -/// // let the compiler make a trait object -/// let object: &dyn Foo = &value; -/// -/// // look at the raw representation -/// let raw_object: raw::TraitObject = unsafe { mem::transmute(object) }; -/// -/// // the data pointer is the address of `value` -/// assert_eq!(raw_object.data as *const i32, &value as *const _); -/// -/// let other_value: i32 = 456; -/// -/// // construct a new object, pointing to a different `i32`, being -/// // careful to use the `i32` vtable from `object` -/// let synthesized: &dyn Foo = unsafe { -/// mem::transmute(raw::TraitObject { -/// data: &other_value as *const _ as *mut (), -/// vtable: raw_object.vtable, -/// }) -/// }; -/// -/// // it should work just as if we had constructed a trait object out of -/// // `other_value` directly -/// assert_eq!(synthesized.bar(), 457); -/// ``` -#[repr(C)] -#[derive(Copy, Clone)] -#[allow(missing_debug_implementations)] -pub struct TraitObject { - pub data: *mut (), - pub vtable: *mut (), -} diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index dee2478886d9a..e50b3bb96f819 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -29,7 +29,6 @@ #![feature(try_find)] #![feature(is_sorted)] #![feature(pattern)] -#![feature(raw)] #![feature(sort_internals)] #![feature(slice_partition_at_index)] #![feature(maybe_uninit_uninit_array)] diff --git a/library/core/tests/mem.rs b/library/core/tests/mem.rs index dfdbc9305d2a3..c780bb32ca96d 100644 --- a/library/core/tests/mem.rs +++ b/library/core/tests/mem.rs @@ -97,28 +97,6 @@ fn test_transmute_copy() { assert_eq!(1, unsafe { transmute_copy(&1) }); } -// Remove this test when `std::raw` is removed. -// The replacement pointer metadata APIs are tested in library/core/tests/ptr.rs -#[allow(deprecated)] -#[test] -fn test_transmute() { - trait Foo { - fn dummy(&self) {} - } - impl Foo for isize {} - - let a = box 100isize as Box; - unsafe { - let x: ::core::raw::TraitObject = transmute(a); - assert!(*(x.data as *const isize) == 100); - let _x: Box = transmute(x); - } - - unsafe { - assert_eq!(transmute::<_, Vec>("L".to_string()), [76]); - } -} - #[test] #[allow(dead_code)] fn test_discriminant_send_sync() { diff --git a/library/panic_unwind/src/lib.rs b/library/panic_unwind/src/lib.rs index d32a3f1f8322c..3622bc8294b08 100644 --- a/library/panic_unwind/src/lib.rs +++ b/library/panic_unwind/src/lib.rs @@ -23,7 +23,6 @@ #![feature(unwind_attributes)] #![feature(abi_thiscall)] #![feature(rustc_attrs)] -#![feature(raw)] #![panic_runtime] #![feature(panic_runtime)] // `real_imp` is unused with Miri, so silence warnings. diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 25f6b3c0182e2..6f389f000af93 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -303,7 +303,6 @@ #![feature(pin_static_ref)] #![feature(prelude_import)] #![feature(ptr_internals)] -#![feature(raw)] #![feature(ready_macro)] #![feature(rustc_attrs)] #![feature(rustc_private)] @@ -455,9 +454,6 @@ pub use core::pin; #[stable(feature = "rust1", since = "1.0.0")] pub use core::ptr; #[stable(feature = "rust1", since = "1.0.0")] -#[allow(deprecated, deprecated_in_future)] -pub use core::raw; -#[stable(feature = "rust1", since = "1.0.0")] pub use core::result; #[unstable(feature = "async_stream", issue = "79024")] pub use core::stream; diff --git a/src/test/ui/cast/fat-ptr-cast-rpass.rs b/src/test/ui/cast/fat-ptr-cast-rpass.rs index 9fa2255e1b348..f5747eb8b9666 100644 --- a/src/test/ui/cast/fat-ptr-cast-rpass.rs +++ b/src/test/ui/cast/fat-ptr-cast-rpass.rs @@ -1,12 +1,6 @@ // run-pass -// Remove this file when `std::raw` is removed. -// The replacement pointer metadata APIs are tested in library/core/tests/ptr.rs -#![allow(deprecated)] -#![feature(raw)] - -use std::mem; -use std::raw; +#![feature(ptr_metadata)] trait Foo { fn foo(&self) {} @@ -31,13 +25,10 @@ fn main() { // And conversion to a void pointer/address for trait objects too. let a: *mut dyn Foo = &mut Bar; - let b = a as *mut (); + let b = a as *mut () as usize; let c = a as *const () as usize; - let d = unsafe { - let r: raw::TraitObject = mem::transmute(a); - r.data - }; + let d = a.to_raw_parts().0 as usize; assert_eq!(b, d); - assert_eq!(c, d as usize); + assert_eq!(c, d); } diff --git a/src/test/ui/unsized/unsized3-rpass.rs b/src/test/ui/unsized/unsized3-rpass.rs index 65efbd6b52070..c5c5ed26c7384 100644 --- a/src/test/ui/unsized/unsized3-rpass.rs +++ b/src/test/ui/unsized/unsized3-rpass.rs @@ -1,12 +1,11 @@ // run-pass // Test structs with always-unsized fields. - #![allow(warnings)] -#![feature(box_syntax, unsize, raw)] +#![feature(box_syntax, unsize, ptr_metadata)] use std::mem; -use std::raw; +use std::ptr; use std::slice; struct Foo { @@ -28,7 +27,7 @@ trait Tr { } struct St { - f: usize + f: usize, } impl Tr for St { @@ -38,7 +37,7 @@ impl Tr for St { } struct Qux<'a> { - f: Tr+'a + f: Tr + 'a, } pub fn main() { @@ -56,10 +55,10 @@ pub fn main() { unsafe { struct Foo_ { - f: [T; 3] + f: [T; 3], } - let data: Box> = box Foo_{f: [1, 2, 3] }; + let data: Box> = box Foo_ { f: [1, 2, 3] }; let x: &Foo = mem::transmute(slice::from_raw_parts(&*data, 3)); assert_eq!(x.f.len(), 3); assert_eq!(x.f[0], 1); @@ -69,8 +68,8 @@ pub fn main() { f2: [u8; 5], } - let data: Box<_> = box Baz_ { - f1: 42, f2: ['a' as u8, 'b' as u8, 'c' as u8, 'd' as u8, 'e' as u8] }; + let data: Box<_> = + box Baz_ { f1: 42, f2: ['a' as u8, 'b' as u8, 'c' as u8, 'd' as u8, 'e' as u8] }; let x: &Baz = mem::transmute(slice::from_raw_parts(&*data, 5)); assert_eq!(x.f1, 42); let chs: Vec = x.f2.chars().collect(); @@ -82,15 +81,13 @@ pub fn main() { assert_eq!(chs[4], 'e'); struct Qux_ { - f: St + f: St, } let obj: Box = box St { f: 42 }; let obj: &Tr = &*obj; - let obj: raw::TraitObject = mem::transmute(&*obj); - let data: Box<_> = box Qux_{ f: St { f: 234 } }; - let x: &Qux = mem::transmute(raw::TraitObject { vtable: obj.vtable, - data: mem::transmute(&*data) }); + let data: Box<_> = box Qux_ { f: St { f: 234 } }; + let x: &Qux = &*ptr::from_raw_parts::((&*data as *const _).cast(), ptr::metadata(obj)); assert_eq!(x.f.foo(), 234); } }