Skip to content

Commit 76a7167

Browse files
committed
Update to let chains and other 2024 idioms
Also reformat in 2024 style
1 parent 339ce9c commit 76a7167

25 files changed

+189
-176
lines changed

src/build_dir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66

77
use std::fs::write;
88

9-
use anyhow::{ensure, Context};
9+
use anyhow::{Context, ensure};
1010
use camino::{Utf8Path, Utf8PathBuf};
1111
use tempfile::TempDir;
1212
use tracing::info;
1313

1414
use crate::{
15+
Result,
1516
console::Console,
1617
copy_tree::copy_tree,
1718
manifest::{fix_cargo_config, fix_manifest},
1819
options::Options,
1920
workspace::Workspace,
20-
Result,
2121
};
2222

2323
/// A directory containing source, that can be mutated, built, and tested.

src/cargo.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::time::{Duration, Instant};
1212
use nextest_metadata::NextestExitCode;
1313
use tracing::{debug, debug_span, warn};
1414

15+
use crate::Result;
1516
use crate::build_dir::BuildDir;
1617
use crate::console::Console;
1718
use crate::interrupt::check_interrupted;
@@ -20,7 +21,6 @@ use crate::outcome::{Phase, PhaseResult};
2021
use crate::output::ScenarioOutput;
2122
use crate::package::PackageSelection;
2223
use crate::process::{Exit, Process};
23-
use crate::Result;
2424

