@@ -1518,6 +1518,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
1518
1518
params,
1519
1519
param_def_id_to_index,
1520
1520
has_self : generics. has_self ,
1521
+ has_constness : generics. has_constness ,
1521
1522
has_late_bound_regions : generics. has_late_bound_regions ,
1522
1523
} ;
1523
1524
}
@@ -1623,7 +1624,9 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
1623
1624
} ;
1624
1625
1625
1626
let has_self = opt_self. is_some ( ) ;
1627
+ let has_constness = tcx. has_attr ( def_id, sym:: const_trait) ;
1626
1628
let mut parent_has_self = false ;
1629
+ let mut parent_has_constness = false ;
1627
1630
let mut own_start = has_self as u32 ;
1628
1631
let parent_count = parent_def_id. map_or ( 0 , |def_id| {
1629
1632
let generics = tcx. generics_of ( def_id) ;
@@ -1632,8 +1635,8 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
1632
1635
own_start = generics. count ( ) as u32 ;
1633
1636
// if parent has constness param, we do not inherit it from the parent, and we
1634
1637
// get it in the end instead of the middle.
1635
- let parent_constness = parent_has_self as usize ;
1636
- generics. parent_count + generics. params . len ( ) - parent_constness
1638
+ parent_has_constness = generics . has_constness ;
1639
+ generics. parent_count + generics. params . len ( ) - parent_has_constness as usize
1637
1640
} ) ;
1638
1641
1639
1642
let mut params: Vec < _ > = Vec :: with_capacity ( ast_generics. params . len ( ) + has_self as usize ) ;
@@ -1759,7 +1762,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
1759
1762
}
1760
1763
}
1761
1764
1762
- if ( has_self || parent_has_self ) && tcx . has_attr ( def_id , sym :: const_trait ) {
1765
+ if has_constness || parent_has_constness {
1763
1766
params. push ( ty:: GenericParamDef {
1764
1767
name : Symbol :: intern ( "<constness>" ) ,
1765
1768
index : type_start + i as u32 ,
@@ -1777,6 +1780,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
1777
1780
params,
1778
1781
param_def_id_to_index,
1779
1782
has_self : has_self || parent_has_self,
1783
+ has_constness : has_constness || parent_has_constness,
1780
1784
has_late_bound_regions : has_late_bound_regions ( tcx, node) ,
1781
1785
}
1782
1786
}
0 commit comments