Skip to content

Commit 90ec05d

Browse files
committed
remove blanket-Freeze for PhantomData
1 parent bc720ad commit 90ec05d

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

compiler/rustc_codegen_cranelift/example/mini_core.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ unsafe impl Sync for [u8; 16] {}
9595
#[lang = "freeze"]
9696
unsafe auto trait Freeze {}
9797

98-
unsafe impl<T: ?Sized> Freeze for PhantomData<T> {}
9998
unsafe impl<T: ?Sized> Freeze for *const T {}
10099
unsafe impl<T: ?Sized> Freeze for *mut T {}
101100
unsafe impl<T: ?Sized> Freeze for &T {}

compiler/rustc_codegen_gcc/example/mini_core.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ unsafe impl Sync for [u8; 16] {}
9191
#[lang = "freeze"]
9292
unsafe auto trait Freeze {}
9393

94-
unsafe impl<T: ?Sized> Freeze for PhantomData<T> {}
9594
unsafe impl<T: ?Sized> Freeze for *const T {}
9695
unsafe impl<T: ?Sized> Freeze for *mut T {}
9796
unsafe impl<T: ?Sized> Freeze for &T {}

library/core/src/marker.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,6 @@ pub(crate) unsafe auto trait Freeze {}
872872
impl<T: ?Sized> !Freeze for UnsafeCell<T> {}
873873
marker_impls! {
874874
unsafe Freeze for
875-
{T: ?Sized} PhantomData<T>,
876875
{T: ?Sized} *const T,
877876
{T: ?Sized} *mut T,
878877
{T: ?Sized} &T,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use std::cell::UnsafeCell;
2+
use std::marker::PhantomData;
3+
4+
// This checks that `PhantomData` does not entirely mask interior mutability.
5+
6+
trait Trait {
7+
const C: (u32, PhantomData<UnsafeCell<u32>>);
8+
}
9+
10+
fn bar<T: Trait>() {
11+
let x: &'static (u32, PhantomData<UnsafeCell<u32>>) = &T::C;
12+
//~^ ERROR: dropped while borrowed
13+
}
14+
15+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0716]: temporary value dropped while borrowed
2+
--> $DIR/phantom-data-not-freeze.rs:11:60
3+
|
4+
LL | let x: &'static (u32, PhantomData<UnsafeCell<u32>>) = &T::C;
5+
| -------------------------------------------- ^^^^ creates a temporary value which is freed while still in use
6+
| |
7+
| type annotation requires that borrow lasts for `'static`
8+
LL |
9+
LL | }
10+
| - temporary value is freed at the end of this statement
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0716`.

0 commit comments

Comments
 (0)