@@ -253,6 +253,7 @@ pub struct ImplTraitHeader<'tcx> {
253253 pub trait_ref : ty:: EarlyBinder < ' tcx , ty:: TraitRef < ' tcx > > ,
254254 pub polarity : ImplPolarity ,
255255 pub safety : hir:: Safety ,
256+ pub constness : hir:: Constness ,
256257}
257258
258259#[ derive( Copy , Clone , PartialEq , Eq , Debug , TypeFoldable , TypeVisitable ) ]
@@ -2004,17 +2005,25 @@ impl<'tcx> TyCtxt<'tcx> {
20042005 let def_id: DefId = def_id. into ( ) ;
20052006 match self . def_kind ( def_id) {
20062007 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 )
20122011 }
20132012 DefKind :: Fn | DefKind :: Ctor ( _, CtorKind :: Fn ) => {
20142013 self . constness ( def_id) == hir:: Constness :: Const
20152014 }
20162015 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 => {
20182027 let parent_def_id = self . parent ( def_id) ;
20192028 match self . def_kind ( parent_def_id) {
20202029 DefKind :: Impl { of_trait : false } => {
@@ -2023,7 +2032,7 @@ impl<'tcx> TyCtxt<'tcx> {
20232032 DefKind :: Impl { of_trait : true } | DefKind :: Trait => {
20242033 self . is_conditionally_const ( parent_def_id)
20252034 }
2026- _ => bug ! ( "unexpected parent item of associated item : {parent_def_id:?}" ) ,
2035+ _ => bug ! ( "unexpected parent item of associated fn : {parent_def_id:?}" ) ,
20272036 }
20282037 }
20292038 DefKind :: OpaqueTy => match self . opaque_ty_origin ( def_id) {
0 commit comments