about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWaffle Lapkin <waffle.lapkin@gmail.com>2024-05-18 00:00:12 +0200
committerWaffle Lapkin <waffle.lapkin@gmail.com>2024-05-18 00:01:32 +0200
commit956e5c18b9589d6f2e9445f28ff407f9f99efcb7 (patch)
treeb11a1de8815588c23bec99bf08c0bb9cecf7a9af
parent1a7397988684934ae01a71f524bdfff24895d8cc (diff)
downloadrust-956e5c18b9589d6f2e9445f28ff407f9f99efcb7.tar.gz
rust-956e5c18b9589d6f2e9445f28ff407f9f99efcb7.zip
Move `lint_never_type_fallback_flowing_into_unsafe_code` into a separate fn
-rw-r--r--compiler/rustc_hir_typeck/src/fallback.rs75
1 files changed, 40 insertions, 35 deletions
diff --git a/compiler/rustc_hir_typeck/src/fallback.rs b/compiler/rustc_hir_typeck/src/fallback.rs
index c79b6be6560..8adc72e6d9d 100644
--- a/compiler/rustc_hir_typeck/src/fallback.rs
+++ b/compiler/rustc_hir_typeck/src/fallback.rs
@@ -364,41 +364,11 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
             };
 
             let mut fallback_to = |ty| {
-                let unsafe_infer_vars = unsafe_infer_vars.get_or_init(|| {
-                    let unsafe_infer_vars = compute_unsafe_infer_vars(self.root_ctxt, self.body_id);
-                    debug!(?unsafe_infer_vars);
-                    unsafe_infer_vars
-                });
-
-                let affected_unsafe_infer_vars =
-                    graph::depth_first_search_as_undirected(&coercion_graph, root_vid)
-                        .filter_map(|x| unsafe_infer_vars.get(&x).copied())
-                        .collect::<Vec<_>>();
-
-                for (hir_id, span, reason) in affected_unsafe_infer_vars {
-                    self.tcx.emit_node_span_lint(
-                        lint::builtin::NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
-                        hir_id,
-                        span,
-                        match reason {
-                            UnsafeUseReason::Call => {
-                                errors::NeverTypeFallbackFlowingIntoUnsafe::Call
-                            }
-                            UnsafeUseReason::Method => {
-                                errors::NeverTypeFallbackFlowingIntoUnsafe::Method
-                            }
-                            UnsafeUseReason::Path => {
-                                errors::NeverTypeFallbackFlowingIntoUnsafe::Path
-                            }
-                            UnsafeUseReason::UnionField => {
-                                errors::NeverTypeFallbackFlowingIntoUnsafe::UnionField
-                            }
-                            UnsafeUseReason::Deref => {
-                                errors::NeverTypeFallbackFlowingIntoUnsafe::Deref
-                            }
-                        },
-                    );
-                }
+                self.lint_never_type_fallback_flowing_into_unsafe_code(
+                    &unsafe_infer_vars,
+                    &coercion_graph,
+                    root_vid,
+                );
 
                 diverging_fallback.insert(diverging_ty, ty);
             };
@@ -464,6 +434,41 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
         diverging_fallback
     }
 
+    fn lint_never_type_fallback_flowing_into_unsafe_code(
+        &self,
+        unsafe_infer_vars: &OnceCell<UnordMap<ty::TyVid, (HirId, Span, UnsafeUseReason)>>,
+        coercion_graph: &VecGraph<ty::TyVid, true>,
+        root_vid: ty::TyVid,
+    ) {
+        let unsafe_infer_vars = unsafe_infer_vars.get_or_init(|| {
+            let unsafe_infer_vars = compute_unsafe_infer_vars(self.root_ctxt, self.body_id);
+            debug!(?unsafe_infer_vars);
+            unsafe_infer_vars
+        });
+
+        let affected_unsafe_infer_vars =
+            graph::depth_first_search_as_undirected(&coercion_graph, root_vid)
+                .filter_map(|x| unsafe_infer_vars.get(&x).copied())
+                .collect::<Vec<_>>();
+
+        for (hir_id, span, reason) in affected_unsafe_infer_vars {
+            self.tcx.emit_node_span_lint(
+                lint::builtin::NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
+                hir_id,
+                span,
+                match reason {
+                    UnsafeUseReason::Call => errors::NeverTypeFallbackFlowingIntoUnsafe::Call,
+                    UnsafeUseReason::Method => errors::NeverTypeFallbackFlowingIntoUnsafe::Method,
+                    UnsafeUseReason::Path => errors::NeverTypeFallbackFlowingIntoUnsafe::Path,
+                    UnsafeUseReason::UnionField => {
+                        errors::NeverTypeFallbackFlowingIntoUnsafe::UnionField
+                    }
+                    UnsafeUseReason::Deref => errors::NeverTypeFallbackFlowingIntoUnsafe::Deref,
+                },
+            );
+        }
+    }
+
     /// Returns a graph whose nodes are (unresolved) inference variables and where
     /// an edge `?A -> ?B` indicates that the variable `?A` is coerced to `?B`.
     fn create_coercion_graph(&self) -> VecGraph<ty::TyVid, true> {