Source code

Revision control

Copy as Markdown

Other Tools

commit d2c024b53a34386d4d4c968cd0403c9194f1db4f
Author: Ralf Jung <post@ralfj.de>
Date: Sat Aug 3 11:17:43 2024 +0200
stabilize const_fn_floating_point_arithmetic
diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs
index 3ded81b90ff..4232c241ad4 100644
--- a/compiler/rustc_const_eval/src/check_consts/check.rs
+++ b/compiler/rustc_const_eval/src/check_consts/check.rs
@@ -569,46 +569,42 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
Rvalue::NullaryOp(
NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_) | NullOp::UbChecks,
_,
) => {}
Rvalue::ShallowInitBox(_, _) => {}
Rvalue::UnaryOp(_, operand) => {
let ty = operand.ty(self.body, self.tcx);
- if is_int_bool_or_char(ty) {
- // Int, bool, and char operations are fine.
- } else if ty.is_floating_point() {
- self.check_op(ops::FloatingPointOp);
+ if is_int_bool_float_or_char(ty) {
+ // Int, bool, float, and char operations are fine.
} else {
span_bug!(self.span, "non-primitive type in `Rvalue::UnaryOp`: {:?}", ty);
}
}
Rvalue::BinaryOp(op, box (lhs, rhs)) => {
let lhs_ty = lhs.ty(self.body, self.tcx);
let rhs_ty = rhs.ty(self.body, self.tcx);
- if is_int_bool_or_char(lhs_ty) && is_int_bool_or_char(rhs_ty) {
- // Int, bool, and char operations are fine.
+ if is_int_bool_float_or_char(lhs_ty) && is_int_bool_float_or_char(rhs_ty) {
+ // Int, bool, float, and char operations are fine.
} else if lhs_ty.is_fn_ptr() || lhs_ty.is_unsafe_ptr() {
assert!(matches!(
op,
BinOp::Eq
| BinOp::Ne
| BinOp::Le
| BinOp::Lt
| BinOp::Ge
| BinOp::Gt
| BinOp::Offset
));
self.check_op(ops::RawPtrComparison);
- } else if lhs_ty.is_floating_point() || rhs_ty.is_floating_point() {
- self.check_op(ops::FloatingPointOp);
} else {
span_bug!(
self.span,
"non-primitive type in `Rvalue::BinaryOp`: {:?} ⚬ {:?}",
lhs_ty,
rhs_ty
);
}
@@ -1003,17 +999,17 @@ fn place_as_reborrow<'tcx>(
return None;
}
}
}
_ => None,
}
}
-fn is_int_bool_or_char(ty: Ty<'_>) -> bool {
- ty.is_bool() || ty.is_integral() || ty.is_char()
+fn is_int_bool_float_or_char(ty: Ty<'_>) -> bool {
+ ty.is_bool() || ty.is_integral() || ty.is_char() || ty.is_floating_point()
}
fn emit_unstable_in_stable_error(ccx: &ConstCx<'_, '_>, span: Span, gate: Symbol) {
let attr_span = ccx.tcx.def_span(ccx.def_id()).shrink_to_lo();
ccx.dcx().emit_err(UnstableInStable { gate: gate.to_string(), span, attr_span });
}
diff --git a/compiler/rustc_const_eval/src/check_consts/ops.rs b/compiler/rustc_const_eval/src/check_consts/ops.rs
index f47a2ec8f75..0b2024ac51f 100644
--- a/compiler/rustc_const_eval/src/check_consts/ops.rs
+++ b/compiler/rustc_const_eval/src/check_consts/ops.rs
@@ -50,38 +50,16 @@ fn status_in_item(&self, _ccx: &ConstCx<'_, 'tcx>) -> Status {
fn importance(&self) -> DiagImportance {
DiagImportance::Primary
}
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx>;
}
-#[derive(Debug)]
-pub struct FloatingPointOp;
-impl<'tcx> NonConstOp<'tcx> for FloatingPointOp {
- fn status_in_item(&self, ccx: &ConstCx<'_, 'tcx>) -> Status {
- if ccx.const_kind() == hir::ConstContext::ConstFn {
- Status::Unstable(sym::const_fn_floating_point_arithmetic)
- } else {
- Status::Allowed
- }
- }
-
- #[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
- fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
- feature_err(
- &ccx.tcx.sess,
- sym::const_fn_floating_point_arithmetic,
- span,
- format!("floating point arithmetic is not allowed in {}s", ccx.const_kind()),
- )
- }
-}
-
/// A function call where the callee is a pointer.
#[derive(Debug)]
pub struct FnCallIndirect;
impl<'tcx> NonConstOp<'tcx> for FnCallIndirect {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
ccx.dcx().create_err(errors::UnallowedFnPointerCall { span, kind: ccx.const_kind() })
}
}
diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs
index 689e2d2771e..63d6b4a07f0 100644
--- a/compiler/rustc_feature/src/accepted.rs
+++ b/compiler/rustc_feature/src/accepted.rs
@@ -108,16 +108,18 @@ macro_rules! declare_features {
/// Allows use of the `#[collapse_debuginfo]` attribute.
(accepted, collapse_debuginfo, "1.79.0", Some(100758)),
/// Allows usage of the `compile_error!` macro.
(accepted, compile_error, "1.20.0", Some(40872)),
/// Allows `impl Trait` in function return types.
(accepted, conservative_impl_trait, "1.26.0", Some(34511)),
/// Allows calling constructor functions in `const fn`.
(accepted, const_constructor, "1.40.0", Some(61456)),
+ /// Allows basic arithmetic on floating point types in a `const fn`.
+ (accepted, const_fn_floating_point_arithmetic, "CURRENT_RUSTC_VERSION", Some(57241)),
/// Allows using and casting function pointers in a `const fn`.
(accepted, const_fn_fn_ptr_basics, "1.61.0", Some(57563)),
/// Allows trait bounds in `const fn`.
(accepted, const_fn_trait_bound, "1.61.0", Some(93706)),
/// Allows calling `transmute` in const fn
(accepted, const_fn_transmute, "1.56.0", Some(53605)),
/// Allows accessing fields of unions inside `const` functions.
(accepted, const_fn_union, "1.56.0", Some(51909)),
diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs
index a3dfd44a094..45be9097fe0 100644
--- a/compiler/rustc_feature/src/unstable.rs
+++ b/compiler/rustc_feature/src/unstable.rs
@@ -397,18 +397,16 @@ pub fn internal(&self, feature: Symbol) -> bool {
/// Allows to use the `#[cmse_nonsecure_entry]` attribute.
(unstable, cmse_nonsecure_entry, "1.48.0", Some(75835)),
/// Allows `async {}` expressions in const contexts.
(unstable, const_async_blocks, "1.53.0", Some(85368)),
/// Allows `const || {}` closures in const contexts.
(incomplete, const_closures, "1.68.0", Some(106003)),
/// Allows the definition of `const extern fn` and `const unsafe extern fn`.
(unstable, const_extern_fn, "1.40.0", Some(64926)),
- /// Allows basic arithmetic on floating point types in a `const fn`.
- (unstable, const_fn_floating_point_arithmetic, "1.48.0", Some(57241)),
/// Allows `for _ in _` loops in const contexts.
(unstable, const_for, "1.56.0", Some(87575)),
/// Allows using `&mut` in constant functions.
(unstable, const_mut_refs, "1.41.0", Some(57349)),
/// Be more precise when looking for live drops in a const context.
(unstable, const_precise_live_drops, "1.46.0", Some(73255)),
/// Allows references to types with interior mutability within constants
(unstable, const_refs_to_cell, "1.51.0", Some(80384)),
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs
index e74900ff747..8746d68e810 100644
--- a/library/core/src/lib.rs
+++ b/library/core/src/lib.rs
@@ -187,26 +187,26 @@
#![feature(unchecked_shifts)]
#![feature(utf16_extra)]
#![feature(utf16_extra_const)]
#![feature(variant_count)]
// tidy-alphabetical-end
//
// Language features:
// tidy-alphabetical-start
+#![cfg_attr(bootstrap, feature(const_fn_floating_point_arithmetic))]
#![feature(abi_unadjusted)]
#![feature(adt_const_params)]
#![feature(allow_internal_unsafe)]
#![feature(allow_internal_unstable)]
#![feature(asm_const)]
#![feature(auto_traits)]
#![feature(cfg_sanitize)]
#![feature(cfg_target_has_atomic)]
#![feature(cfg_target_has_atomic_equal_alignment)]
-#![feature(const_fn_floating_point_arithmetic)]
#![feature(const_for)]
#![feature(const_mut_refs)]
#![feature(const_precise_live_drops)]
#![feature(const_refs_to_cell)]
#![feature(decl_macro)]
#![feature(deprecated_suggestion)]
#![feature(doc_cfg)]
#![feature(doc_cfg_hide)]
diff --git a/src/tools/clippy/tests/ui/floating_point_abs.fixed b/src/tools/clippy/tests/ui/floating_point_abs.fixed
index 5312a8b29c6..33183c76972 100644
--- a/src/tools/clippy/tests/ui/floating_point_abs.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_abs.fixed
@@ -1,9 +1,8 @@
-#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]
/// Allow suboptimal ops in constant context
pub const fn in_const_context(num: f64) -> f64 {
if num >= 0.0 { num } else { -num }
}
struct A {
diff --git a/src/tools/clippy/tests/ui/floating_point_abs.rs b/src/tools/clippy/tests/ui/floating_point_abs.rs
index 8619177130c..a08d5bbcef5 100644
--- a/src/tools/clippy/tests/ui/floating_point_abs.rs
+++ b/src/tools/clippy/tests/ui/floating_point_abs.rs
@@ -1,9 +1,8 @@
-#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]
/// Allow suboptimal ops in constant context
pub const fn in_const_context(num: f64) -> f64 {
if num >= 0.0 { num } else { -num }
}
struct A {
diff --git a/src/tools/clippy/tests/ui/floating_point_abs.stderr b/src/tools/clippy/tests/ui/floating_point_abs.stderr
index f5a778c5b76..0c1f68f3b7f 100644
--- a/src/tools/clippy/tests/ui/floating_point_abs.stderr
+++ b/src/tools/clippy/tests/ui/floating_point_abs.stderr
@@ -1,53 +1,53 @@
error: manual implementation of `abs` method
- --> tests/ui/floating_point_abs.rs:15:5
+ --> tests/ui/floating_point_abs.rs:14:5
|
LL | if num >= 0.0 { num } else { -num }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()`
|
= note: `-D clippy::suboptimal-flops` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]`
error: manual implementation of `abs` method
- --> tests/ui/floating_point_abs.rs:19:5
+ --> tests/ui/floating_point_abs.rs:18:5
|
LL | if 0.0 < num { num } else { -num }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()`
error: manual implementation of `abs` method
- --> tests/ui/floating_point_abs.rs:23:5
+ --> tests/ui/floating_point_abs.rs:22:5
|
LL | if a.a > 0.0 { a.a } else { -a.a }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()`
error: manual implementation of `abs` method
- --> tests/ui/floating_point_abs.rs:27:5
+ --> tests/ui/floating_point_abs.rs:26:5
|
LL | if 0.0 >= num { -num } else { num }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()`
error: manual implementation of `abs` method
- --> tests/ui/floating_point_abs.rs:31:5
+ --> tests/ui/floating_point_abs.rs:30:5
|
LL | if a.a < 0.0 { -a.a } else { a.a }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()`
error: manual implementation of negation of `abs` method
- --> tests/ui/floating_point_abs.rs:35:5
+ --> tests/ui/floating_point_abs.rs:34:5
|
LL | if num < 0.0 { num } else { -num }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()`
error: manual implementation of negation of `abs` method
- --> tests/ui/floating_point_abs.rs:39:5
+ --> tests/ui/floating_point_abs.rs:38:5
|
LL | if 0.0 >= num { num } else { -num }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()`
error: manual implementation of negation of `abs` method
- --> tests/ui/floating_point_abs.rs:44:12
+ --> tests/ui/floating_point_abs.rs:43:12
|
LL | a: if a.a >= 0.0 { -a.a } else { a.a },
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-a.a.abs()`
error: aborting due to 8 previous errors
diff --git a/src/tools/clippy/tests/ui/floating_point_mul_add.fixed b/src/tools/clippy/tests/ui/floating_point_mul_add.fixed
index 3ce2edf2c71..164aac2601a 100644
--- a/src/tools/clippy/tests/ui/floating_point_mul_add.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_mul_add.fixed
@@ -1,9 +1,8 @@
-#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]
/// Allow suboptimal_ops in constant context
pub const fn in_const_context() {
let a: f64 = 1234.567;
let b: f64 = 45.67834;
let c: f64 = 0.0004;
diff --git a/src/tools/clippy/tests/ui/floating_point_mul_add.rs b/src/tools/clippy/tests/ui/floating_point_mul_add.rs
index b5e4a8db4db..ae024b7f224 100644
--- a/src/tools/clippy/tests/ui/floating_point_mul_add.rs
+++ b/src/tools/clippy/tests/ui/floating_point_mul_add.rs
@@ -1,9 +1,8 @@
-#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]
/// Allow suboptimal_ops in constant context
pub const fn in_const_context() {
let a: f64 = 1234.567;
let b: f64 = 45.67834;
let c: f64 = 0.0004;
diff --git a/src/tools/clippy/tests/ui/floating_point_mul_add.stderr b/src/tools/clippy/tests/ui/floating_point_mul_add.stderr
index 3e1a071de73..9c75909f715 100644
--- a/src/tools/clippy/tests/ui/floating_point_mul_add.stderr
+++ b/src/tools/clippy/tests/ui/floating_point_mul_add.stderr
@@ -1,83 +1,83 @@
error: multiply and add expressions can be calculated more efficiently and accurately
- --> tests/ui/floating_point_mul_add.rs:20:13
+ --> tests/ui/floating_point_mul_add.rs:19:13
|
LL | let _ = a * b + c;
| ^^^^^^^^^ help: consider using: `a.mul_add(b, c)`
|
= note: `-D clippy::suboptimal-flops` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> tests/ui/floating_point_mul_add.rs:21:13
+ --> tests/ui/floating_point_mul_add.rs:20:13
|
LL | let _ = a * b - c;
| ^^^^^^^^^ help: consider using: `a.mul_add(b, -c)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> tests/ui/floating_point_mul_add.rs:22:13
+ --> tests/ui/floating_point_mul_add.rs:21:13
|
LL | let _ = c + a * b;
| ^^^^^^^^^ help: consider using: `a.mul_add(b, c)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> tests/ui/floating_point_mul_add.rs:23:13
+ --> tests/ui/floating_point_mul_add.rs:22:13
|
LL | let _ = c - a * b;
| ^^^^^^^^^ help: consider using: `a.mul_add(-b, c)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> tests/ui/floating_point_mul_add.rs:24:13
+ --> tests/ui/floating_point_mul_add.rs:23:13
|
LL | let _ = a + 2.0 * 4.0;
| ^^^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(4.0, a)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> tests/ui/floating_point_mul_add.rs:25:13
+ --> tests/ui/floating_point_mul_add.rs:24:13
|
LL | let _ = a + 2. * 4.;
| ^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(4., a)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> tests/ui/floating_point_mul_add.rs:27:13
+ --> tests/ui/floating_point_mul_add.rs:26:13
|
LL | let _ = (a * b) + c;
| ^^^^^^^^^^^ help: consider using: `a.mul_add(b, c)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> tests/ui/floating_point_mul_add.rs:28:13
+ --> tests/ui/floating_point_mul_add.rs:27:13
|
LL | let _ = c + (a * b);
| ^^^^^^^^^^^ help: consider using: `a.mul_add(b, c)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> tests/ui/floating_point_mul_add.rs:29:13
+ --> tests/ui/floating_point_mul_add.rs:28:13
|
LL | let _ = a * b * c + d;
| ^^^^^^^^^^^^^ help: consider using: `(a * b).mul_add(c, d)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> tests/ui/floating_point_mul_add.rs:31:13
+ --> tests/ui/floating_point_mul_add.rs:30:13
|
LL | let _ = a.mul_add(b, c) * a.mul_add(b, c) + a.mul_add(b, c) + c;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `a.mul_add(b, c).mul_add(a.mul_add(b, c), a.mul_add(b, c))`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> tests/ui/floating_point_mul_add.rs:32:13
+ --> tests/ui/floating_point_mul_add.rs:31:13
|
LL | let _ = 1234.567_f64 * 45.67834_f64 + 0.0004_f64;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1234.567_f64.mul_add(45.67834_f64, 0.0004_f64)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> tests/ui/floating_point_mul_add.rs:34:13
+ --> tests/ui/floating_point_mul_add.rs:33:13
|
LL | let _ = (a * a + b).sqrt();
| ^^^^^^^^^^^ help: consider using: `a.mul_add(a, b)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> tests/ui/floating_point_mul_add.rs:37:13
+ --> tests/ui/floating_point_mul_add.rs:36:13
|
LL | let _ = a - (b * u as f64);
| ^^^^^^^^^^^^^^^^^^ help: consider using: `b.mul_add(-(u as f64), a)`
error: aborting due to 13 previous errors
diff --git a/src/tools/clippy/tests/ui/floating_point_rad.fixed b/src/tools/clippy/tests/ui/floating_point_rad.fixed
index a710bd9bd60..2f93d233cb4 100644
--- a/src/tools/clippy/tests/ui/floating_point_rad.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_rad.fixed
@@ -1,9 +1,8 @@
-#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]
/// Allow suboptimal_flops in constant context
pub const fn const_context() {
let x = 3f32;
let _ = x * 180f32 / std::f32::consts::PI;
}
diff --git a/src/tools/clippy/tests/ui/floating_point_rad.rs b/src/tools/clippy/tests/ui/floating_point_rad.rs
index 14656f021df..9690effc4e1 100644
--- a/src/tools/clippy/tests/ui/floating_point_rad.rs
+++ b/src/tools/clippy/tests/ui/floating_point_rad.rs
@@ -1,9 +1,8 @@
-#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]
/// Allow suboptimal_flops in constant context
pub const fn const_context() {
let x = 3f32;
let _ = x * 180f32 / std::f32::consts::PI;
}
diff --git a/src/tools/clippy/tests/ui/floating_point_rad.stderr b/src/tools/clippy/tests/ui/floating_point_rad.stderr
index 64674342c2b..b834f5374e0 100644
--- a/src/tools/clippy/tests/ui/floating_point_rad.stderr
+++ b/src/tools/clippy/tests/ui/floating_point_rad.stderr
@@ -1,53 +1,53 @@
error: conversion to radians can be done more accurately
- --> tests/ui/floating_point_rad.rs:11:13
+ --> tests/ui/floating_point_rad.rs:10:13
|
LL | let _ = degrees as f64 * std::f64::consts::PI / 180.0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(degrees as f64).to_radians()`
|
= note: `-D clippy::suboptimal-flops` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]`
error: conversion to degrees can be done more accurately
- --> tests/ui/floating_point_rad.rs:12:13
+ --> tests/ui/floating_point_rad.rs:11:13
|
LL | let _ = degrees as f64 * 180.0 / std::f64::consts::PI;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(degrees as f64).to_degrees()`
error: conversion to degrees can be done more accurately
- --> tests/ui/floating_point_rad.rs:17:13
+ --> tests/ui/floating_point_rad.rs:16:13
|
LL | let _ = x * 180f32 / std::f32::consts::PI;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_degrees()`
error: conversion to degrees can be done more accurately
- --> tests/ui/floating_point_rad.rs:18:13
+ --> tests/ui/floating_point_rad.rs:17:13
|
LL | let _ = 90. * 180f64 / std::f64::consts::PI;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.0_f64.to_degrees()`
error: conversion to degrees can be done more accurately
- --> tests/ui/floating_point_rad.rs:19:13
+ --> tests/ui/floating_point_rad.rs:18:13
|
LL | let _ = 90.5 * 180f64 / std::f64::consts::PI;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.5_f64.to_degrees()`
error: conversion to radians can be done more accurately
- --> tests/ui/floating_point_rad.rs:20:13
+ --> tests/ui/floating_point_rad.rs:19:13
|
LL | let _ = x * std::f32::consts::PI / 180f32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_radians()`
error: conversion to radians can be done more accurately
- --> tests/ui/floating_point_rad.rs:21:13
+ --> tests/ui/floating_point_rad.rs:20:13
|
LL | let _ = 90. * std::f32::consts::PI / 180f32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.0_f64.to_radians()`
error: conversion to radians can be done more accurately
- --> tests/ui/floating_point_rad.rs:22:13
+ --> tests/ui/floating_point_rad.rs:21:13
|
LL | let _ = 90.5 * std::f32::consts::PI / 180f32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.5_f64.to_radians()`
error: aborting due to 8 previous errors
diff --git a/tests/ui/consts/const-extern-fn/const-extern-fn-min-const-fn.rs b/tests/ui/consts/const-extern-fn/const-extern-fn-min-const-fn.rs
index c7078e46fa6..efc0a1c2fba 100644
--- a/tests/ui/consts/const-extern-fn/const-extern-fn-min-const-fn.rs
+++ b/tests/ui/consts/const-extern-fn/const-extern-fn-min-const-fn.rs
@@ -1,11 +1,7 @@
#![feature(const_extern_fn)]
-const extern "C" fn unsize(x: &[u8; 3]) -> &[u8] { x }
-const unsafe extern "C" fn closure() -> fn() { || {} }
-const unsafe extern "C" fn use_float() { 1.0 + 1.0; }
-//~^ ERROR floating point arithmetic
const extern "C" fn ptr_cast(val: *const u8) { val as usize; }
//~^ ERROR pointers cannot be cast to integers
fn main() {}
diff --git a/tests/ui/consts/const-extern-fn/const-extern-fn-min-const-fn.stderr b/tests/ui/consts/const-extern-fn/const-extern-fn-min-const-fn.stderr
index 29fa90d611c..9cdeec159be 100644
--- a/tests/ui/consts/const-extern-fn/const-extern-fn-min-const-fn.stderr
+++ b/tests/ui/consts/const-extern-fn/const-extern-fn-min-const-fn.stderr
@@ -1,22 +1,11 @@
-error[E0658]: floating point arithmetic is not allowed in constant functions
- --> $DIR/const-extern-fn-min-const-fn.rs:5:42
- |
-LL | const unsafe extern "C" fn use_float() { 1.0 + 1.0; }
- | ^^^^^^^^^
- |
- = note: see issue #57241 <https://github.com/rust-lang/rust/issues/57241> for more information
- = help: add `#![feature(const_fn_floating_point_arithmetic)]` 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: pointers cannot be cast to integers during const eval
- --> $DIR/const-extern-fn-min-const-fn.rs:7:48
+ --> $DIR/const-extern-fn-min-const-fn.rs:3:48
|
LL | const extern "C" fn ptr_cast(val: *const u8) { val as usize; }
| ^^^^^^^^^^^^
|
= note: at compile-time, pointers do not have an integer value
= note: avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior
-error: aborting due to 2 previous errors
+error: aborting due to 1 previous error
-For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/consts/const-extern-fn/const-extern-fn.rs b/tests/ui/consts/const-extern-fn/const-extern-fn.rs
index 57f5da8d0af..4b164767064 100644
--- a/tests/ui/consts/const-extern-fn/const-extern-fn.rs
+++ b/tests/ui/consts/const-extern-fn/const-extern-fn.rs
@@ -12,24 +12,41 @@
const unsafe extern "C" fn bar1(val: bool) -> bool {
!val
}
const unsafe extern "C" fn bar2(val: bool) -> bool {
!val
}
+#[allow(improper_ctypes_definitions)]
+const extern "C" fn unsize(x: &[u8; 3]) -> &[u8] {
+ x
+}
+
+#[allow(improper_ctypes_definitions)]
+const unsafe extern "C" fn closure() -> fn() {
+ || {}
+}
+
+const unsafe extern "C" fn use_float() -> f32 {
+ 1.0 + 1.0
+}
fn main() {
let a: [u8; foo1(25) as usize] = [0; 26];
let b: [u8; foo2(25) as usize] = [0; 26];
assert_eq!(a, b);
let bar1_res = unsafe { bar1(false) };
let bar2_res = unsafe { bar2(false) };
assert!(bar1_res);
assert_eq!(bar1_res, bar2_res);
let _foo1_cast: extern "C" fn(u8) -> u8 = foo1;
let _foo2_cast: extern "C" fn(u8) -> u8 = foo2;
let _bar1_cast: unsafe extern "C" fn(bool) -> bool = bar1;
let _bar2_cast: unsafe extern "C" fn(bool) -> bool = bar2;
+
+ unsize(&[0, 1, 2]);
+ unsafe { closure(); }
+ unsafe { use_float(); }
}
diff --git a/tests/ui/consts/const_fn_floating_point_arithmetic.gated.stderr b/tests/ui/consts/const_fn_floating_point_arithmetic.gated.stderr
deleted file mode 100644
index e1b8154a287..00000000000
--- a/tests/ui/consts/const_fn_floating_point_arithmetic.gated.stderr
+++ /dev/null
@@ -1,8 +0,0 @@
-error: fatal error triggered by #[rustc_error]
- --> $DIR/const_fn_floating_point_arithmetic.rs:20:1
- |
-LL | fn main() {}
- | ^^^^^^^^^
-
-error: aborting due to 1 previous error
-
diff --git a/tests/ui/consts/const_fn_floating_point_arithmetic.rs b/tests/ui/consts/const_fn_floating_point_arithmetic.rs
deleted file mode 100644
index b0d0bc6b9f4..00000000000
--- a/tests/ui/consts/const_fn_floating_point_arithmetic.rs
+++ /dev/null
@@ -1,20 +0,0 @@
-// gate-test-const_fn_floating_point_arithmetic
-
-//@ revisions: stock gated
-
-#![feature(rustc_attrs)]
-#![cfg_attr(gated, feature(const_fn_floating_point_arithmetic))]
-
-const fn add(f: f32) -> f32 { f + 2.0 }
-//[stock]~^ floating point arithmetic
-const fn sub(f: f32) -> f32 { 2.0 - f }
-//[stock]~^ floating point arithmetic
-const fn mul(f: f32, g: f32) -> f32 { f * g }
-//[stock]~^ floating point arithmetic
-const fn div(f: f32, g: f32) -> f32 { f / g }
-//[stock]~^ floating point arithmetic
-const fn neg(f: f32) -> f32 { -f }
-//[stock]~^ floating point arithmetic
-
-#[rustc_error]
-fn main() {} //[gated]~ fatal error triggered by #[rustc_error]
diff --git a/tests/ui/consts/const_fn_floating_point_arithmetic.stock.stderr b/tests/ui/consts/const_fn_floating_point_arithmetic.stock.stderr
deleted file mode 100644
index b5b94786ebb..00000000000
--- a/tests/ui/consts/const_fn_floating_point_arithmetic.stock.stderr
+++ /dev/null
@@ -1,53 +0,0 @@
-error[E0658]: floating point arithmetic is not allowed in constant functions
- --> $DIR/const_fn_floating_point_arithmetic.rs:8:31
- |
-LL | const fn add(f: f32) -> f32 { f + 2.0 }
- | ^^^^^^^
- |
- = note: see issue #57241 <https://github.com/rust-lang/rust/issues/57241> for more information
- = help: add `#![feature(const_fn_floating_point_arithmetic)]` 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]: floating point arithmetic is not allowed in constant functions
- --> $DIR/const_fn_floating_point_arithmetic.rs:10:31
- |
-LL | const fn sub(f: f32) -> f32 { 2.0 - f }
- | ^^^^^^^
- |
- = note: see issue #57241 <https://github.com/rust-lang/rust/issues/57241> for more information
- = help: add `#![feature(const_fn_floating_point_arithmetic)]` 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]: floating point arithmetic is not allowed in constant functions
- --> $DIR/const_fn_floating_point_arithmetic.rs:12:39
- |
-LL | const fn mul(f: f32, g: f32) -> f32 { f * g }
- | ^^^^^
- |
- = note: see issue #57241 <https://github.com/rust-lang/rust/issues/57241> for more information
- = help: add `#![feature(const_fn_floating_point_arithmetic)]` 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]: floating point arithmetic is not allowed in constant functions
- --> $DIR/const_fn_floating_point_arithmetic.rs:14:39
- |
-LL | const fn div(f: f32, g: f32) -> f32 { f / g }
- | ^^^^^
- |
- = note: see issue #57241 <https://github.com/rust-lang/rust/issues/57241> for more information
- = help: add `#![feature(const_fn_floating_point_arithmetic)]` 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]: floating point arithmetic is not allowed in constant functions
- --> $DIR/const_fn_floating_point_arithmetic.rs:16:31
- |
-LL | const fn neg(f: f32) -> f32 { -f }
- | ^^
- |
- = note: see issue #57241 <https://github.com/rust-lang/rust/issues/57241> for more information
- = help: add `#![feature(const_fn_floating_point_arithmetic)]` 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 5 previous errors
-
-For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/consts/const_let_eq_float.rs b/tests/ui/consts/const_let_eq_float.rs
index 30d839cdc2a..c9ca6b8b7ea 100644
--- a/tests/ui/consts/const_let_eq_float.rs
+++ b/tests/ui/consts/const_let_eq_float.rs
@@ -1,12 +1,10 @@
//@ run-pass
-#![feature(const_fn_floating_point_arithmetic)]
-
struct Foo<T>(T);
struct Bar<T> { x: T }
struct W(f32);
struct A { a: f32 }
#[allow(redundant_semicolons)]
const fn basics((a,): (f32,)) -> f32 {
// Deferred assignment:
diff --git a/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.rs b/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.rs
index bb240fb4ad6..dc653370e51 100644
--- a/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.rs
+++ b/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.rs
@@ -1,14 +1,14 @@
#![unstable(feature = "humans",
reason = "who ever let humans program computers,
we're apparently really bad at it",
issue = "none")]
-#![feature(const_fn_floating_point_arithmetic, foo, foo2)]
+#![feature(const_refs_to_cell, foo, foo2)]
#![feature(staged_api)]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature="foo", issue = "none")]
const fn foo() -> u32 { 42 }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
@@ -20,19 +20,23 @@ const fn foo2() -> u32 { 42 }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
// can't call non-min_const_fn
const fn bar2() -> u32 { foo2() } //~ ERROR not yet stable as a const fn
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
-// Const-stable functions cannot rely on unstable const-eval features.
-const fn bar3() -> u32 { (5f32 + 6f32) as u32 }
-//~^ ERROR const-stable function cannot use `#[feature(const_fn_floating_point_arithmetic)]`
+// conformity is required
+const fn bar3() -> u32 {
+ let x = std::cell::Cell::new(0u32);
+ x.get()
+ //~^ ERROR const-stable function cannot use `#[feature(const_refs_to_cell)]`
+ //~| ERROR cannot call non-const fn
+}
// check whether this function cannot be called even with the feature gate active
#[unstable(feature = "foo2", issue = "none")]
const fn foo2_gated() -> u32 { 42 }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
// can't call non-min_const_fn
diff --git a/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr b/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr
index 7ec2508ca93..e5f8fa25b64 100644
--- a/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr
+++ b/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr
@@ -9,35 +9,44 @@ LL | const fn bar() -> u32 { foo() }
error: `foo2` is not yet stable as a const fn
--> $DIR/min_const_fn_libstd_stability.rs:24:26
|
LL | const fn bar2() -> u32 { foo2() }
| ^^^^^^
|
= help: const-stable functions can only call other const-stable functions
-error: const-stable function cannot use `#[feature(const_fn_floating_point_arithmetic)]`
- --> $DIR/min_const_fn_libstd_stability.rs:29:26
+error: const-stable function cannot use `#[feature(const_refs_to_cell)]`
+ --> $DIR/min_const_fn_libstd_stability.rs:31:5
|
-LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 }
- | ^^^^^^^^^^^^^
+LL | x.get()
+ | ^
|
help: if it is not part of the public API, make this function unstably const
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
-LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 }
+LL | const fn bar3() -> u32 {
|
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)]
-LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 }
+LL + #[rustc_allow_const_fn_unstable(const_refs_to_cell)]
+LL | const fn bar3() -> u32 {
|
+error[E0015]: cannot call non-const fn `Cell::<u32>::get` in constant functions
+ --> $DIR/min_const_fn_libstd_stability.rs:31:7
+ |
+LL | x.get()
+ | ^^^^^
+ |
+ = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
+
error: `foo2_gated` is not yet stable as a const fn
- --> $DIR/min_const_fn_libstd_stability.rs:39:32
+ --> $DIR/min_const_fn_libstd_stability.rs:43:32
|
LL | const fn bar2_gated() -> u32 { foo2_gated() }
| ^^^^^^^^^^^^
|
= help: const-stable functions can only call other const-stable functions
-error: aborting due to 4 previous errors
+error: aborting due to 5 previous errors
+For more information about this error, try `rustc --explain E0015`.
diff --git a/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.rs b/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.rs
index 03084c8674d..f2a54b8a13d 100644
--- a/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.rs
+++ b/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.rs
@@ -1,14 +1,14 @@
#![unstable(feature = "humans",
reason = "who ever let humans program computers,
we're apparently really bad at it",
issue = "none")]
-#![feature(const_fn_floating_point_arithmetic, foo, foo2)]
+#![feature(const_refs_to_cell, foo, foo2)]
#![feature(staged_api)]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature="foo", issue = "none")]
const unsafe fn foo() -> u32 { 42 }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
@@ -18,22 +18,16 @@
#[unstable(feature = "foo2", issue = "none")]
const unsafe fn foo2() -> u32 { 42 }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
// can't call non-min_const_fn
const unsafe fn bar2() -> u32 { unsafe { foo2() } } //~ ERROR not yet stable as a const fn
-#[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
-// conformity is required
-const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 }
-//~^ ERROR const-stable function cannot use `#[feature(const_fn_floating_point_arithmetic)]`
-
// check whether this function cannot be called even with the feature gate active
#[unstable(feature = "foo2", issue = "none")]
const unsafe fn foo2_gated() -> u32 { 42 }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
// can't call non-min_const_fn
const unsafe fn bar2_gated() -> u32 { unsafe { foo2_gated() } }
diff --git a/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr b/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr
index 72c1f175d1d..353b117efbc 100644
--- a/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr
+++ b/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr
@@ -9,35 +9,18 @@ LL | const unsafe fn bar() -> u32 { unsafe { foo() } }
error: `foo2` is not yet stable as a const fn
--> $DIR/min_const_unsafe_fn_libstd_stability.rs:24:42
|
LL | const unsafe fn bar2() -> u32 { unsafe { foo2() } }
| ^^^^^^
|
= help: const-stable functions can only call other const-stable functions
-error: const-stable function cannot use `#[feature(const_fn_floating_point_arithmetic)]`
- --> $DIR/min_const_unsafe_fn_libstd_stability.rs:29:33
- |
-LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 }
- | ^^^^^^^^^^^^^
- |
-help: if it is not part of the public API, make this function unstably const
- |
-LL + #[rustc_const_unstable(feature = "...", issue = "...")]
-LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 }
- |
-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)]
-LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 }
- |
-
error: `foo2_gated` is not yet stable as a const fn
- --> $DIR/min_const_unsafe_fn_libstd_stability.rs:39:48
+ --> $DIR/min_const_unsafe_fn_libstd_stability.rs:33:48
|
LL | const unsafe fn bar2_gated() -> u32 { unsafe { foo2_gated() } }
| ^^^^^^^^^^^^
|
= help: const-stable functions can only call other const-stable functions
-error: aborting due to 4 previous errors
+error: aborting due to 3 previous errors
diff --git a/tests/ui/internal/internal-unstable-const.rs b/tests/ui/internal/internal-unstable-const.rs
deleted file mode 100644
index 4ec2426dfee..00000000000
--- a/tests/ui/internal/internal-unstable-const.rs
+++ /dev/null
@@ -1,13 +0,0 @@
-// Don't allow unstable features in stable functions without `allow_internal_unstable`.
-
-#![stable(feature = "rust1", since = "1.0.0")]
-#![feature(staged_api)]
-#![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() -> f32 {
- 1.0 + 1.0 //~ ERROR const-stable function cannot use `#[feature(const_fn_floating_point_arithmetic)]`
-}
-
-fn main() {}
diff --git a/tests/ui/internal/internal-unstable-const.stderr b/tests/ui/internal/internal-unstable-const.stderr
deleted file mode 100644
index ed9196d2b63..00000000000
--- a/tests/ui/internal/internal-unstable-const.stderr
+++ /dev/null
@@ -1,19 +0,0 @@
-error: const-stable function cannot use `#[feature(const_fn_floating_point_arithmetic)]`
- --> $DIR/internal-unstable-const.rs:10:5
- |
-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 = "...")]
-LL | pub const fn foo() -> f32 {
- |
-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)]
-LL | pub const fn foo() -> f32 {
- |
-
-error: aborting due to 1 previous error
-