-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #121840 - oli-obk:freeze, r=dtolnay
Expose the Freeze trait again (unstably) and forbid implementing it manually non-emoji version of #121501 cc #60715 This trait is useful for generic constants (associated consts of generic traits). See the test (`tests/ui/associated-consts/freeze.rs`) added in this PR for a usage example. The builtin `Freeze` trait is the only way to do it, users cannot work around this issue. It's also a useful trait for building some very specific abstrations, as shown by the usage by the `zerocopy` crate: google/zerocopy#941 cc ```@RalfJung``` T-lang signed off on reexposing this unstably: #121501 (comment)
- Loading branch information
Showing
15 changed files
with
89 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
rustc_attrs, | ||
transparent_unions, | ||
auto_traits, | ||
freeze_impls, | ||
thread_local | ||
)] | ||
#![no_core] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
#![crate_name = "foo"] | ||
|
||
#![feature(negative_impls)] | ||
#![feature(negative_impls, freeze_impls, freeze)] | ||
|
||
pub struct Foo; | ||
|
||
// @has foo/struct.Foo.html | ||
// @!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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#![feature(freeze, negative_impls)] | ||
|
||
use std::marker::Freeze; | ||
|
||
struct Foo; | ||
|
||
unsafe impl Freeze for Foo {} | ||
//~^ explicit impls for the `Freeze` trait are not permitted | ||
|
||
struct Bar; | ||
|
||
impl !Freeze for Bar {} | ||
//~^ explicit impls for the `Freeze` trait are not permitted | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error[E0658]: explicit impls for the `Freeze` trait are not permitted | ||
--> $DIR/feature-gate-freeze-impls.rs:7:1 | ||
| | ||
LL | unsafe impl Freeze for Foo {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of `Freeze` not allowed | ||
| | ||
= note: see issue #121675 <https://github.com/rust-lang/rust/issues/121675> for more information | ||
= help: add `#![feature(freeze_impls)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0658]: explicit impls for the `Freeze` trait are not permitted | ||
--> $DIR/feature-gate-freeze-impls.rs:12:1 | ||
| | ||
LL | impl !Freeze for Bar {} | ||
| ^^^^^^^^^^^^^^^^^^^^ impl of `Freeze` not allowed | ||
| | ||
= note: see issue #121675 <https://github.com/rust-lang/rust/issues/121675> for more information | ||
= help: add `#![feature(freeze_impls)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |