fix clippy lints (#56)

This commit is contained in:
Rob Ede 2020-10-02 07:37:27 +01:00 committed by GitHub
parent 871e9acd74
commit 66fd685062
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 78 additions and 103 deletions

View file

@ -46,7 +46,7 @@ pub async fn analyze_dependencies(
let deps_iter = main_deps.chain(dev_deps).chain(build_deps); let deps_iter = main_deps.chain(dev_deps).chain(build_deps);
let mut releases = engine.fetch_releases(deps_iter); let mut releases = engine.fetch_releases(deps_iter);
for release in releases.next().await { while let Some(release) = releases.next().await {
let release = release?; let release = release?;
analyzer.process(release) analyzer.process(release)
} }

View file

@ -1,7 +1,7 @@
use std::{future::Future, mem, pin::Pin, task::Context, task::Poll}; use std::{future::Future, mem, pin::Pin, task::Context, task::Poll};
use anyhow::Error; use anyhow::Error;
use futures::{ready, Stream}; use futures::{future::BoxFuture, ready, Stream};
use futures::{stream::FuturesOrdered, FutureExt}; use futures::{stream::FuturesOrdered, FutureExt};
use relative_path::RelativePathBuf; use relative_path::RelativePathBuf;
@ -17,9 +17,7 @@ pub struct CrawlManifestFuture {
engine: Engine, engine: Engine,
crawler: ManifestCrawler, crawler: ManifestCrawler,
#[pin] #[pin]
futures: FuturesOrdered< futures: FuturesOrdered<BoxFuture<'static, Result<(RelativePathBuf, String), Error>>>,
Pin<Box<dyn Future<Output = Result<(RelativePathBuf, String), Error>> + Send>>,
>,
} }
impl CrawlManifestFuture { impl CrawlManifestFuture {
@ -63,7 +61,7 @@ impl Future for CrawlManifestFuture {
let future: Pin<Box<dyn Future<Output = _> + Send>> = Box::pin( let future: Pin<Box<dyn Future<Output = _> + Send>> = Box::pin(
self.engine self.engine
.retrieve_manifest_at_path(&self.repo_path, &path) .retrieve_manifest_at_path(&self.repo_path, &path)
.map(move |contents| contents.map(|c| ((path, c)))), .map(move |contents| contents.map(|c| (path, c))),
); );
self.futures.push(future); self.futures.push(future);
} }
@ -71,7 +69,7 @@ impl Future for CrawlManifestFuture {
self.poll(cx) self.poll(cx)
} }
Some(Err(err)) => Poll::Ready(Err(err.into())), Some(Err(err)) => Poll::Ready(Err(err)),
} }
} }
} }

View file

