Skip to content

Commit

Permalink
Clippy fixes (also fixes build with nightly) (denoland#1527)
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus authored and ry committed Jan 15, 2019
1 parent 48ca06e commit d8adeb4
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 76 deletions.
4 changes: 2 additions & 2 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
30 changes: 9 additions & 21 deletions src/deno_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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() + "/";
Expand Down Expand Up @@ -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),
},
}
}
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 0 additions & 5 deletions src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/isolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -212,15 +212,15 @@ 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) };
let v8_exception = cstr.to_str().unwrap();
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)
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/js_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -248,12 +248,12 @@ impl SourceMap {
}
}

return Some(SourceMap { sources, mappings });
Some(SourceMap { sources, mappings })
}
}
}
},
_ => return None,
_ => None,
}
}
}
Expand Down
21 changes: 0 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
5 changes: 4 additions & 1 deletion src/msg.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
7 changes: 0 additions & 7 deletions src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)?;

Expand Down Expand Up @@ -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()?;

Expand Down
2 changes: 1 addition & 1 deletion src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/resolve_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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(']') {
Expand Down
6 changes: 3 additions & 3 deletions src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,20 +452,20 @@ 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))]
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.
Expand Down
4 changes: 1 addition & 3 deletions src/workers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ pub fn spawn(
resource.close();
}).unwrap();

let resource = c.wait().unwrap();

resource
c.wait().unwrap()
}

#[cfg(test)]
Expand Down

0 comments on commit d8adeb4

Please sign in to comment.