Skip to content

Commit a4a780b

Browse files
More rustfmt changes
These ones I can accept tho I don't agree that they are necessarily better than the previous version. I only did these to be more in line with rustfmt output.
1 parent 0971b8f commit a4a780b

File tree

9 files changed

+75
-34
lines changed

9 files changed

+75
-34
lines changed

src/bool/tests.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ use crate::{test_util::assert_parse_ok_eq, BoolLit, Literal};
33
macro_rules! assert_bool_parse {
44
($input:literal, $expected:expr) => {
55
assert_parse_ok_eq(
6-
$input, Literal::parse($input), Literal::Bool($expected), "Literal::parse");
6+
$input,
7+
Literal::parse($input),
8+
Literal::Bool($expected),
9+
"Literal::parse",
10+
);
711
assert_parse_ok_eq($input, BoolLit::parse($input), $expected, "BoolLit::parse");
812
};
913
}

src/byte/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ impl<B: Buffer> fmt::Display for ByteLit<B> {
7979
#[inline(never)]
8080
pub(crate) fn parse_impl(input: &str) -> Result<(u8, usize), ParseError> {
8181
let input_bytes = input.as_bytes();
82-
let first = input_bytes.get(2).ok_or(perr(None, UnterminatedByteLiteral))?;
82+
let first = input_bytes
83+
.get(2)
84+
.ok_or(perr(None, UnterminatedByteLiteral))?;
8385
let (c, len) = match first {
8486
b'\'' if input_bytes.get(3) == Some(&b'\'') => return Err(perr(2, UnescapedSingleQuote)),
8587
b'\'' => return Err(perr(None, EmptyByteLiteral)),

src/bytestr/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ impl<B: Buffer> ByteStringLit<B> {
4747
/// Returns the string value this literal represents (where all escapes have
4848
/// been turned into their respective values).
4949
pub fn value(&self) -> &[u8] {
50-
self.value.as_deref().unwrap_or(&self.raw.as_bytes()[self.inner_range()])
50+
self.value
51+
.as_deref()
52+
.unwrap_or(&self.raw.as_bytes()[self.inner_range()])
5153
}
5254

5355
/// Like `value` but returns a potentially owned version of the value.
@@ -57,7 +59,9 @@ impl<B: Buffer> ByteStringLit<B> {
5759
pub fn into_value(self) -> B::ByteCow {
5860
let inner_range = self.inner_range();
5961
let Self { raw, value, .. } = self;
60-
value.map(B::ByteCow::from).unwrap_or_else(|| raw.cut(inner_range).into_byte_cow())
62+
value
63+
.map(B::ByteCow::from)
64+
.unwrap_or_else(|| raw.cut(inner_range).into_byte_cow())
6165
}
6266

6367
/// The optional suffix. Returns `""` if the suffix is empty/does not exist.

src/bytestr/tests.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@ macro_rules! check {
1919
};
2020

2121
assert_parse_ok_eq(
22-
input, ByteStringLit::parse(input), expected.clone(), "ByteStringLit::parse");
22+
input,
23+
ByteStringLit::parse(input),
24+
expected.clone(),
25+
"ByteStringLit::parse",
26+
);
2327
assert_parse_ok_eq(
24-
input, Literal::parse(input), Literal::ByteString(expected.clone()), "Literal::parse");
28+
input,
29+
Literal::parse(input),
30+
Literal::ByteString(expected.clone()),
31+
"Literal::parse",
32+
);
2533
let lit = ByteStringLit::parse(input).unwrap();
2634
assert_eq!(lit.value(), $lit);
2735
assert_eq!(lit.suffix(), $suffix);
@@ -55,9 +63,17 @@ fn special_whitespace() {
5563
start_suffix: input.len(),
5664
};
5765
assert_parse_ok_eq(
58-
&input, ByteStringLit::parse(&*input), expected.clone(), "ByteStringLit::parse");
66+
&input,
67+
ByteStringLit::parse(&*input),
68+
expected.clone(),
69+
"ByteStringLit::parse",
70+
);
5971
assert_parse_ok_eq(
60-
&input, Literal::parse(&*input), Literal::ByteString(expected), "Literal::parse");
72+
&input,
73+
Literal::parse(&*input),
74+
Literal::ByteString(expected),
75+
"Literal::parse",
76+
);
6177
assert_eq!(ByteStringLit::parse(&*input).unwrap().value(), s.as_bytes());
6278
assert_eq!(ByteStringLit::parse(&*input).unwrap().into_value(), s.as_bytes());
6379
}

