Skip to content

Commit

Permalink
Fix clippy warnings (#1149)
Browse files Browse the repository at this point in the history
  • Loading branch information
hayd authored and ry committed Nov 4, 2018
1 parent 765f229 commit 1241b8e
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 127 deletions.
16 changes: 8 additions & 8 deletions src/deno_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 182,14 @@ impl DenoDir {
let path = Path::new(&filename);
(fs::read_to_string(path)?, map_content_type(path, None))
};
return Ok(CodeFetchOutput {
Ok(CodeFetchOutput {
module_name: module_name.to_string(),
filename: filename.to_string(),
media_type,
source_code,
maybe_output_code: None,
maybe_source_map: None,
});
})
};
let default_attempt = use_extension("");
if default_attempt.is_ok() {
Expand Down Expand Up @@ -307,7 307,7 @@ impl DenoDir {
|| Path::new(&module_specifier).is_absolute()
{
parse_local_or_remote(&module_specifier)?
} else if containing_file.ends_with("/") {
} else if containing_file.ends_with('/') {
let r = Url::from_directory_path(&containing_file);
// TODO(ry) Properly handle error.
if r.is_err() {
Expand All @@ -329,13 329,13 @@ impl DenoDir {
"https" => {
module_name = j.to_string();
filename = deno_fs::normalize_path(
get_cache_filename(self.deps_https.as_path(), j).as_ref(),
get_cache_filename(self.deps_https.as_path(), &j).as_ref(),
)
}
"http" => {
module_name = j.to_string();
filename = deno_fs::normalize_path(
get_cache_filename(self.deps_http.as_path(), j).as_ref(),
get_cache_filename(self.deps_http.as_path(), &j).as_ref(),
)
}
// TODO(kevinkassimo): change this to support other protocols than http
Expand All @@ -347,7 347,7 @@ impl DenoDir {
}
}

fn get_cache_filename(basedir: &Path, url: Url) -> PathBuf {
fn get_cache_filename(basedir: &Path, url: &Url) -> PathBuf {
let host = url.host_str().unwrap();
let host_port = match url.port() {
// Windows doesn't support ":" in filenames, so we represent port using a
Expand All @@ -368,7 368,7 @@ fn get_cache_filename(basedir: &Path, url: Url) -> PathBuf {
fn test_get_cache_filename() {
let url = Url::parse("http://example.com:1234/path/to/file.ts").unwrap();
let basedir = Path::new("/cache/dir/");
let cache_file = get_cache_filename(&basedir, url);
let cache_file = get_cache_filename(&basedir, &url);
assert_eq!(
cache_file,
Path::new("/cache/dir/example.com_PORT1234/path/to/file.ts")
Expand Down Expand Up @@ -814,7 814,7 @@ fn map_content_type(path: &Path, content_type: Option<&str>) -> msg::MediaType {
// sometimes there is additional data after the media type in
// Content-Type so we have to do a bit of manipulation so we are only
// dealing with the actual media type
let ct_vector: Vec<&str> = content_type.split(";").collect();
let ct_vector: Vec<&str> = content_type.split(';').collect();
let ct: &str = ct_vector.first().unwrap();
match ct.to_lowercase().as_ref() {
"application/typescript"
Expand Down
22 changes: 11 additions & 11 deletions src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 28,17 @@ pub struct DenoFlags {
pub types_flag: bool,
}

pub fn process(flags: &DenoFlags, usage_string: String) {
pub fn process(flags: &DenoFlags, usage_string: &str) {
if flags.help {
println!("{}", &usage_string);
exit(0);
}

let mut log_level = log::LevelFilter::Info;
if flags.log_debug {
log_level = log::LevelFilter::Debug;
}
let log_level = if flags.log_debug {
log::LevelFilter::Debug
} else {
log::LevelFilter::Info
};
log::set_max_level(log_level);
}

Expand Down Expand Up @@ -108,8 109,8 @@ pub fn set_flags(
flags.types_flag = true;
}

let rest: Vec<_> = matches.free.iter().map(|s| s.clone()).collect();
return Ok((flags, rest, get_usage(&opts)));
let rest: Vec<_> = matches.free.to_vec();
Ok((flags, rest, get_usage(&opts)))
}

#[test]
Expand Down Expand Up @@ -214,12 215,11 @@ fn v8_set_flags_preprocess(args: Vec<String>) -> (Vec<String>, Vec<String>) {
}).collect();

// Replace args being sent to V8
for idx in 0..args.len() {
if args[idx] == "--v8-options" {
mem::swap(args.get_mut(idx).unwrap(), &mut String::from("--help"));
for mut a in &mut args {
if a == "--v8-options" {
mem::swap(a, &mut String::from("--help"));
}
}

(args, rest)
}

Expand Down
4 changes: 2 additions & 2 deletions src/http_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 37,7 @@ pub fn fetch_sync_string(module_name: &str) -> DenoResult<(String, String)> {
let url = maybe_url.expect("target url should not be None");
client
.get(url)
.map_err(|err| DenoError::from(err))
.map_err(DenoError::from)
.and_then(|response| {
if response.status().is_redirection() {
let new_url_string = response
Expand Down Expand Up @@ -72,7 72,7 @@ pub fn fetch_sync_string(module_name: &str) -> DenoResult<(String, String)> {
.into_body()
.concat2()
.map(|body| String::from_utf8(body.to_vec()).unwrap())
.map_err(|err| DenoError::from(err));
.map_err(DenoError::from);
body.join(future::ok(content_type))
}).and_then(|(body_string, maybe_content_type)| {
future::ok((body_string, maybe_content_type.unwrap()))
Expand Down
10 changes: 5 additions & 5 deletions src/isolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 226,9 @@ impl Isolate {

fn timeout(&mut self) {
let dummy_buf = libdeno::deno_buf {
alloc_ptr: 0 as *mut u8,
alloc_ptr: std::ptr::null_mut(),
alloc_len: 0,
data_ptr: 0 as *mut u8,
data_ptr: std::ptr::null_mut(),
data_len: 0,
};
unsafe {
Expand Down Expand Up @@ -265,11 265,11 @@ impl Isolate {

fn ntasks_increment(&mut self) {
assert!(self.ntasks >= 0);
self.ntasks = self.ntasks 1;
self.ntasks = 1;
}

fn ntasks_decrement(&mut self) {
self.ntasks = self.ntasks - 1;
self.ntasks -= 1;
assert!(self.ntasks >= 0);
}

Expand All @@ -290,7 290,7 @@ impl From<Buf> for libdeno::deno_buf {
let len = x.len();
let ptr = Box::into_raw(x);
libdeno::deno_buf {
alloc_ptr: 0 as *mut u8,
alloc_ptr: std::ptr::null_mut(),
alloc_len: 0,
data_ptr: ptr as *mut u8,
data_len: len,
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 80,7 @@ fn main() {
std::process::exit(1)
});
let mut isolate = isolate::Isolate::new(flags, rest_argv, ops::dispatch);
flags::process(&isolate.state.flags, usage_string);
flags::process(&isolate.state.flags, &usage_string);
tokio_util::init(|| {
isolate
.execute("deno_main.js", "denoMain();")
Expand Down
1 change: 1 addition & 0 deletions src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,5 1,6 @@
#![allow(unused_imports)]
#![allow(dead_code)]
#![cfg_attr(feature = "cargo-clippy", allow(clippy))]
use flatbuffers;
// GN_OUT_DIR is set either by build.rs (for the Cargo build), or by
// build_extra/rust/run.py (for the GN Ninja build).
Expand Down
1 change: 0 additions & 1 deletion src/msg_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 15,6 @@ pub fn serialize_key_value<'bldr>(
&msg::KeyValueArgs {
key: Some(key),
value: Some(value),
..Default::default()
},
)
}
Loading

0 comments on commit 1241b8e

Please sign in to comment.