@@ -202,11 +202,14 @@ pub enum ImmutabilityBlame<'tcx> {
202
202
}
203
203
204
204
impl < ' tcx > cmt_ < ' tcx > {
205
- fn resolve_field ( & self , field_name : FieldName ) -> ( & ' tcx ty:: AdtDef , & ' tcx ty:: FieldDef )
205
+ fn resolve_field ( & self , field_name : FieldName ) -> Option < ( & ' tcx ty:: AdtDef , & ' tcx ty:: FieldDef ) >
206
206
{
207
- let adt_def = self . ty . ty_adt_def ( ) . unwrap_or_else ( || {
208
- bug ! ( "interior cmt {:?} is not an ADT" , self )
209
- } ) ;
207
+ let adt_def = match self . ty . sty {
208
+ ty:: TyAdt ( def, _) => def,
209
+ ty:: TyTuple ( ..) => return None ,
210
+ // closures get `Categorization::Upvar` rather than `Categorization::Interior`
211
+ _ => bug ! ( "interior cmt {:?} is not an ADT" , self )
212
+ } ;
210
213
let variant_def = match self . cat {
211
214
Categorization :: Downcast ( _, variant_did) => {
212
215
adt_def. variant_with_id ( variant_did)
@@ -220,7 +223,7 @@ impl<'tcx> cmt_<'tcx> {
220
223
NamedField ( name) => variant_def. field_named ( name) ,
221
224
PositionalField ( idx) => & variant_def. fields [ idx]
222
225
} ;
223
- ( adt_def, field_def)
226
+ Some ( ( adt_def, field_def) )
224
227
}
225
228
226
229
pub fn immutability_blame ( & self ) -> Option < ImmutabilityBlame < ' tcx > > {
@@ -232,8 +235,9 @@ impl<'tcx> cmt_<'tcx> {
232
235
Categorization :: Local ( node_id) =>
233
236
Some ( ImmutabilityBlame :: LocalDeref ( node_id) ) ,
234
237
Categorization :: Interior ( ref base_cmt, InteriorField ( field_name) ) => {
235
- let ( adt_def, field_def) = base_cmt. resolve_field ( field_name) ;
236
- Some ( ImmutabilityBlame :: AdtFieldDeref ( adt_def, field_def) )
238
+ base_cmt. resolve_field ( field_name) . map ( |( adt_def, field_def) | {
239
+ ImmutabilityBlame :: AdtFieldDeref ( adt_def, field_def)
240
+ } )
237
241
}
238
242
Categorization :: Upvar ( Upvar { id, .. } ) => {
239
243
if let NoteClosureEnv ( ..) = self . note {
0 commit comments