@@ -2,7 +2,6 @@ use crate::edition::Edition;
22use crate :: ext:: base:: { DummyResult , ExtCtxt , MacResult , TTMacroExpander } ;
33use crate :: ext:: base:: { SyntaxExtension , SyntaxExtensionKind } ;
44use crate :: ext:: expand:: { AstFragment , AstFragmentKind } ;
5- use crate :: ext:: hygiene:: Transparency ;
65use crate :: ext:: tt:: macro_parser:: { parse, parse_failure_msg} ;
76use crate :: ext:: tt:: macro_parser:: { Error , Failure , Success } ;
87use crate :: ext:: tt:: macro_parser:: { MatchedNonterminal , MatchedSeq } ;
@@ -15,7 +14,7 @@ use crate::parse::token::{self, NtTT, Token};
1514use crate :: parse:: { Directory , ParseSess } ;
1615use crate :: symbol:: { kw, sym, Symbol } ;
1716use crate :: tokenstream:: { DelimSpan , TokenStream , TokenTree } ;
18- use crate :: { ast, attr} ;
17+ use crate :: { ast, attr, attr :: TransparencyError } ;
1918
2019use errors:: FatalError ;
2120use log:: debug;
@@ -380,17 +379,19 @@ pub fn compile(
380379 let expander: Box < _ > =
381380 Box :: new ( MacroRulesMacroExpander { name : def. ident , lhses, rhses, valid } ) ;
382381
383- let value_str = attr:: first_attr_value_str_by_name ( & def. attrs , sym:: rustc_macro_transparency) ;
384- let default_transparency = value_str. and_then ( |s| Some ( match & * s. as_str ( ) {
385- "transparent" => Transparency :: Transparent ,
386- "semitransparent" => Transparency :: SemiTransparent ,
387- "opaque" => Transparency :: Opaque ,
388- _ => {
389- let msg = format ! ( "unknown macro transparency: `{}`" , s) ;
390- sess. span_diagnostic . span_err ( def. span , & msg) ;
391- return None ;
392- }
393- } ) ) . unwrap_or ( if body. legacy { Transparency :: SemiTransparent } else { Transparency :: Opaque } ) ;
382+ let ( default_transparency, transparency_error) =
383+ attr:: find_transparency ( & def. attrs , body. legacy ) ;
384+ match transparency_error {
385+ Some ( TransparencyError :: UnknownTransparency ( value, span) ) =>
386+ sess. span_diagnostic . span_err (
387+ span, & format ! ( "unknown macro transparency: `{}`" , value)
388+ ) ,
389+ Some ( TransparencyError :: MultipleTransparencyAttrs ( old_span, new_span) ) =>
390+ sess. span_diagnostic . span_err (
391+ vec ! [ old_span, new_span] , "multiple macro transparency attributes"
392+ ) ,
393+ None => { }
394+ }
394395
395396 let allow_internal_unstable =
396397 attr:: find_by_name ( & def. attrs , sym:: allow_internal_unstable) . map ( |attr| {
0 commit comments