@@ -98,14 +98,6 @@ impl SyntaxContextData {
9898 }
9999 }
100100
101- fn decode_placeholder ( ) -> SyntaxContextData {
102- SyntaxContextData { dollar_crate_name : kw:: Empty , ..SyntaxContextData :: root ( ) }
103- }
104-
105- fn is_decode_placeholder ( & self ) -> bool {
106- self . dollar_crate_name == kw:: Empty
107- }
108-
109101 fn key ( & self ) -> SyntaxContextKey {
110102 ( self . parent , self . outer_expn , self . outer_transparency )
111103 }
@@ -460,28 +452,23 @@ impl HygieneData {
460452 }
461453
462454 fn normalize_to_macros_2_0 ( & self , ctxt : SyntaxContext ) -> SyntaxContext {
463- debug_assert ! ( !self . syntax_context_data[ ctxt. 0 as usize ] . is_decode_placeholder( ) ) ;
464455 self . syntax_context_data [ ctxt. 0 as usize ] . opaque
465456 }
466457
467458 fn normalize_to_macro_rules ( & self , ctxt : SyntaxContext ) -> SyntaxContext {
468- debug_assert ! ( !self . syntax_context_data[ ctxt. 0 as usize ] . is_decode_placeholder( ) ) ;
469459 self . syntax_context_data [ ctxt. 0 as usize ] . opaque_and_semiopaque
470460 }
471461
472462 fn outer_expn ( & self , ctxt : SyntaxContext ) -> ExpnId {
473- debug_assert ! ( !self . syntax_context_data[ ctxt. 0 as usize ] . is_decode_placeholder( ) ) ;
474463 self . syntax_context_data [ ctxt. 0 as usize ] . outer_expn
475464 }
476465
477466 fn outer_mark ( & self , ctxt : SyntaxContext ) -> ( ExpnId , Transparency ) {
478- debug_assert ! ( !self . syntax_context_data[ ctxt. 0 as usize ] . is_decode_placeholder( ) ) ;
479467 let data = & self . syntax_context_data [ ctxt. 0 as usize ] ;
480468 ( data. outer_expn , data. outer_transparency )
481469 }
482470
483471 fn parent_ctxt ( & self , ctxt : SyntaxContext ) -> SyntaxContext {
484- debug_assert ! ( !self . syntax_context_data[ ctxt. 0 as usize ] . is_decode_placeholder( ) ) ;
485472 self . syntax_context_data [ ctxt. 0 as usize ] . parent
486473 }
487474
@@ -592,25 +579,27 @@ impl HygieneData {
592579 expn_id : ExpnId ,
593580 transparency : Transparency ,
594581 ) -> SyntaxContext {
595- debug_assert ! ( !self . syntax_context_data[ parent. 0 as usize ] . is_decode_placeholder( ) ) ;
596-
597582 // Look into the cache first.
598583 let key = ( parent, expn_id, transparency) ;
599584 if let Some ( ctxt) = self . syntax_context_map . get ( & key) {
600585 return * ctxt;
601586 }
602587
603588 // Reserve a new syntax context.
589+ // The inserted dummy data can only be potentially accessed by nested `alloc_ctxt` calls,
590+ // the assert below ensures that it doesn't happen.
604591 let ctxt = SyntaxContext :: from_usize ( self . syntax_context_data . len ( ) ) ;
605- self . syntax_context_data . push ( SyntaxContextData :: decode_placeholder ( ) ) ;
592+ self . syntax_context_data
593+ . push ( SyntaxContextData { dollar_crate_name : sym:: dummy, ..SyntaxContextData :: root ( ) } ) ;
606594 self . syntax_context_map . insert ( key, ctxt) ;
607595
608596 // Opaque and semi-opaque versions of the parent. Note that they may be equal to the
609597 // parent itself. E.g. `parent_opaque` == `parent` if the expn chain contains only opaques,
610598 // and `parent_opaque_and_semiopaque` == `parent` if the expn contains only (semi-)opaques.
611- let parent_opaque = self . syntax_context_data [ parent. 0 as usize ] . opaque ;
612- let parent_opaque_and_semiopaque =
613- self . syntax_context_data [ parent. 0 as usize ] . opaque_and_semiopaque ;
599+ let parent_data = & self . syntax_context_data [ parent. 0 as usize ] ;
600+ assert_ne ! ( parent_data. dollar_crate_name, sym:: dummy) ;
601+ let parent_opaque = parent_data. opaque ;
602+ let parent_opaque_and_semiopaque = parent_data. opaque_and_semiopaque ;
614603
615604 // Evaluate opaque and semi-opaque versions of the new syntax context.
616605 let ( opaque, opaque_and_semiopaque) = match transparency {
@@ -650,13 +639,12 @@ pub fn walk_chain_collapsed(span: Span, to: Span) -> Span {
650639
651640pub fn update_dollar_crate_names ( mut get_name : impl FnMut ( SyntaxContext ) -> Symbol ) {
652641 // The new contexts that need updating are at the end of the list and have `$crate` as a name.
653- // Also decoding placeholders can be encountered among both old and new contexts.
654642 let mut to_update = vec ! [ ] ;
655643 HygieneData :: with ( |data| {
656644 for ( idx, scdata) in data. syntax_context_data . iter ( ) . enumerate ( ) . rev ( ) {
657645 if scdata. dollar_crate_name == kw:: DollarCrate {
658646 to_update. push ( ( idx, kw:: DollarCrate ) ) ;
659- } else if !scdata . is_decode_placeholder ( ) {
647+ } else {
660648 break ;
661649 }
662650 }
@@ -922,10 +910,7 @@ impl SyntaxContext {
922910 }
923911
924912 pub ( crate ) fn dollar_crate_name ( self ) -> Symbol {
925- HygieneData :: with ( |data| {
926- debug_assert ! ( !data. syntax_context_data[ self . 0 as usize ] . is_decode_placeholder( ) ) ;
927- data. syntax_context_data [ self . 0 as usize ] . dollar_crate_name
928- } )
913+ HygieneData :: with ( |data| data. syntax_context_data [ self . 0 as usize ] . dollar_crate_name )
929914 }
930915
931916 pub fn edition ( self ) -> Edition {
@@ -1447,15 +1432,7 @@ fn for_all_ctxts_in<F: FnMut(u32, SyntaxContext, &SyntaxContextKey)>(
14471432 mut f : F ,
14481433) {
14491434 let all_data: Vec < _ > = HygieneData :: with ( |data| {
1450- ctxts
1451- . map ( |ctxt| {
1452- ( ctxt, {
1453- let item = data. syntax_context_data [ ctxt. 0 as usize ] ;
1454- debug_assert ! ( !item. is_decode_placeholder( ) ) ;
1455- item. key ( )
1456- } )
1457- } )
1458- . collect ( )
1435+ ctxts. map ( |ctxt| ( ctxt, data. syntax_context_data [ ctxt. 0 as usize ] . key ( ) ) ) . collect ( )
14591436 } ) ;
14601437 for ( ctxt, data) in all_data. into_iter ( ) {
14611438 f ( ctxt. 0 , ctxt, & data) ;
0 commit comments