1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

chore: clippy future cleanups (#8514)

This commit is contained in:
Kitson Kelly 2020-11-28 06:47:35 +11:00 committed by GitHub
parent 40bf26b37d
commit e2858d0bbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 51 additions and 67 deletions

View file

@ -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);

View file

@ -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)
}

View file

@ -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()
}
@ -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()
}

View file

@ -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)
}

View file

@ -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(
@ -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)]
@ -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) => {{
@ -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)]
@ -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(
@ -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()

View file

@ -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)?;

View file

@ -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);
@ -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);

View file

@ -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()

View file

@ -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>;

View file

@ -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();
@ -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(())
@ -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());
@ -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) {
@ -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();
@ -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();
@ -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(
@ -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);
}
}
}
@ -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 {
@ -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();
@ -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 {
@ -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(
@ -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);
}

View file

@ -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());
@ -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;
}
@ -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 {