use old ctx if has same expand environment during decode span · rust-lang/rust@07481b9 (original) (raw)

Original file line number Diff line number Diff line change
@@ -1413,6 +1413,14 @@ pub fn decode_syntax_context<D: Decoder, F: FnOnce(&mut D, u32) -> SyntaxContext
1413 1413
1414 1414 // Overwrite the dummy data with our decoded SyntaxContextData
1415 1415 HygieneData::with(|hygiene_data
1416 +if let Some(old) = hygiene_data.syntax_context_data.get(raw_id as usize)
1417 + && old.outer_expn == ctxt_data.outer_expn
1418 + && old.outer_transparency == ctxt_data.outer_transparency
1419 + && old.parent == ctxt_data.parent
1420 +{
1421 + ctxt_data = old.clone();
1422 +}
1423 +
1416 1424 let dummy = std::mem::replace(
1417 1425 &mut hygiene_data.syntax_context_data[ctxt.as_u32() as usize],
1418 1426 ctxt_data,