@@ -59,13 +59,12 @@ pub struct Mark(u32);
59
59
#[ derive( Clone , Debug ) ]
60
60
struct MarkData {
61
61
parent : Mark ,
62
- default_transparency : Transparency ,
63
62
expn_info : Option < ExpnInfo > ,
64
63
}
65
64
66
65
/// A property of a macro expansion that determines how identifiers
67
66
/// 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 ) ]
69
68
pub enum Transparency {
70
69
/// Identifier produced by a transparent expansion is always resolved at call-site.
71
70
/// Call-site spans in procedural macros, hygiene opt-out in `macro` should use this.
@@ -85,12 +84,7 @@ pub enum Transparency {
85
84
impl Mark {
86
85
pub fn fresh ( parent : Mark ) -> Self {
87
86
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 } ) ;
94
88
Mark ( data. marks . len ( ) as u32 - 1 )
95
89
} )
96
90
}
@@ -126,12 +120,6 @@ impl Mark {
126
120
HygieneData :: with ( |data| data. marks [ self . 0 as usize ] . expn_info = Some ( info) )
127
121
}
128
122
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
-
135
123
pub fn is_descendant_of ( self , ancestor : Mark ) -> bool {
136
124
HygieneData :: with ( |data| data. is_descendant_of ( self , ancestor) )
137
125
}
@@ -172,9 +160,8 @@ impl Mark {
172
160
#[ inline]
173
161
pub fn looks_like_proc_macro_derive ( self ) -> bool {
174
162
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 {
178
165
if let ExpnFormat :: MacroAttribute ( name) = expn_info. format {
179
166
if name. as_str ( ) . starts_with ( "derive(" ) {
180
167
return true ;
@@ -199,9 +186,6 @@ impl HygieneData {
199
186
HygieneData {
200
187
marks : vec ! [ MarkData {
201
188
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 ,
205
189
expn_info: None ,
206
190
} ] ,
207
191
syntax_contexts : vec ! [ SyntaxContextData {
@@ -235,7 +219,9 @@ impl HygieneData {
235
219
}
236
220
237
221
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
+ )
239
225
}
240
226
241
227
fn modern ( & self , ctxt : SyntaxContext ) -> SyntaxContext {
@@ -427,7 +413,6 @@ impl SyntaxContext {
427
413
HygieneData :: with ( |data| {
428
414
data. marks . push ( MarkData {
429
415
parent : Mark :: root ( ) ,
430
- default_transparency : Transparency :: SemiTransparent ,
431
416
expn_info : Some ( expansion_info) ,
432
417
} ) ;
433
418
@@ -651,6 +636,7 @@ impl fmt::Debug for SyntaxContext {
651
636
/// Extra information for tracking spans of macro and syntax sugar expansion
652
637
#[ derive( Clone , Hash , Debug , RustcEncodable , RustcDecodable ) ]
653
638
pub struct ExpnInfo {
639
+ // --- The part unique to each expansion.
654
640
/// The location of the actual macro invocation or syntax sugar , e.g.
655
641
/// `let x = foo!();` or `if let Some(y) = x {}`
656
642
///
@@ -661,13 +647,18 @@ pub struct ExpnInfo {
661
647
/// call_site span would have its own ExpnInfo, with the call_site
662
648
/// pointing to the `foo!` invocation.
663
649
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.
664
655
/// The span of the macro definition itself. The macro may not
665
656
/// have a sensible definition span (e.g., something defined
666
657
/// completely inside libsyntax) in which case this is None.
667
658
/// This span serves only informational purpose and is not used for resolution.
668
659
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 ,
671
662
/// List of #[unstable]/feature-gated features that the macro is allowed to use
672
663
/// internally without forcing the whole crate to opt-in
673
664
/// to them.
@@ -687,8 +678,9 @@ impl ExpnInfo {
687
678
pub fn default ( format : ExpnFormat , call_site : Span , edition : Edition ) -> ExpnInfo {
688
679
ExpnInfo {
689
680
call_site,
690
- def_site : None ,
691
681
format,
682
+ def_site : None ,
683
+ default_transparency : Transparency :: SemiTransparent ,
692
684
allow_internal_unstable : None ,
693
685
allow_internal_unsafe : false ,
694
686
local_inner_macros : false ,
0 commit comments