tamer: span::Span::offset_add: Make const

This behavior is unchanged, but it allows us to create more constant spans
for testing.  For example:

  const S = DUMMY_SPAN.offset_add(1).unwrap();

This, in turn, will allow for removing lazy_static! for tests that use it
for span generation.

DEV-10863
main
Mike Gerwitz 2022-03-16 14:14:42 -04:00
parent 18cb5e7b39
commit ce48a654b1
1 changed files with 8 additions and 4 deletions

View File

@ -313,10 +313,14 @@ impl Span {
/// provided value.
/// If the resulting offset exceeds [`global::SourceFileSize`],
/// the result will be [`None`].
pub fn offset_add(self, value: global::SourceFileSize) -> Option<Self> {
self.offset
.checked_add(value)
.map(|offset| Self { offset, ..self })
pub const fn offset_add(
self,
value: global::SourceFileSize,
) -> Option<Self> {
match self.offset.checked_add(value) {
Some(offset) => Some(Self { offset, ..self }),
None => None,
}
}
}