diff options
| author | bors <bors@rust-lang.org> | 2024-06-16 14:46:34 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-06-16 14:46:34 +0000 |
| commit | 55cac26a9ef17da1c9c77c0816e88e178b7cc5dd (patch) | |
| tree | 979350436e560304d4a735bd3c6318d181b0c9f7 /compiler/rustc_span/src/span_encoding.rs | |
| parent | f6236f63d2c2ccbb363cf98f29c994d60ad1eb64 (diff) | |
| parent | 14da80c37279ada8d92d3f900414ebc0d7935e13 (diff) | |
| download | rust-55cac26a9ef17da1c9c77c0816e88e178b7cc5dd.tar.gz rust-55cac26a9ef17da1c9c77c0816e88e178b7cc5dd.zip | |
Auto merge of #126545 - petrochenkov:spimprove, r=BoxyUwU
rustc_span: Minor improvements
Introduce `{IndexNewtype,SyntaxContext}::from_u16` for convenience because small indices are sometimes encoded as `u16`.
Use `SpanData::span` instead of `Span::new` where appropriate.
Add a clarifying comment about decoding span parents.
Diffstat (limited to 'compiler/rustc_span/src/span_encoding.rs')
| -rw-r--r-- | compiler/rustc_span/src/span_encoding.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/compiler/rustc_span/src/span_encoding.rs b/compiler/rustc_span/src/span_encoding.rs index 9d5bc5b0512..31d2a9db01d 100644 --- a/compiler/rustc_span/src/span_encoding.rs +++ b/compiler/rustc_span/src/span_encoding.rs @@ -121,7 +121,7 @@ impl InlineCtxt { SpanData { lo: BytePos(self.lo), hi: BytePos(self.lo.debug_strict_add(len)), - ctxt: SyntaxContext::from_u32(self.ctxt as u32), + ctxt: SyntaxContext::from_u16(self.ctxt), parent: None, } } @@ -146,7 +146,7 @@ impl InlineParent { lo: BytePos(self.lo), hi: BytePos(self.lo.debug_strict_add(len)), ctxt: SyntaxContext::root(), - parent: Some(LocalDefId { local_def_index: DefIndex::from_u32(self.parent as u32) }), + parent: Some(LocalDefId { local_def_index: DefIndex::from_u16(self.parent) }), } } #[inline] @@ -167,7 +167,7 @@ impl PartiallyInterned { #[inline] fn data(self) -> SpanData { SpanData { - ctxt: SyntaxContext::from_u32(self.ctxt as u32), + ctxt: SyntaxContext::from_u16(self.ctxt), ..with_span_interner(|interner| interner.spans[self.index as usize]) } } @@ -331,8 +331,7 @@ impl Span { match_span_kind! { self, InlineCtxt(span) => { - updated_ctxt32 = - update(SyntaxContext::from_u32(span.ctxt as u32)).as_u32(); + updated_ctxt32 = update(SyntaxContext::from_u16(span.ctxt)).as_u32(); // Any small new context including zero will preserve the format. if updated_ctxt32 <= MAX_CTXT { return InlineCtxt::span(span.lo, span.len, updated_ctxt32 as u16); @@ -349,7 +348,7 @@ impl Span { data = span.data(); }, PartiallyInterned(span) => { - updated_ctxt32 = update(SyntaxContext::from_u32(span.ctxt as u32)).as_u32(); + updated_ctxt32 = update(SyntaxContext::from_u16(span.ctxt)).as_u32(); // Any small new context excluding zero will preserve the format. // Zero may change the format to `InlineParent` if parent and len are small enough. if updated_ctxt32 <= MAX_CTXT && updated_ctxt32 != 0 { @@ -373,9 +372,9 @@ impl Span { fn inline_ctxt(self) -> Result<SyntaxContext, usize> { match_span_kind! { self, - InlineCtxt(span) => Ok(SyntaxContext::from_u32(span.ctxt as u32)), + InlineCtxt(span) => Ok(SyntaxContext::from_u16(span.ctxt)), InlineParent(_span) => Ok(SyntaxContext::root()), - PartiallyInterned(span) => Ok(SyntaxContext::from_u32(span.ctxt as u32)), + PartiallyInterned(span) => Ok(SyntaxContext::from_u16(span.ctxt)), Interned(span) => Err(span.index as usize), } } |
