1
Fork 0

resolve typerelative ctors to adt

This commit is contained in:
Eric Mark Martin 2023-06-30 08:26:56 -04:00
parent 5bd28f5eac
commit 76a7772759
2 changed files with 28 additions and 13 deletions

View file

@ -351,19 +351,34 @@ impl<'tcx> Cx<'tcx> {
}); });
} }
} }
let adt_data = let adt_data = if let hir::ExprKind::Path(qpath) = fun.kind {
if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = 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.
expr_ty.ty_adt_def().and_then(|adt_def| match path.res { hir::QPath::Resolved(_, ref path) => {
Res::Def(DefKind::Ctor(_, CtorKind::Fn), ctor_id) => { expr_ty.ty_adt_def().and_then(|adt_def| match path.res {
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id))) 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, Res::SelfCtor(..) => Some((adt_def, FIRST_VARIANT)),
}) _ => None,
} else { })
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
}
})
}
_ => None,
}
} else {
None
};
if let Some((adt_def, index)) = adt_data { if let Some((adt_def, index)) = adt_data {
let substs = self.typeck_results().node_substs(fun.hir_id); let substs = self.typeck_results().node_substs(fun.hir_id);
let user_provided_types = self.typeck_results().user_provided_types(); let user_provided_types = self.typeck_results().user_provided_types();

View file

@ -147,7 +147,7 @@ LL | fn test_variants<'a, 'b, 'c>() {
| -- lifetime `'b` defined here | -- lifetime `'b` defined here
... ...
LL | <Ty<'b>>::Tuple(); LL | <Ty<'b>>::Tuple();
| ^^^^^^^^^^^^^^^ requires that `'b` must outlive `'static` | ^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'static`
error: lifetime may not live long enough error: lifetime may not live long enough
--> $DIR/normalization-2.rs:93:5 --> $DIR/normalization-2.rs:93:5