1
Fork 0
This commit is contained in:
Eric Mark Martin 2023-07-02 18:44:26 -04:00
parent b9e991a105
commit 07b1912acc

View file

@ -208,17 +208,18 @@ impl<'tcx> Cx<'tcx> {
// so we wouldn't have to compute and store the actual value // so we wouldn't have to compute and store the actual value
let hir::ExprKind::Path(ref qpath) = source.kind else { let hir::ExprKind::Path(ref qpath) = source.kind else {
return ExprKind::Cast { source: self.mirror_expr(source)}; return ExprKind::Cast { source: self.mirror_expr(source) };
}; };
let res = self.typeck_results().qpath_res(qpath, source.hir_id); let res = self.typeck_results().qpath_res(qpath, source.hir_id);
let ty = self.typeck_results().node_type(source.hir_id); let ty = self.typeck_results().node_type(source.hir_id);
let ty::Adt(adt_def, substs) = ty.kind() else { let ty::Adt(adt_def, substs) = ty.kind() else {
return ExprKind::Cast { source: self.mirror_expr(source)}; return ExprKind::Cast { source: self.mirror_expr(source) };
}; };
let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Const), variant_ctor_id) = res else { let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Const), variant_ctor_id) = res
return ExprKind::Cast { source: self.mirror_expr(source)}; else {
return ExprKind::Cast { source: self.mirror_expr(source) };
}; };
let idx = adt_def.variant_index_with_ctor_id(variant_ctor_id); let idx = adt_def.variant_index_with_ctor_id(variant_ctor_id);
@ -351,20 +352,21 @@ impl<'tcx> Cx<'tcx> {
}); });
} }
} }
let adt_data = if let hir::ExprKind::Path(qpath) = fun.kind {
match qpath {
// Tuple-like ADTs are represented as ExprKind::Call. We convert them here. // Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
let adt_data = if let hir::ExprKind::Path(ref qpath) = fun.kind
&& let Some(adt_def) = expr_ty.ty_adt_def() {
match qpath {
hir::QPath::Resolved(_, ref path) => { hir::QPath::Resolved(_, ref path) => {
expr_ty.ty_adt_def().and_then(|adt_def| match path.res { match path.res {
Res::Def(DefKind::Ctor(_, CtorKind::Fn), ctor_id) => { Res::Def(DefKind::Ctor(_, CtorKind::Fn), ctor_id) => {
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id))) Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
} }
Res::SelfCtor(..) => Some((adt_def, FIRST_VARIANT)), Res::SelfCtor(..) => Some((adt_def, FIRST_VARIANT)),
_ => None, _ => None,
}) }
} }
hir::QPath::TypeRelative(_ty, _) => { hir::QPath::TypeRelative(_ty, _) => {
expr_ty.ty_adt_def().and_then(|adt_def| {
if let Some((DefKind::Ctor(_, CtorKind::Fn), ctor_id)) = if let Some((DefKind::Ctor(_, CtorKind::Fn), ctor_id)) =
self.typeck_results().type_dependent_def(fun.hir_id) self.typeck_results().type_dependent_def(fun.hir_id)
{ {
@ -372,7 +374,7 @@ impl<'tcx> Cx<'tcx> {
} else { } else {
None None
} }
})
} }
_ => None, _ => None,
} }