refactor
This commit is contained in:
parent
b9e991a105
commit
07b1912acc
1 changed files with 19 additions and 17 deletions
|
@ -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,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 {
|
match qpath {
|
||||||
// Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
|
|
||||||
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)
|
{
|
||||||
{
|
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
|
||||||
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
|
} else {
|
||||||
} else {
|
None
|
||||||
None
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue