@@ -449,8 +449,11 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
449449 assert_eq ! ( fcx_typeck_results. hir_owner, self . typeck_results. hir_owner) ;
450450 let common_hir_owner = fcx_typeck_results. hir_owner ;
451451
452- for ( id, origin) in fcx_typeck_results. closure_kind_origins ( ) . iter ( ) {
453- let hir_id = hir:: HirId { owner : common_hir_owner, local_id : * id } ;
452+ let fcx_closure_kind_origins =
453+ fcx_typeck_results. closure_kind_origins ( ) . items_in_stable_order ( self . tcx ( ) ) ;
454+
455+ for ( & local_id, origin) in fcx_closure_kind_origins {
456+ let hir_id = hir:: HirId { owner : common_hir_owner, local_id } ;
454457 let place_span = origin. 0 ;
455458 let place = self . resolve ( origin. 1 . clone ( ) , & place_span) ;
456459 self . typeck_results . closure_kind_origins_mut ( ) . insert ( hir_id, ( place_span, place) ) ;
@@ -477,22 +480,15 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
477480 assert_eq ! ( fcx_typeck_results. hir_owner, self . typeck_results. hir_owner) ;
478481 let common_hir_owner = fcx_typeck_results. hir_owner ;
479482
480- let mut errors_buffer = Vec :: new ( ) ;
481- for ( & local_id, c_ty) in fcx_typeck_results. user_provided_types ( ) . iter ( ) {
482- let hir_id = hir:: HirId { owner : common_hir_owner, local_id } ;
483-
484- if cfg ! ( debug_assertions) && c_ty. needs_infer ( ) {
485- span_bug ! (
486- hir_id. to_span( self . fcx. tcx) ,
487- "writeback: `{:?}` has inference variables" ,
488- c_ty
489- ) ;
490- } ;
483+ if self . rustc_dump_user_substs {
484+ let sorted_user_provided_types =
485+ fcx_typeck_results. user_provided_types ( ) . items_in_stable_order ( self . tcx ( ) ) ;
491486
492- self . typeck_results . user_provided_types_mut ( ) . insert ( hir_id, * c_ty) ;
487+ let mut errors_buffer = Vec :: new ( ) ;
488+ for ( & local_id, c_ty) in sorted_user_provided_types {
489+ let hir_id = hir:: HirId { owner : common_hir_owner, local_id } ;
493490
494- if let ty:: UserType :: TypeOf ( _, user_substs) = c_ty. value {
495- if self . rustc_dump_user_substs {
491+ if let ty:: UserType :: TypeOf ( _, user_substs) = c_ty. value {
496492 // This is a unit-testing mechanism.
497493 let span = self . tcx ( ) . hir ( ) . span ( hir_id) ;
498494 // We need to buffer the errors in order to guarantee a consistent
@@ -504,31 +500,49 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
504500 err. buffer ( & mut errors_buffer) ;
505501 }
506502 }
507- }
508503
509- if !errors_buffer. is_empty ( ) {
510- errors_buffer. sort_by_key ( |diag| diag. span . primary_span ( ) ) ;
511- for mut diag in errors_buffer {
512- self . tcx ( ) . sess . diagnostic ( ) . emit_diagnostic ( & mut diag) ;
504+ if !errors_buffer. is_empty ( ) {
505+ errors_buffer. sort_by_key ( |diag| diag. span . primary_span ( ) ) ;
506+ for mut diag in errors_buffer {
507+ self . tcx ( ) . sess . diagnostic ( ) . emit_diagnostic ( & mut diag) ;
508+ }
513509 }
514510 }
511+
512+ self . typeck_results . user_provided_types_mut ( ) . extend (
513+ fcx_typeck_results. user_provided_types ( ) . items ( ) . map ( |( local_id, c_ty) | {
514+ let hir_id = hir:: HirId { owner : common_hir_owner, local_id } ;
515+
516+ if cfg ! ( debug_assertions) && c_ty. needs_infer ( ) {
517+ span_bug ! (
518+ hir_id. to_span( self . fcx. tcx) ,
519+ "writeback: `{:?}` has inference variables" ,
520+ c_ty
521+ ) ;
522+ } ;
523+
524+ ( hir_id, * c_ty)
525+ } ) ,
526+ ) ;
515527 }
516528
517529 fn visit_user_provided_sigs ( & mut self ) {
518530 let fcx_typeck_results = self . fcx . typeck_results . borrow ( ) ;
519531 assert_eq ! ( fcx_typeck_results. hir_owner, self . typeck_results. hir_owner) ;
520532
521- for ( & def_id, c_sig) in fcx_typeck_results. user_provided_sigs . iter ( ) {
522- if cfg ! ( debug_assertions) && c_sig. needs_infer ( ) {
523- span_bug ! (
524- self . fcx. tcx. def_span( def_id) ,
525- "writeback: `{:?}` has inference variables" ,
526- c_sig
527- ) ;
528- } ;
529-
530- self . typeck_results . user_provided_sigs . insert ( def_id, * c_sig) ;
531- }
533+ self . typeck_results . user_provided_sigs . extend (
534+ fcx_typeck_results. user_provided_sigs . items ( ) . map ( |( & def_id, c_sig) | {
535+ if cfg ! ( debug_assertions) && c_sig. needs_infer ( ) {
536+ span_bug ! (
537+ self . fcx. tcx. def_span( def_id) ,
538+ "writeback: `{:?}` has inference variables" ,
539+ c_sig
540+ ) ;
541+ } ;
542+
543+ ( def_id, * c_sig)
544+ } ) ,
545+ ) ;
532546 }
533547
534548 fn visit_generator_interior_types ( & mut self ) {
@@ -647,7 +661,10 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
647661 assert_eq ! ( fcx_typeck_results. hir_owner, self . typeck_results. hir_owner) ;
648662 let common_hir_owner = fcx_typeck_results. hir_owner ;
649663
650- for ( & local_id, & fn_sig) in fcx_typeck_results. liberated_fn_sigs ( ) . iter ( ) {
664+ let fcx_liberated_fn_sigs =
665+ fcx_typeck_results. liberated_fn_sigs ( ) . items_in_stable_order ( self . tcx ( ) ) ;
666+
667+ for ( & local_id, & fn_sig) in fcx_liberated_fn_sigs {
651668 let hir_id = hir:: HirId { owner : common_hir_owner, local_id } ;
652669 let fn_sig = self . resolve ( fn_sig, & hir_id) ;
653670 self . typeck_results . liberated_fn_sigs_mut ( ) . insert ( hir_id, fn_sig) ;
@@ -659,7 +676,10 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
659676 assert_eq ! ( fcx_typeck_results. hir_owner, self . typeck_results. hir_owner) ;
660677 let common_hir_owner = fcx_typeck_results. hir_owner ;
661678
662- for ( & local_id, ftys) in fcx_typeck_results. fru_field_types ( ) . iter ( ) {
679+ let fcx_fru_field_types =
680+ fcx_typeck_results. fru_field_types ( ) . items_in_stable_order ( self . tcx ( ) ) ;
681+
682+ for ( & local_id, ftys) in fcx_fru_field_types {
663683 let hir_id = hir:: HirId { owner : common_hir_owner, local_id } ;
664684 let ftys = self . resolve ( ftys. clone ( ) , & hir_id) ;
665685 self . typeck_results . fru_field_types_mut ( ) . insert ( hir_id, ftys) ;
0 commit comments