From d8adeb41de2daab15a0d30eeead9796fa58bfbc3 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Tue, 15 Jan 2019 13:06:25 +0100 Subject: [PATCH] Clippy fixes (also fixes build with nightly) (#1527) --- src/compiler.rs | 4 ++-- src/deno_dir.rs | 30 +++++++++--------------------- src/flags.rs | 5 ----- src/isolate.rs | 6 +++--- src/js_errors.rs | 10 +++++----- src/main.rs | 21 --------------------- src/msg.rs | 5 ++++- src/ops.rs | 7 ------- src/repl.rs | 2 +- src/resolve_addr.rs | 8 ++++---- src/resources.rs | 6 +++--- src/workers.rs | 4 +--- 12 files changed, 32 insertions(+), 76 deletions(-) diff --git a/src/compiler.rs b/src/compiler.rs index ca77213c7a612..bfbcad1dbc72c 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -29,9 +29,9 @@ pub struct CodeFetchOutput { } impl CodeFetchOutput { - pub fn js_source<'a>(&'a self) -> String { + pub fn js_source(&self) -> String { if self.media_type == msg::MediaType::Json { - return String::from(format!("export default {};", self.source_code)); + return format!("export default {};", self.source_code); } match self.maybe_output_code { None => self.source_code.clone(), diff --git a/src/deno_dir.rs b/src/deno_dir.rs index 1838db771d29a..fa1bff9553d82 100644 --- a/src/deno_dir.rs +++ b/src/deno_dir.rs @@ -265,10 +265,10 @@ impl DenoDir { if let Some(output) = maybe_remote_source { return Ok(output); } - return Err(DenoError::from(std::io::Error::new( + Err(DenoError::from(std::io::Error::new( std::io::ErrorKind::NotFound, format!("cannot find remote file '{}'", filename), - ))); + ))) } pub fn code_fetch( @@ -371,7 +371,7 @@ impl DenoDir { specifier, referrer ); - if referrer.starts_with(".") { + if referrer.starts_with('.') { let cwd = std::env::current_dir().unwrap(); let referrer_path = cwd.join(referrer); referrer = referrer_path.to_str().unwrap().to_string() + "/"; @@ -423,16 +423,10 @@ impl DenoDir { impl SourceMapGetter for DenoDir { fn get_source_map(&self, script_name: &str) -> Option { match self.code_fetch(script_name, ".") { - Err(_e) => { - return None; - } + Err(_e) => None, Ok(out) => match out.maybe_source_map { - None => { - return None; - } - Some(source_map) => { - return Some(source_map); - } + None => None, + Some(source_map) => Some(source_map), }, } } @@ -941,15 +935,9 @@ mod tests { let test_cases = [ ( "./subdir/print_hello.ts", - add_root!( - "/Users/rld/go/src/github.com/denoland/deno/testdata/006_url_imports.ts" - ), - add_root!( - "/Users/rld/go/src/github.com/denoland/deno/testdata/subdir/print_hello.ts" - ), - add_root!( - "/Users/rld/go/src/github.com/denoland/deno/testdata/subdir/print_hello.ts" - ), + add_root!("/Users/rld/go/src/github.com/denoland/deno/testdata/006_url_imports.ts"), + add_root!("/Users/rld/go/src/github.com/denoland/deno/testdata/subdir/print_hello.ts"), + add_root!("/Users/rld/go/src/github.com/denoland/deno/testdata/subdir/print_hello.ts"), ), ( "testdata/001_hello.js", diff --git a/src/flags.rs b/src/flags.rs index 739b9c9e8b0f1..f2d0150b161c1 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -312,17 +312,12 @@ pub fn v8_set_flags(args: Vec) -> Vec { // Store the length of the c_argv array in a local variable. We'll pass // a pointer to this local variable to deno_set_v8_flags(), which then // updates its value. - #[cfg_attr( - feature = "cargo-clippy", - allow(cast_possible_truncation, cast_possible_wrap) - )] let mut c_argv_len = c_argv.len() as c_int; // Let v8 parse the arguments it recognizes and remove them from c_argv. unsafe { libdeno::deno_set_v8_flags(&mut c_argv_len, c_argv.as_mut_ptr()); }; // If c_argv_len was updated we have to change the length of c_argv to match. - #[cfg_attr(feature = "cargo-clippy", allow(cast_sign_loss))] c_argv.truncate(c_argv_len as usize); // Copy the modified arguments list into a proper rust vec and return it. c_argv diff --git a/src/isolate.rs b/src/isolate.rs index b0bd085de6694..9c9e7dd4fd54e 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -89,7 +89,7 @@ impl IsolateState { permissions: DenoPermissions::new(&flags), flags, metrics: Metrics::default(), - worker_channels: worker_channels.map(|wc| Mutex::new(wc)), + worker_channels: worker_channels.map(Mutex::new), } } @@ -212,7 +212,7 @@ impl Isolate { pub fn last_exception(&self) -> Option { let ptr = unsafe { libdeno::deno_last_exception(self.libdeno_isolate) }; - if ptr == std::ptr::null() { + if ptr.is_null() { None } else { let cstr = unsafe { CStr::from_ptr(ptr) }; @@ -220,7 +220,7 @@ impl Isolate { debug!("v8_exception\n{}\n", v8_exception); let js_error = JSError::from_v8_exception(v8_exception).unwrap(); let js_error_mapped = js_error.apply_source_map(&self.state.dir); - return Some(js_error_mapped); + Some(js_error_mapped) } } diff --git a/src/js_errors.rs b/src/js_errors.rs index b16a6dc354b7e..ea94f7c0a194e 100644 --- a/src/js_errors.rs +++ b/src/js_errors.rs @@ -60,7 +60,7 @@ impl ToString for StackFrame { fn to_string(&self) -> String { // Note when we print to string, we change from 0-indexed to 1-indexed. let (line, column) = (self.line + 1, self.column + 1); - if self.function_name.len() > 0 { + if !self.function_name.is_empty() { format!( " at {} ({}:{}:{})", self.function_name, self.script_name, line, column @@ -228,10 +228,10 @@ impl SourceMap { // Ugly. Maybe use serde_derive. match serde_json::from_str::(json_str) { Ok(serde_json::Value::Object(map)) => match map["mappings"].as_str() { - None => return None, + None => None, Some(mappings_str) => { match parse_mappings::<()>(mappings_str.as_bytes()) { - Err(_) => return None, + Err(_) => None, Ok(mappings) => { if !map["sources"].is_array() { return None; @@ -248,12 +248,12 @@ impl SourceMap { } } - return Some(SourceMap { sources, mappings }); + Some(SourceMap { sources, mappings }) } } } }, - _ => return None, + _ => None, } } } diff --git a/src/main.rs b/src/main.rs index f17f1691c1170..a9c3f42f0e5ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,25 +1,4 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -use dirs; -use flatbuffers; -use getopts; -use http; -use hyper; -use hyper_rustls; -use libc; -use rand; -use remove_dir_all; -use ring; -use rustyline; -use source_map_mappings; -use tempfile; -use tokio; -use tokio_executor; -use tokio_fs; -use tokio_io; -use tokio_process; -use tokio_threadpool; -use url; - #[macro_use] extern crate lazy_static; #[macro_use] diff --git a/src/msg.rs b/src/msg.rs index b47d588bd4ffa..9a146a5d392df 100644 --- a/src/msg.rs +++ b/src/msg.rs @@ -1,6 +1,9 @@ #![allow(unused_imports)] #![allow(dead_code)] -#![cfg_attr(feature = "cargo-clippy", allow(clippy, pedantic))] +#![cfg_attr( + feature = "cargo-clippy", + allow(clippy::all, clippy::pedantic) +)] use flatbuffers; use std::sync::atomic::Ordering; diff --git a/src/ops.rs b/src/ops.rs index 48d0995c720dd..abc7b8d34ecdc 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -1003,7 +1003,6 @@ fn op_read_dir( path: Some(path), mode: get_mode(&metadata.permissions()), has_mode: cfg!(target_family = "unix"), - ..Default::default() }, ) }).collect(); @@ -1172,9 +1171,6 @@ fn op_repl_readline( let prompt = inner.prompt().unwrap().to_owned(); debug!("op_repl_readline {} {}", rid, prompt); - // Ignore this clippy warning until this issue is addressed: - // https://github.com/rust-lang-nursery/rust-clippy/issues/1684 - #[cfg_attr(feature = "cargo-clippy", allow(redundant_closure_call))] blocking(base.sync(), move || -> OpResult { let line = resources::readline(rid, &prompt)?; @@ -1237,9 +1233,6 @@ fn op_listen( assert_eq!(network, "tcp"); let address = inner.address().unwrap(); - // Ignore this clippy warning until this issue is addressed: - // https://github.com/rust-lang-nursery/rust-clippy/issues/1684 - #[cfg_attr(feature = "cargo-clippy", allow(redundant_closure_call))] Box::new(futures::future::result((move || { let addr = resolve_addr(address).wait()?; diff --git a/src/repl.rs b/src/repl.rs index 83e228b514bd2..107d8a1872e9c 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -71,7 +71,7 @@ impl Repl { repl } - fn load_history(&mut self) -> () { + fn load_history(&mut self) { debug!("Loading REPL history: {:?}", self.history_file); self .editor diff --git a/src/resolve_addr.rs b/src/resolve_addr.rs index 3ef21094cc2bb..591f9727dd588 100644 --- a/src/resolve_addr.rs +++ b/src/resolve_addr.rs @@ -60,7 +60,7 @@ impl Future for ResolveAddrFuture { // I absolutely despise the .to_socket_addrs() API. let r = addr_port_pair .to_socket_addrs() - .map_err(|e| ResolveAddrError::Resolution(e)); + .map_err(ResolveAddrError::Resolution); r.and_then(|mut iter| match iter.next() { Some(a) => Ok(Async::Ready(a)), @@ -71,11 +71,11 @@ impl Future for ResolveAddrFuture { } } -fn split<'a>(address: &'a str) -> Option<(&'a str, u16)> { - address.rfind(":").and_then(|i| { +fn split(address: &str) -> Option<(&str, u16)> { + address.rfind(':').and_then(|i| { let (a, p) = address.split_at(i); // Default to localhost if given just the port. Example: ":80" - let addr = if a.len() > 0 { a } else { "0.0.0.0" }; + let addr = if !a.is_empty() { a } else { "0.0.0.0" }; // If this looks like an ipv6 IP address. Example: "[2001:db8::1]" // Then we remove the brackets. let addr = if addr.starts_with('[') && addr.ends_with(']') { diff --git a/src/resources.rs b/src/resources.rs index fd136881ddb0d..55e1a9f641bb1 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -452,7 +452,7 @@ pub fn eager_read>( resource: Resource, mut buf: T, ) -> EagerRead { - Either::A(tokio_io::io::read(resource, buf)).into() + Either::A(tokio_io::io::read(resource, buf)) } #[cfg(not(unix))] @@ -460,12 +460,12 @@ pub fn eager_write>( resource: Resource, buf: T, ) -> EagerWrite { - Either::A(tokio_write::write(resource, buf)).into() + Either::A(tokio_write::write(resource, buf)) } #[cfg(not(unix))] pub fn eager_accept(resource: Resource) -> EagerAccept { - Either::A(tokio_util::accept(resource)).into() + Either::A(tokio_util::accept(resource)) } // This is an optimization that Tokio should do. diff --git a/src/workers.rs b/src/workers.rs index d3b2ef008e5d3..0cc2225b61439 100644 --- a/src/workers.rs +++ b/src/workers.rs @@ -83,9 +83,7 @@ pub fn spawn( resource.close(); }).unwrap(); - let resource = c.wait().unwrap(); - - resource + c.wait().unwrap() } #[cfg(test)]