diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2022-02-03 22:20:24 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-03 22:20:24 +0900 |
| commit | 2fe9f763d08cf493896262da0533fd1a3c8ae3dd (patch) | |
| tree | 2a6f4e7f881a372fd1ba43468580d734f56aa66d /compiler/rustc_const_eval | |
| parent | 9298bd8197ebffac1d310ff90f5845a30a512a23 (diff) | |
| parent | 73ad8df70d94d318fea0df3079504bd23e5b4901 (diff) | |
| download | rust-2fe9f763d08cf493896262da0533fd1a3c8ae3dd.tar.gz rust-2fe9f763d08cf493896262da0533fd1a3c8ae3dd.zip | |
Rollup merge of #92802 - compiler-errors:deduplicate-stack-trace, r=oli-obk
Deduplicate lines in long const-eval stack trace Lemme know if this is kinda overkill, lol. Fixes #92796
Diffstat (limited to 'compiler/rustc_const_eval')
| -rw-r--r-- | compiler/rustc_const_eval/src/const_eval/error.rs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/compiler/rustc_const_eval/src/const_eval/error.rs b/compiler/rustc_const_eval/src/const_eval/error.rs index 87298023980..89a0f8245e5 100644 --- a/compiler/rustc_const_eval/src/const_eval/error.rs +++ b/compiler/rustc_const_eval/src/const_eval/error.rs @@ -156,9 +156,37 @@ impl<'tcx> ConstEvalErr<'tcx> { } // Add spans for the stacktrace. Don't print a single-line backtrace though. if self.stacktrace.len() > 1 { + // Helper closure to print duplicated lines. + let mut flush_last_line = |last_frame, times| { + if let Some((line, span)) = last_frame { + err.span_label(span, &line); + // Don't print [... additional calls ...] if the number of lines is small + if times < 3 { + for _ in 0..times { + err.span_label(span, &line); + } + } else { + err.span_label( + span, + format!("[... {} additional calls {} ...]", times, &line), + ); + } + } + }; + + let mut last_frame = None; + let mut times = 0; for frame_info in &self.stacktrace { - err.span_label(frame_info.span, frame_info.to_string()); + let frame = (frame_info.to_string(), frame_info.span); + if last_frame.as_ref() == Some(&frame) { + times += 1; + } else { + flush_last_line(last_frame, times); + last_frame = Some(frame); + times = 0; + } } + flush_last_line(last_frame, times); } // Let the caller finish the job. emit(err) |
