summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert Belder <bertbelder@gmail.com>2019-01-15 13:06:25 +0100
committerRyan Dahl <ry@tinyclouds.org>2019-01-15 07:06:25 -0500
commitd8adeb41de2daab15a0d30eeead9796fa58bfbc3 (patch)
tree030670147587a2ebc04506a3dcad7bd34bce1016
parent48ca06e420d08d15ac6653ab73c6249eb99428a7 (diff)
Clippy fixes (also fixes build with nightly) (#1527)
-rw-r--r--src/compiler.rs4
-rw-r--r--src/deno_dir.rs30
-rw-r--r--src/flags.rs5
-rw-r--r--src/isolate.rs6
-rw-r--r--src/js_errors.rs10
-rw-r--r--src/main.rs21
-rw-r--r--src/msg.rs5
-rw-r--r--src/ops.rs7
-rw-r--r--src/repl.rs2
-rw-r--r--src/resolve_addr.rs8
-rw-r--r--src/resources.rs6
-rw-r--r--src/workers.rs4
12 files changed, 32 insertions, 76 deletions
diff --git a/src/compiler.rs b/src/compiler.rs
index ca77213c7..bfbcad1db 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 1838db771..fa1bff955 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<String> {
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 739b9c9e8..f2d0150b1 100644
--- a/src/flags.rs
+++ b/src/flags.rs
@@ -312,17 +312,12 @@ pub fn v8_set_flags(args: Vec<String>) -> Vec<String> {
// 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 b0bd085de..9c9e7dd4f 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<JSError> {
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 b16a6dc35..ea94f7c0a 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::<serde_json::Value>(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 f17f1691c..a9c3f42f0 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 b47d588bd..9a146a5d3 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 48d0995c7..abc7b8d34 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 83e228b51..107d8a187 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 3ef21094c..591f9727d 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 fd136881d..55e1a9f64 100644
--- a/src/resources.rs
+++ b/src/resources.rs
@@ -452,7 +452,7 @@ pub fn eager_read<T: AsMut<[u8]>>(
resource: Resource,
mut buf: T,
) -> EagerRead<Resource, T> {
- 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<T: AsRef<[u8]>>(
resource: Resource,
buf: T,
) -> EagerWrite<Resource, T> {
- 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 d3b2ef008..0cc2225b6 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)]