Skip to content

Commit 5b2cb61

Browse files
authored
Merge pull request #263 from oli-obk/clippy
Run on clippy and make everything work again
2 parents b22e2bb + 753fc1b commit 5b2cb61

File tree

9 files changed

+418
-405
lines changed

9 files changed

+418
-405
lines changed

src/core.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,17 @@ pub enum CrateType {
9494

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

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

125128
for thread in threads {

src/custom_flags/rustfix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fn compile_fixed(
216216
};
217217
let mut cmd = fixed_config.build_command(build_manager)?;
218218
cmd.arg("--crate-name")
219-
.arg(format!("{crate_name}_________{}", i + 1));
219+
.arg(format!("__{crate_name}_{}", i + 1));
220220
build_manager.add_new_job(move || {
221221
let output = cmd.output().unwrap();
222222
let result = if fixed_config.aborted() {

src/lib.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub use color_eyre::eyre::Result;
1717
pub use core::run_and_collect;
1818
pub use core::CrateType;
1919
use crossbeam_channel::Sender;
20+
use crossbeam_channel::TryRecvError;
2021
pub use filter::Match;
2122
use per_test_config::TestConfig;
2223
use spanned::Spanned;
@@ -198,12 +199,12 @@ pub fn run_tests_generic(
198199
let mut filtered = 0;
199200
core::run_and_collect(
200201
num_threads,
201-
|submit| {
202+
|[submit, priority_submit]| {
202203
let mut todo = VecDeque::new();
203204

204205
let configs: Vec<_> = configs
205206
.into_iter()
206-
.map(|config| Arc::new(BuildManager::new(config, submit.clone())))
207+
.map(|config| Arc::new(BuildManager::new(config, priority_submit.clone())))
207208
.collect();
208209
for build_manager in &configs {
209210
todo.push_back((
@@ -287,11 +288,24 @@ pub fn run_tests_generic(
287288
}
288289
}
289290
},
290-
|receive, finished_files_sender| -> Result<()> {
291-
for closure in receive {
292-
closure(&finished_files_sender)?;
291+
|[receive, priority_receive], finished_files_sender| -> Result<()> {
292+
loop {
293+
for closure in priority_receive.try_iter() {
294+
closure(&finished_files_sender)?;
295+
}
296+
match receive.try_recv() {
297+
Ok(closure) => {
298+
closure(&finished_files_sender)?;
299+
}
300+
Err(TryRecvError::Empty) => {}
301+
Err(TryRecvError::Disconnected) => {
302+
for closure in priority_receive {
303+
closure(&finished_files_sender)?;
304+
}
305+
return Ok(());
306+
}
307+
}
293308
}
294-
Ok(())
295309
},
296310
|finished_files_recv| {
297311
for run in finished_files_recv {

src/parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,9 @@ impl CommentParser<Comments> {
474474

475475
if let Some((_, comment)) =
476476
line.split_once_str(self.comment_start)
477-
.filter(|(pre, c)| match c[0] {
478-
b'@' => pre.is_empty(),
479-
b'~' => true,
477+
.filter(|(pre, c)| match &c[..] {
478+
[b'@', ..] => pre.is_empty(),
479+
[b'~', ..] => true,
480480
_ => false,
481481
})
482482
{

0 commit comments

Comments
 (0)