@ -85,7 +85,7 @@ impl ManifestCrawler {
.chain(deps.dev.iter()) .chain(deps.dev.iter())
.chain(deps.build.iter()) .chain(deps.build.iter())
{ {
if let &CrateDep::Internal(ref path) = dep { if let CrateDep::Internal(ref path) = dep {
self.register_interest(base_path, path, output); self.register_interest(base_path, path, output);
} }
} }

View file

@ -48,7 +48,7 @@ impl Service<Request<Body>> for ServiceHttpClient {
type Future = ResponseFuture; type Future = ResponseFuture;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.0.poll_ready(cx).map_err(|err| err.into()) self.0.poll_ready(cx)
} }
fn call(&mut self, req: Request<Body>) -> Self::Future { fn call(&mut self, req: Request<Body>) -> Self::Future {
@ -97,7 +97,7 @@ impl Engine {
); );
Engine { Engine {
client: client.clone(), client,
logger, logger,
metrics, metrics,
query_crate: Arc::new(Mutex::new(query_crate)), query_crate: Arc::new(Mutex::new(query_crate)),
@ -156,7 +156,7 @@ impl Engine {
pub async fn get_popular_crates(&self) -> Result<Vec<CratePath>, Error> { pub async fn get_popular_crates(&self) -> Result<Vec<CratePath>, Error> {
let crates = self.get_popular_crates.lock().unwrap().call(()); let crates = self.get_popular_crates.lock().unwrap().call(());
let crates = crates.await?; let crates = crates.await?;
Ok(crates.clone()) Ok(crates)
} }
pub async fn analyze_repo_dependencies( pub async fn analyze_repo_dependencies(
@ -264,7 +264,7 @@ impl Engine {
.lock() .lock()
.unwrap() .unwrap()
.call(name) .call(name)
.map(|resp| resp.map(|r| r.releases.clone())) .map(|resp| resp.map(|r| r.releases))
}) })
.collect::<FuturesUnordered<_>>() .collect::<FuturesUnordered<_>>()
} }

View file

@ -1,10 +1,8 @@
use std::pin::Pin; use std::{str, task::Context, task::Poll};
use std::{future::Future, task::Poll};
use std::{str, task::Context};
use anyhow::{anyhow, Error}; use anyhow::{anyhow, Error};
use futures::{ use futures::{
future::{err, ok, ready}, future::{err, ok, ready, BoxFuture},
TryFutureExt, TryFutureExt,
}; };
use hyper::{ use hyper::{
@ -44,12 +42,7 @@ fn convert_pkgs(
.map(|package| { .map(|package| {
let mut deps = CrateDeps::default(); let mut deps = CrateDeps::default();
for dep in package.deps { for dep in package.deps {
match dep match dep.kind.unwrap_or_else(|| "normal".into()).as_ref() {
.kind
.map(|k| k.clone())
.unwrap_or_else(|| "normal".into())
.as_ref()
{
"normal" => deps "normal" => deps
.main .main
.insert(dep.name.parse()?, CrateDep::External(dep.req)), .insert(dep.name.parse()?, CrateDep::External(dep.req)),
@ -62,13 +55,13 @@ fn convert_pkgs(
Ok(CrateRelease { Ok(CrateRelease {
name: name.clone(), name: name.clone(),
version: package.vers, version: package.vers,
deps: deps, deps,
yanked: package.yanked, yanked: package.yanked,
}) })
}) })
.collect::<Result<_, Error>>()?; .collect::<Result<_, Error>>()?;
Ok(QueryCrateResponse { releases: releases }) Ok(QueryCrateResponse { releases })
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -86,7 +79,7 @@ where
{ {
type Response = QueryCrateResponse; type Response = QueryCrateResponse;
type Error = Error; type Error = Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>; type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.0.poll_ready(cx).map_err(|err| err.into()) self.0.poll_ready(cx).map_err(|err| err.into())
@ -175,7 +168,7 @@ where
{ {
type Response = Vec<CratePath>; type Response = Vec<CratePath>;
type Error = Error; type Error = Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>; type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.0.poll_ready(cx).map_err(|err| err.into()) self.0.poll_ready(cx).map_err(|err| err.into())

View file

@ -1,8 +1,8 @@
use std::{future::Future, pin::Pin, task::Context, task::Poll}; use std::{task::Context, task::Poll};
use anyhow::{anyhow, Error}; use anyhow::{anyhow, Error};
use futures::{ use futures::{
future::{err, ok, ready}, future::{err, ok, ready, BoxFuture},
TryFutureExt, TryFutureExt,
}; };
use hyper::{ use hyper::{
@ -12,7 +12,7 @@ use serde::Deserialize;
use crate::models::repo::{RepoPath, Repository}; use crate::models::repo::{RepoPath, Repository};
const GITHUB_API_BASE_URI: &'static str = "https://api.github.com"; const GITHUB_API_BASE_URI: &str = "https://api.github.com";
#[derive(Deserialize)] #[derive(Deserialize)]
struct GithubSearchResponse { struct GithubSearchResponse {
@ -41,7 +41,7 @@ where
{ {
type Response = Vec<Repository>; type Response = Vec<Repository>;
type Error = Error; type Error = Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>; type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.0.poll_ready(cx).map_err(|err| err.into()) self.0.poll_ready(cx).map_err(|err| err.into())

View file

@ -1,9 +1,8 @@
use std::{future::Future, task::Poll}; use std::{task::Context, task::Poll};
use std::{pin::Pin, task::Context};
use anyhow::{anyhow, Error}; use anyhow::{anyhow, Error};
use futures::{ use futures::{
future::{err, ok, ready}, future::{err, ok, ready, BoxFuture},
TryFutureExt, TryFutureExt,
}; };
use hyper::{ use hyper::{
@ -27,7 +26,7 @@ where
{ {
type Response = String; type Response = String;
type Error = Error; type Error = Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>; type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.0.poll_ready(cx).map_err(|err| err.into()) self.0.poll_ready(cx).map_err(|err| err.into())

View file

@ -1,7 +1,7 @@
use std::{pin::Pin, sync::Arc, task::Context, task::Poll}; use std::{sync::Arc, task::Context, task::Poll};
use anyhow::Error; use anyhow::Error;
use futures::{future::ready, Future}; use futures::{future::ready, future::BoxFuture};
use hyper::{service::Service, Body, Error as HyperError, Request, Response}; use hyper::{service::Service, Body, Error as HyperError, Request, Response};
use rustsec::database::Database; use rustsec::database::Database;
@ -15,7 +15,7 @@ where
{ {
type Response = Arc<Database>; type Response = Arc<Database>;
type Error = Error; type Error = Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>; type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
// TODO: should be this when async client is used again // TODO: should be this when async client is used again
@ -28,9 +28,7 @@ where
let _service = self.0.clone(); let _service = self.0.clone();
Box::pin(ready( Box::pin(ready(
rustsec::Database::fetch() rustsec::Database::fetch().map(Arc::new).map_err(Into::into),
.map(|db| Arc::new(db))
.map_err(|err| err.into()),
)) ))
} }
} }

View file

@ -73,11 +73,7 @@ pub enum CrateDep {
impl CrateDep { impl CrateDep {
pub fn is_external(&self) -> bool { pub fn is_external(&self) -> bool {
if let &CrateDep::External(_) = self { matches!(self, CrateDep::External(_))
true
} else {
false
}
} }
} }
@ -124,7 +120,7 @@ impl AnalyzedDependencies {
.main .main
.iter() .iter()
.filter_map(|(name, dep)| { .filter_map(|(name, dep)| {
if let &CrateDep::External(ref req) = dep { if let CrateDep::External(ref req) = dep {
Some((name.clone(), AnalyzedDependency::new(req.clone()))) Some((name.clone(), AnalyzedDependency::new(req.clone())))
} else { } else {
None None
@ -135,7 +131,7 @@ impl AnalyzedDependencies {
.dev .dev
.iter() .iter()
.filter_map(|(name, dep)| { .filter_map(|(name, dep)| {
if let &CrateDep::External(ref req) = dep { if let CrateDep::External(ref req) = dep {
Some((name.clone(), AnalyzedDependency::new(req.clone()))) Some((name.clone(), AnalyzedDependency::new(req.clone())))
} else { } else {
None None
@ -146,7 +142,7 @@ impl AnalyzedDependencies {
.build .build
.iter() .iter()
.filter_map(|(name, dep)| { .filter_map(|(name, dep)| {
if let &CrateDep::External(ref req) = dep { if let CrateDep::External(ref req) = dep {
Some((name.clone(), AnalyzedDependency::new(req.clone()))) Some((name.clone(), AnalyzedDependency::new(req.clone())))
} else { } else {
None None

View file

@ -50,9 +50,9 @@ pub enum RepoSite {
impl RepoSite { impl RepoSite {
pub fn to_base_uri(&self) -> &'static str { pub fn to_base_uri(&self) -> &'static str {
match self { match self {
&RepoSite::Github => "https://github.com", RepoSite::Github => "https://github.com",
&RepoSite::Gitlab => "https://gitlab.com", RepoSite::Gitlab => "https://gitlab.com",
&RepoSite::Bitbucket => "https://bitbucket.org", RepoSite::Bitbucket => "https://bitbucket.org",
} }
} }
@ -88,9 +88,9 @@ impl FromStr for RepoSite {
impl AsRef<str> for RepoSite { impl AsRef<str> for RepoSite {
fn as_ref(&self) -> &str { fn as_ref(&self) -> &str {
match self { match self {
&RepoSite::Github => "github", RepoSite::Github => "github",
&RepoSite::Gitlab => "gitlab", RepoSite::Gitlab => "gitlab",
&RepoSite::Bitbucket => "bitbucket", RepoSite::Bitbucket => "bitbucket",
} }
} }
} }

View file

@ -51,30 +51,25 @@ fn convert_dependency(
cargo_dep: (String, CargoTomlDependency), cargo_dep: (String, CargoTomlDependency),
) -> Option<Result<(CrateName, CrateDep), Error>> { ) -> Option<Result<(CrateName, CrateDep), Error>> {
match cargo_dep { match cargo_dep {
(name, CargoTomlDependency::Simple(string)) => Some( (name, CargoTomlDependency::Simple(string)) => {
name.parse::<CrateName>() Some(name.parse::<CrateName>().and_then(|parsed_name| {
.map_err(|err| err.into())
.and_then(|parsed_name| {
string string
.parse::<VersionReq>() .parse::<VersionReq>()
.map_err(|err| err.into()) .map_err(|err| err.into())
.map(|version| (parsed_name, CrateDep::External(version))) .map(|version| (parsed_name, CrateDep::External(version)))
}), }))
), }
(name, CargoTomlDependency::Complex(cplx)) => { (name, CargoTomlDependency::Complex(cplx)) => {
if cplx.git.is_some() { if cplx.git.is_some() {
None None
} else if cplx.path.is_some() { } else if cplx.path.is_some() {
cplx.path.map(|path| { cplx.path.map(|path| {
name.parse::<CrateName>() name.parse::<CrateName>()
.map_err(|err| err.into())
.map(|parsed_name| (parsed_name, CrateDep::Internal(path))) .map(|parsed_name| (parsed_name, CrateDep::Internal(path)))
}) })
} else { } else {
cplx.version.map(|string| { cplx.version.map(|string| {
name.parse::<CrateName>() name.parse::<CrateName>().and_then(|parsed_name| {
.map_err(|err| err.into())
.and_then(|parsed_name| {
string string
.parse::<VersionReq>() .parse::<VersionReq>()
.map_err(|err| err.into()) .map_err(|err| err.into())

View file

@ -86,36 +86,33 @@ impl App {
.new(o!("http_path" => req.uri().path().to_owned())); .new(o!("http_path" => req.uri().path().to_owned()));
if let Ok(route_match) = self.router.recognize(req.uri().path()) { if let Ok(route_match) = self.router.recognize(req.uri().path()) {
match route_match.handler { match (req.method(), route_match.handler) {
&Route::Index => { (&Method::GET, Route::Index) => {
if *req.method() == Method::GET {
return self.index(req, route_match.params, logger).await; return self.index(req, route_match.params, logger).await;
} }
}
&Route::RepoStatus(format) => { (&Method::GET, Route::RepoStatus(format)) => {
if *req.method() == Method::GET {
return self return self
.repo_status(req, route_match.params, logger, format) .repo_status(req, route_match.params, logger, *format)
.await; .await;
} }
}
&Route::CrateStatus(format) => { (&Method::GET, Route::CrateStatus(format)) => {
if *req.method() == Method::GET {
return self return self
.crate_status(req, route_match.params, logger, format) .crate_status(req, route_match.params, logger, *format)
.await; .await;
} }
}
&Route::CrateRedirect => { (&Method::GET, Route::CrateRedirect) => {
if *req.method() == Method::GET {
return self.crate_redirect(req, route_match.params, logger).await; return self.crate_redirect(req, route_match.params, logger).await;
} }
(&Method::GET, Route::Static(file)) => {
return Ok(App::static_file(*file));
} }
&Route::Static(file) => {
if *req.method() == Method::GET { // fall through to 404
return Ok(App::static_file(file)); _ => {}
}
}
} }
} }

View file

@ -48,7 +48,7 @@ fn popular_table(popular_repos: Vec<Repository>, popular_crates: Vec<CratePath>)
tr { tr {
td { td {
a href=(format!("{}/crate/{}/{}", &super::SELF_BASE_URL as &str, crate_path.name.as_ref(), crate_path.version)) { a href=(format!("{}/crate/{}/{}", &super::SELF_BASE_URL as &str, crate_path.name.as_ref(), crate_path.version)) {
(format!("{}", crate_path.name.as_ref())) (crate_path.name.as_ref().to_string())
} }
} }
td class="has-text-right" { td class="has-text-right" {

View file

@ -48,8 +48,7 @@ fn render_navbar() -> Markup {
} }
fn render_footer(duration: Option<Duration>) -> Markup { fn render_footer(duration: Option<Duration>) -> Markup {
let duration_millis = let duration_millis = duration.map(|d| d.as_secs() * 1000 + (d.subsec_millis()) as u64);
duration.map(|d| d.as_secs() * 1000 + (d.subsec_nanos() / 1000 / 1000) as u64);
html! { html! {
footer class="footer" { footer class="footer" {

View file

@ -43,7 +43,7 @@ where
pub fn new(service: S, duration: Duration, capacity: usize) -> Cache<S, Req> { pub fn new(service: S, duration: Duration, capacity: usize) -> Cache<S, Req> {
Cache { Cache {
inner: service, inner: service,
duration: duration, duration,
cache: Mutex::new(LruCache::new(capacity)), cache: Mutex::new(LruCache::new(capacity)),
} }
} }
@ -77,7 +77,7 @@ where
// } // }
// } // }
self.inner.call(req.clone()) self.inner.call(req)
// .and_then(|response| { // .and_then(|response| {
// // cache.insert(req, (now + self.duration, response.clone())); // // cache.insert(req, (now + self.duration, response.clone()));
// ok(response) // ok(response)