@@ -1481,17 +1481,21 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
14811481
14821482 // Figure out if this is a type/trait segment,
14831483 // which requires object lifetime defaults.
1484- let type_def_id = match res {
1485- Res :: Def ( DefKind :: AssocTy , def_id) if depth == 1 => Some ( self . tcx . parent ( def_id) ) ,
1486- Res :: Def ( DefKind :: Variant , def_id) if depth == 0 => Some ( self . tcx . parent ( def_id) ) ,
1487- Res :: Def (
1488- DefKind :: Struct
1489- | DefKind :: Union
1490- | DefKind :: Enum
1491- | DefKind :: TyAlias
1492- | DefKind :: Trait ,
1493- def_id,
1494- ) if depth == 0 => Some ( def_id) ,
1484+ let type_def_id = match ( res, depth) {
1485+ ( Res :: Def ( DefKind :: AssocTy , def_id) , 1 ) => Some ( self . tcx . parent ( def_id) ) ,
1486+ ( Res :: Def ( DefKind :: Variant , def_id) , 0 ) => Some ( self . tcx . parent ( def_id) ) ,
1487+ (
1488+ Res :: Def (
1489+ DefKind :: Struct
1490+ | DefKind :: Union
1491+ | DefKind :: Enum
1492+ | DefKind :: TyAlias
1493+ | DefKind :: Trait
1494+ | DefKind :: AssocTy ,
1495+ def_id,
1496+ ) ,
1497+ 0 ,
1498+ ) => Some ( def_id) ,
14951499 _ => None ,
14961500 } ;
14971501
@@ -1535,9 +1539,6 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
15351539 let map = & self . map ;
15361540 let generics = self . tcx . generics_of ( def_id) ;
15371541
1538- // `type_def_id` points to an item, so there is nothing to inherit generics from.
1539- debug_assert_eq ! ( generics. parent_count, 0 ) ;
1540-
15411542 let set_to_region = |set : ObjectLifetimeDefault | match set {
15421543 ObjectLifetimeDefault :: Empty => {
15431544 if in_body {
@@ -1548,8 +1549,8 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
15481549 }
15491550 ObjectLifetimeDefault :: Static => Some ( ResolvedArg :: StaticLifetime ) ,
15501551 ObjectLifetimeDefault :: Param ( param_def_id) => {
1551- // This index can be used with `generic_args` since `parent_count == 0`.
15521552 let index = generics. param_def_id_to_index [ & param_def_id] as usize ;
1553+ let index = index - generics. parent_count ;
15531554 generic_args. args . get ( index) . and_then ( |arg| match arg {
15541555 GenericArg :: Lifetime ( lt) => map. defs . get ( & lt. hir_id ) . copied ( ) ,
15551556 _ => None ,
0 commit comments