This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +24
-12
lines changed
rustc_const_eval/src/const_eval Expand file tree Collapse file tree 5 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,7 @@ fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
1818 let node = tcx. hir_node_by_def_id ( def_id) ;
1919
2020 match node {
21- hir:: Node :: Ctor ( _)
22- | hir:: Node :: AnonConst ( _)
23- | hir:: Node :: ConstBlock ( _)
21+ hir:: Node :: Ctor ( hir:: VariantData :: Tuple ( ..) )
2422 | hir:: Node :: ImplItem ( hir:: ImplItem { kind : hir:: ImplItemKind :: Const ( ..) , .. } ) => {
2523 hir:: Constness :: Const
2624 }
@@ -41,7 +39,10 @@ fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
4139 let is_const = is_parent_const_impl_raw ( tcx, def_id) ;
4240 if is_const { hir:: Constness :: Const } else { hir:: Constness :: NotConst }
4341 } else {
44- hir:: Constness :: NotConst
42+ tcx. dcx ( ) . span_bug (
43+ tcx. def_span ( def_id) ,
44+ format ! ( "should not be requesting the constness of items that can't be const: {node:#?}: {:?}" , tcx. def_kind( def_id) )
45+ )
4546 }
4647 }
4748 }
Original file line number Diff line number Diff line change @@ -4044,9 +4044,7 @@ impl<'hir> Node<'hir> {
40444044 _ => None ,
40454045 } ,
40464046 Node :: TraitItem ( ti) => match ti. kind {
4047- TraitItemKind :: Fn ( ref sig, TraitFn :: Provided ( _) ) => {
4048- Some ( FnKind :: Method ( ti. ident , sig) )
4049- }
4047+ TraitItemKind :: Fn ( ref sig, _) => Some ( FnKind :: Method ( ti. ident , sig) ) ,
40504048 _ => None ,
40514049 } ,
40524050 Node :: ImplItem ( ii) => match ii. kind {
Original file line number Diff line number Diff line change @@ -1268,8 +1268,7 @@ fn should_encode_constness(def_kind: DefKind) -> bool {
12681268 | DefKind :: AssocFn
12691269 | DefKind :: Closure
12701270 | DefKind :: Impl { of_trait : true }
1271- | DefKind :: Variant
1272- | DefKind :: Ctor ( ..) => true ,
1271+ | DefKind :: Ctor ( _, CtorKind :: Fn ) => true ,
12731272
12741273 DefKind :: Struct
12751274 | DefKind :: Union
@@ -1296,6 +1295,8 @@ fn should_encode_constness(def_kind: DefKind) -> bool {
12961295 | DefKind :: LifetimeParam
12971296 | DefKind :: GlobalAsm
12981297 | DefKind :: ExternCrate
1298+ | DefKind :: Ctor ( _, CtorKind :: Const )
1299+ | DefKind :: Variant
12991300 | DefKind :: SyntheticCoroutineBody => false ,
13001301 }
13011302}
Original file line number Diff line number Diff line change @@ -746,7 +746,9 @@ rustc_queries! {
746746 desc { |tcx| "computing drop-check constraints for `{}`" , tcx. def_path_str( key) }
747747 }
748748
749- /// Returns `true` if this is a const fn / const impl.
749+ /// Returns the constness of functions and impls.
750+ ///
751+ /// Will ICE if used on things that are always const or never const.
750752 ///
751753 /// **Do not call this function manually.** It is only meant to cache the base data for the
752754 /// higher-level functions. Consider using `is_const_fn` or `is_const_trait_impl` instead.
Original file line number Diff line number Diff line change @@ -2014,7 +2014,17 @@ impl<'tcx> TyCtxt<'tcx> {
20142014 self . constness ( def_id) == hir:: Constness :: Const
20152015 }
20162016 DefKind :: Trait => self . is_const_trait ( def_id) ,
2017- DefKind :: AssocTy | DefKind :: AssocFn => {
2017+ DefKind :: AssocTy => {
2018+ let parent_def_id = self . parent ( def_id) ;
2019+ match self . def_kind ( parent_def_id) {
2020+ DefKind :: Impl { of_trait : false } => false ,
2021+ DefKind :: Impl { of_trait : true } | DefKind :: Trait => {
2022+ self . is_conditionally_const ( parent_def_id)
2023+ }
2024+ _ => bug ! ( "unexpected parent item of associated type: {parent_def_id:?}" ) ,
2025+ }
2026+ }
2027+ DefKind :: AssocFn => {
20182028 let parent_def_id = self . parent ( def_id) ;
20192029 match self . def_kind ( parent_def_id) {
20202030 DefKind :: Impl { of_trait : false } => {
@@ -2023,7 +2033,7 @@ impl<'tcx> TyCtxt<'tcx> {
20232033 DefKind :: Impl { of_trait : true } | DefKind :: Trait => {
20242034 self . is_conditionally_const ( parent_def_id)
20252035 }
2026- _ => bug ! ( "unexpected parent item of associated item : {parent_def_id:?}" ) ,
2036+ _ => bug ! ( "unexpected parent item of associated fn : {parent_def_id:?}" ) ,
20272037 }
20282038 }
20292039 DefKind :: OpaqueTy => match self . opaque_ty_origin ( def_id) {
You can’t perform that action at this time.
0 commit comments