Skip to content

Commit f12a7fa

Browse files
committed
Auto merge of rust-lang#110497 - cjgillot:span-ctxt, r=b-naber
Refactor `SyntaxContext::ctxt` logic. I'm still trying to make a test from the issue. cc `@deepink-mas` does this solve the issue? Fixes rust-lang#110230
2 parents 9de7d91 + 99962a8 commit f12a7fa

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

compiler/rustc_span/src/span_encoding.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,23 @@ impl Span {
181181
#[inline]
182182
pub fn ctxt(self) -> SyntaxContext {
183183
let ctxt_or_tag = self.ctxt_or_tag as u32;
184-
if ctxt_or_tag <= MAX_CTXT {
185-
if self.len_or_tag == LEN_TAG || self.len_or_tag & PARENT_MASK == 0 {
186-
// Inline format or interned format with inline ctxt.
187-
SyntaxContext::from_u32(ctxt_or_tag)
184+
// Check for interned format.
185+
if self.len_or_tag == LEN_TAG {
186+
if ctxt_or_tag == CTXT_TAG {
187+
// Fully interned format.
188+
let index = self.base_or_index;
189+
with_span_interner(|interner| interner.spans[index as usize].ctxt)
188190
} else {
189-
// Inline format or interned format with inline parent.
190-
// We know that the SyntaxContext is root.
191-
SyntaxContext::root()
191+
// Interned format with inline ctxt.
192+
SyntaxContext::from_u32(ctxt_or_tag)
192193
}
194+
} else if self.len_or_tag & PARENT_MASK == 0 {
195+
// Inline format with inline ctxt.
196+
SyntaxContext::from_u32(ctxt_or_tag)
193197
} else {
194-
// Interned format.
195-
let index = self.base_or_index;
196-
with_span_interner(|interner| interner.spans[index as usize].ctxt)
198+
// Inline format with inline parent.
199+
// We know that the SyntaxContext is root.
200+
SyntaxContext::root()
197201
}
198202
}
199203
}

0 commit comments

Comments
 (0)