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
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 ty = self.typeck_results().node_type(source.hir_id);
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 {
return ExprKind::Cast { source: self.mirror_expr(source)};
let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Const), variant_ctor_id) = res
else {
return ExprKind::Cast { source: self.mirror_expr(source) };
};
let idx = adt_def.variant_index_with_ctor_id(variant_ctor_id);
@ -351,28 +352,29 @@ impl<'tcx> Cx<'tcx> {
});
}
}
let adt_data = if let hir::ExprKind::Path(qpath) = fun.kind {
// 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 {
// Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
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) => {
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
}
Res::SelfCtor(..) => Some((adt_def, FIRST_VARIANT)),
_ => None,
})
}
}
hir::QPath::TypeRelative(_ty, _) => {
expr_ty.ty_adt_def().and_then(|adt_def| {
if let Some((DefKind::Ctor(_, CtorKind::Fn), ctor_id)) =
self.typeck_results().type_dependent_def(fun.hir_id)
{
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
} else {
None
}
})
if let Some((DefKind::Ctor(_, CtorKind::Fn), ctor_id)) =
self.typeck_results().type_dependent_def(fun.hir_id)
{
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
} else {
None
}
}
_ => None,
}