Skip to content

Commit cf566ea

Browse files
committed
Make enum variant paths induce trait object lifetime defaults in the enum path segment
1 parent 6aa9277 commit cf566ea

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,9 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
16911691
// which requires object lifetime defaults.
16921692
let type_def_id = match res {
16931693
Res::Def(DefKind::AssocTy, def_id) if depth == 1 => Some(self.tcx.parent(def_id)),
1694-
Res::Def(DefKind::Variant, def_id) if depth == 0 => Some(self.tcx.parent(def_id)),
1694+
Res::Def(DefKind::Variant, def_id) if depth == 0 || depth == 1 => {
1695+
Some(self.tcx.parent(def_id))
1696+
}
16951697
Res::Def(
16961698
DefKind::Struct
16971699
| DefKind::Union
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ check-pass
2+
3+
enum Enum<'a, T: ?Sized + 'a> {
4+
Variant,
5+
6+
Carry(&'a T),
7+
}
8+
9+
fn scope<'any>() {
10+
// We elaborate `dyn Trait` to `dyn Trait + 'any` due to bound `'a` on `T`.
11+
let _: Enum<'_, dyn Trait + 'any> = Enum::Variant::<'any, dyn Trait> {};
12+
13+
// Similarly here.
14+
let _: Enum<'_, dyn Trait + 'any> = Enum::<'any, dyn Trait>::Variant {};
15+
}
16+
17+
trait Trait {}
18+
19+
fn main() {}

0 commit comments

Comments
 (0)