]> git.lizzy.rs Git - rust.git/commitdiff
Allow `Abort` terminators in a const-context
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Sat, 3 Oct 2020 21:38:01 +0000 (14:38 -0700)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Sat, 3 Oct 2020 21:38:01 +0000 (14:38 -0700)
These appear along the cleanup path inside functions with
`#[unwind(aborts)]`. We don't const-check the cleanup path anyways,
since const-eval already has "abort-on-panic" semantics and there's
often drops that would otherwise be forbidden, so the check wasn't
really preventing anything anyways.

compiler/rustc_mir/src/transform/check_consts/ops.rs
compiler/rustc_mir/src/transform/check_consts/validation.rs

index 32e233e337da34350a593b7372b17ab8c062b393..9a1b77e994d1350d66b89fe561d28d5a1ab13ac0 100644 (file)
@@ -41,18 +41,6 @@ fn importance(&self) -> DiagnosticImportance {
     fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx>;
 }
 
-#[derive(Debug)]
-pub struct Abort;
-impl NonConstOp for Abort {
-    fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
-        mcf_status_in_item(ccx)
-    }
-
-    fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
-        mcf_build_error(ccx, span, "abort is not stable in const fn")
-    }
-}
-
 #[derive(Debug)]
 pub struct FloatingPointOp;
 impl NonConstOp for FloatingPointOp {
index 4e714bfeed310c582c62b1bac484456bdaa44737..ab78e3d541c3604abcabacb57efee91d408c7696 100644 (file)
@@ -874,13 +874,13 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
             }
 
             TerminatorKind::InlineAsm { .. } => self.check_op(ops::InlineAsm),
-            TerminatorKind::Abort => self.check_op(ops::Abort),
 
             TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => {
                 self.check_op(ops::Generator(hir::GeneratorKind::Gen))
             }
 
-            TerminatorKind::Assert { .. }
+            TerminatorKind::Abort
+            | TerminatorKind::Assert { .. }
             | TerminatorKind::FalseEdge { .. }
             | TerminatorKind::FalseUnwind { .. }
             | TerminatorKind::Goto { .. }