Skip to content

Commit de7d43b

Browse files
committed
make lint description easier to read, prevent ICE
1 parent 7aa4bab commit de7d43b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

clippy_lints/src/large_stack_frames.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::ops::AddAssign;
22

33
use clippy_utils::diagnostics::span_lint_and_note;
4+
use clippy_utils::fn_has_unsatisfiable_preds;
45
use rustc_hir::def_id::LocalDefId;
56
use rustc_hir::intravisit::FnKind;
67
use rustc_hir::Body;
@@ -27,7 +28,7 @@ declare_clippy_lint! {
2728
///
2829
/// Keep in mind that the code path to construction of large types does not even need to be reachable;
2930
/// it purely needs to *exist* inside of the function to contribute to the stack size.
30-
/// For example, this causes a stack overflow even though the branch is unreachable (with `-Zmir-opt-level=0`):
31+
/// For example, this causes a stack overflow even though the branch is unreachable:
3132
/// ```rust,ignore
3233
/// fn main() {
3334
/// if false {
@@ -43,11 +44,9 @@ declare_clippy_lint! {
4344
/// Modern compilers are very smart and are able to optimize away a lot of unnecessary stack allocations.
4445
/// In debug mode however, it is usually more accurate.
4546
///
46-
/// This lint works by summing up the size of all locals and comparing them against a (configurable, but high-by-default)
47-
/// threshold.
48-
/// Note that "locals" in this context refers to [MIR locals](https://rustc-dev-guide.rust-lang.org/mir/index.html#key-mir-vocabulary),
49-
/// i.e. real local variables that the user typed, storage for temporary values, function arguments
50-
/// and the return value.
47+
/// This lint works by summing up the size of all variables that the user typed, variables that were
48+
/// implicitly introduced by the compiler for temporaries, function arguments and the return value,
49+
/// and comparing them against a (configurable, but high-by-default).
5150
///
5251
/// ### Example
5352
/// 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 {
133132
local_def_id: LocalDefId,
134133
) {
135134
let def_id = local_def_id.to_def_id();
135+
// Building MIR for `fn`s with unsatisfiable preds results in ICE.
136+
if fn_has_unsatisfiable_preds(cx, def_id) {
137+
return;
138+
}
136139

137140
let mir = cx.tcx.optimized_mir(def_id);
138141
let param_env = cx.tcx.param_env(def_id);

0 commit comments

Comments
 (0)