11use std:: mem;
22
3+ use rustc_data_structures:: fx:: FxHashSet ;
34use rustc_errors:: { Diag , DiagArgName , DiagArgValue , DiagMessage , IntoDiagArg } ;
45use rustc_middle:: mir:: AssertKind ;
56use rustc_middle:: mir:: interpret:: { AllocId , 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 CtfeProvenance , ErrorHandled , Frame , InterpErrorInfo , InterpErrorKind , MachineStopType ,
1516 Pointer , err_inval, err_machine_stop,
@@ -93,7 +94,7 @@ impl<'tcx> Into<InterpErrorInfo<'tcx>> for ConstEvalErrKind {
9394pub fn get_span_and_frames < ' tcx > (
9495 tcx : TyCtxtAt < ' tcx > ,
9596 stack : & [ Frame < ' tcx , impl Provenance , impl Sized > ] ,
96- ) -> ( Span , Vec < errors :: FrameNote > ) {
97+ ) -> ( Span , Vec < FrameNote > ) {
9798 let mut stacktrace = Frame :: generate_stacktrace_from_stack ( stack) ;
9899 // Filter out `requires_caller_location` frames.
99100 stacktrace. retain ( |frame| !frame. instance . def . requires_caller_location ( * tcx) ) ;
@@ -104,8 +105,8 @@ pub fn get_span_and_frames<'tcx>(
104105 // Add notes to the backtrace. Don't print a single-line backtrace though.
105106 if stacktrace. len ( ) > 1 {
106107 // Helper closure to print duplicated lines.
107- let mut add_frame = |mut frame : errors :: FrameNote | {
108- frames. push ( errors :: FrameNote { times : 0 , ..frame. clone ( ) } ) ;
108+ let mut add_frame = |mut frame : FrameNote | {
109+ frames. push ( FrameNote { times : 0 , ..frame. clone ( ) } ) ;
109110 // Don't print [... additional calls ...] if the number of lines is small
110111 if frame. times < 3 {
111112 let times = frame. times ;
@@ -116,21 +117,19 @@ pub fn get_span_and_frames<'tcx>(
116117 }
117118 } ;
118119
119- let mut last_frame: Option < errors:: FrameNote > = None ;
120+ let mut last_frame: Option < FrameNote > = None ;
121+ let mut seen = FxHashSet :: default ( ) ;
120122 for frame_info in & stacktrace {
121123 let frame = frame_info. as_note ( * tcx) ;
122124 match last_frame. as_mut ( ) {
123- Some ( last_frame)
124- if last_frame. span == frame. span
125- && last_frame. where_ == frame. where_
126- && last_frame. instance == frame. instance =>
127- {
125+ Some ( last_frame) if !seen. insert ( frame. clone ( ) ) => {
128126 last_frame. times += 1 ;
129127 }
130128 Some ( last_frame) => {
131129 add_frame ( mem:: replace ( last_frame, frame) ) ;
132130 }
133131 None => {
132+ seen. insert ( frame. clone ( ) ) ;
134133 last_frame = Some ( frame) ;
135134 }
136135 }
@@ -219,7 +218,7 @@ pub(super) fn lint<'tcx, L>(
219218 tcx : TyCtxtAt < ' tcx > ,
220219 machine : & CompileTimeMachine < ' tcx > ,
221220 lint : & ' static rustc_session:: lint:: Lint ,
222- decorator : impl FnOnce ( Vec < errors :: FrameNote > ) -> L ,
221+ decorator : impl FnOnce ( Vec < FrameNote > ) -> L ,
223222) where
224223 L : for < ' a > rustc_errors:: LintDiagnostic < ' a , ( ) > ,
225224{
0 commit comments