This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
compiler/rustc_passes/src Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,8 @@ impl CheckAttrVisitor<'tcx> {
8787 self . check_rustc_args_required_const ( & attr, span, target, item)
8888 } else if self . tcx . sess . check_name ( attr, sym:: allow_internal_unstable) {
8989 self . check_allow_internal_unstable ( & attr, span, target, & attrs)
90+ } else if self . tcx . sess . check_name ( attr, sym:: rustc_allow_const_fn_unstable) {
91+ self . check_rustc_allow_const_fn_unstable ( & attr, span, target)
9092 } else {
9193 // lint-only checks
9294 if self . tcx . sess . check_name ( attr, sym:: cold) {
@@ -791,6 +793,26 @@ impl CheckAttrVisitor<'tcx> {
791793 . emit ( ) ;
792794 false
793795 }
796+
797+ /// Outputs an error for `#[allow_internal_unstable]` which can only be applied to macros.
798+ /// (Allows proc_macro functions)
799+ fn check_rustc_allow_const_fn_unstable (
800+ & self ,
801+ attr : & Attribute ,
802+ span : & Span ,
803+ target : Target ,
804+ ) -> bool {
805+ if let Target :: Fn | Target :: Method ( _) = target {
806+ // FIXME Check that this isn't just a function, but a const fn
807+ return true ;
808+ }
809+ self . tcx
810+ . sess
811+ . struct_span_err ( attr. span , "attribute should be applied to `const fn`" )
812+ . span_label ( * span, "not a `const fn`" )
813+ . emit ( ) ;
814+ false
815+ }
794816}
795817
796818impl Visitor < ' tcx > for CheckAttrVisitor < ' tcx > {
You can’t perform that action at this time.
0 commit comments