diff --git a/compiler/rustc_codegen_cranelift/example/mini_core.rs b/compiler/rustc_codegen_cranelift/example/mini_core.rs index 9ecc4c5dd5b64..c02d123cce675 100644 --- a/compiler/rustc_codegen_cranelift/example/mini_core.rs +++ b/compiler/rustc_codegen_cranelift/example/mini_core.rs @@ -95,7 +95,6 @@ unsafe impl Sync for [u8; 16] {} #[lang = "freeze"] unsafe auto trait Freeze {} -unsafe impl Freeze for PhantomData {} unsafe impl Freeze for *const T {} unsafe impl Freeze for *mut T {} unsafe impl Freeze for &T {} diff --git a/compiler/rustc_codegen_gcc/example/mini_core.rs b/compiler/rustc_codegen_gcc/example/mini_core.rs index 0cd7e6047c20a..988d30139ecd6 100644 --- a/compiler/rustc_codegen_gcc/example/mini_core.rs +++ b/compiler/rustc_codegen_gcc/example/mini_core.rs @@ -91,7 +91,6 @@ unsafe impl Sync for [u8; 16] {} #[lang = "freeze"] unsafe auto trait Freeze {} -unsafe impl Freeze for PhantomData {} unsafe impl Freeze for *const T {} unsafe impl Freeze for *mut T {} unsafe impl Freeze for &T {} diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 60b07485c3a8e..5b25269877dec 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -318,7 +318,7 @@ pub struct Rc< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, > { ptr: NonNull>, - phantom: PhantomData>, + phantom: PhantomData>>, alloc: A, } @@ -3400,7 +3400,7 @@ fn data_offset_align(align: usize) -> usize { #[derive(Debug)] pub struct UniqueRc { ptr: NonNull>, - phantom: PhantomData>, + phantom: PhantomData>>, } impl UniqueRc { diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 6c701225a848f..5f7873117a6a3 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -251,7 +251,7 @@ pub struct Arc< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, > { ptr: NonNull>, - phantom: PhantomData>, + phantom: PhantomData>>, alloc: A, } diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 5ec751e5168bf..3bbad5a7b83c0 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -872,7 +872,6 @@ pub(crate) unsafe auto trait Freeze {} impl !Freeze for UnsafeCell {} marker_impls! { unsafe Freeze for - {T: ?Sized} PhantomData, {T: ?Sized} *const T, {T: ?Sized} *mut T, {T: ?Sized} &T, diff --git a/library/core/src/ptr/unique.rs b/library/core/src/ptr/unique.rs index bf8b86677d568..440dbf2917aaf 100644 --- a/library/core/src/ptr/unique.rs +++ b/library/core/src/ptr/unique.rs @@ -1,6 +1,6 @@ use crate::convert::From; use crate::fmt; -use crate::marker::{PhantomData, Unsize}; +use crate::marker::{Freeze, PhantomData, Unsize}; use crate::ops::{CoerceUnsized, DispatchFromDyn}; use crate::ptr::NonNull; @@ -58,6 +58,10 @@ unsafe impl Send for Unique {} #[unstable(feature = "ptr_internals", issue = "none")] unsafe impl Sync for Unique {} +/// `Unique` pointers are always `Freeze` since any interior mutability that might exist in `T` is +/// masked by the pointer indirection. +unsafe impl Freeze for Unique {} + #[unstable(feature = "ptr_internals", issue = "none")] impl Unique { /// Creates a new `Unique` that is dangling, but well-aligned. diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index 3414924007b90..be8c5066e92c1 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -11,7 +11,7 @@ use std::path::{Path, PathBuf}; const ENTRY_LIMIT: usize = 900; // FIXME: The following limits should be reduced eventually. const ISSUES_ENTRY_LIMIT: usize = 1891; -const ROOT_ENTRY_LIMIT: usize = 866; +const ROOT_ENTRY_LIMIT: usize = 867; // this includes files *and* folders! const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[ "rs", // test source files diff --git a/tests/ui/unsafe-cell/phantom-data-not-freeze.rs b/tests/ui/unsafe-cell/phantom-data-not-freeze.rs new file mode 100644 index 0000000000000..90a2614518727 --- /dev/null +++ b/tests/ui/unsafe-cell/phantom-data-not-freeze.rs @@ -0,0 +1,15 @@ +use std::cell::UnsafeCell; +use std::marker::PhantomData; + +// This checks that `PhantomData` does not entirely mask interior mutability. + +trait Trait { + const C: (u32, PhantomData>); +} + +fn bar() { + let x: &'static (u32, PhantomData>) = &T::C; + //~^ ERROR: dropped while borrowed +} + +fn main() {} diff --git a/tests/ui/unsafe-cell/phantom-data-not-freeze.stderr b/tests/ui/unsafe-cell/phantom-data-not-freeze.stderr new file mode 100644 index 0000000000000..f9d1745e4cfc5 --- /dev/null +++ b/tests/ui/unsafe-cell/phantom-data-not-freeze.stderr @@ -0,0 +1,14 @@ +error[E0716]: temporary value dropped while borrowed + --> $DIR/phantom-data-not-freeze.rs:11:60 + | +LL | let x: &'static (u32, PhantomData>) = &T::C; + | -------------------------------------------- ^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +LL | +LL | } + | - temporary value is freed at the end of this statement + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0716`.