about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform
diff options
context:
space:
mode:
authorDavid Wood <david.wood2@arm.com>2024-12-12 15:58:10 +0000
committerDavid Wood <david.wood2@arm.com>2025-01-10 18:37:56 +0000
commit5f316f5e0025ffa9ed31e01becf549fd73e61ed4 (patch)
treea4c3d7be0b9d256a15066c5311a42ea2347734b0 /compiler/rustc_mir_transform
parent90066c0df3a564db756d9f7bd20a565f4675e267 (diff)
downloadrust-5f316f5e0025ffa9ed31e01becf549fd73e61ed4.tar.gz
rust-5f316f5e0025ffa9ed31e01becf549fd73e61ed4.zip
validator: move force inline check
Diffstat (limited to 'compiler/rustc_mir_transform')
-rw-r--r--compiler/rustc_mir_transform/src/validate.rs33
1 files changed, 10 insertions, 23 deletions
diff --git a/compiler/rustc_mir_transform/src/validate.rs b/compiler/rustc_mir_transform/src/validate.rs
index 9444c5b61dd..035670d4903 100644
--- a/compiler/rustc_mir_transform/src/validate.rs
+++ b/compiler/rustc_mir_transform/src/validate.rs
@@ -80,7 +80,7 @@ impl<'tcx> crate::MirPass<'tcx> for Validator {
             cfg_checker.fail(location, msg);
         }
 
-        if let MirPhase::Runtime(phase) = body.phase {
+        if let MirPhase::Runtime(_) = body.phase {
             if let ty::InstanceKind::Item(_) = body.source.instance {
                 if body.has_free_regions() {
                     cfg_checker.fail(
@@ -89,27 +89,6 @@ impl<'tcx> crate::MirPass<'tcx> for Validator {
                     );
                 }
             }
-
-            if phase >= RuntimePhase::Optimized
-                && body
-                    .basic_blocks
-                    .iter()
-                    .filter_map(|bb| match &bb.terminator().kind {
-                        TerminatorKind::Call { func, .. }
-                        | TerminatorKind::TailCall { func, .. } => Some(func),
-                        _ => None,
-                    })
-                    .filter_map(|func| match func.ty(&body.local_decls, tcx).kind() {
-                        ty::FnDef(did, ..) => Some(did),
-                        _ => None,
-                    })
-                    .any(|did| matches!(tcx.codegen_fn_attrs(did).inline, InlineAttr::Force { .. }))
-            {
-                cfg_checker.fail(
-                    Location::START,
-                    "`#[rustc_force_inline]`-annotated function not inlined",
-                );
-            }
         }
     }
 }
@@ -388,7 +367,8 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
                 self.check_edge(location, *target, EdgeKind::Normal);
                 self.check_unwind_edge(location, *unwind);
             }
-            TerminatorKind::Call { args, .. } | TerminatorKind::TailCall { args, .. } => {
+            TerminatorKind::Call { func, args, .. }
+            | TerminatorKind::TailCall { func, args, .. } => {
                 // FIXME(explicit_tail_calls): refactor this & add tail-call specific checks
                 if let TerminatorKind::Call { target, unwind, destination, .. } = terminator.kind {
                     if let Some(target) = target {
@@ -441,6 +421,13 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
                         }
                     }
                 }
+
+                if let ty::FnDef(did, ..) = func.ty(&self.body.local_decls, self.tcx).kind()
+                    && self.body.phase >= MirPhase::Runtime(RuntimePhase::Optimized)
+                    && matches!(self.tcx.codegen_fn_attrs(did).inline, InlineAttr::Force { .. })
+                {
+                    self.fail(location, "`#[rustc_force_inline]`-annotated function not inlined");
+                }
             }
             TerminatorKind::Assert { target, unwind, .. } => {
                 self.check_edge(location, *target, EdgeKind::Normal);