@@ -757,6 +757,11 @@ pub struct SyntaxExtension {
757757 /// Built-in macros have a couple of special properties like availability
758758 /// in `#[no_implicit_prelude]` modules, so we have to keep this flag.
759759 pub builtin_name : Option < Symbol > ,
760+ /// Whether this macro is either a compiler intrinsic (implied by the above field) or a macro
761+ /// provided by the standard library where the specific of its implementation are not relevant
762+ /// to the end user, like for `format!` or `println!`, which are normal macros by example, but
763+ /// that is an implementation detail.
764+ pub builtin : bool ,
760765 /// Suppresses the `unsafe_code` lint for code produced by this macro.
761766 pub allow_internal_unsafe : bool ,
762767 /// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`) for this macro.
@@ -792,6 +797,7 @@ impl SyntaxExtension {
792797 helper_attrs : Vec :: new ( ) ,
793798 edition,
794799 builtin_name : None ,
800+ builtin : false ,
795801 kind,
796802 allow_internal_unsafe : false ,
797803 local_inner_macros : false ,
@@ -888,17 +894,19 @@ impl SyntaxExtension {
888894 )
889895 } )
890896 . unwrap_or_else ( || ( None , helper_attrs) ) ;
897+ let builtin = builtin_name. is_some ( )
898+ || ast:: attr:: find_by_name ( attrs, sym:: rustc_diagnostic_item) . is_some ( ) ;
891899
892- let stability = find_attr ! ( attrs, AttributeKind :: Stability { stability, ..} => * stability) ;
900+ let stability = find_attr ! ( attrs, AttributeKind :: Stability { stability, .. } => * stability) ;
893901
894902 // FIXME(jdonszelmann): make it impossible to miss the or_else in the typesystem
895- if let Some ( sp) = find_attr ! ( attrs, AttributeKind :: ConstStability { span, ..} => * span) {
903+ if let Some ( sp) = find_attr ! ( attrs, AttributeKind :: ConstStability { span, .. } => * span) {
896904 sess. dcx ( ) . emit_err ( errors:: MacroConstStability {
897905 span : sp,
898906 head_span : sess. source_map ( ) . guess_head_span ( span) ,
899907 } ) ;
900908 }
901- if let Some ( sp) = find_attr ! ( attrs, AttributeKind :: BodyStability { span, ..} => * span) {
909+ if let Some ( sp) = find_attr ! ( attrs, AttributeKind :: BodyStability { span, .. } => * span) {
902910 sess. dcx ( ) . emit_err ( errors:: MacroBodyStability {
903911 span : sp,
904912 head_span : sess. source_map ( ) . guess_head_span ( span) ,
@@ -912,10 +920,14 @@ impl SyntaxExtension {
912920 // FIXME(jdonszelmann): avoid the into_iter/collect?
913921 . then ( || allow_internal_unstable. iter ( ) . map ( |i| i. 0 ) . collect :: < Vec < _ > > ( ) . into ( ) ) ,
914922 stability,
915- deprecation : find_attr ! ( attrs, AttributeKind :: Deprecation { deprecation, ..} => * deprecation) ,
923+ deprecation : find_attr ! (
924+ attrs,
925+ AttributeKind :: Deprecation { deprecation, .. } => * deprecation
926+ ) ,
916927 helper_attrs,
917928 edition,
918929 builtin_name,
930+ builtin,
919931 allow_internal_unsafe,
920932 local_inner_macros,
921933 collapse_debuginfo,
@@ -1000,6 +1012,7 @@ impl SyntaxExtension {
10001012 self . allow_internal_unsafe ,
10011013 self . local_inner_macros ,
10021014 self . collapse_debuginfo ,
1015+ self . builtin ,
10031016 )
10041017 }
10051018}
0 commit comments