1
Fork 0

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.
This commit is contained in:
Vadim Petrochenkov 2024-06-16 00:53:00 +03:00
parent 12b33d36f3
commit 14da80c372
6 changed files with 33 additions and 14 deletions

View file

@ -967,7 +967,7 @@ impl Span {
/// This span, but in a larger context, may switch to the metavariable span if suitable.
pub fn with_neighbor(self, neighbor: Span) -> Span {
match Span::prepare_to_combine(self, neighbor) {
Ok((this, ..)) => Span::new(this.lo, this.hi, this.ctxt, this.parent),
Ok((this, ..)) => this.span(),
Err(_) => self,
}
}
@ -1352,7 +1352,7 @@ impl fmt::Debug for Span {
impl fmt::Debug for SpanData {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&Span::new(self.lo, self.hi, self.ctxt, self.parent), f)
fmt::Debug::fmt(&self.span(), f)
}
}