Skip to content

Commit

Permalink
chore: clippy future cleanups (denoland#8514)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk authored Nov 27, 2020
1 parent 40bf26b commit e2858d0
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 67 deletions.
2 changes: 1 addition & 1 deletion cli/deno_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mod dirs {
// The same code is used by the dirs crate
unsafe fn fallback() -> Option<std::ffi::OsString> {
let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) {
n if n < 0 => 512 as usize,
n if n < 0 => 512_usize,
n => n as usize,
};
let mut buf = Vec::with_capacity(amt);
Expand Down
8 changes: 4 additions & 4 deletions cli/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ impl Serialize for DiagnosticCategory {
S: Serializer,
{
let value = match self {
DiagnosticCategory::Warning => 0 as i32,
DiagnosticCategory::Error => 1 as i32,
DiagnosticCategory::Suggestion => 2 as i32,
DiagnosticCategory::Message => 3 as i32,
DiagnosticCategory::Warning => 0_i32,
DiagnosticCategory::Error => 1_i32,
DiagnosticCategory::Suggestion => 2_i32,
DiagnosticCategory::Message => 3_i32,
};
Serialize::serialize(&value, serializer)
}
Expand Down
4 changes: 2 additions & 2 deletions cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2574,7 +2574,7 @@ mod tests {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
seed: Some(250 as u64),
seed: Some(250_u64),
v8_flags: Some(svec!["--random-seed=250"]),
..Flags::default()
}
Expand All @@ -2597,7 +2597,7 @@ mod tests {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
seed: Some(250 as u64),
seed: Some(250_u64),
v8_flags: Some(svec!["--expose-gc", "--random-seed=250"]),
..Flags::default()
}
Expand Down
20 changes: 10 additions & 10 deletions cli/media_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ impl Serialize for MediaType {
S: Serializer,
{
let value = match self {
MediaType::JavaScript => 0 as i32,
MediaType::JSX => 1 as i32,
MediaType::TypeScript => 2 as i32,
MediaType::Dts => 3 as i32,
MediaType::TSX => 4 as i32,
MediaType::Json => 5 as i32,
MediaType::Wasm => 6 as i32,
MediaType::TsBuildInfo => 7 as i32,
MediaType::SourceMap => 8 as i32,
MediaType::Unknown => 9 as i32,
MediaType::JavaScript => 0_i32,
MediaType::JSX => 1_i32,
MediaType::TypeScript => 2_i32,
MediaType::Dts => 3_i32,
MediaType::TSX => 4_i32,
MediaType::Json => 5_i32,
MediaType::Wasm => 6_i32,
MediaType::TsBuildInfo => 7_i32,
MediaType::SourceMap => 8_i32,
MediaType::Unknown => 9_i32,
};
Serialize::serialize(&value, serializer)
}
Expand Down
12 changes: 6 additions & 6 deletions cli/ops/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ fn op_fstat_sync(
Ok(std_file) => std_file.metadata().map_err(AnyError::from),
Err(_) => Err(type_error("cannot stat this type of resource".to_string())),
})?;
Ok(get_stat_json(metadata).unwrap())
Ok(get_stat_json(metadata))
}

async fn op_fstat_async(
Expand All @@ -377,7 +377,7 @@ async fn op_fstat_async(
Err(type_error("cannot stat this type of resource".to_string()))
}
})?;
Ok(get_stat_json(metadata).unwrap())
Ok(get_stat_json(metadata))
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -818,7 +818,7 @@ fn to_msec(maybe_time: Result<SystemTime, io::Error>) -> Value {
}

#[inline(always)]
fn get_stat_json(metadata: std::fs::Metadata) -> Result<Value, AnyError> {
fn get_stat_json(metadata: std::fs::Metadata) -> Value {
// Unix stat member (number types only). 0 if not on unix.
macro_rules! usm {
($member:ident) => {{
Expand Down Expand Up @@ -857,7 +857,7 @@ fn get_stat_json(metadata: std::fs::Metadata) -> Result<Value, AnyError> {
"blksize": usm!(blksize),
"blocks": usm!(blocks),
});
Ok(json_val)
json_val
}

#[derive(Deserialize)]
Expand All @@ -882,7 +882,7 @@ fn op_stat_sync(
} else {
std::fs::metadata(&path)?
};
get_stat_json(metadata)
Ok(get_stat_json(metadata))
}

async fn op_stat_async(
Expand All @@ -906,7 +906,7 @@ async fn op_stat_async(
} else {
std::fs::metadata(&path)?
};
get_stat_json(metadata)
Ok(get_stat_json(metadata))
})
.await
.unwrap()
Expand Down
6 changes: 3 additions & 3 deletions cli/ops/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,21 @@ fn op_run(
}

// TODO: make this work with other resources, eg. sockets
if run_args.stdin != "" {
if !run_args.stdin.is_empty() {
c.stdin(subprocess_stdio_map(run_args.stdin.as_ref())?);
} else {
let file = clone_file(state, run_args.stdin_rid)?;
c.stdin(file);
}

if run_args.stdout != "" {
if !run_args.stdout.is_empty() {
c.stdout(subprocess_stdio_map(run_args.stdout.as_ref())?);
} else {
let file = clone_file(state, run_args.stdout_rid)?;
c.stdout(file);
}

if run_args.stderr != "" {
if !run_args.stderr.is_empty() {
c.stderr(subprocess_stdio_map(run_args.stderr.as_ref())?);
} else {
let file = clone_file(state, run_args.stderr_rid)?;
Expand Down
7 changes: 2 additions & 5 deletions core/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ fn print(
_rv: v8::ReturnValue,
) {
let arg_len = args.length();
assert!(arg_len >= 0 && arg_len <= 2);
assert!((0..=2).contains(&arg_len));

let obj = args.get(0);
let is_err_arg = args.get(1);
Expand Down Expand Up @@ -850,10 +850,7 @@ fn get_proxy_details(
rv.set(proxy_details.into());
}

fn throw_type_error<'s>(
scope: &mut v8::HandleScope<'s>,
message: impl AsRef<str>,
) {
fn throw_type_error(scope: &mut v8::HandleScope, message: impl AsRef<str>) {
let message = v8::String::new(scope, message.as_ref()).unwrap();
let exception = v8::Exception::type_error(scope, message);
scope.throw_exception(exception);
Expand Down
6 changes: 3 additions & 3 deletions core/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ impl JsError {
.and_then(|m| m.to_string(scope))
.map(|s| s.to_rust_string_lossy(scope))
.unwrap_or_else(|| "".to_string());
let message = if name != "" && message_prop != "" {
let message = if !name.is_empty() && !message_prop.is_empty() {
format!("Uncaught {}: {}", name, message_prop)
} else if name != "" {
} else if !name.is_empty() {
format!("Uncaught {}", name)
} else if message_prop != "" {
} else if !message_prop.is_empty() {
format!("Uncaught {}", message_prop)
} else {
"Uncaught".to_string()
Expand Down
1 change: 1 addition & 0 deletions core/resources2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl dyn Resource {
}

#[inline(always)]
#[allow(clippy::needless_lifetimes)]
fn downcast_rc<'a, T: Resource>(self: &'a Rc<Self>) -> Option<&'a Rc<T>> {
if self.is::<T>() {
let ptr = self as *const Rc<_> as *const Rc<T>;
Expand Down
46 changes: 16 additions & 30 deletions core/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,13 @@ impl JsRuntime {
let poll_imports = self.poll_dyn_imports(cx)?;
assert!(poll_imports.is_ready());

self.evaluate_dyn_imports()?;
self.evaluate_dyn_imports();

self.check_promise_exceptions()?;
}

// Top level module
self.evaluate_pending_module()?;
self.evaluate_pending_module();

let state = state_rc.borrow();
let has_pending_ops = !state.pending_ops.is_empty();
Expand Down Expand Up @@ -814,7 +814,7 @@ impl JsRuntime {
}

if status == v8::ModuleStatus::Evaluated {
self.dyn_import_done(load_id, id)?;
self.dyn_import_done(load_id, id);
}

Ok(())
Expand All @@ -828,7 +828,7 @@ impl JsRuntime {
fn mod_evaluate_inner(
&mut self,
id: ModuleId,
) -> Result<mpsc::Receiver<Result<(), AnyError>>, AnyError> {
) -> mpsc::Receiver<Result<(), AnyError>> {
self.shared_init();

let state_rc = Self::state(self.v8_isolate());
Expand Down Expand Up @@ -894,11 +894,11 @@ impl JsRuntime {
}
}

Ok(receiver)
receiver
}

pub async fn mod_evaluate(&mut self, id: ModuleId) -> Result<(), AnyError> {
let mut receiver = self.mod_evaluate_inner(id)?;
let mut receiver = self.mod_evaluate_inner(id);

poll_fn(|cx| {
if let Poll::Ready(maybe_result) = receiver.poll_next_unpin(cx) {
Expand All @@ -915,11 +915,7 @@ impl JsRuntime {
.await
}

fn dyn_import_error(
&mut self,
id: ModuleLoadId,
err: AnyError,
) -> Result<(), AnyError> {
fn dyn_import_error(&mut self, id: ModuleLoadId, err: AnyError) {
let state_rc = Self::state(self.v8_isolate());
let context = self.global_context();

Expand All @@ -943,14 +939,9 @@ impl JsRuntime {

resolver.reject(scope, exception).unwrap();
scope.perform_microtask_checkpoint();
Ok(())
}

fn dyn_import_done(
&mut self,
id: ModuleLoadId,
mod_id: ModuleId,
) -> Result<(), AnyError> {
fn dyn_import_done(&mut self, id: ModuleLoadId, mod_id: ModuleId) {
let state_rc = Self::state(self.v8_isolate());
let context = self.global_context();

Expand Down Expand Up @@ -978,7 +969,6 @@ impl JsRuntime {
let module_namespace = module.get_module_namespace();
resolver.resolve(scope, module_namespace).unwrap();
scope.perform_microtask_checkpoint();
Ok(())
}

fn prepare_dyn_imports(
Expand Down Expand Up @@ -1011,7 +1001,7 @@ impl JsRuntime {
state.pending_dyn_imports.push(load.into_future());
}
Err(err) => {
self.dyn_import_error(dyn_import_id, err)?;
self.dyn_import_error(dyn_import_id, err);
}
}
}
Expand Down Expand Up @@ -1057,14 +1047,14 @@ impl JsRuntime {
let state = state_rc.borrow_mut();
state.pending_dyn_imports.push(load.into_future());
}
Err(err) => self.dyn_import_error(dyn_import_id, err)?,
Err(err) => self.dyn_import_error(dyn_import_id, err),
}
}
Err(err) => {
// A non-javascript error occurred; this could be due to a an invalid
// module specifier, or a problem with the source map, or a failure
// to fetch the module source code.
self.dyn_import_error(dyn_import_id, err)?
self.dyn_import_error(dyn_import_id, err)
}
}
} else {
Expand Down Expand Up @@ -1092,7 +1082,7 @@ impl JsRuntime {
/// Thus during turn of event loop we need to check if V8 has
/// resolved or rejected the promise. If the promise is still pending
/// then another turn of event loop must be performed.
fn evaluate_pending_module(&mut self) -> Result<(), AnyError> {
fn evaluate_pending_module(&mut self) {
let state_rc = Self::state(self.v8_isolate());

let context = self.global_context();
Expand Down Expand Up @@ -1130,11 +1120,9 @@ impl JsRuntime {
}
}
};

Ok(())
}

fn evaluate_dyn_imports(&mut self) -> Result<(), AnyError> {
fn evaluate_dyn_imports(&mut self) {
let state_rc = Self::state(self.v8_isolate());

loop {
Expand Down Expand Up @@ -1184,18 +1172,16 @@ impl JsRuntime {
if let Some(result) = maybe_result {
match result {
Ok((dyn_import_id, module_id)) => {
self.dyn_import_done(dyn_import_id, module_id)?;
self.dyn_import_done(dyn_import_id, module_id);
}
Err((dyn_import_id, err1)) => {
self.dyn_import_error(dyn_import_id, err1)?;
self.dyn_import_error(dyn_import_id, err1);
}
}
} else {
break;
}
}

Ok(())
}

fn register_during_load(
Expand Down Expand Up @@ -2268,7 +2254,7 @@ pub mod tests {
runtime.mod_instantiate(mod_a).unwrap();
assert_eq!(dispatch_count.load(Ordering::Relaxed), 0);

runtime.mod_evaluate_inner(mod_a).unwrap();
runtime.mod_evaluate_inner(mod_a);
assert_eq!(dispatch_count.load(Ordering::Relaxed), 1);
}

Expand Down
6 changes: 3 additions & 3 deletions test_util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ pub fn pattern_match(pattern: &str, s: &str, wildcard: &str) -> bool {
// needs to be pre-pended so it can safely match anything or nothing and
// continue matching.
if pattern.lines().next() == Some(wildcard) {
s.insert_str(0, "\n");
s.insert(0, '\n');
}

let mut t = s.split_at(parts[0].len());
Expand All @@ -941,7 +941,7 @@ pub fn pattern_match(pattern: &str, s: &str, wildcard: &str) -> bool {
continue;
}
dbg!(part, i);
if i == parts.len() - 1 && (*part == "" || *part == "\n") {
if i == parts.len() - 1 && (part.is_empty() || *part == "\n") {
dbg!("exit 1 true", i);
return true;
}
Expand Down Expand Up @@ -1071,7 +1071,7 @@ pub fn parse_strace_output(output: &str) -> HashMap<String, StraceOutput> {
let len = syscall_fields.len();
let syscall_name = syscall_fields.last().unwrap();

if 5 <= len && len <= 6 {
if (5..=6).contains(&len) {
summary.insert(
syscall_name.to_string(),
StraceOutput {
Expand Down

0 comments on commit e2858d0

Please sign in to comment.