Skip to content

Commit 07481b9

Browse files
committed
use old ctx if has same expand environment during decode span
1 parent 9f877c9 commit 07481b9

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

compiler/rustc_span/src/hygiene.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,14 @@ pub fn decode_syntax_context<D: Decoder, F: FnOnce(&mut D, u32) -> SyntaxContext
14131413

14141414
// Overwrite the dummy data with our decoded SyntaxContextData
14151415
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+
14161424
let dummy = std::mem::replace(
14171425
&mut hygiene_data.syntax_context_data[ctxt.as_u32() as usize],
14181426
ctxt_data,

tests/incremental/decl_macro.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//@ revisions: rpass1 rpass2
2+
3+
// issue#112680
4+
5+
#![feature(decl_macro)]
6+
7+
pub trait T {
8+
type Key;
9+
fn index_from_key(key: Self::Key) -> usize;
10+
}
11+
12+
pub macro m($key_ty:ident, $val_ty:ident) {
13+
struct $key_ty {
14+
inner: usize,
15+
}
16+
17+
impl T for $val_ty {
18+
type Key = $key_ty;
19+
20+
fn index_from_key(key: Self::Key) -> usize {
21+
key.inner
22+
}
23+
}
24+
}
25+
26+
m!(TestId, Test);
27+
28+
#[cfg(rpass1)]
29+
struct Test(u32);
30+
31+
#[cfg(rpass2)]
32+
struct Test;
33+
34+
fn main() {}

0 commit comments

Comments
 (0)