Expose Freeze trait again

This commit is contained in:
Oli Scherer 2024-02-23 11:53:25 +00:00
parent 71a7b66f20
commit f030d49536
6 changed files with 30 additions and 9 deletions

View File

@ -810,15 +810,21 @@ pub trait DiscriminantKind {
type Discriminant: Clone + Copy + Debug + Eq + PartialEq + Hash + Send + Sync + Unpin;
}
/// Compiler-internal trait used to determine whether a type contains
/// Used to determine whether a type contains
/// any `UnsafeCell` internally, but not through an indirection.
/// This affects, for example, whether a `static` of that type is
/// placed in read-only static memory or writable static memory.
/// This can be used to declare that a constant with a generic type
/// will not contain interior mutability, and subsequently allow
/// placing the constant behind references.
#[lang = "freeze"]
pub(crate) unsafe auto trait Freeze {}
#[unstable(feature = "freeze", issue = "60715")]
pub unsafe auto trait Freeze {}
#[unstable(feature = "freeze", issue = "60715")]
impl<T: ?Sized> !Freeze for UnsafeCell<T> {}
marker_impls! {
#[unstable(feature = "freeze", issue = "60715")]
unsafe Freeze for
{T: ?Sized} PhantomData<T>,
{T: ?Sized} *const T,

View File

@ -1,5 +1,5 @@
// https://github.com/rust-lang/rust/issues/50159
#![crate_name="foo"]
#![crate_name = "foo"]
pub trait Signal {
type Item;
@ -9,7 +9,10 @@ pub trait Signal2 {
type Item2;
}
impl<B, C> Signal2 for B where B: Signal<Item = C> {
impl<B, C> Signal2 for B
where
B: Signal<Item = C>,
{
type Item2 = C;
}
@ -17,7 +20,7 @@ impl<B, C> Signal2 for B where B: Signal<Item = C> {
// @has - '//h3[@class="code-header"]' 'impl<B> Send for Switch<B>where <B as Signal>::Item: Send'
// @has - '//h3[@class="code-header"]' 'impl<B> Sync for Switch<B>where <B as Signal>::Item: Sync'
// @count - '//*[@id="implementations-list"]//*[@class="impl"]' 0
// @count - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]' 5
// @count - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]' 6
pub struct Switch<B: Signal> {
pub inner: <B as Signal2>::Item2,
}

View File

@ -1,6 +1,5 @@
#![crate_name = "foo"]
#![feature(negative_impls)]
#![feature(negative_impls, freeze_impls, freeze)]
pub struct Foo;
@ -8,6 +7,7 @@
// @!hasraw - 'Auto Trait Implementations'
impl !Send for Foo {}
impl !Sync for Foo {}
impl !std::marker::Freeze for Foo {}
impl !std::marker::Unpin for Foo {}
impl !std::panic::RefUnwindSafe for Foo {}
impl !std::panic::UnwindSafe for Foo {}

View File

@ -2,7 +2,7 @@
// @has - '//h3[@class="code-header"]' 'impl<T> Send for Foo<T>where T: Send'
// @has - '//h3[@class="code-header"]' 'impl<T> Sync for Foo<T>where T: Sync'
// @count - '//*[@id="implementations-list"]//*[@class="impl"]' 0
// @count - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]' 5
// @count - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]' 6
pub struct Foo<T> {
field: T,
}

View File

@ -6,7 +6,7 @@
// 'impl<T> Send for Foo<T>'
//
// @count - '//*[@id="trait-implementations-list"]//*[@class="impl"]' 1
// @count - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]' 4
// @count - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]' 5
pub struct Foo<T> {
field: T,
}

View File

@ -0,0 +1,12 @@
#![feature(freeze)]
//@ check-pass
use std::marker::Freeze;
trait Trait<T: Freeze + 'static> {
const VALUE: T;
const VALUE_REF: &'static T = &Self::VALUE;
}
fn main() {}