about summary refs log tree commit diff
diff options
context:
space:
mode:
authory21 <30553356+y21@users.noreply.github.com>2023-06-08 12:42:12 +0200
committery21 <30553356+y21@users.noreply.github.com>2023-06-12 12:21:38 +0200
commitde7d43bc610f5f2ac107d947de1c2438401f7a2b (patch)
treeb75317d7175ff5c0db22dd1cfd3bd52602a47d7a
parent7aa4babb5ce26208d49be1c1fc404962d87a721e (diff)
downloadrust-de7d43bc610f5f2ac107d947de1c2438401f7a2b.tar.gz
rust-de7d43bc610f5f2ac107d947de1c2438401f7a2b.zip
make lint description easier to read, prevent ICE
-rw-r--r--clippy_lints/src/large_stack_frames.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/clippy_lints/src/large_stack_frames.rs b/clippy_lints/src/large_stack_frames.rs
index d638279b5d1..9c0cc978a39 100644
--- a/clippy_lints/src/large_stack_frames.rs
+++ b/clippy_lints/src/large_stack_frames.rs
@@ -1,6 +1,7 @@
 use std::ops::AddAssign;
 
 use clippy_utils::diagnostics::span_lint_and_note;
+use clippy_utils::fn_has_unsatisfiable_preds;
 use rustc_hir::def_id::LocalDefId;
 use rustc_hir::intravisit::FnKind;
 use rustc_hir::Body;
@@ -27,7 +28,7 @@ declare_clippy_lint! {
     ///
     /// Keep in mind that the code path to construction of large types does not even need to be reachable;
     /// it purely needs to *exist* inside of the function to contribute to the stack size.
-    /// For example, this causes a stack overflow even though the branch is unreachable (with `-Zmir-opt-level=0`):
+    /// For example, this causes a stack overflow even though the branch is unreachable:
     /// ```rust,ignore
     /// fn main() {
     ///     if false {
@@ -43,11 +44,9 @@ declare_clippy_lint! {
     /// Modern compilers are very smart and are able to optimize away a lot of unnecessary stack allocations.
     /// In debug mode however, it is usually more accurate.
     ///
-    /// This lint works by summing up the size of all locals and comparing them against a (configurable, but high-by-default)
-    /// threshold.
-    /// Note that "locals" in this context refers to [MIR locals](https://rustc-dev-guide.rust-lang.org/mir/index.html#key-mir-vocabulary),
-    /// i.e. real local variables that the user typed, storage for temporary values, function arguments
-    /// and the return value.
+    /// This lint works by summing up the size of all variables that the user typed, variables that were
+    /// implicitly introduced by the compiler for temporaries, function arguments and the return value,
+    /// and comparing them against a (configurable, but high-by-default).
     ///
     /// ### Example
     /// This function creates four 500 KB arrays on the stack. Quite big but just small enough to not trigger `large_stack_arrays`.
@@ -133,6 +132,10 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackFrames {
         local_def_id: LocalDefId,
     ) {
         let def_id = local_def_id.to_def_id();
+        // Building MIR for `fn`s with unsatisfiable preds results in ICE.
+        if fn_has_unsatisfiable_preds(cx, def_id) {
+            return;
+        }
 
         let mir = cx.tcx.optimized_mir(def_id);
         let param_env = cx.tcx.param_env(def_id);