about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_mir/build/mod.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs
index cc927df6350..054fb5f4581 100644
--- a/src/librustc_mir/build/mod.rs
+++ b/src/librustc_mir/build/mod.rs
@@ -114,11 +114,20 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
                 hir::Unsafety::Normal => Safety::Safe,
                 hir::Unsafety::Unsafe => Safety::FnUnsafe,
             };
-            let safety = if implicit_argument.is_none() && tcx.is_min_const_fn(fn_def_id) {
-                // the body of `const unsafe fn`s is treated like the body of safe `const fn`s
-                Safety::Safe
-            } else {
-                safety
+
+            let safety = match fn_sig.unsafety {
+                hir::Unsafety::Normal => Safety::Safe,
+                hir::Unsafety::Unsafe => {
+                    if tcx.is_min_const_fn(fn_def_id) => {
+                        // As specified in #55607, a `const unsafe fn` differs
+                        // from an `unsafe fn` in that its body is still considered
+                        // safe code by default.
+                        assert!(!implicit_argument.is_none());
+                        Safety::Safe
+                    } else {
+                        Safety::Unsafe
+                    }
+                }
             };
 
             let body = tcx.hir.body(body_id);