Skip to content

Commit

Permalink
chore: Satisfy clippy by requiring Send + Sync in several places …
Browse files Browse the repository at this point in the history
…and replacing `filter_map` with `filter` and `map` in two places.
  • Loading branch information
vcfxb committed Jun 19, 2024
1 parent 4a5e6a2 commit 30922de
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion hipcheck/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<T> Context<T> for Result<T, Error> {

impl<T, E> Context<T> for Result<T, E>
where
E: StdError + 'static,
E: StdError + Send + Sync + 'static,
{
fn context<C>(self, context: C) -> Result<T, Error>
where
Expand Down
6 changes: 4 additions & 2 deletions hipcheck/src/data/query/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ fn commits_for_module(
let commits = db
.commits_for_modules()?
.iter()
.filter_map(|(m, c)| (**m == *module.as_ref()).then(|| Arc::clone(c)))
.filter(|(m, _)| **m == *module.as_ref())
.map(|(_, c)| Arc::clone(c))
.collect();

Ok(Arc::new(commits))
Expand All @@ -75,7 +76,8 @@ fn modules_for_commit(
let modules = db
.commits_for_modules()?
.iter()
.filter_map(|(m, c)| (**c == *commit.as_ref()).then(|| Arc::clone(m)))
.filter(|(_, c)| **c == *commit.as_ref())
.map(|(m, _)| Arc::clone(m))
.collect();

Ok(Arc::new(modules))
Expand Down
22 changes: 11 additions & 11 deletions hipcheck/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::error::Error as StdError;
use std::fmt;
use std::fmt::Debug;
use std::fmt::Display;
use std::rc::Rc;
use std::sync::Arc;

pub type Result<T> = std::result::Result<T, Error>;

Expand All @@ -29,7 +29,7 @@ impl<T: Into<Cow<'static, str>>> Introspect for T {}
/// An error type compatible with Salsa.
pub struct Error {
/// The start of the error linked list.
head: Rc<ErrorNode>,
head: Arc<ErrorNode>,
}

impl Error {
Expand All @@ -45,11 +45,11 @@ impl Error {
/// Create a new `Error` from a source error.
pub fn new<M>(error: M) -> Self
where
M: StdError + 'static,
M: StdError + Send + Sync + 'static,
{
Error {
head: Rc::new(ErrorNode {
current: Rc::new(error),
head: Arc::new(ErrorNode {
current: Arc::new(error),
next: None,
}),
}
Expand All @@ -69,8 +69,8 @@ impl Error {
);

Error {
head: Rc::new(ErrorNode {
current: Rc::new(Message(message)),
head: Arc::new(ErrorNode {
current: Arc::new(Message(message)),
next: Some(self.head),
}),
}
Expand All @@ -85,7 +85,7 @@ impl Error {
/// Allows use of `?` operator on query system entry.
impl<T> From<T> for Error
where
T: StdError + 'static,
T: StdError + Send + Sync + 'static,
{
fn from(std_error: T) -> Error {
Error::new(std_error)
Expand All @@ -95,7 +95,7 @@ where
impl Clone for Error {
fn clone(&self) -> Error {
Error {
head: Rc::clone(&self.head),
head: Arc::clone(&self.head),
}
}
}
Expand Down Expand Up @@ -178,10 +178,10 @@ impl StdError for ErrorNode {
}

/// A reference-counted fat pointer to a standard error type.
type ErrorObj = Rc<dyn StdError + 'static>;
type ErrorObj = Arc<dyn StdError + Send + Sync + 'static>;

/// A link in the linked list.
type ErrorLink = Rc<ErrorNode>;
type ErrorLink = Arc<ErrorNode>;

/// A string-only error message, which can either be a static string
/// slice, or an owned string.
Expand Down
2 changes: 1 addition & 1 deletion hipcheck/src/metric/typo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn typos_for_javascript(
for dependency in &dependencies.deps {
for typo in fuzzer.fuzz(dependency) {
typos.push(TypoDep {
dependency: Arc::clone(&dependency),
dependency: Arc::clone(dependency),
typo: typo.clone(),
})
}
Expand Down

0 comments on commit 30922de

Please sign in to comment.