-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Stabilize const_fn_transmute
, const_fn_union
#85769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
// run-pass | ||
|
||
#![feature(const_fn_union)] | ||
#![allow(dead_code)] | ||
|
||
#[repr(C)] | ||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#![feature(const_fn_union)] | ||
|
||
#![allow(const_err)] | ||
|
||
#[repr(C)] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#![feature(const_fn_union)] | ||
|
||
#![deny(const_err)] | ||
|
||
#[repr(C)] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
// stderr-per-bitwidth | ||
#![feature(const_fn_union)] | ||
|
||
fn main() { | ||
let n: Int = 40; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
// stderr-per-bitwidth | ||
#![feature(const_fn_transmute)] | ||
|
||
const fn foo() -> ! { | ||
unsafe { std::mem::transmute(()) } | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
// Don't allow unstable features in stable functions without `allow_internal_unstable`. | ||
jhpratt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#![stable(feature = "rust1", since = "1.0.0")] | ||
|
||
#![feature(staged_api)] | ||
#![feature(const_transmute)] | ||
#![feature(const_fn_floating_point_arithmetic)] | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_const_stable(feature = "rust1", since = "1.0.0")] | ||
pub const fn foo() -> i32 { | ||
unsafe { std::mem::transmute(4u32) } //~ ERROR `transmute` | ||
pub const fn foo() -> f32 { | ||
1.0 + 1.0 //~ ERROR const-stable function cannot use `#[feature(const_fn_floating_point_arithmetic)]` | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
error[E0658]: `transmute` is not allowed in constant functions | ||
--> $DIR/internal-unstable-const.rs:11:14 | ||
error: const-stable function cannot use `#[feature(const_fn_floating_point_arithmetic)]` | ||
--> $DIR/internal-unstable-const.rs:10:5 | ||
| | ||
LL | unsafe { std::mem::transmute(4u32) } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | 1.0 + 1.0 | ||
| ^^^^^^^^^ | ||
| | ||
help: if it is not part of the public API, make this function unstably const | ||
| | ||
LL | #[rustc_const_unstable(feature = "...", issue = "...")] | ||
| | ||
help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks | ||
| | ||
LL | #[rustc_allow_const_fn_unstable(const_fn_floating_point_arithmetic)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh fancy, it's a completely different error that previously... @oli-obk is that expected? Seems like a bug that the fancy error was not already used before. Anyway, the new test looks good! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea, the way I unstabilized transmute was not a point of pride |
||
| | ||
= note: see issue #53605 <https://github.com/rust-lang/rust/issues/53605> for more information | ||
= help: add `#![feature(const_fn_transmute)]` to the crate attributes to enable | ||
= note: `transmute` is only allowed in constants and statics for now | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#![feature(const_fn_transmute)] | ||
#![allow(dead_code)] | ||
|
||
extern crate core; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#![feature(const_fn_transmute)] | ||
#![warn(clippy::transmute_float_to_int)] | ||
|
||
fn float_to_int() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my understanding is that transmuting pointers to integers is currently UB in all contexts, const-time or run-time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, nothing in this list makes it UB, but it is also not explicitly allowed anywhere to my knowledge. It exists in the grey area of unspecified Rust. There are reasons we might want to make it UB, but I wouldn't know that there is T-lang consensus for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but isn't it the case that llvm already cannot perform the transmute properly and will already miscompile in some situations? Because if it's just plain broken we should just come clean about it, even if we do relax the rule again later once things are fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are theoretical miscompilations, yes.