@@ -25,7 +25,7 @@ use rustc_parse::parser::{
2525use rustc_parse:: validate_attr;
2626use rustc_session:: lint:: builtin:: { UNUSED_ATTRIBUTES , UNUSED_DOC_COMMENTS } ;
2727use rustc_session:: lint:: BuiltinLintDiag ;
28- use rustc_session:: parse:: feature_err ;
28+ use rustc_session:: parse:: get_feature_diagnostics ;
2929use rustc_session:: { Limit , Session } ;
3030use rustc_span:: hygiene:: SyntaxContext ;
3131use rustc_span:: symbol:: { sym, Ident } ;
@@ -35,11 +35,11 @@ use smallvec::SmallVec;
3535use crate :: base:: * ;
3636use crate :: config:: StripUnconfigured ;
3737use crate :: errors:: {
38- EmptyDelegationMac , GlobDelegationOutsideImpls , GlobDelegationTraitlessQpath , IncompleteParse ,
39- RecursionLimitReached , RemoveExprNotSupported , RemoveNodeNotSupported , UnsupportedKeyValue ,
40- WrongFragmentKind ,
38+ CustomAttributesForbidden , EmptyDelegationMac , GlobDelegationOutsideImpls ,
39+ GlobDelegationTraitlessQpath , IncompleteParse , NonInlineModuleInProcMacroUnstable ,
40+ RecursionLimitReached , RemoveExprNotSupported , RemoveNodeNotSupported , StatementOrExpression ,
41+ UnsupportedKeyValue , WrongFragmentKind ,
4142} ;
42- use crate :: fluent_generated;
4343use crate :: mbe:: diagnostics:: annotate_err_with_kind;
4444use crate :: module:: { mod_dir_path, parse_external_mod, DirOwnership , ParsedExternalMod } ;
4545use crate :: placeholders:: { placeholder, PlaceholderExpander } ;
@@ -841,7 +841,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
841841 } )
842842 }
843843
844- #[ allow( rustc:: untranslatable_diagnostic) ] // FIXME: make this translatable
845844 fn gate_proc_macro_attr_item ( & self , span : Span , item : & Annotatable ) {
846845 let kind = match item {
847846 Annotatable :: Item ( _)
@@ -854,9 +853,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
854853 if stmt. is_item ( ) {
855854 return ;
856855 }
857- "statements"
856+ StatementOrExpression :: Statement
858857 }
859- Annotatable :: Expr ( _) => "expressions" ,
858+ Annotatable :: Expr ( _) => StatementOrExpression :: Expression ,
860859 Annotatable :: Arm ( ..)
861860 | Annotatable :: ExprField ( ..)
862861 | Annotatable :: PatField ( ..)
@@ -868,13 +867,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
868867 if self . cx . ecfg . features . proc_macro_hygiene {
869868 return ;
870869 }
871- feature_err (
872- & self . cx . sess ,
873- sym:: proc_macro_hygiene,
870+ self . cx . dcx ( ) . emit_err ( CustomAttributesForbidden {
874871 span,
875- format ! ( "custom attributes cannot be applied to {kind}" ) ,
876- )
877- . emit ( ) ;
872+ subdiag : get_feature_diagnostics ( & self . cx . sess , sym :: proc_macro_hygiene ) ,
873+ kind ,
874+ } ) ;
878875 }
879876
880877 fn gate_proc_macro_input ( & self , annotatable : & Annotatable ) {
@@ -888,13 +885,10 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
888885 ItemKind :: Mod ( _, mod_kind)
889886 if !matches ! ( mod_kind, ModKind :: Loaded ( _, Inline :: Yes , _) ) =>
890887 {
891- feature_err (
892- self . sess ,
893- sym:: proc_macro_hygiene,
894- item. span ,
895- fluent_generated:: expand_non_inline_modules_in_proc_macro_input_are_unstable,
896- )
897- . emit ( ) ;
888+ self . sess . dcx ( ) . emit_err ( NonInlineModuleInProcMacroUnstable {
889+ span : item. span ,
890+ subdiag : get_feature_diagnostics ( self . sess , sym:: proc_macro_hygiene) ,
891+ } ) ;
898892 }
899893 _ => { }
900894 }
0 commit comments