Skip to content

Commit 31764d2

Browse files
committed
style: Make clippy happy
1 parent a42c3a7 commit 31764d2

File tree

12 files changed

+84
-79
lines changed

12 files changed

+84
-79
lines changed

crates/lexarg/src/ext.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ use std::ffi::OsStr;
22

33
pub(crate) trait OsStrExt: private::Sealed {
44
/// Converts to a string slice.
5-
/// The Utf8Error is guaranteed to have a valid UTF8 boundary
5+
/// The `Utf8Error` is guaranteed to have a valid UTF8 boundary
66
/// in its `valid_up_to()`
77
fn try_str(&self) -> Result<&str, std::str::Utf8Error>;
88
/// Returns `true` if the given pattern matches a sub-slice of
99
/// this string slice.
1010
///
1111
/// Returns `false` if it does not.
12+
#[allow(dead_code)]
1213
fn contains(&self, needle: &str) -> bool;
1314
/// Returns the byte index of the first character of this string slice that
1415
/// matches the pattern.
@@ -29,6 +30,7 @@ pub(crate) trait OsStrExt: private::Sealed {
2930
fn starts_with(&self, prefix: &str) -> bool;
3031
/// An iterator over substrings of this string slice, separated by
3132
/// characters matched by a pattern.
33+
#[allow(dead_code)]
3234
fn split<'s, 'n>(&'s self, needle: &'n str) -> Split<'s, 'n>;
3335
/// Splits the string on the first occurrence of the specified delimiter and
3436
/// returns prefix before delimiter and suffix after delimiter.
@@ -92,17 +94,18 @@ impl OsStrExt for OsStr {
9294
}
9395

9496
mod private {
95-
pub trait Sealed {}
97+
pub(crate) trait Sealed {}
9698

9799
impl Sealed for std::ffi::OsStr {}
98100
}
99101

100-
pub struct Split<'s, 'n> {
102+
#[allow(dead_code)]
103+
pub(crate) struct Split<'s, 'n> {
101104
haystack: Option<&'s OsStr>,
102105
needle: &'n str,
103106
}
104107

105-
impl<'s, 'n> Iterator for Split<'s, 'n> {
108+
impl<'s> Iterator for Split<'s, '_> {
106109
type Item = &'s OsStr;
107110

108111
fn next(&mut self) -> Option<Self::Item> {
@@ -129,10 +132,12 @@ impl<'s, 'n> Iterator for Split<'s, 'n> {
129132
///
130133
/// `index` must be at a valid UTF-8 boundary
131134
pub(crate) unsafe fn split_at(os: &OsStr, index: usize) -> (&OsStr, &OsStr) {
132-
let bytes = os.as_encoded_bytes();
133-
let (first, second) = bytes.split_at(index);
134-
(
135-
OsStr::from_encoded_bytes_unchecked(first),
136-
OsStr::from_encoded_bytes_unchecked(second),
137-
)
135+
unsafe {
136+
let bytes = os.as_encoded_bytes();
137+
let (first, second) = bytes.split_at(index);
138+
(
139+
OsStr::from_encoded_bytes_unchecked(first),
140+
OsStr::from_encoded_bytes_unchecked(second),
141+
)
142+
}
138143
}

crates/lexarg/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ enum State<'a> {
417417
Escaped,
418418
}
419419

420-
impl<'a> State<'a> {
420+
impl State<'_> {
421421
#[cfg(test)]
422422
fn has_pending(&self) -> bool {
423423
match self {
@@ -455,7 +455,7 @@ fn split_nonutf8_once(b: &OsStr) -> (&str, Option<&OsStr>) {
455455
}
456456

457457
mod private {
458-
use super::*;
458+
use super::OsStr;
459459

460460
pub trait Sealed {}
461461
impl<const C: usize, S> Sealed for [S; C] where S: AsRef<OsStr> + std::fmt::Debug {}
@@ -784,7 +784,7 @@ mod tests {
784784
}
785785
permutations = new;
786786
for permutation in &permutations {
787-
println!("Starting {:?}", permutation);
787+
println!("Starting {permutation:?}");
788788
let p = Parser::new(permutation);
789789
exhaust(p, vec![]);
790790
}
@@ -794,7 +794,7 @@ mod tests {
794794
/// Run many sequences of methods on a Parser.
795795
fn exhaust(parser: Parser<'_>, path: Vec<String>) {
796796
if path.len() > 100 {
797-
panic!("Stuck in loop: {:?}", path);
797+
panic!("Stuck in loop: {path:?}");
798798
}
799799

800800
if parser.has_pending() {
@@ -806,7 +806,7 @@ mod tests {
806806
"{next:?} via {path:?}",
807807
);
808808
let mut path = path.clone();
809-
path.push(format!("pending-next-{:?}", next));
809+
path.push(format!("pending-next-{next:?}"));
810810
exhaust(parser, path);
811811
}
812812

@@ -815,7 +815,7 @@ mod tests {
815815
let next = parser.flag_value();
816816
assert!(next.is_some(), "{next:?} via {path:?}",);
817817
let mut path = path;
818-
path.push(format!("pending-value-{:?}", next));
818+
path.push(format!("pending-value-{next:?}"));
819819
exhaust(parser, path);
820820
}
821821
} else {
@@ -832,8 +832,8 @@ mod tests {
832832
}
833833
_ => {
834834
let mut path = path.clone();
835-
path.push(format!("next-{:?}", next));
836-
exhaust(parser, path)
835+
path.push(format!("next-{next:?}"));
836+
exhaust(parser, path);
837837
}
838838
}
839839
}
@@ -857,7 +857,7 @@ mod tests {
857857
"{next:?} via {path:?}",
858858
);
859859
let mut path = path;
860-
path.push(format!("value-{:?}", next));
860+
path.push(format!("value-{next:?}"));
861861
exhaust(parser, path);
862862
}
863863
}

crates/libtest2-harness/src/case.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub use crate::*;
1+
pub(crate) use crate::*;
22

33
pub trait Case: Send + Sync + 'static {
44
/// The name of a test

crates/libtest2-harness/src/harness.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use libtest_lexarg::OutputFormat;
22

3-
use crate::*;
3+
use crate::{Case, RunError, RunMode, State, cli, notify, shuffle};
44

55
pub struct Harness {
66
raw: Vec<std::ffi::OsString>,
@@ -33,7 +33,7 @@ impl Harness {
3333
pub fn main(mut self) -> ! {
3434
let mut parser = cli::Parser::new(&self.raw);
3535
let opts = parse(&mut parser).unwrap_or_else(|err| {
36-
eprintln!("{}", err);
36+
eprintln!("{err}");
3737
std::process::exit(1)
3838
});
3939

@@ -45,11 +45,11 @@ impl Harness {
4545
.write_global();
4646

4747
let mut notifier = notifier(&opts).unwrap_or_else(|err| {
48-
eprintln!("{}", err);
48+
eprintln!("{err}");
4949
std::process::exit(1)
5050
});
5151
discover(&opts, &mut self.cases, notifier.as_mut()).unwrap_or_else(|err| {
52-
eprintln!("{}", err);
52+
eprintln!("{err}");
5353
std::process::exit(1)
5454
});
5555

@@ -70,7 +70,7 @@ impl Harness {
7070

7171
const ERROR_EXIT_CODE: i32 = 101;
7272

73-
fn parse(parser: &mut cli::Parser) -> cli::Result<libtest_lexarg::TestOpts> {
73+
fn parse(parser: &mut cli::Parser<'_>) -> cli::Result<libtest_lexarg::TestOpts> {
7474
let mut test_opts = libtest_lexarg::TestOptsParseState::new();
7575

7676
let bin = parser.bin();
@@ -194,7 +194,7 @@ fn discover(
194194
retain_cases.push(retain_case);
195195
notifier.notify(notify::Event::DiscoverCase {
196196
name: case.name().to_owned(),
197-
mode: notify::RunMode::Test,
197+
mode: RunMode::Test,
198198
run: retain_case,
199199
})?;
200200
}
@@ -253,8 +253,8 @@ fn run(
253253
"`--test` and `-bench` are mutually exclusive",
254254
));
255255
}
256-
(true, false) => notify::RunMode::Test,
257-
(false, true) => notify::RunMode::Bench,
256+
(true, false) => RunMode::Test,
257+
(false, true) => RunMode::Bench,
258258
(false, false) => unreachable!("libtest-lexarg` should always ensure at least one is set"),
259259
};
260260
state.set_mode(mode);
@@ -309,7 +309,7 @@ fn run(
309309
let case = remaining.pop_front().unwrap();
310310
let name = case.name().to_owned();
311311

312-
let cfg = std::thread::Builder::new().name(name.to_owned());
312+
let cfg = std::thread::Builder::new().name(name.clone());
313313
let tx = tx.clone();
314314
let case = std::sync::Arc::new(case);
315315
let case_fallback = case.clone();
@@ -402,7 +402,7 @@ fn run_case(
402402

403403
let msg = match payload {
404404
Some(payload) => format!("test panicked: {payload}"),
405-
None => "test panicked".to_string(),
405+
None => "test panicked".to_owned(),
406406
};
407407
Err(RunError::fail(msg))
408408
});
@@ -412,7 +412,7 @@ fn run_case(
412412
let message = err.and_then(|e| e.cause().map(|c| c.to_string()));
413413
notifier.notify(notify::Event::CaseComplete {
414414
name: case.name().to_owned(),
415-
mode: notify::RunMode::Test,
415+
mode: RunMode::Test,
416416
status,
417417
message,
418418
elapsed_s: Some(notify::Elapsed(timer.elapsed())),

crates/libtest2-harness/src/notify/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl<W: std::io::Write> JsonNotifier<W> {
1414
impl<W: std::io::Write> super::Notifier for JsonNotifier<W> {
1515
fn notify(&mut self, event: Event) -> std::io::Result<()> {
1616
let event = serde_json::to_string(&event)?;
17-
writeln!(self.writer, "{}", event)?;
17+
writeln!(self.writer, "{event}")?;
1818
Ok(())
1919
}
2020
}

crates/libtest2-harness/src/notify/summary.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ impl Summary {
5959
// Print messages of all tests
6060
for (name, msg) in &self.failures {
6161
if let Some(msg) = msg {
62-
writeln!(writer, "---- {} ----", name)?;
63-
writeln!(writer, "{}", msg)?;
62+
writeln!(writer, "---- {name} ----")?;
63+
writeln!(writer, "{msg}")?;
6464
writeln!(writer)?;
6565
}
6666
}
@@ -69,7 +69,7 @@ impl Summary {
6969
writeln!(writer)?;
7070
writeln!(writer, "failures:")?;
7171
for name in self.failures.keys() {
72-
writeln!(writer, " {}", name)?;
72+
writeln!(writer, " {name}")?;
7373
}
7474
}
7575
writeln!(writer)?;

crates/libtest2-harness/src/shuffle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
44

55
use crate::Case;
66

7-
pub fn get_shuffle_seed(opts: &libtest_lexarg::TestOpts) -> Option<u64> {
7+
pub(crate) fn get_shuffle_seed(opts: &libtest_lexarg::TestOpts) -> Option<u64> {
88
opts.shuffle_seed.or_else(|| {
99
opts.shuffle.then(|| {
1010
SystemTime::now()
@@ -15,7 +15,7 @@ pub fn get_shuffle_seed(opts: &libtest_lexarg::TestOpts) -> Option<u64> {
1515
})
1616
}
1717

18-
pub fn shuffle_tests(shuffle_seed: u64, tests: &mut [Box<dyn Case>]) {
18+
pub(crate) fn shuffle_tests(shuffle_seed: u64, tests: &mut [Box<dyn Case>]) {
1919
let test_names: Vec<&str> = tests.iter().map(|test| test.name()).collect();
2020
let test_names_hash = calculate_hash(&test_names);
2121
let mut rng = Rng::new(shuffle_seed, test_names_hash);

crates/libtest2-harness/src/state.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
pub use crate::*;
1+
pub(crate) use crate::*;
22

33
#[derive(Debug)]
44
pub struct State {
5-
mode: notify::RunMode,
5+
mode: RunMode,
66
run_ignored: bool,
77
}
88

@@ -23,7 +23,7 @@ impl State {
2323
}
2424
}
2525

26-
pub fn current_mode(&self) -> notify::RunMode {
26+
pub fn current_mode(&self) -> RunMode {
2727
self.mode
2828
}
2929
}
@@ -36,7 +36,7 @@ impl State {
3636
}
3737
}
3838

39-
pub(crate) fn set_mode(&mut self, mode: notify::RunMode) {
39+
pub(crate) fn set_mode(&mut self, mode: RunMode) {
4040
self.mode = mode;
4141
}
4242

0 commit comments

Comments
 (0)