Skip to content

Commit

Permalink
Merge pull request #263 from oli-obk/clippy
Browse files Browse the repository at this point in the history
Run on clippy and make everything work again
  • Loading branch information
oli-obk authored Aug 21, 2024
2 parents b22e2bb + 753fc1b commit 5b2cb61
Show file tree
Hide file tree
Showing 9 changed files with 418 additions and 405 deletions.
13 changes: 8 additions & 5 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,17 @@ pub enum CrateType {

/// A generic multithreaded runner that has a thread for producing work,
/// a thread for collecting work, and `num_threads` threads for doing the work.
pub fn run_and_collect<SUBMISSION: Send, RESULT: Send>(
pub fn run_and_collect<const N: usize, SUBMISSION: Send, RESULT: Send>(
num_threads: NonZeroUsize,
submitter: impl FnOnce(Sender<SUBMISSION>) + Send,
runner: impl Sync + Fn(&Receiver<SUBMISSION>, Sender<RESULT>) -> Result<()>,
submitter: impl FnOnce([Sender<SUBMISSION>; N]) + Send,
runner: impl Sync + Fn(&[Receiver<SUBMISSION>; N], Sender<RESULT>) -> Result<()>,
collector: impl FnOnce(Receiver<RESULT>) + Send,
) -> Result<()> {
// A channel for files to process
let (submit, receive) = unbounded();
let (submit, receive): (Vec<_>, Vec<_>) = std::iter::repeat_with(unbounded).take(N).unzip();
let receive = receive[..].try_into().unwrap();
let mut submit = submit.into_iter();
let submit = std::array::from_fn(|_| submit.next().unwrap());

thread::scope(|s| {
// Create a thread that is in charge of walking the directory and submitting jobs.
Expand All @@ -119,7 +122,7 @@ pub fn run_and_collect<SUBMISSION: Send, RESULT: Send>(
// Create N worker threads that receive files to test.
for _ in 0..num_threads.get() {
let finished_files_sender = finished_files_sender.clone();
threads.push(s.spawn(|| runner(&receive, finished_files_sender)));
threads.push(s.spawn(|| runner(receive, finished_files_sender)));
}

for thread in threads {
Expand Down
2 changes: 1 addition & 1 deletion src/custom_flags/rustfix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fn compile_fixed(
};
let mut cmd = fixed_config.build_command(build_manager)?;
cmd.arg("--crate-name")
.arg(format!("{crate_name}_________{}", i + 1));
.arg(format!("__{crate_name}_{}", i + 1));
build_manager.add_new_job(move || {
let output = cmd.output().unwrap();
let result = if fixed_config.aborted() {
Expand Down
26 changes: 20 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub use color_eyre::eyre::Result;
pub use core::run_and_collect;
pub use core::CrateType;
use crossbeam_channel::Sender;
use crossbeam_channel::TryRecvError;
pub use filter::Match;
use per_test_config::TestConfig;
use spanned::Spanned;
Expand Down Expand Up @@ -198,12 +199,12 @@ pub fn run_tests_generic(
let mut filtered = 0;
core::run_and_collect(
num_threads,
|submit| {
|[submit, priority_submit]| {
let mut todo = VecDeque::new();

let configs: Vec<_> = configs
.into_iter()
.map(|config| Arc::new(BuildManager::new(config, submit.clone())))
.map(|config| Arc::new(BuildManager::new(config, priority_submit.clone())))
.collect();
for build_manager in &configs {
todo.push_back((
Expand Down Expand Up @@ -287,11 +288,24 @@ pub fn run_tests_generic(
}
}
},
|receive, finished_files_sender| -> Result<()> {
for closure in receive {
closure(&finished_files_sender)?;
|[receive, priority_receive], finished_files_sender| -> Result<()> {
loop {
for closure in priority_receive.try_iter() {
closure(&finished_files_sender)?;
}
match receive.try_recv() {
Ok(closure) => {
closure(&finished_files_sender)?;
}
Err(TryRecvError::Empty) => {}
Err(TryRecvError::Disconnected) => {
for closure in priority_receive {
closure(&finished_files_sender)?;
}
return Ok(());
}
}
}
Ok(())
},
|finished_files_recv| {
for run in finished_files_recv {
Expand Down
6 changes: 3 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,9 @@ impl CommentParser<Comments> {

if let Some((_, comment)) =
line.split_once_str(self.comment_start)
.filter(|(pre, c)| match c[0] {
b'@' => pre.is_empty(),
b'~' => true,
.filter(|(pre, c)| match &c[..] {
[b'@', ..] => pre.is_empty(),
[b'~', ..] => true,
_ => false,
})
{
Expand Down
Loading

0 comments on commit 5b2cb61

Please sign in to comment.