cargo fmt

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-05-05 17:22:39 -04:00
parent ae99bbfc1e
commit 7698e49baf
5 changed files with 82 additions and 65 deletions

View File

@@ -1,4 +1,4 @@
use std::fmt::{Display, Formatter, self};
use std::fmt::{self, Display, Formatter};
#[derive(Debug, Clone, Copy, Eq)]
#[cfg_attr(not(test), derive(PartialEq))]
@@ -38,7 +38,11 @@ impl PartialEq for Pos {
impl Pos {
pub fn from_char(c: char, source: usize, line: usize, col: usize, byte: usize) -> Self {
Pos {
source, line, col, byte, len: c.len_utf8(),
source,
line,
col,
byte,
len: c.len_utf8(),
}
}
@@ -98,9 +102,20 @@ impl Display for Span {
if self.start == self.end {
Display::fmt(&self.start, fmt)
} else if self.start.line == self.end.line {
write!(fmt, "line {} at {}-{}", self.start.line + 1, self.start.col + 1, self.end.col + 1)
write!(
fmt,
"line {} at {}-{}",
self.start.line + 1,
self.start.col + 1,
self.end.col + 1
)
} else {
write!(fmt, "lines {} to {}", self.start.line + 1, self.end.line + 1)
write!(
fmt,
"lines {} to {}",
self.start.line + 1,
self.end.line + 1
)
}
}
}
@@ -110,7 +125,7 @@ pub trait Spanned {
fn text_at<'t>(&self, text: &'t str) -> &'t str {
let Span { start, end } = self.span();
&text[start.byte .. end.byte]
&text[start.byte..end.byte]
}
}
@@ -146,7 +161,7 @@ mod test {
#[test]
fn test_pos_min() {
let small = Pos::default();
let large = Pos {
let large = Pos {
source: 1,
byte: 1,
..Default::default()
@@ -159,7 +174,7 @@ mod test {
#[test]
fn test_pos_max() {
let small = Pos::default();
let large = Pos {
let large = Pos {
source: 1,
byte: 1,
..Default::default()
@@ -178,7 +193,7 @@ mod test {
col: 15,
byte: 15,
..Default::default()
}
},
};
let second = Span {
@@ -193,7 +208,7 @@ mod test {
col: 27,
byte: 27,
..Default::default()
}
},
};
let expected = Span {