1212use std:: fmt;
1313
1414use rustc_middle:: thir:: PatRange ;
15- use rustc_middle:: ty:: { self , AdtDef , Ty } ;
15+ use rustc_middle:: ty:: { self , AdtDef , Ty , TyCtxt } ;
1616use rustc_middle:: { bug, mir} ;
1717use rustc_span:: sym;
1818use rustc_target:: abi:: { FieldIdx , VariantIdx } ;
@@ -70,7 +70,7 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
7070 PatKind :: Never => write ! ( f, "!" ) ,
7171 PatKind :: Box { ref subpattern } => write ! ( f, "box {subpattern}" ) ,
7272 PatKind :: StructLike { ref enum_info, ref subpatterns } => {
73- write_struct_like ( f, self . ty , enum_info, subpatterns)
73+ ty :: tls :: with ( |tcx| write_struct_like ( f, tcx , self . ty , enum_info, subpatterns) )
7474 }
7575 PatKind :: Deref { ref subpattern } => write_ref_like ( f, self . ty , subpattern) ,
7676 PatKind :: Constant { value } => write ! ( f, "{value}" ) ,
@@ -105,12 +105,13 @@ pub(crate) enum EnumInfo<'tcx> {
105105
106106fn write_struct_like < ' tcx > (
107107 f : & mut impl fmt:: Write ,
108+ tcx : TyCtxt < ' _ > ,
108109 ty : Ty < ' tcx > ,
109110 enum_info : & EnumInfo < ' tcx > ,
110111 subpatterns : & [ FieldPat < ' tcx > ] ,
111112) -> fmt:: Result {
112113 let variant_and_name = match * enum_info {
113- EnumInfo :: Enum { adt_def, variant_index } => ty :: tls :: with ( |tcx| {
114+ EnumInfo :: Enum { adt_def, variant_index } => {
114115 let variant = adt_def. variant ( variant_index) ;
115116 let adt_did = adt_def. did ( ) ;
116117 let name = if tcx. get_diagnostic_item ( sym:: Option ) == Some ( adt_did)
@@ -121,9 +122,9 @@ fn write_struct_like<'tcx>(
121122 format ! ( "{}::{}" , tcx. def_path_str( adt_def. did( ) ) , variant. name)
122123 } ;
123124 Some ( ( variant, name) )
124- } ) ,
125+ }
125126 EnumInfo :: NotEnum => ty. ty_adt_def ( ) . and_then ( |adt_def| {
126- ty :: tls :: with ( |tcx| Some ( ( adt_def. non_enum_variant ( ) , tcx. def_path_str ( adt_def. did ( ) ) ) ) )
127+ Some ( ( adt_def. non_enum_variant ( ) , tcx. def_path_str ( adt_def. did ( ) ) ) )
127128 } ) ,
128129 } ;
129130
0 commit comments