Skip to content

Commit 64b00e7

Browse files
committed
Reformat
1 parent 3c741d5 commit 64b00e7

File tree

6 files changed

+33
-70
lines changed

6 files changed

+33
-70
lines changed

lib/smol_str/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,5 @@ serde = ["dep:serde_core"]
3333
name = "bench"
3434
harness = false
3535

36-
[profile.bench]
37-
lto = "fat"
38-
3936
[lints]
4037
workspace = true

lib/smol_str/src/lib.rs

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ impl Clone for SmolStr {
115115
impl Default for SmolStr {
116116
#[inline(always)]
117117
fn default() -> SmolStr {
118-
SmolStr(Repr::Inline {
119-
len: InlineSize::_V0,
120-
buf: [0; INLINE_CAP],
121-
})
118+
SmolStr(Repr::Inline { len: InlineSize::_V0, buf: [0; INLINE_CAP] })
122119
}
123120
}
124121

@@ -216,13 +213,13 @@ impl hash::Hash for SmolStr {
216213
}
217214

218215
impl fmt::Debug for SmolStr {
219-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
216+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
220217
fmt::Debug::fmt(self.as_str(), f)
221218
}
222219
}
223220

224221
impl fmt::Display for SmolStr {
225-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
222+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
226223
fmt::Display::fmt(self.as_str(), f)
227224
}
228225
}
@@ -245,11 +242,8 @@ fn from_buf_and_chars(
245242
) -> SmolStr {
246243
let min_size = iter.size_hint().0 + buf_len;
247244
if min_size > INLINE_CAP {
248-
let heap: String = core::str::from_utf8(&buf[..buf_len])
249-
.unwrap()
250-
.chars()
251-
.chain(iter)
252-
.collect();
245+
let heap: String =
246+
core::str::from_utf8(&buf[..buf_len]).unwrap().chars().chain(iter).collect();
253247
if heap.len() <= INLINE_CAP {
254248
// size hint lied
255249
return SmolStr::new_inline(&heap);
@@ -490,10 +484,7 @@ impl InlineSize {
490484

491485
#[derive(Clone, Debug)]
492486
enum Repr {
493-
Inline {
494-
len: InlineSize,
495-
buf: [u8; INLINE_CAP],
496-
},
487+
Inline { len: InlineSize, buf: [u8; INLINE_CAP] },
497488
Static(&'static str),
498489
Heap(Arc<str>),
499490
}
@@ -521,10 +512,8 @@ impl Repr {
521512
if len <= N_NEWLINES + N_SPACES {
522513
let bytes = text.as_bytes();
523514
let possible_newline_count = cmp::min(len, N_NEWLINES);
524-
let newlines = bytes[..possible_newline_count]
525-
.iter()
526-
.take_while(|&&b| b == b'\n')
527-
.count();
515+
let newlines =
516+
bytes[..possible_newline_count].iter().take_while(|&&b| b == b'\n').count();
528517
let possible_space_count = len - newlines;
529518
if possible_space_count <= N_SPACES && bytes[newlines..].iter().all(|&b| b == b' ') {
530519
let spaces = possible_space_count;
@@ -576,16 +565,9 @@ impl Repr {
576565
match (self, other) {
577566
(Self::Heap(l0), Self::Heap(r0)) => Arc::ptr_eq(l0, r0),
578567
(Self::Static(l0), Self::Static(r0)) => core::ptr::eq(l0, r0),
579-
(
580-
Self::Inline {
581-
len: l_len,
582-
buf: l_buf,
583-
},
584-
Self::Inline {
585-
len: r_len,
586-
buf: r_buf,
587-
},
588-
) => l_len == r_len && l_buf == r_buf,
568+
(Self::Inline { len: l_len, buf: l_buf }, Self::Inline { len: r_len, buf: r_buf }) => {
569+
l_len == r_len && l_buf == r_buf
570+
}
589571
_ => false,
590572
}
591573
}
@@ -649,11 +631,7 @@ impl StrExt for str {
649631
let len = self.len();
650632
if len <= INLINE_CAP {
651633
let (buf, rest) = inline_convert_while_ascii(self, u8::to_ascii_lowercase);
652-
from_buf_and_chars(
653-
buf,
654-
len - rest.len(),
655-
rest.chars().flat_map(|c| c.to_lowercase()),
656-
)
634+
from_buf_and_chars(buf, len - rest.len(), rest.chars().flat_map(|c| c.to_lowercase()))
657635
} else {
658636
self.to_lowercase().into()
659637
}
@@ -664,11 +642,7 @@ impl StrExt for str {
664642
let len = self.len();
665643
if len <= INLINE_CAP {
666644
let (buf, rest) = inline_convert_while_ascii(self, u8::to_ascii_uppercase);
667-
from_buf_and_chars(
668-
buf,
669-
len - rest.len(),
670-
rest.chars().flat_map(|c| c.to_uppercase()),
671-
)
645+
from_buf_and_chars(buf, len - rest.len(), rest.chars().flat_map(|c| c.to_uppercase()))
672646
} else {
673647
self.to_uppercase().into()
674648
}
@@ -878,21 +852,15 @@ enum SmolStrBuilderRepr {
878852
impl Default for SmolStrBuilderRepr {
879853
#[inline]
880854
fn default() -> Self {
881-
SmolStrBuilderRepr::Inline {
882-
buf: [0; INLINE_CAP],
883-
len: 0,
884-
}
855+
SmolStrBuilderRepr::Inline { buf: [0; INLINE_CAP], len: 0 }
885856
}
886857
}
887858

888859
impl SmolStrBuilder {
889860
/// Creates a new empty [`SmolStrBuilder`].
890861
#[must_use]
891862
pub const fn new() -> Self {
892-
Self(SmolStrBuilderRepr::Inline {
893-
buf: [0; INLINE_CAP],
894-
len: 0,
895-
})
863+
Self(SmolStrBuilderRepr::Inline { buf: [0; INLINE_CAP], len: 0 })
896864
}
897865

898866
/// Builds a [`SmolStr`] from `self`.

lib/smol_str/src/serde.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ where
6767
{
6868
match String::from_utf8(v) {
6969
Ok(s) => Ok(SmolStr::from(s)),
70-
Err(e) => Err(Error::invalid_value(
71-
Unexpected::Bytes(&e.into_bytes()),
72-
&self,
73-
)),
70+
Err(e) => Err(Error::invalid_value(Unexpected::Bytes(&e.into_bytes()), &self)),
7471
}
7572
}
7673
}

lib/smol_str/tests/test.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::disallowed_types)]
12
use std::sync::Arc;
23

34
#[cfg(not(miri))]
@@ -8,10 +9,7 @@ use smol_str::{SmolStr, SmolStrBuilder};
89
#[test]
910
#[cfg(target_pointer_width = "64")]
1011
fn smol_str_is_smol() {
11-
assert_eq!(
12-
::std::mem::size_of::<SmolStr>(),
13-
::std::mem::size_of::<String>(),
14-
);
12+
assert_eq!(::std::mem::size_of::<SmolStr>(), ::std::mem::size_of::<String>(),);
1513
}
1614

1715
#[test]
@@ -341,10 +339,7 @@ mod test_str_ext {
341339
#[test]
342340
fn large() {
343341
let lowercase = "aaaaaaAAAAAaaaaaaaaaaaaaaaaaaaaaAAAAaaaaaaaaaaaaaa".to_lowercase_smolstr();
344-
assert_eq!(
345-
lowercase,
346-
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
347-
);
342+
assert_eq!(lowercase, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
348343
assert!(lowercase.is_heap_allocated());
349344
}
350345

lib/smol_str/tests/tidy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::disallowed_methods, clippy::print_stdout)]
12
#![cfg(not(miri))]
23
use std::{
34
env,

xtask/src/tidy.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,24 @@ fn check_cargo_toml(path: &Path, text: String) {
127127
}
128128

129129
fn check_licenses(sh: &Shell) {
130-
const EXPECTED: [&str; 20] = [
130+
const EXPECTED: &[&str] = &[
131131
"(MIT OR Apache-2.0) AND Unicode-3.0",
132132
"0BSD OR MIT OR Apache-2.0",
133-
"Apache-2.0",
133+
"Apache-2.0 / MIT",
134134
"Apache-2.0 OR BSL-1.0",
135135
"Apache-2.0 OR MIT",
136-
"Apache-2.0 WITH LLVM-exception",
137136
"Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT",
137+
"Apache-2.0 WITH LLVM-exception",
138+
"Apache-2.0",
138139
"Apache-2.0/MIT",
140+
"BSD-2-Clause OR Apache-2.0 OR MIT",
139141
"CC0-1.0",
140142
"ISC",
141-
"MIT",
142143
"MIT / Apache-2.0",
144+
"MIT OR Apache-2.0 OR LGPL-2.1-or-later",
143145
"MIT OR Apache-2.0",
144146
"MIT OR Zlib OR Apache-2.0",
147+
"MIT",
145148
"MIT/Apache-2.0",
146149
"MPL-2.0",
147150
"Unicode-3.0",
@@ -159,26 +162,28 @@ fn check_licenses(sh: &Shell) {
159162
.collect::<Vec<_>>();
160163
licenses.sort_unstable();
161164
licenses.dedup();
162-
if licenses != EXPECTED {
165+
let mut expected = EXPECTED.to_vec();
166+
expected.sort_unstable();
167+
if licenses != expected {
163168
let mut diff = String::new();
164169

165170
diff.push_str("New Licenses:\n");
166171
for &l in licenses.iter() {
167-
if !EXPECTED.contains(&l) {
172+
if !expected.contains(&l) {
168173
diff += &format!(" {l}\n")
169174
}
170175
}
171176

172177
diff.push_str("\nMissing Licenses:\n");
173-
for l in EXPECTED {
178+
for l in expected {
174179
if !licenses.contains(&l) {
175180
diff += &format!(" {l}\n")
176181
}
177182
}
178183

179184
panic!("different set of licenses!\n{diff}");
180185
}
181-
assert_eq!(licenses, EXPECTED);
186+
assert_eq!(licenses, expected);
182187
}
183188

184189
fn check_test_attrs(path: &Path, text: &str) {

0 commit comments

Comments
 (0)