@@ -215,17 +215,18 @@ impl<'tcx> Cx<'tcx> {
215215 // so we wouldn't have to compute and store the actual value
216216
217217 let hir:: ExprKind :: Path ( ref qpath) = source. kind else {
218- return ExprKind :: Cast { source : self . mirror_expr ( source) } ;
218+ return ExprKind :: Cast { source : self . mirror_expr ( source) } ;
219219 } ;
220220
221221 let res = self . typeck_results ( ) . qpath_res ( qpath, source. hir_id ) ;
222222 let ty = self . typeck_results ( ) . node_type ( source. hir_id ) ;
223223 let ty:: Adt ( adt_def, substs) = ty. kind ( ) else {
224- return ExprKind :: Cast { source : self . mirror_expr ( source) } ;
224+ return ExprKind :: Cast { source : self . mirror_expr ( source) } ;
225225 } ;
226226
227- let Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , CtorKind :: Const ) , variant_ctor_id) = res else {
228- return ExprKind :: Cast { source : self . mirror_expr ( source) } ;
227+ let Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , CtorKind :: Const ) , variant_ctor_id) = res
228+ else {
229+ return ExprKind :: Cast { source : self . mirror_expr ( source) } ;
229230 } ;
230231
231232 let idx = adt_def. variant_index_with_ctor_id ( variant_ctor_id) ;
@@ -358,19 +359,35 @@ impl<'tcx> Cx<'tcx> {
358359 } ) ;
359360 }
360361 }
361- let adt_data =
362- if let hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, ref path) ) = fun. kind {
363- // Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
364- expr_ty. ty_adt_def ( ) . and_then ( |adt_def| match path. res {
365- Res :: Def ( DefKind :: Ctor ( _, CtorKind :: Fn ) , ctor_id) => {
362+
363+ // Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
364+ let adt_data = if let hir:: ExprKind :: Path ( ref qpath) = fun. kind
365+ && let Some ( adt_def) = expr_ty. ty_adt_def ( ) {
366+ match qpath {
367+ hir:: QPath :: Resolved ( _, ref path) => {
368+ match path. res {
369+ Res :: Def ( DefKind :: Ctor ( _, CtorKind :: Fn ) , ctor_id) => {
370+ Some ( ( adt_def, adt_def. variant_index_with_ctor_id ( ctor_id) ) )
371+ }
372+ Res :: SelfCtor ( ..) => Some ( ( adt_def, FIRST_VARIANT ) ) ,
373+ _ => None ,
374+ }
375+ }
376+ hir:: QPath :: TypeRelative ( _ty, _) => {
377+ if let Some ( ( DefKind :: Ctor ( _, CtorKind :: Fn ) , ctor_id) ) =
378+ self . typeck_results ( ) . type_dependent_def ( fun. hir_id )
379+ {
366380 Some ( ( adt_def, adt_def. variant_index_with_ctor_id ( ctor_id) ) )
381+ } else {
382+ None
367383 }
368- Res :: SelfCtor ( ..) => Some ( ( adt_def, FIRST_VARIANT ) ) ,
369- _ => None ,
370- } )
371- } else {
372- None
373- } ;
384+
385+ }
386+ _ => None ,
387+ }
388+ } else {
389+ None
390+ } ;
374391 if let Some ( ( adt_def, index) ) = adt_data {
375392 let substs = self . typeck_results ( ) . node_substs ( fun. hir_id ) ;
376393 let user_provided_types = self . typeck_results ( ) . user_provided_types ( ) ;
0 commit comments