12
12
use std:: fmt;
13
13
14
14
use rustc_middle:: thir:: PatRange ;
15
- use rustc_middle:: ty:: { self , AdtDef , Ty } ;
15
+ use rustc_middle:: ty:: { self , AdtDef , Ty , TyCtxt } ;
16
16
use rustc_middle:: { bug, mir} ;
17
17
use rustc_span:: sym;
18
18
use rustc_target:: abi:: { FieldIdx , VariantIdx } ;
@@ -70,7 +70,7 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
70
70
PatKind :: Never => write ! ( f, "!" ) ,
71
71
PatKind :: Box { ref subpattern } => write ! ( f, "box {subpattern}" ) ,
72
72
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) )
74
74
}
75
75
PatKind :: Deref { ref subpattern } => write_ref_like ( f, self . ty , subpattern) ,
76
76
PatKind :: Constant { value } => write ! ( f, "{value}" ) ,
@@ -105,12 +105,13 @@ pub(crate) enum EnumInfo<'tcx> {
105
105
106
106
fn write_struct_like < ' tcx > (
107
107
f : & mut impl fmt:: Write ,
108
+ tcx : TyCtxt < ' _ > ,
108
109
ty : Ty < ' tcx > ,
109
110
enum_info : & EnumInfo < ' tcx > ,
110
111
subpatterns : & [ FieldPat < ' tcx > ] ,
111
112
) -> fmt:: Result {
112
113
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 } => {
114
115
let variant = adt_def. variant ( variant_index) ;
115
116
let adt_did = adt_def. did ( ) ;
116
117
let name = if tcx. get_diagnostic_item ( sym:: Option ) == Some ( adt_did)
@@ -121,9 +122,9 @@ fn write_struct_like<'tcx>(
121
122
format ! ( "{}::{}" , tcx. def_path_str( adt_def. did( ) ) , variant. name)
122
123
} ;
123
124
Some ( ( variant, name) )
124
- } ) ,
125
+ }
125
126
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 ( ) ) ) )
127
128
} ) ,
128
129
} ;
129
130
0 commit comments