Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyBF committed Jul 17, 2022
1 parent ec04682 commit 545feac
Show file tree
Hide file tree
Showing 39 changed files with 141 additions and 148 deletions.
8 changes: 2 additions & 6 deletions rayon-core/src/compile_fail/rc_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
use std::rc::Rc;
fn main() {
rayon_core::join(|| Rc::new(22), || ()); //~ ERROR
}
rayon_core::join(|| Rc::new(22), || ()); //~ ERROR
``` */
mod left {}
Expand All @@ -13,9 +11,7 @@ mod left {}
use std::rc::Rc;
fn main() {
rayon_core::join(|| (), || Rc::new(23)); //~ ERROR
}
rayon_core::join(|| (), || Rc::new(23)); //~ ERROR
``` */
mod right {}
8 changes: 3 additions & 5 deletions rayon-core/src/compile_fail/rc_upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
use std::rc::Rc;
fn main() {
let r = Rc::new(22);
rayon_core::join(|| r.clone(), || r.clone());
//~^ ERROR
}
let r = Rc::new(22);
rayon_core::join(|| r.clone(), || r.clone());
//~^ ERROR
``` */
10 changes: 1 addition & 9 deletions rayon-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ pub struct ThreadPoolBuilder<S = DefaultSpawn> {
///
/// [`ThreadPoolBuilder`]: struct.ThreadPoolBuilder.html
#[deprecated(note = "Use `ThreadPoolBuilder`")]
#[derive(Default)]
pub struct Configuration {
builder: ThreadPoolBuilder,
}
Expand Down Expand Up @@ -748,15 +749,6 @@ impl<S> fmt::Debug for ThreadPoolBuilder<S> {
}
}

#[allow(deprecated)]
impl Default for Configuration {
fn default() -> Self {
Configuration {
builder: Default::default(),
}
}
}

#[allow(deprecated)]
impl fmt::Debug for Configuration {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
46 changes: 20 additions & 26 deletions rayon-core/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,25 @@ impl Logger {

let (sender, receiver) = crossbeam_channel::unbounded();

if env_log.starts_with("tail:") {
let filename = env_log["tail:".len()..].to_string();
if let Some(filename) = env_log.strip_prefix("tail:") {
let filename = filename.to_string();
::std::thread::spawn(move || {
Self::tail_logger_thread(num_workers, filename, 10_000, receiver)
});
} else if env_log == "all" {
::std::thread::spawn(move || Self::all_logger_thread(num_workers, receiver));
} else if env_log.starts_with("profile:") {
let filename = env_log["profile:".len()..].to_string();
} else if let Some(filename) = env_log.strip_prefix("profile:") {
let filename = filename.to_string();
::std::thread::spawn(move || {
Self::profile_logger_thread(num_workers, filename, 10_000, receiver)
});
} else {
panic!("RAYON_LOG should be 'tail:<file>' or 'profile:<file>'");
}

return Logger {
Logger {
sender: Some(sender),
};
}
}

fn disabled() -> Logger {
Expand Down Expand Up @@ -219,31 +219,25 @@ impl Logger {
let mut skipped = false;

loop {
loop {
match receiver.recv_timeout(timeout) {
Ok(event) => {
if let Event::Flush = event {
// We ignore Flush events in tail mode --
// we're really just looking for
// deadlocks.
continue;
} else {
if events.len() == capacity {
let event = events.pop_front().unwrap();
state.simulate(&event);
skipped = true;
}

events.push_back(event);
}
while let Ok(event) = receiver.recv_timeout(timeout) {
if let Event::Flush = event {
// We ignore Flush events in tail mode --
// we're really just looking for
// deadlocks.
continue;
} else {
if events.len() == capacity {
let event = events.pop_front().unwrap();
state.simulate(&event);
skipped = true;
}

Err(_) => break,
events.push_back(event);
}
}

if skipped {
write!(writer, "...\n").unwrap();
writeln!(writer, "...").unwrap();
skipped = false;
}

Expand Down Expand Up @@ -417,7 +411,7 @@ impl SimulatorState {
}
}

write!(w, "\n")?;
writeln!(w)?;
Ok(())
}
}
2 changes: 1 addition & 1 deletion rayon-core/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl ThreadBuilder {

/// Gets the string that was specified by `ThreadPoolBuilder::name()`.
pub fn name(&self) -> Option<&str> {
self.name.as_ref().map(String::as_str)
self.name.as_deref()
}

/// Gets the value that was specified by `ThreadPoolBuilder::stack_size()`.
Expand Down
4 changes: 2 additions & 2 deletions rayon-core/src/scope/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn scope_divide_and_conquer() {
scope(|s| s.spawn(move |s| divide_and_conquer(s, counter_p, 1024)));

let counter_s = &AtomicUsize::new(0);
divide_and_conquer_seq(&counter_s, 1024);
divide_and_conquer_seq(counter_s, 1024);

let p = counter_p.load(Ordering::SeqCst);
let s = counter_s.load(Ordering::SeqCst);
Expand Down Expand Up @@ -75,7 +75,7 @@ struct Tree<T: Send> {
}

impl<T: Send> Tree<T> {
fn iter<'s>(&'s self) -> vec::IntoIter<&'s T> {
fn iter(&self) -> vec::IntoIter<&T> {
once(&self.value)
.chain(self.children.iter().flat_map(Tree::iter))
.collect::<Vec<_>>() // seems like it shouldn't be needed... but prevents overflow
Expand Down
2 changes: 2 additions & 0 deletions rayon-core/src/sleep/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ const THREADS_BITS: usize = 8;

/// Bits to shift to select the sleeping threads
/// (used with `select_bits`).
#[allow(clippy::erasing_op)]
const SLEEPING_SHIFT: usize = 0 * THREADS_BITS;

/// Bits to shift to select the inactive threads
/// (used with `select_bits`).
#[allow(clippy::identity_op)]
const INACTIVE_SHIFT: usize = 1 * THREADS_BITS;

/// Bits to shift to select the JEC
Expand Down
2 changes: 1 addition & 1 deletion rayon-core/tests/double_init_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::error::Error;
#[test]
fn double_init_fail() {
let result1 = ThreadPoolBuilder::new().build_global();
assert_eq!(result1.unwrap(), ());
assert!(result1.is_ok());
let err = ThreadPoolBuilder::new().build_global().unwrap_err();
assert!(err.source().is_none());
assert_eq!(
Expand Down
9 changes: 4 additions & 5 deletions rayon-demo/src/life/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::cpu_time::{self, CpuMeasure};
use rand::distributions::Standard;
use rand::{thread_rng, Rng};
use std::iter::repeat;
use std::num::Wrapping;
use std::sync::Arc;
use std::thread;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -131,14 +130,14 @@ impl Board {
}

fn living_neighbors(&self, x: usize, y: usize) -> usize {
let Wrapping(x_1) = Wrapping(x) - Wrapping(1);
let Wrapping(y_1) = Wrapping(y) - Wrapping(1);
let x_1 = x.wrapping_sub(1);
let y_1 = y.wrapping_sub(1);
let neighbors = [
self.cell_live(x_1, y_1),
self.cell_live(x, y_1),
self.cell_live(x + 1, y_1),
self.cell_live(x_1, y + 0),
self.cell_live(x + 1, y + 0),
self.cell_live(x_1, y),
self.cell_live(x + 1, y),
self.cell_live(x_1, y + 1),
self.cell_live(x, y + 1),
self.cell_live(x + 1, y + 1),
Expand Down
9 changes: 7 additions & 2 deletions rayon-demo/src/matmul/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::uninit_vec)]

const USAGE: &str = "
Usage: matmul bench [--size N]
matmul --help
Expand All @@ -16,11 +18,11 @@ pub struct Args {
flag_size: usize,
}

use std::time::Instant;

use docopt::Docopt;
use rayon::prelude::*;

use std::time::Instant;

// TODO: Investigate other cache patterns for row-major order that may be more
// parallelizable.
// https://tavianator.com/a-quick-trick-for-faster-naive-matrix-multiplication/
Expand Down Expand Up @@ -116,6 +118,7 @@ pub fn seq_matmulz(a: &[f32], b: &[f32], dest: &mut [f32]) {
}
}

#[allow(clippy::identity_op)]
const MULT_CHUNK: usize = 1 * 1024;
const LINEAR_CHUNK: usize = 64 * 1024;

Expand Down Expand Up @@ -152,6 +155,7 @@ where
(r1, r2, r3, r4)
}

#[allow(clippy::too_many_arguments)]
fn join8<F1, F2, F3, F4, F5, F6, F7, F8, R1, R2, R3, R4, R5, R6, R7, R8>(
f1: F1,
f2: F2,
Expand Down Expand Up @@ -253,6 +257,7 @@ pub fn matmul_strassen(a: &[f32], b: &[f32], dest: &mut [f32]) {

fn raw_buffer(n: usize) -> Vec<f32> {
let mut tmp = Vec::with_capacity(n);
// We always overwrite the buffer (using `rcopy`) before reading from it.
unsafe {
tmp.set_len(n);
}
Expand Down
2 changes: 2 additions & 0 deletions rayon-demo/src/mergesort/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::uninit_vec)]

use rand::distributions::Standard;
use rand::Rng;

Expand Down
1 change: 1 addition & 0 deletions rayon-demo/src/nbody/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::time::Instant;

#[cfg(test)]
mod bench;
#[allow(clippy::module_inception)]
mod nbody;
mod visualize;
use self::nbody::NBodyBenchmark;
Expand Down
2 changes: 1 addition & 1 deletion rayon-demo/src/tsp/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Graph {
}
}

pub fn edges<'a>(&'a self, source: Node) -> impl Iterator<Item = Edge> + 'a {
pub fn edges(&self, source: Node) -> impl Iterator<Item = Edge> + '_ {
self.all_nodes().filter_map(move |target| {
self.edge_weight(source, target).map(|weight| Edge {
source,
Expand Down
3 changes: 2 additions & 1 deletion rayon-demo/src/tsp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use docopt::Docopt;
use std::error::Error;
use std::fmt::Write;
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
Expand Down Expand Up @@ -93,7 +94,7 @@ fn run_solver(datafile: &Path, seq_threshold: usize, from: usize) -> Result<(),
println!("Cheapest path cost: {}", weight.to_usize());
let mut output = "Cheapest path:".to_string();
for node in path {
output.push_str(&format!(" {}", node.index()));
let _ = write!(output, " {}", node.index());
}
println!("{}", output);
} else {
Expand Down
2 changes: 2 additions & 0 deletions rayon-demo/src/tsp/parser.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::needless_lifetimes)]

use regex::Regex;
use std::collections::HashMap;
use std::str::{FromStr, Lines};
Expand Down
2 changes: 1 addition & 1 deletion rayon-demo/src/tsp/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fn complete_tour(solver: &SolverCx<'_>, path: &mut Vec<Node>, weight: Weight) {
let last = *path.last().unwrap();
if let Some(home_weight) = graph.edge_weight(last, home) {
path.push(home);
solver.add_complete_tour(&path, weight + home_weight);
solver.add_complete_tour(path, weight + home_weight);
path.pop();
}
}
4 changes: 2 additions & 2 deletions src/collections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ mod drain_guard {
pub(super) fn new(collection: &'a mut C) -> Self {
Self {
// Temporarily steal the inner `Vec` so we can drain in place.
vec: Vec::from(mem::replace(collection, C::default())),
vec: Vec::from(mem::take(collection)),
collection,
}
}
Expand All @@ -65,7 +65,7 @@ mod drain_guard {
impl<'a, T, C: From<Vec<T>>> Drop for DrainGuard<'a, T, C> {
fn drop(&mut self) {
// Restore the collection from the `Vec` with its original capacity.
*self.collection = C::from(mem::replace(&mut self.vec, Vec::new()));
*self.collection = C::from(mem::take(&mut self.vec));
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/compile_fail/cannot_collect_filtermap_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ use rayon::prelude::*;
// zip requires data of exact size, but filter yields only bounded
// size, so check that we cannot apply it.
fn main() {
let a: Vec<usize> = (0..1024).collect();
let mut v = vec![];
a.par_iter()
.filter_map(|&x| Some(x as f32))
.collect_into_vec(&mut v); //~ ERROR no method
}
let a: Vec<usize> = (0..1024).collect();
let mut v = vec![];
a.par_iter()
.filter_map(|&x| Some(x as f32))
.collect_into_vec(&mut v); //~ ERROR no method
``` */
10 changes: 4 additions & 6 deletions src/compile_fail/cannot_zip_filtered_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ use rayon::prelude::*;
// zip requires data of exact size, but filter yields only bounded
// size, so check that we cannot apply it.
fn main() {
let mut a: Vec<usize> = (0..1024).rev().collect();
let b: Vec<usize> = (0..1024).collect();
let mut a: Vec<usize> = (0..1024).rev().collect();
let b: Vec<usize> = (0..1024).collect();
a.par_iter()
.zip(b.par_iter().filter(|&&x| x > 3)); //~ ERROR
}
a.par_iter()
.zip(b.par_iter().filter(|&&x| x > 3)); //~ ERROR
``` */
10 changes: 4 additions & 6 deletions src/compile_fail/cell_par_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
use rayon::prelude::*;
use std::cell::Cell;
fn main() {
let c = Cell::new(42_i32);
(0_i32..1024).into_par_iter()
.map(|_| c.get()) //~ ERROR E0277
.min();
}
let c = Cell::new(42_i32);
(0_i32..1024).into_par_iter()
.map(|_| c.get()) //~ ERROR E0277
.min();
``` */
Loading

0 comments on commit 545feac

Please sign in to comment.