Skip to content

Commit 8013f71

Browse files
committed
Simplify decode_span.
1 parent ea80b1a commit 8013f71

File tree

1 file changed

+35
-41
lines changed

1 file changed

+35
-41
lines changed

compiler/rustc_middle/src/query/on_disk_cache.rs

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -646,47 +646,41 @@ impl<'a, 'tcx> SpanDecoder for CacheDecoder<'a, 'tcx> {
646646
let parent = Option::<LocalDefId>::decode(self);
647647
let tag: u8 = Decodable::decode(self);
648648

649-
if tag == TAG_PARTIAL_SPAN {
650-
return Span::new(BytePos(0), BytePos(0), ctxt, parent);
651-
} else if tag == TAG_RELATIVE_SPAN {
652-
let dlo = u32::decode(self);
653-
let dto = u32::decode(self);
654-
655-
let enclosing = self.tcx.source_span_untracked(parent.unwrap()).data_untracked();
656-
let span = Span::new(
657-
enclosing.lo + BytePos::from_u32(dlo),
658-
enclosing.lo + BytePos::from_u32(dto),
659-
ctxt,
660-
parent,
661-
);
662-
663-
return span;
664-
} else if tag == TAG_RELATIVE_OUTER_SPAN {
665-
let dlo = isize::decode(self);
666-
let dto = isize::decode(self);
667-
668-
let enclosing = self.tcx.source_span_untracked(parent.unwrap()).data_untracked();
669-
let span = Span::new(
670-
BytePos::from_usize((enclosing.lo.to_u32() as isize + dlo) as usize),
671-
BytePos::from_usize((enclosing.lo.to_u32() as isize + dto) as usize),
672-
ctxt,
673-
parent,
674-
);
675-
676-
return span;
677-
} else {
678-
debug_assert_eq!(tag, TAG_FULL_SPAN);
679-
}
680-
681-
let file_lo_index = SourceFileIndex::decode(self);
682-
let line_lo = usize::decode(self);
683-
let col_lo = RelativeBytePos::decode(self);
684-
let len = BytePos::decode(self);
685-
686-
let file_lo = self.file_index_to_file(file_lo_index);
687-
let lo = file_lo.lines()[line_lo - 1] + col_lo;
688-
let lo = file_lo.absolute_position(lo);
689-
let hi = lo + len;
649+
let (lo, hi) = match tag {
650+
TAG_PARTIAL_SPAN => (BytePos(0), BytePos(0)),
651+
TAG_RELATIVE_SPAN => {
652+
let dlo = u32::decode(self);
653+
let dto = u32::decode(self);
654+
655+
let enclosing = self.tcx.source_span_untracked(parent.unwrap()).data_untracked();
656+
(enclosing.lo + BytePos::from_u32(dlo), enclosing.lo + BytePos::from_u32(dto))
657+
}
658+
TAG_RELATIVE_OUTER_SPAN => {
659+
let dlo = isize::decode(self);
660+
let dto = isize::decode(self);
661+
662+
let enclosing = self.tcx.source_span_untracked(parent.unwrap()).data_untracked();
663+
let reference = enclosing.lo.to_u32() as isize;
664+
(
665+
BytePos::from_usize((reference + dlo) as usize),
666+
BytePos::from_usize((reference + dto) as usize),
667+
)
668+
}
669+
TAG_FULL_SPAN => {
670+
let file_lo_index = SourceFileIndex::decode(self);
671+
let line_lo = usize::decode(self);
672+
let col_lo = RelativeBytePos::decode(self);
673+
let len = BytePos::decode(self);
674+
675+
let file_lo = self.file_index_to_file(file_lo_index);
676+
let lo = file_lo.lines()[line_lo - 1] + col_lo;
677+
let lo = file_lo.absolute_position(lo);
678+
let hi = lo + len;
679+
680+
(lo, hi)
681+
}
682+
_ => unreachable!(),
683+
};
690684

691685
Span::new(lo, hi, ctxt, parent)
692686
}

0 commit comments

Comments
 (0)