]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_mir/src/transform/check_consts/ops.rs
Add `const_fn_floating_point_arithmetic`
[rust.git] / compiler / rustc_mir / src / transform / check_consts / ops.rs
index 496e620dd9df61d10b53e061b1eee67008561b04..1d741085853609e926d7f997f5190b94431a95f0 100644 (file)
@@ -112,6 +112,30 @@ fn emit_error(&self, ccx: &ConstCx<'_, '_>, span: Span) {
     }
 }
 
+#[derive(Debug)]
+pub struct FloatingPointOp;
+impl NonConstOp for FloatingPointOp {
+    const STOPS_CONST_CHECKING: bool = true;
+
+    fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
+        if ccx.const_kind() == hir::ConstContext::ConstFn {
+            Status::Unstable(sym::const_fn_floating_point_arithmetic)
+        } else {
+            Status::Allowed
+        }
+    }
+
+    fn emit_error(&self, ccx: &ConstCx<'_, '_>, span: Span) {
+        feature_err(
+            &ccx.tcx.sess.parse_sess,
+            sym::const_fn_floating_point_arithmetic,
+            span,
+            &format!("floating point arithmetic is not allowed in {}s", ccx.const_kind()),
+        )
+        .emit();
+    }
+}
+
 #[derive(Debug)]
 pub struct NonPrimitiveOp;
 impl NonConstOp for NonPrimitiveOp {