Skip to content

Commit 76a7772

Browse files
resolve typerelative ctors to adt
1 parent 5bd28f5 commit 76a7772

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

compiler/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -351,19 +351,34 @@ impl<'tcx> Cx<'tcx> {
351351
});
352352
}
353353
}
354-
let adt_data =
355-
if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = fun.kind {
354+
let adt_data = if let hir::ExprKind::Path(qpath) = fun.kind {
355+
match qpath {
356356
// Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
357-
expr_ty.ty_adt_def().and_then(|adt_def| match path.res {
358-
Res::Def(DefKind::Ctor(_, CtorKind::Fn), ctor_id) => {
359-
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
360-
}
361-
Res::SelfCtor(..) => Some((adt_def, FIRST_VARIANT)),
362-
_ => None,
363-
})
364-
} else {
365-
None
366-
};
357+
hir::QPath::Resolved(_, ref path) => {
358+
expr_ty.ty_adt_def().and_then(|adt_def| match path.res {
359+
Res::Def(DefKind::Ctor(_, CtorKind::Fn), ctor_id) => {
360+
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
361+
}
362+
Res::SelfCtor(..) => Some((adt_def, FIRST_VARIANT)),
363+
_ => None,
364+
})
365+
}
366+
hir::QPath::TypeRelative(_ty, _) => {
367+
expr_ty.ty_adt_def().and_then(|adt_def| {
368+
if let Some((DefKind::Ctor(_, CtorKind::Fn), ctor_id)) =
369+
self.typeck_results().type_dependent_def(fun.hir_id)
370+
{
371+
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
372+
} else {
373+
None
374+
}
375+
})
376+
}
377+
_ => None,
378+
}
379+
} else {
380+
None
381+
};
367382
if let Some((adt_def, index)) = adt_data {
368383
let substs = self.typeck_results().node_substs(fun.hir_id);
369384
let user_provided_types = self.typeck_results().user_provided_types();

tests/ui/nll/user-annotations/normalization-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ LL | fn test_variants<'a, 'b, 'c>() {
147147
| -- lifetime `'b` defined here
148148
...
149149
LL | <Ty<'b>>::Tuple();
150-
| ^^^^^^^^^^^^^^^ requires that `'b` must outlive `'static`
150+
| ^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'static`
151151

152152
error: lifetime may not live long enough
153153
--> $DIR/normalization-2.rs:93:5

0 commit comments

Comments
 (0)