@@ -1406,7 +1406,7 @@ impl HygieneEncodeContext {
14061406pub struct HygieneDecodeContext {
14071407 // A cache mapping raw serialized per-crate syntax context ids to corresponding decoded
14081408 // `SyntaxContext`s in the current global `HygieneData`.
1409- remapped_ctxts : Lock < IndexVec < SyntaxContext , Option < SyntaxContext > > > ,
1409+ remapped_ctxts : Lock < IndexVec < ExternalSyntaxContext , Option < SyntaxContext > > > ,
14101410}
14111411
14121412/// Register an expansion which has been decoded from the on-disk-cache for the local crate.
@@ -1473,16 +1473,37 @@ pub fn decode_expn_id(
14731473 register_expn_id ( krate, index, expn_data, hash)
14741474}
14751475
1476+ rustc_index:: newtype_index! {
1477+ /// A syntax context that is obtained from metadata of an external crate and
1478+ /// was not yet remapped to local `SyntaxContext`.
1479+ #[ encodable]
1480+ pub struct ExternalSyntaxContext { }
1481+ }
1482+
1483+ impl ExternalSyntaxContext {
1484+ #[ inline( always) ]
1485+ pub fn is_root ( self ) -> bool {
1486+ self . as_u32 ( ) == 0
1487+ }
1488+ }
1489+
1490+ impl From < SyntaxContext > for ExternalSyntaxContext {
1491+ #[ inline]
1492+ fn from ( ctxt : SyntaxContext ) -> Self {
1493+ ExternalSyntaxContext :: from_u32 ( ctxt. as_u32 ( ) )
1494+ }
1495+ }
1496+
14761497// Decodes `SyntaxContext`, using the provided `HygieneDecodeContext`
14771498// to track which `SyntaxContext`s we have already decoded.
14781499// The provided closure will be invoked to deserialize a `SyntaxContextData`
14791500// if we haven't already seen the id of the `SyntaxContext` we are deserializing.
14801501pub fn decode_syntax_context < D : Decoder > (
14811502 d : & mut D ,
14821503 context : & HygieneDecodeContext ,
1483- decode_data : impl FnOnce ( & mut D , SyntaxContext ) -> SyntaxContextKey ,
1504+ decode_data : impl FnOnce ( & mut D , ExternalSyntaxContext ) -> SyntaxContextKey ,
14841505) -> SyntaxContext {
1485- let external_ctxt = SyntaxContext :: from_u32 ( Decodable :: decode ( d) ) ;
1506+ let external_ctxt: ExternalSyntaxContext = Decodable :: decode ( d) ;
14861507 if external_ctxt. is_root ( ) {
14871508 trace ! ( "decode_syntax_context: deserialized root" ) ;
14881509 // The root is special
0 commit comments