11use std:: mem;
22
3+ use rustc_data_structures:: fx:: FxHashSet ;
34use rustc_errors:: { DiagArgName , DiagArgValue , DiagMessage , Diagnostic , IntoDiagArg } ;
45use rustc_middle:: mir:: AssertKind ;
56use rustc_middle:: mir:: interpret:: { Provenance , ReportedErrorInfo } ;
@@ -9,7 +10,7 @@ use rustc_middle::ty::{ConstInt, TyCtxt};
910use rustc_span:: { Span , Symbol } ;
1011
1112use super :: CompileTimeMachine ;
12- use crate :: errors:: { self , FrameNote , ReportErrorExt } ;
13+ use crate :: errors:: { FrameNote , ReportErrorExt } ;
1314use crate :: interpret:: {
1415 ErrorHandled , Frame , InterpErrorInfo , InterpErrorKind , MachineStopType , err_inval,
1516 err_machine_stop,
@@ -68,7 +69,7 @@ impl<'tcx> Into<InterpErrorInfo<'tcx>> for ConstEvalErrKind {
6869pub fn get_span_and_frames < ' tcx > (
6970 tcx : TyCtxtAt < ' tcx > ,
7071 stack : & [ Frame < ' tcx , impl Provenance , impl Sized > ] ,
71- ) -> ( Span , Vec < errors :: FrameNote > ) {
72+ ) -> ( Span , Vec < FrameNote > ) {
7273 let mut stacktrace = Frame :: generate_stacktrace_from_stack ( stack) ;
7374 // Filter out `requires_caller_location` frames.
7475 stacktrace. retain ( |frame| !frame. instance . def . requires_caller_location ( * tcx) ) ;
@@ -79,8 +80,8 @@ pub fn get_span_and_frames<'tcx>(
7980 // Add notes to the backtrace. Don't print a single-line backtrace though.
8081 if stacktrace. len ( ) > 1 {
8182 // 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 ( ) } ) ;
8485 // Don't print [... additional calls ...] if the number of lines is small
8586 if frame. times < 3 {
8687 let times = frame. times ;
@@ -91,21 +92,19 @@ pub fn get_span_and_frames<'tcx>(
9192 }
9293 } ;
9394
94- let mut last_frame: Option < errors:: FrameNote > = None ;
95+ let mut last_frame: Option < FrameNote > = None ;
96+ let mut seen = FxHashSet :: default ( ) ;
9597 for frame_info in & stacktrace {
9698 let frame = frame_info. as_note ( * tcx) ;
9799 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 ( ) ) => {
103101 last_frame. times += 1 ;
104102 }
105103 Some ( last_frame) => {
106104 add_frame ( mem:: replace ( last_frame, frame) ) ;
107105 }
108106 None => {
107+ seen. insert ( frame. clone ( ) ) ;
109108 last_frame = Some ( frame) ;
110109 }
111110 }
@@ -184,7 +183,7 @@ pub(super) fn lint<'tcx, L>(
184183 tcx : TyCtxtAt < ' tcx > ,
185184 machine : & CompileTimeMachine < ' tcx > ,
186185 lint : & ' static rustc_session:: lint:: Lint ,
187- decorator : impl FnOnce ( Vec < errors :: FrameNote > ) -> L ,
186+ decorator : impl FnOnce ( Vec < FrameNote > ) -> L ,
188187) where
189188 L : for < ' a > rustc_errors:: LintDiagnostic < ' a , ( ) > ,
190189{
0 commit comments