@@ -241,6 +241,11 @@ impl<'a, 'tcx> SpecializedDecoder<CrateNum> for DecodeContext<'a, 'tcx> {
241
241
impl < ' a , ' tcx > SpecializedDecoder < hygiene:: Mark > for DecodeContext < ' a , ' tcx > {
242
242
fn specialized_decode ( & mut self ) -> Result < hygiene:: Mark , Self :: Error > {
243
243
let mark = u32:: decode ( self ) ?;
244
+ //
245
+ // We only perform translation if hygiene info is already available and if the
246
+ // mark actually needs translation. That way we avoid loops (as obtaining hygiene
247
+ // info for an external crate involves decoding marks) and avoid incorrectly translated
248
+ // default marks.
244
249
if self . cdata ( ) . hygiene_data_import_info . borrow ( ) . is_some ( ) && mark != 0 {
245
250
let imported_hygiene = self . cdata ( ) . imported_hygiene_data ( ) ;
246
251
@@ -254,6 +259,11 @@ impl<'a, 'tcx> SpecializedDecoder<hygiene::Mark> for DecodeContext<'a, 'tcx> {
254
259
impl < ' a , ' tcx > SpecializedDecoder < SyntaxContext > for DecodeContext < ' a , ' tcx > {
255
260
fn specialized_decode ( & mut self ) -> Result < SyntaxContext , Self :: Error > {
256
261
let ctxt = u32:: decode ( self ) ?;
262
+
263
+ // We only perform translation if hygiene info is already available and if the
264
+ // syntax context actually needs translation. That way we avoid loops (as obtaining
265
+ // hygiene info for an external crate involves decoding syntax contexts) and avoid
266
+ // incorrectly translated default contexts.
257
267
if self . cdata ( ) . hygiene_data_import_info . borrow ( ) . is_some ( ) && ctxt != 0 {
258
268
let imported_hygiene = self . cdata ( ) . imported_hygiene_data ( ) ;
259
269
0 commit comments