use old ctx if has same expand environment during decode span

This commit is contained in:
bohan 2024-07-05 00:59:58 +08:00
parent 9f877c9cd2
commit 07481b9e90
2 changed files with 42 additions and 0 deletions

View File

@ -1413,6 +1413,14 @@ pub fn decode_syntax_context<D: Decoder, F: FnOnce(&mut D, u32) -> SyntaxContext
// Overwrite the dummy data with our decoded SyntaxContextData // Overwrite the dummy data with our decoded SyntaxContextData
HygieneData::with(|hygiene_data| { HygieneData::with(|hygiene_data| {
if let Some(old) = hygiene_data.syntax_context_data.get(raw_id as usize)
&& old.outer_expn == ctxt_data.outer_expn
&& old.outer_transparency == ctxt_data.outer_transparency
&& old.parent == ctxt_data.parent
{
ctxt_data = old.clone();
}
let dummy = std::mem::replace( let dummy = std::mem::replace(
&mut hygiene_data.syntax_context_data[ctxt.as_u32() as usize], &mut hygiene_data.syntax_context_data[ctxt.as_u32() as usize],
ctxt_data, ctxt_data,

View File

@ -0,0 +1,34 @@
//@ revisions: rpass1 rpass2
// issue#112680
#![feature(decl_macro)]
pub trait T {
type Key;
fn index_from_key(key: Self::Key) -> usize;
}
pub macro m($key_ty:ident, $val_ty:ident) {
struct $key_ty {
inner: usize,
}
impl T for $val_ty {
type Key = $key_ty;
fn index_from_key(key: Self::Key) -> usize {
key.inner
}
}
}
m!(TestId, Test);
#[cfg(rpass1)]
struct Test(u32);
#[cfg(rpass2)]
struct Test;
fn main() {}