@@ -762,7 +762,12 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
762762 if let Some ( rib) = & self . last_block_rib
763763 && let RibKind :: Normal = rib. kind
764764 {
765- for ( ident, & res) in & rib. bindings {
765+ // It is sorted before usage so ordering is not important here.
766+ #[ allow( rustc:: potential_query_instability) ]
767+ let mut bindings: Vec < _ > = rib. bindings . clone ( ) . into_iter ( ) . collect ( ) ;
768+ bindings. sort_by_key ( |( ident, _) | ident. span ) ;
769+
770+ for ( ident, res) in & bindings {
766771 if let Res :: Local ( _) = res
767772 && path. len ( ) == 1
768773 && ident. span . eq_ctxt ( path[ 0 ] . ident . span )
@@ -944,7 +949,12 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
944949 if let Some ( err_code) = err. code {
945950 if err_code == E0425 {
946951 for label_rib in & self . label_ribs {
947- for ( label_ident, node_id) in & label_rib. bindings {
952+ // It is sorted before usage so ordering is not important here.
953+ #[ allow( rustc:: potential_query_instability) ]
954+ let mut bindings: Vec < _ > = label_rib. bindings . clone ( ) . into_iter ( ) . collect ( ) ;
955+ bindings. sort_by_key ( |( ident, _) | ident. span ) ;
956+
957+ for ( label_ident, node_id) in & bindings {
948958 let ident = path. last ( ) . unwrap ( ) . ident ;
949959 if format ! ( "'{ident}" ) == label_ident. to_string ( ) {
950960 err. span_label ( label_ident. span , "a label with a similar name exists" ) ;
@@ -2142,6 +2152,8 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
21422152 } ;
21432153
21442154 // Locals and type parameters
2155+ // `names` is sorted below so ordering is not important here.
2156+ #[ allow( rustc:: potential_query_instability) ]
21452157 for ( ident, & res) in & rib. bindings {
21462158 if filter_fn ( res) && ident. span . ctxt ( ) == rib_ctxt {
21472159 names. push ( TypoSuggestion :: typo_from_ident ( * ident, res) ) ;
@@ -2605,18 +2617,28 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
26052617 let within_scope = self . is_label_valid_from_rib ( rib_index) ;
26062618
26072619 let rib = & self . label_ribs [ rib_index] ;
2608- let names = rib
2620+ // `names` is sorted below so ordering is not important here.
2621+ #[ allow( rustc:: potential_query_instability) ]
2622+ let mut names = rib
26092623 . bindings
26102624 . iter ( )
26112625 . filter ( |( id, _) | id. span . eq_ctxt ( label. span ) )
26122626 . map ( |( id, _) | id. name )
26132627 . collect :: < Vec < Symbol > > ( ) ;
26142628
2629+ // Make sure error reporting is deterministic.
2630+ names. sort ( ) ;
2631+
26152632 find_best_match_for_name ( & names, label. name , None ) . map ( |symbol| {
2633+ // It is sorted before usage so ordering is not important here.
2634+ #[ allow( rustc:: potential_query_instability) ]
2635+ let mut bindings: Vec < _ > = rib. bindings . clone ( ) . into_iter ( ) . collect ( ) ;
2636+ bindings. sort_by_key ( |( ident, _) | ident. span ) ;
2637+
26162638 // Upon finding a similar name, get the ident that it was from - the span
26172639 // contained within helps make a useful diagnostic. In addition, determine
26182640 // whether this candidate is within scope.
2619- let ( ident, _) = rib . bindings . iter ( ) . find ( |( ident, _) | ident. name == symbol) . unwrap ( ) ;
2641+ let ( ident, _) = bindings. iter ( ) . find ( |( ident, _) | ident. name == symbol) . unwrap ( ) ;
26202642 ( * ident, within_scope)
26212643 } )
26222644 }
0 commit comments