11use std:: ops:: AddAssign ;
22
33use clippy_utils:: diagnostics:: span_lint_and_note;
4+ use clippy_utils:: fn_has_unsatisfiable_preds;
45use rustc_hir:: def_id:: LocalDefId ;
56use rustc_hir:: intravisit:: FnKind ;
67use 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