Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Apr 17, 2019
1 parent 90c2b10 commit 8477daa
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 27 deletions.
2 changes: 1 addition & 1 deletion cli/deno_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ fn fetch_remote_source_async(
filename: filename.to_string(),
media_type: map_content_type(
&p,
maybe_content_type.as_ref().map(|s| s.as_str()),
maybe_content_type.as_ref().map(String::as_str),
),
source_code: source.as_bytes().to_owned(),
maybe_output_code_filename: None,
Expand Down
6 changes: 2 additions & 4 deletions cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static ENV_VARIABLES_HELP: &str = "ENVIRONMENT VARIABLES:
NO_COLOR Set to disable color";

fn create_cli_app<'a, 'b>() -> App<'a, 'b> {
let cli_app = App::new("deno")
App::new("deno")
.bin_name("deno")
.global_settings(&[AppSettings::ColorNever])
.settings(&[
Expand Down Expand Up @@ -194,9 +194,7 @@ fn create_cli_app<'a, 'b>() -> App<'a, 'b> {
// AppSettings:AllowExternalSubcommand to treat it as an
// entry point script
SubCommand::with_name("<script>").about("Script to run"),
);

cli_app
)
}

#[cfg_attr(feature = "cargo-clippy", allow(stutter))]
Expand Down
2 changes: 1 addition & 1 deletion cli/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ fn op_start(
let mut builder = FlatBufferBuilder::new();

let state = state;
let argv = state.argv.iter().map(|s| s.as_str()).collect::<Vec<_>>();
let argv = state.argv.iter().map(String::as_str).collect::<Vec<_>>();
let argv_off = builder.create_vector_of_strings(argv.as_slice());

let cwd_path = std::env::current_dir().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion cli/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl ThreadSafeState {
argv_rest: Vec<String>,
dispatch_selector: ops::OpSelector,
) -> Self {
let custom_root = env::var("DENO_DIR").map(|s| s.into()).ok();
let custom_root = env::var("DENO_DIR").map(String::into).ok();

let (worker_in_tx, worker_in_rx) = async_mpsc::channel::<Buf>(1);
let (worker_out_tx, worker_out_rx) = async_mpsc::channel::<Buf>(1);
Expand Down
1 change: 0 additions & 1 deletion cli/tokio_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ pub fn init<F>(f: F)
where
F: FnOnce(),
{
use tokio_executor;
let rt = tokio::runtime::Runtime::new().unwrap();
let mut executor = rt.executor();
let mut enter = tokio_executor::enter().expect("Multiple executors at once");
Expand Down
5 changes: 2 additions & 3 deletions cli/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub fn resolve_module_spec(
// two-character sequence U+002E FULL STOP, U+002F SOLIDUS (./), or the
// three-character sequence U+002E FULL STOP, U+002E FULL STOP, U+002F
// SOLIDUS (../), return failure.
if !specifier.starts_with("/")
if !specifier.starts_with('/')
&& !specifier.starts_with("./")
&& !specifier.starts_with("../")
{
Expand Down Expand Up @@ -158,8 +158,7 @@ impl Loader for Worker {
type Error = DenoError;

fn resolve(specifier: &str, referrer: &str) -> Result<String, Self::Error> {
resolve_module_spec(specifier, referrer)
.map_err(|url_err| DenoError::from(url_err))
resolve_module_spec(specifier, referrer).map_err(DenoError::from)
}

/// Given an absolute url, load its source code.
Expand Down
3 changes: 2 additions & 1 deletion core/examples/http_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ impl Into<Buf> for Record {

impl From<&[u8]> for Record {
fn from(s: &[u8]) -> Record {
#[allow(clippy::cast_ptr_alignment)]
let ptr = s.as_ptr() as *const i32;
let ints = unsafe { std::slice::from_raw_parts(ptr, 4) };
Record {
Expand All @@ -75,7 +76,7 @@ impl From<&[u8]> for Record {
impl From<Buf> for Record {
fn from(buf: Buf) -> Record {
assert_eq!(buf.len(), 4 * 4);
//let byte_len = buf.len();
#[allow(clippy::cast_ptr_alignment)]
let ptr = Box::into_raw(buf) as *mut [i32; 4];
let ints: Box<[i32]> = unsafe { Box::from_raw(ptr) };
assert_eq!(ints.len(), 4);
Expand Down
13 changes: 7 additions & 6 deletions core/js_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// It would require calling into Rust from Error.prototype.prepareStackTrace.

use serde_json;
use serde_json::value::Value;
use std::fmt;
use std::str;

Expand Down Expand Up @@ -214,12 +215,12 @@ impl JSError {
let script_resource_name = obj
.get("scriptResourceName")
.and_then(|v| v.as_str().map(String::from));
let line_number = obj.get("lineNumber").and_then(|v| v.as_i64());
let start_position = obj.get("startPosition").and_then(|v| v.as_i64());
let end_position = obj.get("endPosition").and_then(|v| v.as_i64());
let error_level = obj.get("errorLevel").and_then(|v| v.as_i64());
let start_column = obj.get("startColumn").and_then(|v| v.as_i64());
let end_column = obj.get("endColumn").and_then(|v| v.as_i64());
let line_number = obj.get("lineNumber").and_then(Value::as_i64);
let start_position = obj.get("startPosition").and_then(Value::as_i64);
let end_position = obj.get("endPosition").and_then(Value::as_i64);
let error_level = obj.get("errorLevel").and_then(Value::as_i64);
let start_column = obj.get("startColumn").and_then(Value::as_i64);
let end_column = obj.get("endColumn").and_then(Value::as_i64);

let frames_v = &obj["frames"];
if !frames_v.is_array() {
Expand Down
15 changes: 6 additions & 9 deletions core/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl<L: Loader> Future for RecursiveLoad<L> {
return Ok(Async::NotReady);
}

let root_id = self.root_id.unwrap().clone();
let root_id = self.root_id.unwrap();
let mut loader = self.take_loader();
let (isolate, modules) = loader.isolate_and_modules();
let result = {
Expand Down Expand Up @@ -460,13 +460,10 @@ mod tests {

fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
self.counter += 1;
if self.url == "never_ready.js" {
// never_ready.js is never ready.
if self.url == "never_ready.js"
|| (self.url == "slow.js" && self.counter < 2)
{
return Ok(Async::NotReady);
} else if self.url == "slow.js" {
if self.counter < 2 {
return Ok(Async::NotReady);
}
}
match mock_source_code(&self.url) {
Some(src) => Ok(Async::Ready(src.to_string())),
Expand Down Expand Up @@ -560,7 +557,7 @@ mod tests {
assert_eq!(modules.get_children(c_id), Some(&vec!["d.js".to_string()]));
assert_eq!(modules.get_children(d_id), Some(&vec![]));
} else {
assert!(false);
panic!("this shouldn't happen");
}
}

Expand Down Expand Up @@ -619,7 +616,7 @@ mod tests {
])
);
} else {
assert!(false);
panic!("this shouldn't happen");
}
}

Expand Down

0 comments on commit 8477daa

Please sign in to comment.