@@ -59,13 +59,12 @@ pub struct Mark(u32);
5959#[ derive( Clone ,  Debug ) ]  
6060struct  MarkData  { 
6161    parent :  Mark , 
62-     default_transparency :  Transparency , 
6362    expn_info :  Option < ExpnInfo > , 
6463} 
6564
6665/// A property of a macro expansion that determines how identifiers 
6766/// produced by that expansion are resolved. 
68- #[ derive( Copy ,  Clone ,  PartialEq ,  Eq ,  PartialOrd ,  Hash ,  Debug ) ]  
67+ #[ derive( Copy ,  Clone ,  PartialEq ,  Eq ,  PartialOrd ,  Hash ,  Debug ,   RustcEncodable ,   RustcDecodable ) ]  
6968pub  enum  Transparency  { 
7069    /// Identifier produced by a transparent expansion is always resolved at call-site. 
7170     /// Call-site spans in procedural macros, hygiene opt-out in `macro` should use this. 
@@ -85,12 +84,7 @@ pub enum Transparency {
8584impl  Mark  { 
8685    pub  fn  fresh ( parent :  Mark )  -> Self  { 
8786        HygieneData :: with ( |data| { 
88-             data. marks . push ( MarkData  { 
89-                 parent, 
90-                 // By default expansions behave like `macro_rules`. 
91-                 default_transparency :  Transparency :: SemiTransparent , 
92-                 expn_info :  None , 
93-             } ) ; 
87+             data. marks . push ( MarkData  {  parent,  expn_info :  None  } ) ; 
9488            Mark ( data. marks . len ( )  as  u32  - 1 ) 
9589        } ) 
9690    } 
@@ -126,12 +120,6 @@ impl Mark {
126120        HygieneData :: with ( |data| data. marks [ self . 0  as  usize ] . expn_info  = Some ( info) ) 
127121    } 
128122
129-     #[ inline]  
130-     pub  fn  set_default_transparency ( self ,  transparency :  Transparency )  { 
131-         assert_ne ! ( self ,  Mark :: root( ) ) ; 
132-         HygieneData :: with ( |data| data. marks [ self . 0  as  usize ] . default_transparency  = transparency) 
133-     } 
134- 
135123    pub  fn  is_descendant_of ( self ,  ancestor :  Mark )  -> bool  { 
136124        HygieneData :: with ( |data| data. is_descendant_of ( self ,  ancestor) ) 
137125    } 
@@ -172,9 +160,8 @@ impl Mark {
172160    #[ inline]  
173161    pub  fn  looks_like_proc_macro_derive ( self )  -> bool  { 
174162        HygieneData :: with ( |data| { 
175-             let  mark_data = & data. marks [ self . 0  as  usize ] ; 
176-             if  mark_data. default_transparency  == Transparency :: Opaque  { 
177-                 if  let  Some ( expn_info)  = & mark_data. expn_info  { 
163+             if  data. default_transparency ( self )  == Transparency :: Opaque  { 
164+                 if  let  Some ( expn_info)  = & data. marks [ self . 0  as  usize ] . expn_info  { 
178165                    if  let  ExpnFormat :: MacroAttribute ( name)  = expn_info. format  { 
179166                        if  name. as_str ( ) . starts_with ( "derive(" )  { 
180167                            return  true ; 
@@ -199,9 +186,6 @@ impl HygieneData {
199186        HygieneData  { 
200187            marks :  vec ! [ MarkData  { 
201188                parent:  Mark :: root( ) , 
202-                 // If the root is opaque, then loops searching for an opaque mark 
203-                 // will automatically stop after reaching it. 
204-                 default_transparency:  Transparency :: Opaque , 
205189                expn_info:  None , 
206190            } ] , 
207191            syntax_contexts :  vec ! [ SyntaxContextData  { 
@@ -235,7 +219,9 @@ impl HygieneData {
235219    } 
236220
237221    fn  default_transparency ( & self ,  mark :  Mark )  -> Transparency  { 
238-         self . marks [ mark. 0  as  usize ] . default_transparency 
222+         self . marks [ mark. 0  as  usize ] . expn_info . as_ref ( ) . map_or ( 
223+             Transparency :: SemiTransparent ,  |einfo| einfo. default_transparency 
224+         ) 
239225    } 
240226
241227    fn  modern ( & self ,  ctxt :  SyntaxContext )  -> SyntaxContext  { 
@@ -427,7 +413,6 @@ impl SyntaxContext {
427413        HygieneData :: with ( |data| { 
428414            data. marks . push ( MarkData  { 
429415                parent :  Mark :: root ( ) , 
430-                 default_transparency :  Transparency :: SemiTransparent , 
431416                expn_info :  Some ( expansion_info) , 
432417            } ) ; 
433418
@@ -651,6 +636,7 @@ impl fmt::Debug for SyntaxContext {
651636/// Extra information for tracking spans of macro and syntax sugar expansion 
652637#[ derive( Clone ,  Hash ,  Debug ,  RustcEncodable ,  RustcDecodable ) ]  
653638pub  struct  ExpnInfo  { 
639+     // --- The part unique to each expansion. 
654640    /// The location of the actual macro invocation or syntax sugar , e.g. 
655641     /// `let x = foo!();` or `if let Some(y) = x {}` 
656642     /// 
@@ -661,13 +647,18 @@ pub struct ExpnInfo {
661647     /// call_site span would have its own ExpnInfo, with the call_site 
662648     /// pointing to the `foo!` invocation. 
663649     pub  call_site :  Span , 
650+     /// The format with which the macro was invoked. 
651+      pub  format :  ExpnFormat , 
652+ 
653+     // --- The part specific to the macro/desugaring definition. 
654+     // --- FIXME: Share it between expansions with the same definition. 
664655    /// The span of the macro definition itself. The macro may not 
665656     /// have a sensible definition span (e.g., something defined 
666657     /// completely inside libsyntax) in which case this is None. 
667658     /// This span serves only informational purpose and is not used for resolution. 
668659     pub  def_site :  Option < Span > , 
669-     /// The format  with which the macro was invoked . 
670-      pub  format :   ExpnFormat , 
660+     /// Transparency used by `apply_mark` for mark  with this expansion info by default . 
661+      pub  default_transparency :   Transparency , 
671662    /// List of #[unstable]/feature-gated features that the macro is allowed to use 
672663     /// internally without forcing the whole crate to opt-in 
673664     /// to them. 
@@ -687,8 +678,9 @@ impl ExpnInfo {
687678     pub  fn  default ( format :  ExpnFormat ,  call_site :  Span ,  edition :  Edition )  -> ExpnInfo  { 
688679        ExpnInfo  { 
689680            call_site, 
690-             def_site :  None , 
691681            format, 
682+             def_site :  None , 
683+             default_transparency :  Transparency :: SemiTransparent , 
692684            allow_internal_unstable :  None , 
693685            allow_internal_unsafe :  false , 
694686            local_inner_macros :  false , 
0 commit comments