1
1
use std:: ops:: AddAssign ;
2
2
3
3
use clippy_utils:: diagnostics:: span_lint_and_note;
4
+ use clippy_utils:: fn_has_unsatisfiable_preds;
4
5
use rustc_hir:: def_id:: LocalDefId ;
5
6
use rustc_hir:: intravisit:: FnKind ;
6
7
use rustc_hir:: Body ;
@@ -27,7 +28,7 @@ declare_clippy_lint! {
27
28
///
28
29
/// Keep in mind that the code path to construction of large types does not even need to be reachable;
29
30
/// 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:
31
32
/// ```rust,ignore
32
33
/// fn main() {
33
34
/// if false {
@@ -43,11 +44,9 @@ declare_clippy_lint! {
43
44
/// Modern compilers are very smart and are able to optimize away a lot of unnecessary stack allocations.
44
45
/// In debug mode however, it is usually more accurate.
45
46
///
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).
51
50
///
52
51
/// ### Example
53
52
/// 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 {
133
132
local_def_id : LocalDefId ,
134
133
) {
135
134
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
+ }
136
139
137
140
let mir = cx. tcx . optimized_mir ( def_id) ;
138
141
let param_env = cx. tcx . param_env ( def_id) ;
0 commit comments