@@ -23,6 +23,7 @@ use super::{
2323 AstOwner , FnDeclKind , ImplTraitContext , ImplTraitPosition , LoweringContext , ParamMode ,
2424 RelaxedBoundForbiddenReason , RelaxedBoundPolicy , ResolverAstLoweringExt ,
2525} ;
26+ use crate :: errors:: ConstComptimeFn ;
2627
2728pub ( super ) struct ItemLowerer < ' a , ' hir > {
2829 pub ( super ) tcx : TyCtxt < ' hir > ,
@@ -1537,12 +1538,23 @@ impl<'hir> LoweringContext<'_, 'hir> {
15371538 safety. into ( )
15381539 } ;
15391540
1540- hir:: FnHeader {
1541- safety,
1542- asyncness,
1543- constness : self . lower_constness ( h. constness ) ,
1544- abi : self . lower_extern ( h. ext ) ,
1541+ let mut constness = self . lower_constness ( h. constness ) ;
1542+ if let Some ( & attr_span) = find_attr ! ( attrs, AttributeKind :: Comptime ( span) => span) {
1543+ match std:: mem:: replace ( & mut constness, rustc_hir:: Constness :: Comptime ) {
1544+ rustc_hir:: Constness :: Comptime => {
1545+ unreachable ! ( "lower_constness cannot produce comptime" )
1546+ }
1547+ // A function can't be `const` and `comptime` at the same time
1548+ rustc_hir:: Constness :: Const => {
1549+ let Const :: Yes ( span) = h. constness else { unreachable ! ( ) } ;
1550+ self . dcx ( ) . emit_err ( ConstComptimeFn { span, attr_span } ) ;
1551+ }
1552+ // Good
1553+ rustc_hir:: Constness :: NotConst => { }
1554+ }
15451555 }
1556+
1557+ hir:: FnHeader { safety, asyncness, constness, abi : self . lower_extern ( h. ext ) }
15461558 }
15471559
15481560 pub ( super ) fn lower_abi ( & mut self , abi_str : StrLit ) -> ExternAbi {
0 commit comments