File tree 5 files changed +24
-12
lines changed
rustc_const_eval/src/const_eval
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 {
18
18
let node = tcx. hir_node_by_def_id ( def_id) ;
19
19
20
20
match node {
21
- hir:: Node :: Ctor ( _)
22
- | hir:: Node :: AnonConst ( _)
23
- | hir:: Node :: ConstBlock ( _)
21
+ hir:: Node :: Ctor ( hir:: VariantData :: Tuple ( ..) )
24
22
| hir:: Node :: ImplItem ( hir:: ImplItem { kind : hir:: ImplItemKind :: Const ( ..) , .. } ) => {
25
23
hir:: Constness :: Const
26
24
}
@@ -41,7 +39,10 @@ fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
41
39
let is_const = is_parent_const_impl_raw ( tcx, def_id) ;
42
40
if is_const { hir:: Constness :: Const } else { hir:: Constness :: NotConst }
43
41
} 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
+ )
45
46
}
46
47
}
47
48
}
Original file line number Diff line number Diff line change @@ -4044,9 +4044,7 @@ impl<'hir> Node<'hir> {
4044
4044
_ => None ,
4045
4045
} ,
4046
4046
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) ) ,
4050
4048
_ => None ,
4051
4049
} ,
4052
4050
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 {
1268
1268
| DefKind :: AssocFn
1269
1269
| DefKind :: Closure
1270
1270
| DefKind :: Impl { of_trait : true }
1271
- | DefKind :: Variant
1272
- | DefKind :: Ctor ( ..) => true ,
1271
+ | DefKind :: Ctor ( _, CtorKind :: Fn ) => true ,
1273
1272
1274
1273
DefKind :: Struct
1275
1274
| DefKind :: Union
@@ -1296,6 +1295,8 @@ fn should_encode_constness(def_kind: DefKind) -> bool {
1296
1295
| DefKind :: LifetimeParam
1297
1296
| DefKind :: GlobalAsm
1298
1297
| DefKind :: ExternCrate
1298
+ | DefKind :: Ctor ( _, CtorKind :: Const )
1299
+ | DefKind :: Variant
1299
1300
| DefKind :: SyntheticCoroutineBody => false ,
1300
1301
}
1301
1302
}
Original file line number Diff line number Diff line change @@ -746,7 +746,9 @@ rustc_queries! {
746
746
desc { |tcx| "computing drop-check constraints for `{}`" , tcx. def_path_str( key) }
747
747
}
748
748
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.
750
752
///
751
753
/// **Do not call this function manually.** It is only meant to cache the base data for the
752
754
/// 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> {
2014
2014
self . constness ( def_id) == hir:: Constness :: Const
2015
2015
}
2016
2016
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 => {
2018
2028
let parent_def_id = self . parent ( def_id) ;
2019
2029
match self . def_kind ( parent_def_id) {
2020
2030
DefKind :: Impl { of_trait : false } => {
@@ -2023,7 +2033,7 @@ impl<'tcx> TyCtxt<'tcx> {
2023
2033
DefKind :: Impl { of_trait : true } | DefKind :: Trait => {
2024
2034
self . is_conditionally_const ( parent_def_id)
2025
2035
}
2026
- _ => bug ! ( "unexpected parent item of associated item : {parent_def_id:?}" ) ,
2036
+ _ => bug ! ( "unexpected parent item of associated fn : {parent_def_id:?}" ) ,
2027
2037
}
2028
2038
}
2029
2039
DefKind :: OpaqueTy => match self . opaque_ty_origin ( def_id) {
You can’t perform that action at this time.
0 commit comments