@@ -79,12 +79,14 @@ struct TopInfo<'tcx> {
79
79
span : Option < Span > ,
80
80
}
81
81
82
- #[ derive( Clone ) ]
82
+ #[ derive( Copy , Clone ) ]
83
83
struct PatInfo < ' tcx , ' a > {
84
84
binding_mode : BindingMode ,
85
85
top_info : TopInfo < ' tcx > ,
86
86
decl_origin : Option < DeclOrigin < ' a > > ,
87
- history : Vec < PatKind < ' tcx > > ,
87
+
88
+ parent_kind : Option < PatKind < ' tcx > > ,
89
+ current_kind : Option < PatKind < ' tcx > > ,
88
90
}
89
91
90
92
impl < ' tcx > FnCtxt < ' _ , ' tcx > {
@@ -154,8 +156,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
154
156
decl_origin : Option < DeclOrigin < ' tcx > > ,
155
157
) {
156
158
let info = TopInfo { expected, origin_expr, span } ;
157
- let pat_info =
158
- PatInfo { binding_mode : INITIAL_BM , top_info : info, decl_origin, history : Vec :: new ( ) } ;
159
+ let pat_info = PatInfo {
160
+ binding_mode : INITIAL_BM ,
161
+ top_info : info,
162
+ decl_origin,
163
+ parent_kind : None ,
164
+ current_kind : None ,
165
+ } ;
159
166
self . check_pat ( pat, expected, pat_info) ;
160
167
}
161
168
@@ -166,7 +173,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
166
173
/// Conversely, inside this module, `check_pat_top` should never be used.
167
174
#[ instrument( level = "debug" , skip( self , pat_info) ) ]
168
175
fn check_pat ( & self , pat : & ' tcx Pat < ' tcx > , expected : Ty < ' tcx > , pat_info : PatInfo < ' tcx , ' _ > ) {
169
- let PatInfo { binding_mode : def_bm, top_info : ti, mut history, .. } = pat_info;
176
+ let PatInfo { binding_mode : def_bm, top_info : ti, current_kind, parent_kind, .. } =
177
+ pat_info;
178
+
179
+ println ! ( "{:#?} -> {:#?}" , parent_kind, current_kind) ;
180
+
170
181
let path_res = match & pat. kind {
171
182
PatKind :: Path ( qpath) => Some (
172
183
self . resolve_ty_and_res_fully_qualified_call ( qpath, pat. hir_id , pat. span , None ) ,
@@ -175,12 +186,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
175
186
} ;
176
187
let adjust_mode = self . calc_adjust_mode ( pat, path_res. map ( |( res, ..) | res) ) ;
177
188
let ( expected, def_bm) = self . calc_default_binding_mode ( pat, expected, def_bm, adjust_mode) ;
178
- history. push ( pat. kind ) ;
179
189
let pat_info = PatInfo {
180
190
binding_mode : def_bm,
181
191
top_info : ti,
182
192
decl_origin : pat_info. decl_origin ,
183
- history,
193
+ parent_kind : current_kind,
194
+ current_kind : Some ( pat. kind ) ,
184
195
} ;
185
196
186
197
let ty = match pat. kind {
@@ -1054,7 +1065,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1054
1065
expected : Ty < ' tcx > ,
1055
1066
pat_info : PatInfo < ' tcx , ' _ > ,
1056
1067
) -> Ty < ' tcx > {
1057
- let PatInfo { binding_mode : def_bm, top_info : ti, decl_origin, history } = pat_info;
1068
+ let PatInfo { binding_mode : def_bm, top_info : ti, decl_origin, parent_kind, current_kind } =
1069
+ pat_info;
1058
1070
let tcx = self . tcx ;
1059
1071
let on_error = |e| {
1060
1072
for pat in subpats {
@@ -1065,7 +1077,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1065
1077
binding_mode : def_bm,
1066
1078
top_info : ti,
1067
1079
decl_origin,
1068
- history : history. clone ( ) ,
1080
+ parent_kind,
1081
+ current_kind,
1069
1082
} ,
1070
1083
) ;
1071
1084
}
@@ -1140,7 +1153,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1140
1153
binding_mode : def_bm,
1141
1154
top_info : ti,
1142
1155
decl_origin,
1143
- history : history. clone ( ) ,
1156
+ parent_kind,
1157
+ current_kind,
1144
1158
} ,
1145
1159
) ;
1146
1160
@@ -2296,7 +2310,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2296
2310
expected_ty : Ty < ' tcx > ,
2297
2311
pat_info : PatInfo < ' tcx , ' _ > ,
2298
2312
) -> ErrorGuaranteed {
2299
- let PatInfo { top_info : ti, history , .. } = pat_info;
2313
+ let PatInfo { top_info : ti, parent_kind , .. } = pat_info;
2300
2314
2301
2315
let mut err = struct_span_code_err ! (
2302
2316
self . dcx( ) ,
@@ -2334,9 +2348,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2334
2348
_ => ( ) ,
2335
2349
}
2336
2350
2337
- let enclosure_is_struct = history
2338
- . get ( history. len ( ) - 2 )
2339
- . map_or ( false , |enclosure| matches ! ( enclosure, PatKind :: Struct ( ..) ) ) ;
2351
+ let enclosure_is_struct =
2352
+ parent_kind. map_or ( false , |enclosure| matches ! ( enclosure, PatKind :: Struct ( ..) ) ) ;
2340
2353
2341
2354
if is_slice_or_array_or_vector && !enclosure_is_struct {
2342
2355
err. span_suggestion (
0 commit comments