1
1
use std:: mem;
2
2
3
+ use rustc_data_structures:: fx:: FxHashSet ;
3
4
use rustc_errors:: { DiagArgName , DiagArgValue , DiagMessage , Diagnostic , IntoDiagArg } ;
4
5
use rustc_middle:: mir:: AssertKind ;
5
6
use rustc_middle:: mir:: interpret:: { Provenance , ReportedErrorInfo } ;
@@ -9,7 +10,7 @@ use rustc_middle::ty::{ConstInt, TyCtxt};
9
10
use rustc_span:: { Span , Symbol } ;
10
11
11
12
use super :: CompileTimeMachine ;
12
- use crate :: errors:: { self , FrameNote , ReportErrorExt } ;
13
+ use crate :: errors:: { FrameNote , ReportErrorExt } ;
13
14
use crate :: interpret:: {
14
15
ErrorHandled , Frame , InterpErrorInfo , InterpErrorKind , MachineStopType , err_inval,
15
16
err_machine_stop,
@@ -68,7 +69,7 @@ impl<'tcx> Into<InterpErrorInfo<'tcx>> for ConstEvalErrKind {
68
69
pub fn get_span_and_frames < ' tcx > (
69
70
tcx : TyCtxtAt < ' tcx > ,
70
71
stack : & [ Frame < ' tcx , impl Provenance , impl Sized > ] ,
71
- ) -> ( Span , Vec < errors :: FrameNote > ) {
72
+ ) -> ( Span , Vec < FrameNote > ) {
72
73
let mut stacktrace = Frame :: generate_stacktrace_from_stack ( stack) ;
73
74
// Filter out `requires_caller_location` frames.
74
75
stacktrace. retain ( |frame| !frame. instance . def . requires_caller_location ( * tcx) ) ;
@@ -79,8 +80,8 @@ pub fn get_span_and_frames<'tcx>(
79
80
// Add notes to the backtrace. Don't print a single-line backtrace though.
80
81
if stacktrace. len ( ) > 1 {
81
82
// Helper closure to print duplicated lines.
82
- let mut add_frame = |mut frame : errors :: FrameNote | {
83
- frames. push ( errors :: FrameNote { times : 0 , ..frame. clone ( ) } ) ;
83
+ let mut add_frame = |mut frame : FrameNote | {
84
+ frames. push ( FrameNote { times : 0 , ..frame. clone ( ) } ) ;
84
85
// Don't print [... additional calls ...] if the number of lines is small
85
86
if frame. times < 3 {
86
87
let times = frame. times ;
@@ -91,21 +92,19 @@ pub fn get_span_and_frames<'tcx>(
91
92
}
92
93
} ;
93
94
94
- let mut last_frame: Option < errors:: FrameNote > = None ;
95
+ let mut last_frame: Option < FrameNote > = None ;
96
+ let mut seen = FxHashSet :: default ( ) ;
95
97
for frame_info in & stacktrace {
96
98
let frame = frame_info. as_note ( * tcx) ;
97
99
match last_frame. as_mut ( ) {
98
- Some ( last_frame)
99
- if last_frame. span == frame. span
100
- && last_frame. where_ == frame. where_
101
- && last_frame. instance == frame. instance =>
102
- {
100
+ Some ( last_frame) if !seen. insert ( frame. clone ( ) ) => {
103
101
last_frame. times += 1 ;
104
102
}
105
103
Some ( last_frame) => {
106
104
add_frame ( mem:: replace ( last_frame, frame) ) ;
107
105
}
108
106
None => {
107
+ seen. insert ( frame. clone ( ) ) ;
109
108
last_frame = Some ( frame) ;
110
109
}
111
110
}
@@ -184,7 +183,7 @@ pub(super) fn lint<'tcx, L>(
184
183
tcx : TyCtxtAt < ' tcx > ,
185
184
machine : & CompileTimeMachine < ' tcx > ,
186
185
lint : & ' static rustc_session:: lint:: Lint ,
187
- decorator : impl FnOnce ( Vec < errors :: FrameNote > ) -> L ,
186
+ decorator : impl FnOnce ( Vec < FrameNote > ) -> L ,
188
187
) where
189
188
L : for < ' a > rustc_errors:: LintDiagnostic < ' a , ( ) > ,
190
189
{
0 commit comments