11use crate :: base:: * ;
22use crate :: config:: StripUnconfigured ;
33use crate :: errors:: {
4- EmptyDelegationList , IncompleteParse , RecursionLimitReached , RemoveExprNotSupported ,
5- RemoveNodeNotSupported , UnsupportedKeyValue , WrongFragmentKind ,
4+ CustomAttributesForbidden , EmptyDelegationList , IncompleteParse ,
5+ NonInlineModuleInProcMacroUnstable , RecursionLimitReached , RemoveExprNotSupported ,
6+ RemoveNodeNotSupported , StatementOrExpression , UnsupportedKeyValue , WrongFragmentKind ,
67} ;
78use crate :: mbe:: diagnostics:: annotate_err_with_kind;
89use crate :: module:: { mod_dir_path, parse_external_mod, DirOwnership , ParsedExternalMod } ;
@@ -29,7 +30,7 @@ use rustc_parse::parser::{
2930use rustc_parse:: validate_attr;
3031use rustc_session:: lint:: builtin:: { UNUSED_ATTRIBUTES , UNUSED_DOC_COMMENTS } ;
3132use rustc_session:: lint:: BuiltinLintDiag ;
32- use rustc_session:: parse:: feature_err ;
33+ use rustc_session:: parse:: get_feature_diagnostics ;
3334use rustc_session:: { Limit , Session } ;
3435use rustc_span:: hygiene:: SyntaxContext ;
3536use rustc_span:: symbol:: { sym, Ident } ;
@@ -796,7 +797,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
796797 } )
797798 }
798799
799- #[ allow( rustc:: untranslatable_diagnostic) ] // FIXME: make this translatable
800800 fn gate_proc_macro_attr_item ( & self , span : Span , item : & Annotatable ) {
801801 let kind = match item {
802802 Annotatable :: Item ( _)
@@ -810,9 +810,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
810810 if stmt. is_item ( ) {
811811 return ;
812812 }
813- "statements"
813+ StatementOrExpression :: Statement
814814 }
815- Annotatable :: Expr ( _) => "expressions" ,
815+ Annotatable :: Expr ( _) => StatementOrExpression :: Expression ,
816816 Annotatable :: Arm ( ..)
817817 | Annotatable :: ExprField ( ..)
818818 | Annotatable :: PatField ( ..)
@@ -824,13 +824,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
824824 if self . cx . ecfg . features . proc_macro_hygiene {
825825 return ;
826826 }
827- feature_err (
828- & self . cx . sess ,
829- sym:: proc_macro_hygiene,
827+ self . cx . dcx ( ) . emit_err ( CustomAttributesForbidden {
830828 span,
831- format ! ( "custom attributes cannot be applied to {kind}" ) ,
832- )
833- . emit ( ) ;
829+ subdiag : get_feature_diagnostics ( & self . cx . sess , sym :: proc_macro_hygiene ) ,
830+ kind ,
831+ } ) ;
834832 }
835833
836834 fn gate_proc_macro_input ( & self , annotatable : & Annotatable ) {
@@ -839,19 +837,15 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
839837 }
840838
841839 impl < ' ast , ' a > Visitor < ' ast > for GateProcMacroInput < ' a > {
842- #[ allow( rustc:: untranslatable_diagnostic) ] // FIXME: make this translatable
843840 fn visit_item ( & mut self , item : & ' ast ast:: Item ) {
844841 match & item. kind {
845842 ItemKind :: Mod ( _, mod_kind)
846843 if !matches ! ( mod_kind, ModKind :: Loaded ( _, Inline :: Yes , _) ) =>
847844 {
848- feature_err (
849- self . sess ,
850- sym:: proc_macro_hygiene,
851- item. span ,
852- "non-inline modules in proc macro input are unstable" ,
853- )
854- . emit ( ) ;
845+ self . sess . dcx ( ) . emit_err ( NonInlineModuleInProcMacroUnstable {
846+ span : item. span ,
847+ subdiag : get_feature_diagnostics ( self . sess , sym:: proc_macro_hygiene) ,
848+ } ) ;
855849 }
856850 _ => { }
857851 }
0 commit comments