@@ -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,10 +1538,26 @@ impl<'hir> LoweringContext<'_, 'hir> {
15371538 safety. into ( )
15381539 } ;
15391540
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+ }
1555+ }
1556+
15401557 hir:: FnHeader {
15411558 safety,
15421559 asyncness,
1543- constness : self . lower_constness ( h . constness ) ,
1560+ constness,
15441561 abi : self . lower_extern ( h. ext ) ,
15451562 }
15461563 }
0 commit comments