@@ -35,7 +35,7 @@ struct PatCtxt<'a, 'tcx> {
3535 typeck_results : & ' a ty:: TypeckResults < ' tcx > ,
3636
3737 /// Used by the Rust 2024 migration lint.
38- rust_2024_migration_suggestion : Option < Rust2024IncompatiblePatSugg < ' a > > ,
38+ rust_2024_migration_suggestion : Option < Rust2024IncompatiblePatSugg > ,
3939}
4040
4141pub ( super ) fn pat_from_hir < ' a , ' tcx > (
@@ -44,25 +44,23 @@ pub(super) fn pat_from_hir<'a, 'tcx>(
4444 typeck_results : & ' a ty:: TypeckResults < ' tcx > ,
4545 pat : & ' tcx hir:: Pat < ' tcx > ,
4646) -> Box < Pat < ' tcx > > {
47+ let migration_labels = typeck_results. rust_2024_migration_desugared_pats ( ) . get ( pat. hir_id ) ;
4748 let mut pcx = PatCtxt {
4849 tcx,
4950 typing_env,
5051 typeck_results,
51- rust_2024_migration_suggestion : typeck_results
52- . rust_2024_migration_desugared_pats ( )
53- . get ( pat. hir_id )
54- . map ( |labels| Rust2024IncompatiblePatSugg {
55- suggestion : Vec :: new ( ) ,
56- ref_pattern_count : 0 ,
57- binding_mode_count : 0 ,
58- labels : labels. as_slice ( ) ,
59- } ) ,
52+ rust_2024_migration_suggestion : migration_labels. and ( Some ( Rust2024IncompatiblePatSugg {
53+ suggestion : Vec :: new ( ) ,
54+ ref_pattern_count : 0 ,
55+ binding_mode_count : 0 ,
56+ } ) ) ,
6057 } ;
6158 let result = pcx. lower_pattern ( pat) ;
6259 debug ! ( "pat_from_hir({:?}) = {:?}" , pat, result) ;
63- if let Some ( sugg) = pcx. rust_2024_migration_suggestion {
64- let mut spans = MultiSpan :: from_spans ( sugg. labels . iter ( ) . map ( |( span, _) | * span) . collect ( ) ) ;
65- for ( span, label) in sugg. labels {
60+ if let Some ( labels) = migration_labels {
61+ let sugg = pcx. rust_2024_migration_suggestion . expect ( "suggestion should be present" ) ;
62+ let mut spans = MultiSpan :: from_spans ( labels. iter ( ) . map ( |( span, _) | * span) . collect ( ) ) ;
63+ for ( span, label) in labels {
6664 spans. push_span_label ( * span, label. clone ( ) ) ;
6765 }
6866 // If a relevant span is from at least edition 2024, this is a hard error.
0 commit comments