File tree Expand file tree Collapse file tree 3 files changed +14
-7
lines changed Expand file tree Collapse file tree 3 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -2264,10 +2264,12 @@ pub enum ConstContext {
22642264 /// - Array length expressions
22652265 /// - Enum discriminants
22662266 /// - Const generics
2267- ///
2268- /// For the most part, other contexts are treated just like a regular `const`, so they are
2269- /// lumped into the same category.
2270- Const { inline : bool } ,
2267+ Const {
2268+ /// For backwards compatibility `const` items allow
2269+ /// calls to `const fn` to get promoted.
2270+ /// We forbid that in comptime fns and inline consts.
2271+ allow_const_fn_promotion : bool ,
2272+ } ,
22712273}
22722274
22732275impl ConstContext {
Original file line number Diff line number Diff line change @@ -314,13 +314,15 @@ impl<'tcx> TyCtxt<'tcx> {
314314 pub fn hir_body_const_context ( self , def_id : LocalDefId ) -> Option < ConstContext > {
315315 let def_id = def_id. into ( ) ;
316316 let ccx = match self . hir_body_owner_kind ( def_id) {
317- BodyOwnerKind :: Const { inline } => ConstContext :: Const { inline } ,
317+ BodyOwnerKind :: Const { inline } => {
318+ ConstContext :: Const { allow_const_fn_promotion : !inline }
319+ }
318320 BodyOwnerKind :: Static ( mutability) => ConstContext :: Static ( mutability) ,
319321
320322 BodyOwnerKind :: Fn if self . is_constructor ( def_id) => return None ,
321323 BodyOwnerKind :: Fn | BodyOwnerKind :: Closure if self . is_const_fn ( def_id) => {
322324 if self . constness ( def_id) == rustc_hir:: Constness :: Comptime {
323- ConstContext :: Const { inline : true }
325+ ConstContext :: Const { allow_const_fn_promotion : false }
324326 } else {
325327 ConstContext :: ConstFn
326328 }
Original file line number Diff line number Diff line change @@ -668,7 +668,10 @@ impl<'tcx> Validator<'_, 'tcx> {
668668 // backwards compatibility reason to allow more promotion inside of them.
669669 let promote_all_fn = matches ! (
670670 self . const_kind,
671- Some ( hir:: ConstContext :: Static ( _) | hir:: ConstContext :: Const { inline: false } )
671+ Some (
672+ hir:: ConstContext :: Static ( _)
673+ | hir:: ConstContext :: Const { allow_const_fn_promotion: false }
674+ )
672675 ) ;
673676 if !promote_all_fn {
674677 return Err ( Unpromotable ) ;
You can’t perform that action at this time.
0 commit comments