@@ -112,16 +112,14 @@ impl Mark {
112
112
HygieneData :: with ( |data| data. marks [ self . 0 as usize ] . default_transparency = transparency)
113
113
}
114
114
115
- pub fn is_descendant_of ( mut self , ancestor : Mark ) -> bool {
116
- HygieneData :: with ( |data| {
117
- while self != ancestor {
118
- if self == Mark :: root ( ) {
119
- return false ;
120
- }
121
- self = data. marks [ self . 0 as usize ] . parent ;
122
- }
123
- true
124
- } )
115
+ pub fn is_descendant_of ( self , ancestor : Mark ) -> bool {
116
+ HygieneData :: with ( |data| data. is_descendant_of ( self , ancestor) )
117
+ }
118
+
119
+ /// `mark.outer_is_descendant_of(ctxt)` is equivalent to but faster than
120
+ /// `mark.is_descendant_of(ctxt.outer())`.
121
+ pub fn outer_is_descendant_of ( self , ctxt : SyntaxContext ) -> bool {
122
+ HygieneData :: with ( |data| data. is_descendant_of ( self , data. outer ( ctxt) ) )
125
123
}
126
124
127
125
/// Computes a mark such that both input marks are descendants of (or equal to) the returned
@@ -201,6 +199,24 @@ impl HygieneData {
201
199
fn with < T , F : FnOnce ( & mut HygieneData ) -> T > ( f : F ) -> T {
202
200
GLOBALS . with ( |globals| f ( & mut * globals. hygiene_data . borrow_mut ( ) ) )
203
201
}
202
+
203
+ fn outer ( & self , ctxt : SyntaxContext ) -> Mark {
204
+ self . syntax_contexts [ ctxt. 0 as usize ] . outer_mark
205
+ }
206
+
207
+ fn expn_info ( & self , mark : Mark ) -> Option < ExpnInfo > {
208
+ self . marks [ mark. 0 as usize ] . expn_info . clone ( )
209
+ }
210
+
211
+ fn is_descendant_of ( & self , mut mark : Mark , ancestor : Mark ) -> bool {
212
+ while mark != ancestor {
213
+ if mark == Mark :: root ( ) {
214
+ return false ;
215
+ }
216
+ mark = self . marks [ mark. 0 as usize ] . parent ;
217
+ }
218
+ true
219
+ }
204
220
}
205
221
206
222
pub fn clear_markings ( ) {
@@ -416,7 +432,7 @@ impl SyntaxContext {
416
432
/// or `None` if we privacy check as usual (i.e., not w.r.t. a macro definition scope).
417
433
pub fn adjust ( & mut self , expansion : Mark ) -> Option < Mark > {
418
434
let mut scope = None ;
419
- while !expansion. is_descendant_of ( self . outer ( ) ) {
435
+ while !expansion. outer_is_descendant_of ( * self ) {
420
436
scope = Some ( self . remove_mark ( ) ) ;
421
437
}
422
438
scope
@@ -450,7 +466,7 @@ impl SyntaxContext {
450
466
pub fn glob_adjust ( & mut self , expansion : Mark , mut glob_ctxt : SyntaxContext )
451
467
-> Option < Option < Mark > > {
452
468
let mut scope = None ;
453
- while !expansion. is_descendant_of ( glob_ctxt. outer ( ) ) {
469
+ while !expansion. outer_is_descendant_of ( glob_ctxt) {
454
470
scope = Some ( glob_ctxt. remove_mark ( ) ) ;
455
471
if self . remove_mark ( ) != scope. unwrap ( ) {
456
472
return None ;
@@ -476,7 +492,7 @@ impl SyntaxContext {
476
492
}
477
493
478
494
let mut marks = Vec :: new ( ) ;
479
- while !expansion. is_descendant_of ( glob_ctxt. outer ( ) ) {
495
+ while !expansion. outer_is_descendant_of ( glob_ctxt) {
480
496
marks. push ( glob_ctxt. remove_mark ( ) ) ;
481
497
}
482
498
@@ -499,7 +515,14 @@ impl SyntaxContext {
499
515
500
516
#[ inline]
501
517
pub fn outer ( self ) -> Mark {
502
- HygieneData :: with ( |data| data. syntax_contexts [ self . 0 as usize ] . outer_mark )
518
+ HygieneData :: with ( |data| data. outer ( self ) )
519
+ }
520
+
521
+ /// `ctxt.outer_expn_info()` is equivalent to but faster than
522
+ /// `ctxt.outer().expn_info()`.
523
+ #[ inline]
524
+ pub fn outer_expn_info ( self ) -> Option < ExpnInfo > {
525
+ HygieneData :: with ( |data| data. expn_info ( data. outer ( self ) ) )
503
526
}
504
527
505
528
pub fn dollar_crate_name ( self ) -> Symbol {
0 commit comments