@@ -208,17 +208,18 @@ impl<'tcx> Cx<'tcx> {
208
208
// so we wouldn't have to compute and store the actual value
209
209
210
210
let hir:: ExprKind :: Path ( ref qpath) = source. kind else {
211
- return ExprKind :: Cast { source : self . mirror_expr ( source) } ;
211
+ return ExprKind :: Cast { source : self . mirror_expr ( source) } ;
212
212
} ;
213
213
214
214
let res = self . typeck_results ( ) . qpath_res ( qpath, source. hir_id ) ;
215
215
let ty = self . typeck_results ( ) . node_type ( source. hir_id ) ;
216
216
let ty:: Adt ( adt_def, substs) = ty. kind ( ) else {
217
- return ExprKind :: Cast { source : self . mirror_expr ( source) } ;
217
+ return ExprKind :: Cast { source : self . mirror_expr ( source) } ;
218
218
} ;
219
219
220
- let Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , CtorKind :: Const ) , variant_ctor_id) = res else {
221
- return ExprKind :: Cast { source : self . mirror_expr ( source) } ;
220
+ let Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , CtorKind :: Const ) , variant_ctor_id) = res
221
+ else {
222
+ return ExprKind :: Cast { source : self . mirror_expr ( source) } ;
222
223
} ;
223
224
224
225
let idx = adt_def. variant_index_with_ctor_id ( variant_ctor_id) ;
@@ -351,28 +352,29 @@ impl<'tcx> Cx<'tcx> {
351
352
} ) ;
352
353
}
353
354
}
354
- let adt_data = if let hir:: ExprKind :: Path ( qpath) = fun. kind {
355
+
356
+ // Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
357
+ let adt_data = if let hir:: ExprKind :: Path ( ref qpath) = fun. kind
358
+ && let Some ( adt_def) = expr_ty. ty_adt_def ( ) {
355
359
match qpath {
356
- // Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
357
360
hir:: QPath :: Resolved ( _, ref path) => {
358
- expr_ty . ty_adt_def ( ) . and_then ( |adt_def| match path. res {
361
+ match path. res {
359
362
Res :: Def ( DefKind :: Ctor ( _, CtorKind :: Fn ) , ctor_id) => {
360
363
Some ( ( adt_def, adt_def. variant_index_with_ctor_id ( ctor_id) ) )
361
364
}
362
365
Res :: SelfCtor ( ..) => Some ( ( adt_def, FIRST_VARIANT ) ) ,
363
366
_ => None ,
364
- } )
367
+ }
365
368
}
366
369
hir:: QPath :: TypeRelative ( _ty, _) => {
367
- expr_ty. ty_adt_def ( ) . and_then ( |adt_def| {
368
- if let Some ( ( DefKind :: Ctor ( _, CtorKind :: Fn ) , ctor_id) ) =
369
- self . typeck_results ( ) . type_dependent_def ( fun. hir_id )
370
- {
371
- Some ( ( adt_def, adt_def. variant_index_with_ctor_id ( ctor_id) ) )
372
- } else {
373
- None
374
- }
375
- } )
370
+ if let Some ( ( DefKind :: Ctor ( _, CtorKind :: Fn ) , ctor_id) ) =
371
+ self . typeck_results ( ) . type_dependent_def ( fun. hir_id )
372
+ {
373
+ Some ( ( adt_def, adt_def. variant_index_with_ctor_id ( ctor_id) ) )
374
+ } else {
375
+ None
376
+ }
377
+
376
378
}
377
379
_ => None ,
378
380
}
0 commit comments