2525
// Allowed nextest codes (those will be considered a mutation caught / ignored without a warning)
2626
const NEXTEST_ALLOWED_CODES: &[i32] = &[
@@ -66,12 +66,13 @@ pub fn run_cargo(
6666
)?;
6767
check_interrupted()?;
6868
debug!(?process_status, elapsed = ?start.elapsed());
69-
if let Exit::Failure(code) = process_status {
70-
if argv[1] == "nextest" && !NEXTEST_ALLOWED_CODES.contains(&code) {
71-
// Nextest returns detailed exit codes. I think we should still treat any non-zero result as just an
72-
// error, but we can at least warn if it's unexpected.
73-
warn!(%code, "nextest process exited with unexpected code (allowed: {NEXTEST_ALLOWED_CODES:?})");
74-
}
69+
if let Exit::Failure(code) = process_status
70+
&& argv[1] == "nextest"
71+
&& !NEXTEST_ALLOWED_CODES.contains(&code)
72+
{
73+
// Nextest returns detailed exit codes. I think we should still treat any non-zero result as
74+
// just an error, but we can at least warn if it's unexpected.
75+
warn!(%code, "nextest process exited with unexpected code (allowed: {NEXTEST_ALLOWED_CODES:?})");
7576
}
7677
Ok(PhaseResult {
7778
phase,
@@ -207,8 +208,8 @@ mod test {
207208
use rusty_fork::rusty_fork_test;
208209

209210
use crate::{
210-
test_util::{single_threaded_remove_env_var, single_threaded_set_env_var},
211211
Args,
212+
test_util::{single_threaded_remove_env_var, single_threaded_set_env_var},
212213
};
213214

214215
use super::*;

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use schemars::JsonSchema;
1919
use serde::Deserialize;
2020
use tracing::debug;
2121

22-
use crate::options::Common;
2322
use crate::Result;
23+
use crate::options::Common;
2424

2525
// NOTE: Docstrings on this struct and its members turn into descriptions in the JSON schema,
2626
// so keep them focused on the externally-visible behavior.

src/console.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::sync::{Arc, Mutex};
1010
use std::time::{Duration, Instant};
1111

1212
use camino::{Utf8Path, Utf8PathBuf};
13-
use console::{style, StyledObject};
13+
use console::{StyledObject, style};
1414
use nutmeg::Destination;
1515
use tracing::Level;
1616
use tracing_subscriber::fmt::MakeWriter;
@@ -116,12 +116,12 @@ impl Console {
116116
}
117117
s.push('\n');
118118
self.message(&s);
119-
if let Some(mutant) = scenario.mutant() {
120-
if outcome.mutant_missed() {
121-
let annotation = options.annotations.format(mutant);
122-
if !annotation.is_empty() {
123-
self.message(&annotation);
124-
}
119+
if let Some(mutant) = scenario.mutant()
120+
&& outcome.mutant_missed()
121+
{
122+
let annotation = options.annotations.format(mutant);
123+
if !annotation.is_empty() {
124+
self.message(&annotation);
125125
}
126126
}
127127
}

src/copy_tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use tempfile::TempDir;
1313
use tracing::{debug, warn};
1414

1515
use crate::options::Options;
16-
use crate::{check_interrupted, Console, Result};
16+
use crate::{Console, Result, check_interrupted};
1717

1818
#[cfg(unix)]
1919
mod unix;
@@ -161,9 +161,9 @@ mod test {
161161
use camino::Utf8PathBuf;
162162
use tempfile::TempDir;
163163

164+
use crate::Result;
164165
use crate::console::Console;
165166
use crate::options::Options;
166-
use crate::Result;
167167

168168
use super::copy_tree;
169169

src/fnvalue.rs

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -247,24 +247,15 @@ fn path_ends_with(path: &Path, ident: &str) -> bool {
247247

248248
fn match_impl_iterator(TypeImplTrait { bounds, .. }: &TypeImplTrait) -> Option<&Type> {
249249
for bound in bounds {
250-
if let TypeParamBound::Trait(TraitBound { path, .. }) = bound {
251-
if let Some(last_segment) = path.segments.last() {
252-
if last_segment.ident == "Iterator" {
253-
if let PathArguments::AngleBracketed(AngleBracketedGenericArguments {
254-
args,
255-
..
256-
}) = &last_segment.arguments
257-
{
258-
if let Some(GenericArgument::AssocType(AssocType { ident, ty, .. })) =
259-
args.first()
260-
{
261-
if ident == "Item" {
262-
return Some(ty);
263-
}
264-
}
265-
}
266-
}
267-
}
250+
if let TypeParamBound::Trait(TraitBound { path, .. }) = bound
251+
&& let Some(last_segment) = path.segments.last()
252+
&& last_segment.ident == "Iterator"
253+
&& let PathArguments::AngleBracketed(AngleBracketedGenericArguments { args, .. }) =
254+
&last_segment.arguments
255+
&& let Some(GenericArgument::AssocType(AssocType { ident, ty, .. })) = args.first()
256+
&& ident == "Item"
257+
{
258+
return Some(ty);
268259
}
269260
}
270261
None
@@ -279,17 +270,15 @@ fn known_container(path: &Path) -> Option<(&Ident, &Type)> {
279270
if ["Box", "Cell", "RefCell", "Arc", "Rc", "Mutex"]
280271
.iter()
281272
.any(|v| last.ident == v)
282-
{
283-
if let PathArguments::AngleBracketed(AngleBracketedGenericArguments { args, .. }) =
273+
&& let PathArguments::AngleBracketed(AngleBracketedGenericArguments { args, .. }) =
284274
&last.arguments
275+
{
276+
// TODO: Skip lifetime args.
277+
// TODO: Return the path with args stripped out.
278+
if args.len() == 1
279+
&& let Some(GenericArgument::Type(inner_type)) = args.first()
285280
{
286-
// TODO: Skip lifetime args.
287-
// TODO: Return the path with args stripped out.
288-
if args.len() == 1 {
289-
if let Some(GenericArgument::Type(inner_type)) = args.first() {
290-
return Some((&last.ident, inner_type));
291-
}
292-
}
281+
return Some((&last.ident, inner_type));
293282
}
294283
}
295284
None
@@ -318,10 +307,10 @@ fn known_collection(path: &Path) -> Option<(&Ident, &Type)> {
318307
{
319308
// TODO: Skip lifetime args.
320309
// TODO: Return the path with args stripped out.
321-
if args.len() == 1 {
322-
if let Some(GenericArgument::Type(inner_type)) = args.first() {
323-
return Some((&last.ident, inner_type));
324-
}
310+
if args.len() == 1
311+
&& let Some(GenericArgument::Type(inner_type)) = args.first()
312+
{
313+
return Some((&last.ident, inner_type));
325314
}
326315
}
327316
None
@@ -421,16 +410,15 @@ fn path_is_nonzero_unsigned(path: &Path) -> bool {
421410
fn match_first_type_arg<'p>(path: &'p Path, expected_ident: &str) -> Option<&'p Type> {
422411
// TODO: Maybe match only things with one arg?
423412
let last = path.segments.last()?;
424-
if last.ident == expected_ident {
425-
if let PathArguments::AngleBracketed(AngleBracketedGenericArguments { args, .. }) =
413+
if last.ident == expected_ident
414+
&& let PathArguments::AngleBracketed(AngleBracketedGenericArguments { args, .. }) =
426415
&last.arguments
427-
{
428-
for arg in args {
429-
match arg {
430-
GenericArgument::Type(arg_type) => return Some(arg_type),
431-
GenericArgument::Lifetime(_) => (),
432-
_ => return None,
433-
}
416+
{
417+
for arg in args {
418+
match arg {
419+
GenericArgument::Type(arg_type) => return Some(arg_type),
420+
GenericArgument::Lifetime(_) => (),
421+
_ => return None,
434422
}
435423
}
436424
}

src/glob.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ mod test {
5050

5151
#[test]
5252
fn empty_globs() {
53-
assert!(build_glob_set(&[] as &[&str])
54-
.expect("build GlobSet")
55-
.is_none());
53+
assert!(
54+
build_glob_set(&[] as &[&str])
55+
.expect("build GlobSet")
56+
.is_none()
57+
);
5658
}
5759

5860
#[test]

src/in_diff.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use tracing::{error, trace, warn};
1818

1919
use crate::mutant::Mutant;
2020
use crate::source::SourceFile;
21-
use crate::{exit_code, Result};
21+
use crate::{Result, exit_code};
2222

2323
/// The result of filtering mutants based on a diff.
2424
#[derive(Debug, PartialEq, Eq, Clone)]
@@ -239,7 +239,7 @@ fn affected_lines(patch: &Patch) -> Vec<usize> {
239239
Line::Add(_) | Line::Context(_) => {
240240
if prev_removed {
241241
debug_assert!(
242-
affected_lines.last().map_or(true, |last| *last < lineno),
242+
affected_lines.last().is_none_or(|last| *last < lineno),
243243
"{lineno} {affected_lines:?}"
244244
);
245245
debug_assert!(lineno >= 1, "{lineno}");
@@ -253,7 +253,7 @@ fn affected_lines(patch: &Patch) -> Vec<usize> {
253253
lineno += 1;
254254
}
255255
Line::Add(_) => {
256-
if affected_lines.last().map_or(true, |last| *last != lineno) {
256+
if affected_lines.last().is_none_or(|last| *last != lineno) {
257257
affected_lines.push(lineno);
258258
}
259259
lineno += 1;
@@ -262,7 +262,7 @@ fn affected_lines(patch: &Patch) -> Vec<usize> {
262262
if lineno > 1
263263
&& affected_lines
264264
.last()
265-
.map_or(true, |last| *last != (lineno - 1))
265+
.is_none_or(|last| *last != (lineno - 1))
266266
{
267267
affected_lines.push(lineno - 1);
268268
}
@@ -293,7 +293,7 @@ fn partial_new_file<'d>(patch: &Patch<'d>) -> Vec<(usize, &'d str)> {
293293
Line::Context(text) | Line::Add(text) => {
294294
debug_assert!(lineno >= 1, "{lineno}");
295295
debug_assert!(
296-
r.last().map_or(true, |last| last.0 < lineno),
296+
r.last().is_none_or(|last| last.0 < lineno),
297297
"{lineno} {r:?}"
298298
);
299299
r.push((lineno, text));

src/lab.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ use jiff::Timestamp;
1616
use tracing::{debug, debug_span, error, trace, warn};
1717

1818
use crate::{
19-
cargo::run_cargo, options::TestPackages, outcome::LabOutcome, output::OutputDir,
20-
package::Package, package::PackageSelection, timeouts::Timeouts, workspace::Workspace,
2119
BaselineStrategy, BuildDir, Console, Context, Mutant, Options, Phase, Result, Scenario,
22-
ScenarioOutcome,
20+
ScenarioOutcome, cargo::run_cargo, options::TestPackages, outcome::LabOutcome,
21+
output::OutputDir, package::Package, package::PackageSelection, timeouts::Timeouts,
22+
workspace::Workspace,
2323
};
2424

2525
/// Run all possible mutation experiments.
@@ -123,7 +123,9 @@ pub fn test_mutants(
123123
// the tree if no mutants are generated.
124124
warn!("No mutants were generated");
125125
} else if lab_outcome.unviable == lab_outcome.total_mutants {
126-
warn!("No mutants were viable: perhaps there is a problem with building in a scratch directory. Look in mutants.out/log/* for more information.");
126+
warn!(
127+
"No mutants were viable: perhaps there is a problem with building in a scratch directory. Look in mutants.out/log/* for more information."
128+
);
127129
}
128130
Ok(lab_outcome)
129131
}

src/list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
#![allow(clippy::module_name_repetitions)]
77

88
use itertools::Itertools;
9-
use serde_json::{json, Value};
9+
use serde_json::{Value, json};
1010

11+
use crate::Options;
1112
use crate::mutant::Mutant;
1213
use crate::path::Utf8PathSlashes;
1314
use crate::source::SourceFile;
14-
use crate::Options;
1515

1616
/// Return a string representation of a list of mutants.
1717
///

0 commit comments

Comments
 (0)