diff options
| author | Eric Mark Martin <ericmarkmartin@gmail.com> | 2023-06-30 08:26:56 -0400 |
|---|---|---|
| committer | Eric Mark Martin <ericmarkmartin@gmail.com> | 2023-06-30 08:26:56 -0400 |
| commit | 76a7772759247e00365a90be936504289c359165 (patch) | |
| tree | 8b42b1262ab3fe4b4bc245934d417490600d24a2 | |
| parent | 5bd28f5eac1ba3569bfa8d49ec3f5acbdfdff7a0 (diff) | |
| download | rust-76a7772759247e00365a90be936504289c359165.tar.gz rust-76a7772759247e00365a90be936504289c359165.zip | |
resolve typerelative ctors to adt
| -rw-r--r-- | compiler/rustc_mir_build/src/thir/cx/expr.rs | 39 | ||||
| -rw-r--r-- | tests/ui/nll/user-annotations/normalization-2.stderr | 2 |
2 files changed, 28 insertions, 13 deletions
diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 791c10c1748..26192c8e3c6 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -351,19 +351,34 @@ impl<'tcx> Cx<'tcx> { }); } } - let adt_data = - if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = fun.kind { + 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. - expr_ty.ty_adt_def().and_then(|adt_def| 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, - }) - } else { - None - }; + hir::QPath::Resolved(_, ref path) => { + expr_ty.ty_adt_def().and_then(|adt_def| 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 + } + }) + } + _ => None, + } + } else { + None + }; if let Some((adt_def, index)) = adt_data { let substs = self.typeck_results().node_substs(fun.hir_id); let user_provided_types = self.typeck_results().user_provided_types(); diff --git a/tests/ui/nll/user-annotations/normalization-2.stderr b/tests/ui/nll/user-annotations/normalization-2.stderr index 5299282ea15..6b0dcb414ae 100644 --- a/tests/ui/nll/user-annotations/normalization-2.stderr +++ b/tests/ui/nll/user-annotations/normalization-2.stderr @@ -147,7 +147,7 @@ LL | fn test_variants<'a, 'b, 'c>() { | -- lifetime `'b` defined here ... LL | <Ty<'b>>::Tuple(); - | ^^^^^^^^^^^^^^^ requires that `'b` must outlive `'static` + | ^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'static` error: lifetime may not live long enough --> $DIR/normalization-2.rs:93:5 |
