11use crate :: base:: * ;
22use crate :: config:: StripUnconfigured ;
33use crate :: errors:: {
4- IncompleteParse , RecursionLimitReached , RemoveExprNotSupported , RemoveNodeNotSupported ,
4+ CustomAttributesForbidden , IncompleteParse , NonInlineModuleInProcMacroUnstable ,
5+ RecursionLimitReached , RemoveExprNotSupported , RemoveNodeNotSupported , StatementOrExpression ,
56 UnsupportedKeyValue , WrongFragmentKind ,
67} ;
78use crate :: hygiene:: SyntaxContext ;
@@ -30,7 +31,7 @@ use rustc_parse::parser::{
3031use rustc_parse:: validate_attr;
3132use rustc_session:: lint:: builtin:: { UNUSED_ATTRIBUTES , UNUSED_DOC_COMMENTS } ;
3233use rustc_session:: lint:: BuiltinLintDiag ;
33- use rustc_session:: parse:: feature_err;
34+ use rustc_session:: parse:: { feature_err, get_feature_diagnostics } ;
3435use rustc_session:: { Limit , Session } ;
3536use rustc_span:: symbol:: { sym, Ident } ;
3637use rustc_span:: { ErrorGuaranteed , FileName , LocalExpnId , Span } ;
@@ -792,7 +793,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
792793 } )
793794 }
794795
795- #[ allow( rustc:: untranslatable_diagnostic) ] // FIXME: make this translatable
796796 fn gate_proc_macro_attr_item ( & self , span : Span , item : & Annotatable ) {
797797 let kind = match item {
798798 Annotatable :: Item ( _)
@@ -806,9 +806,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
806806 if stmt. is_item ( ) {
807807 return ;
808808 }
809- "statements"
809+ StatementOrExpression :: Statement
810810 }
811- Annotatable :: Expr ( _) => "expressions" ,
811+ Annotatable :: Expr ( _) => StatementOrExpression :: Expression ,
812812 Annotatable :: Arm ( ..)
813813 | Annotatable :: ExprField ( ..)
814814 | Annotatable :: PatField ( ..)
@@ -820,13 +820,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
820820 if self . cx . ecfg . features . proc_macro_hygiene {
821821 return ;
822822 }
823- feature_err (
824- & self . cx . sess ,
825- sym:: proc_macro_hygiene,
823+ self . cx . dcx ( ) . emit_err ( CustomAttributesForbidden {
826824 span,
827- format ! ( "custom attributes cannot be applied to {kind}" ) ,
828- )
829- . emit ( ) ;
825+ subdiag : get_feature_diagnostics ( & self . cx . sess , sym :: proc_macro_hygiene ) ,
826+ kind ,
827+ } ) ;
830828 }
831829
832830 fn gate_proc_macro_input ( & self , annotatable : & Annotatable ) {
@@ -835,19 +833,15 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
835833 }
836834
837835 impl < ' ast , ' a > Visitor < ' ast > for GateProcMacroInput < ' a > {
838- #[ allow( rustc:: untranslatable_diagnostic) ] // FIXME: make this translatable
839836 fn visit_item ( & mut self , item : & ' ast ast:: Item ) {
840837 match & item. kind {
841838 ItemKind :: Mod ( _, mod_kind)
842839 if !matches ! ( mod_kind, ModKind :: Loaded ( _, Inline :: Yes , _) ) =>
843840 {
844- feature_err (
845- self . sess ,
846- sym:: proc_macro_hygiene,
847- item. span ,
848- "non-inline modules in proc macro input are unstable" ,
849- )
850- . emit ( ) ;
841+ self . sess . dcx ( ) . emit_err ( NonInlineModuleInProcMacroUnstable {
842+ span : item. span ,
843+ subdiag : get_feature_diagnostics ( self . sess , sym:: proc_macro_hygiene) ,
844+ } ) ;
851845 }
852846 _ => { }
853847 }
0 commit comments