@@ -253,6 +253,7 @@ pub struct ImplTraitHeader<'tcx> {
253
253
pub trait_ref : ty:: EarlyBinder < ' tcx , ty:: TraitRef < ' tcx > > ,
254
254
pub polarity : ImplPolarity ,
255
255
pub safety : hir:: Safety ,
256
+ pub constness : hir:: Constness ,
256
257
}
257
258
258
259
#[ derive( Copy , Clone , PartialEq , Eq , Debug , TypeFoldable , TypeVisitable ) ]
@@ -2004,17 +2005,25 @@ impl<'tcx> TyCtxt<'tcx> {
2004
2005
let def_id: DefId = def_id. into ( ) ;
2005
2006
match self . def_kind ( def_id) {
2006
2007
DefKind :: Impl { of_trait : true } => {
2007
- self . constness ( def_id) == hir:: Constness :: Const
2008
- && self . is_const_trait (
2009
- self . trait_id_of_impl ( def_id)
2010
- . expect ( "expected trait for trait implementation" ) ,
2011
- )
2008
+ let header = self . impl_trait_header ( def_id) . unwrap ( ) ;
2009
+ header. constness == hir:: Constness :: Const
2010
+ && self . is_const_trait ( header. trait_ref . skip_binder ( ) . def_id )
2012
2011
}
2013
2012
DefKind :: Fn | DefKind :: Ctor ( _, CtorKind :: Fn ) => {
2014
2013
self . constness ( def_id) == hir:: Constness :: Const
2015
2014
}
2016
2015
DefKind :: Trait => self . is_const_trait ( def_id) ,
2017
- DefKind :: AssocTy | DefKind :: AssocFn => {
2016
+ DefKind :: AssocTy => {
2017
+ let parent_def_id = self . parent ( def_id) ;
2018
+ match self . def_kind ( parent_def_id) {
2019
+ DefKind :: Impl { of_trait : false } => false ,
2020
+ DefKind :: Impl { of_trait : true } | DefKind :: Trait => {
2021
+ self . is_conditionally_const ( parent_def_id)
2022
+ }
2023
+ _ => bug ! ( "unexpected parent item of associated type: {parent_def_id:?}" ) ,
2024
+ }
2025
+ }
2026
+ DefKind :: AssocFn => {
2018
2027
let parent_def_id = self . parent ( def_id) ;
2019
2028
match self . def_kind ( parent_def_id) {
2020
2029
DefKind :: Impl { of_trait : false } => {
@@ -2023,7 +2032,7 @@ impl<'tcx> TyCtxt<'tcx> {
2023
2032
DefKind :: Impl { of_trait : true } | DefKind :: Trait => {
2024
2033
self . is_conditionally_const ( parent_def_id)
2025
2034
}
2026
- _ => bug ! ( "unexpected parent item of associated item : {parent_def_id:?}" ) ,
2035
+ _ => bug ! ( "unexpected parent item of associated fn : {parent_def_id:?}" ) ,
2027
2036
}
2028
2037
}
2029
2038
DefKind :: OpaqueTy => match self . opaque_ty_origin ( def_id) {
0 commit comments