1+ use crate :: ast;
2+ use crate :: attr:: { self , TransparencyError } ;
13use crate :: edition:: Edition ;
24use crate :: ext:: base:: { DummyResult , ExtCtxt , MacResult , TTMacroExpander } ;
35use crate :: ext:: base:: { SyntaxExtension , SyntaxExtensionKind } ;
@@ -15,7 +17,6 @@ use crate::parse::token::{self, NtTT, Token};
1517use crate :: parse:: { Directory , ParseSess } ;
1618use crate :: symbol:: { kw, sym, Symbol } ;
1719use crate :: tokenstream:: { DelimSpan , TokenStream , TokenTree } ;
18- use crate :: { ast, attr, attr:: TransparencyError } ;
1920
2021use errors:: { DiagnosticBuilder , FatalError } ;
2122use log:: debug;
@@ -290,6 +291,7 @@ pub fn compile(
290291 def : & ast:: Item ,
291292 edition : Edition ,
292293) -> SyntaxExtension {
294+ let diag = & sess. span_diagnostic ;
293295 let lhs_nm = ast:: Ident :: new ( sym:: lhs, def. span ) ;
294296 let rhs_nm = ast:: Ident :: new ( sym:: rhs, def. span ) ;
295297 let tt_spec = ast:: Ident :: new ( sym:: tt, def. span ) ;
@@ -423,71 +425,25 @@ pub fn compile(
423425 let ( transparency, transparency_error) = attr:: find_transparency ( & def. attrs , body. legacy ) ;
424426 match transparency_error {
425427 Some ( TransparencyError :: UnknownTransparency ( value, span) ) =>
426- sess. span_diagnostic . span_err (
427- span, & format ! ( "unknown macro transparency: `{}`" , value)
428- ) ,
428+ diag. span_err ( span, & format ! ( "unknown macro transparency: `{}`" , value) ) ,
429429 Some ( TransparencyError :: MultipleTransparencyAttrs ( old_span, new_span) ) =>
430- sess. span_diagnostic . span_err (
431- vec ! [ old_span, new_span] , "multiple macro transparency attributes"
432- ) ,
430+ diag. span_err ( vec ! [ old_span, new_span] , "multiple macro transparency attributes" ) ,
433431 None => { }
434432 }
435433
436434 let expander: Box < _ > = Box :: new ( MacroRulesMacroExpander {
437435 name : def. ident , span : def. span , transparency, lhses, rhses, valid
438436 } ) ;
439437
440- let allow_internal_unstable =
441- attr:: find_by_name ( & def. attrs , sym:: allow_internal_unstable) . map ( |attr| {
442- attr. meta_item_list ( )
443- . map ( |list| {
444- list. iter ( )
445- . filter_map ( |it| {
446- let name = it. ident ( ) . map ( |ident| ident. name ) ;
447- if name. is_none ( ) {
448- sess. span_diagnostic . span_err (
449- it. span ( ) ,
450- "allow internal unstable expects feature names" ,
451- )
452- }
453- name
454- } )
455- . collect :: < Vec < Symbol > > ( )
456- . into ( )
457- } )
458- . unwrap_or_else ( || {
459- sess. span_diagnostic . span_warn (
460- attr. span ,
461- "allow_internal_unstable expects list of feature names. In the \
462- future this will become a hard error. Please use `allow_internal_unstable(\
463- foo, bar)` to only allow the `foo` and `bar` features",
464- ) ;
465- vec ! [ sym:: allow_internal_unstable_backcompat_hack] . into ( )
466- } )
467- } ) ;
468-
469- let mut local_inner_macros = false ;
470- if let Some ( macro_export) = attr:: find_by_name ( & def. attrs , sym:: macro_export) {
471- if let Some ( l) = macro_export. meta_item_list ( ) {
472- local_inner_macros = attr:: list_contains_name ( & l, sym:: local_inner_macros) ;
473- }
474- }
475-
476- let is_builtin = attr:: contains_name ( & def. attrs , sym:: rustc_builtin_macro) ;
477-
478- SyntaxExtension {
479- kind : SyntaxExtensionKind :: LegacyBang ( expander) ,
480- span : def. span ,
481- allow_internal_unstable,
482- allow_internal_unsafe : attr:: contains_name ( & def. attrs , sym:: allow_internal_unsafe) ,
483- local_inner_macros,
484- stability : attr:: find_stability ( & sess, & def. attrs , def. span ) ,
485- deprecation : attr:: find_deprecation ( & sess, & def. attrs , def. span ) ,
486- helper_attrs : Vec :: new ( ) ,
438+ SyntaxExtension :: new (
439+ sess,
440+ SyntaxExtensionKind :: LegacyBang ( expander) ,
441+ def. span ,
442+ Vec :: new ( ) ,
487443 edition,
488- is_builtin ,
489- is_derive_copy : is_builtin && def. ident . name == sym :: Copy ,
490- }
444+ def . ident . name ,
445+ & def. attrs ,
446+ )
491447}
492448
493449fn check_lhs_nt_follows (
0 commit comments