src/char/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ pub(crate) fn parse_impl(input: &str) -> Result<(char, usize), ParseError> {
8080
let (c, len) = match first {
8181
'\'' if input.chars().nth(2) == Some('\'') => return Err(perr(1, UnescapedSingleQuote)),
8282
'\'' => return Err(perr(None, EmptyCharLiteral)),
83-
'\n' | '\t' | '\r'
84-
=> return Err(perr(1, UnescapedSpecialWhitespace)),
83+
'\n' | '\t' | '\r' => return Err(perr(1, UnescapedSpecialWhitespace)),
8584

8685
'\\' => {
8786
let (v, len) = unescape(&input[1..], true, false, true).map_err(|e| e.offset_span(1))?;

src/escape.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ pub(crate) fn unescape(
2424
byte_escapes: bool,
2525
allow_nul: bool,
2626
) -> Result<(Unescape, usize), ParseError> {
27-
let first = input.as_bytes().get(1)
28-
.ok_or(perr(0, UnterminatedEscape))?;
27+
let first = input.as_bytes().get(1).ok_or(perr(0, UnterminatedEscape))?;
2928
let out = match first {
3029
// Quote escapes
3130
b'\'' => (Unescape::Byte(b'\''), 2),
@@ -45,10 +44,8 @@ pub(crate) fn unescape(
4544
let hex_string = input.get(2..4)
4645
.ok_or(perr(0..input.len(), UnterminatedEscape))?
4746
.as_bytes();
48-
let first = hex_digit_value(hex_string[0])
49-
.ok_or(perr(0..4, InvalidXEscape))?;
50-
let second = hex_digit_value(hex_string[1])
51-
.ok_or(perr(0..4, InvalidXEscape))?;
47+
let first = hex_digit_value(hex_string[0]).ok_or(perr(0..4, InvalidXEscape))?;
48+
let second = hex_digit_value(hex_string[1]).ok_or(perr(0..4, InvalidXEscape))?;
5249
let value = second + 16 * first;
5350

5451
if !byte_escapes && value > 0x7F {
@@ -87,8 +84,7 @@ pub(crate) fn unescape(
8784
continue;
8885
}
8986

90-
let digit = hex_digit_value(b)
91-
.ok_or(perr(3 + i, NonHexDigitInUnicodeEscape))?;
87+
let digit = hex_digit_value(b).ok_or(perr(3 + i, NonHexDigitInUnicodeEscape))?;
9288

9389
if digit_count == 6 {
9490
return Err(perr(3 + i, TooManyDigitInUnicodeEscape));
@@ -148,9 +144,15 @@ pub(crate) trait EscapeContainer {
148144
}
149145

150146
impl EscapeContainer for Vec<u8> {
151-
fn new() -> Self { Self::new() }
152-
fn is_empty(&self) -> bool { self.is_empty() }
153-
fn push_str(&mut self, s: &str) { self.extend_from_slice(s.as_bytes()); }
147+
fn new() -> Self {
148+
Self::new()
149+
}
150+
fn is_empty(&self) -> bool {
151+
self.is_empty()
152+
}
153+
fn push_str(&mut self, s: &str) {
154+
self.extend_from_slice(s.as_bytes());
155+
}
154156
fn push(&mut self, v: Unescape) {
155157
match v {
156158
Unescape::Byte(b) => self.push(b),
@@ -164,10 +166,18 @@ impl EscapeContainer for Vec<u8> {
164166
}
165167

166168
impl EscapeContainer for String {
167-
fn new() -> Self { Self::new() }
168-
fn is_empty(&self) -> bool { self.is_empty() }
169-
fn push_str(&mut self, s: &str) { self.push_str(s); }
170-
fn push(&mut self, v: Unescape) { self.push(v.unwrap_char()); }
169+
fn new() -> Self {
170+
Self::new()
171+
}
172+
fn is_empty(&self) -> bool {
173+
self.is_empty()
174+
}
175+
fn push_str(&mut self, s: &str) {
176+
self.push_str(s);
177+
}
178+
fn push(&mut self, v: Unescape) {
179+
self.push(v.unwrap_char());
180+
}
171181
}
172182

173183

src/parse.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ pub fn parse<B: Buffer>(input: B) -> Result<Literal<B>, ParseError> {
2727
// The first non-decimal char in a float literal must
2828
// be '.', 'e' or 'E'.
2929
match input.as_bytes().get(1 + end_dec_digits(rest)) {
30-
Some(b'.') | Some(b'e') | Some(b'E')
31-
=> FloatLit::parse(input).map(Literal::Float),
30+
Some(b'.') | Some(b'e') | Some(b'E') => FloatLit::parse(input).map(Literal::Float),
3231

3332
_ => IntegerLit::parse(input).map(Literal::Integer),
3433
}
@@ -38,8 +37,9 @@ pub fn parse<B: Buffer>(input: B) -> Result<Literal<B>, ParseError> {
3837
b'"' | b'r' => StringLit::parse(input).map(Literal::String),
3938

4039
b'b' if second == Some(b'\'') => ByteLit::parse(input).map(Literal::Byte),
41-
b'b' if second == Some(b'r') || second == Some(b'"')
42-
=> ByteStringLit::parse(input).map(Literal::ByteString),
40+
b'b' if second == Some(b'r') || second == Some(b'"') => {
41+
ByteStringLit::parse(input).map(Literal::ByteString)
42+
}
4343

4444
b'c' => CStringLit::parse(input).map(Literal::CString),
4545

src/string/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ impl<B: Buffer> StringLit<B> {
4646
/// Returns the string value this literal represents (where all escapes have
4747
/// been turned into their respective values).
4848
pub fn value(&self) -> &str {
49-
self.value.as_deref().unwrap_or(&self.raw[self.inner_range()])
49+
self.value
50+
.as_deref()
51+
.unwrap_or(&self.raw[self.inner_range()])
5052
}
5153

5254
/// Like `value` but returns a potentially owned version of the value.
@@ -56,7 +58,9 @@ impl<B: Buffer> StringLit<B> {
5658
pub fn into_value(self) -> B::Cow {
5759
let inner_range = self.inner_range();
5860
let Self { raw, value, .. } = self;
59-
value.map(B::Cow::from).unwrap_or_else(|| raw.cut(inner_range).into_cow())
61+
value
62+
.map(B::Cow::from)
63+
.unwrap_or_else(|| raw.cut(inner_range).into_cow())
6064
}
6165

6266
/// The optional suffix. Returns `""` if the suffix is empty/does not exist.

src/tests.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,14 @@ fn proc_macro() {
108108
if err.expected != $expected {
109109
panic!(
110110
"err.expected was expected to be {:?}, but is {:?}",
111-
$expected,
112-
err.expected,
111+
$expected, err.expected,
113112
);
114113
}
115114
if err.actual != $actual {
116-
panic!("err.actual was expected to be {:?}, but is {:?}", $actual, err.actual);
115+
panic!(
116+
"err.actual was expected to be {:?}, but is {:?}",
117+
$actual, err.actual
118+
);
117119
}
118120
};
119121
}

0 commit comments

Comments
 (0)