diff --git a/cli/args/config_file.rs b/cli/args/config_file.rs index 0a708eeeed..0c0e5d2fae 100644 --- a/cli/args/config_file.rs +++ b/cli/args/config_file.rs @@ -71,7 +71,7 @@ pub struct IgnoredCompilerOptions { impl fmt::Display for IgnoredCompilerOptions { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut codes = self.items.clone(); - codes.sort(); + codes.sort_unstable(); if let Some(specifier) = &self.maybe_specifier { write!(f, "Unsupported compiler options in \"{}\".\n The following options were ignored:\n {}", specifier, codes.join(", ")) } else { diff --git a/cli/args/lockfile.rs b/cli/args/lockfile.rs index 5f690b3a13..87f47255a3 100644 --- a/cli/args/lockfile.rs +++ b/cli/args/lockfile.rs @@ -1,4 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +use std::collections::BTreeMap; +use std::io::Write; +use std::path::PathBuf; use deno_core::anyhow::Context; use deno_core::error::AnyError; @@ -6,9 +9,6 @@ use deno_core::serde::Deserialize; use deno_core::serde::Serialize; use deno_core::serde_json; use log::debug; -use std::collections::BTreeMap; -use std::io::Write; -use std::path::PathBuf; use crate::args::config_file::LockConfig; use crate::args::ConfigFile; diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 97b70698dd..d677cf8323 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -329,11 +329,11 @@ impl CliOptions { // if a location is set, then the ascii serialization of the location is // used, unless the origin is opaque, and then no storage origin is set, as // we can't expect the origin to be reproducible - let storage_origin = location.origin().ascii_serialization(); - if storage_origin == "null" { - None + let storage_origin = location.origin(); + if storage_origin.is_tuple() { + Some(storage_origin.ascii_serialization()) } else { - Some(storage_origin) + None } } else if let Some(config_file) = &self.maybe_config_file { // otherwise we will use the path to the config file diff --git a/cli/bench/http.rs b/cli/bench/http.rs index c95ba97219..7c416f93cd 100644 --- a/cli/bench/http.rs +++ b/cli/bench/http.rs @@ -1,8 +1,10 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -use super::Result; use std::sync::atomic::{AtomicU16, Ordering}; use std::{collections::HashMap, path::Path, process::Command, time::Duration}; + +use super::Result; + pub use test_util::{parse_wrk_output, WrkOutput as HttpBenchmarkResult}; // Some of the benchmarks in this file have been renamed. In case the history // somehow gets messed up: @@ -27,7 +29,7 @@ pub fn benchmark( let mut res = HashMap::new(); let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR")); let http_dir = manifest_dir.join("bench").join("http"); - for entry in std::fs::read_dir(http_dir.clone())? { + for entry in std::fs::read_dir(&http_dir)? { let entry = entry?; let pathbuf = entry.path(); let path = pathbuf.to_str().unwrap(); diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 62db0a82cd..d815e33119 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -571,7 +571,7 @@ pub async fn create_graph_and_maybe_check( &graph.roots, Arc::new(RwLock::new(graph_data)), &cache, - ps.npm_resolver.clone(), + &ps.npm_resolver, check::CheckOptions { type_check_mode: ps.options.type_check_mode(), debug: ps.options.log_level() == Some(log::Level::Debug), diff --git a/cli/node/mod.rs b/cli/node/mod.rs index 5c083e2fdb..e6cc222555 100644 --- a/cli/node/mod.rs +++ b/cli/node/mod.rs @@ -5,8 +5,6 @@ use std::collections::VecDeque; use std::path::Path; use std::path::PathBuf; -use crate::cache::NodeAnalysisCache; -use crate::deno_std::CURRENT_STD_URL; use deno_ast::CjsAnalysis; use deno_ast::MediaType; use deno_ast::ModuleSpecifier; @@ -36,6 +34,8 @@ use deno_runtime::deno_node::NODE_GLOBAL_THIS_NAME; use once_cell::sync::Lazy; use regex::Regex; +use crate::cache::NodeAnalysisCache; +use crate::deno_std::CURRENT_STD_URL; use crate::file_fetcher::FileFetcher; use crate::npm::NpmPackageReference; use crate::npm::NpmPackageReq; diff --git a/cli/npm/resolution/mod.rs b/cli/npm/resolution/mod.rs index c6e1c5d25e..bd408e3ec1 100644 --- a/cli/npm/resolution/mod.rs +++ b/cli/npm/resolution/mod.rs @@ -210,7 +210,7 @@ impl NpmResolutionPackage { pub struct NpmResolution { api: RealNpmRegistryApi, snapshot: RwLock, - update_sempahore: tokio::sync::Semaphore, + update_semaphore: tokio::sync::Semaphore, } impl std::fmt::Debug for NpmResolution { @@ -230,7 +230,7 @@ impl NpmResolution { Self { api, snapshot: RwLock::new(initial_snapshot.unwrap_or_default()), - update_sempahore: tokio::sync::Semaphore::new(1), + update_semaphore: tokio::sync::Semaphore::new(1), } } @@ -239,7 +239,7 @@ impl NpmResolution { package_reqs: Vec, ) -> Result<(), AnyError> { // only allow one thread in here at a time - let _permit = self.update_sempahore.acquire().await.unwrap(); + let _permit = self.update_semaphore.acquire().await.unwrap(); let snapshot = self.snapshot.read().clone(); let snapshot = self @@ -255,7 +255,7 @@ impl NpmResolution { package_reqs: HashSet, ) -> Result<(), AnyError> { // only allow one thread in here at a time - let _permit = self.update_sempahore.acquire().await.unwrap(); + let _permit = self.update_semaphore.acquire().await.unwrap(); let snapshot = self.snapshot.read().clone(); let has_removed_package = !snapshot diff --git a/cli/npm/resolution/specifier.rs b/cli/npm/resolution/specifier.rs index 7ab327ba51..06efac156b 100644 --- a/cli/npm/resolution/specifier.rs +++ b/cli/npm/resolution/specifier.rs @@ -132,7 +132,7 @@ impl std::fmt::Display for NpmPackageReq { impl NpmPackageReq { pub fn from_str(text: &str) -> Result { - // probably should do something more targetted in the future + // probably should do something more targeted in the future let reference = NpmPackageReference::from_str(&format!("npm:{}", text))?; Ok(reference.req) } diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 2fe1f44f2e..eb672d8d04 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -448,7 +448,7 @@ impl ProcState { &roots, graph_data, &check_cache, - self.npm_resolver.clone(), + &self.npm_resolver, options, )?; if !check_result.diagnostics.is_empty() { diff --git a/cli/standalone.rs b/cli/standalone.rs index 006575b8d9..c93631327a 100644 --- a/cli/standalone.rs +++ b/cli/standalone.rs @@ -161,14 +161,13 @@ impl ModuleLoader for EmbeddedModuleLoader { _maybe_referrer: Option, _is_dynamic: bool, ) -> Pin> { - let module_specifier = module_specifier.clone(); - - let is_data_uri = get_source_from_data_url(&module_specifier).ok(); + let is_data_uri = get_source_from_data_url(module_specifier).ok(); let module = self .eszip .get_module(module_specifier.as_str()) .ok_or_else(|| type_error("Module not found")); + let module_specifier = module_specifier.clone(); async move { if let Some((source, _)) = is_data_uri { return Ok(deno_core::ModuleSource { diff --git a/cli/tools/check.rs b/cli/tools/check.rs index 0c57af0b0a..6e2ccd4ffe 100644 --- a/cli/tools/check.rs +++ b/cli/tools/check.rs @@ -58,7 +58,7 @@ pub fn check( roots: &[(ModuleSpecifier, ModuleKind)], graph_data: Arc>, cache: &TypeCheckCache, - npm_resolver: NpmPackageResolver, + npm_resolver: &NpmPackageResolver, options: CheckOptions, ) -> Result { let check_js = options.ts_config.get_check_js(); diff --git a/cli/tools/repl/mod.rs b/cli/tools/repl/mod.rs index 929a1b5d87..fc03dee2f5 100644 --- a/cli/tools/repl/mod.rs +++ b/cli/tools/repl/mod.rs @@ -183,5 +183,5 @@ pub async fn run(flags: Flags, repl_flags: ReplFlags) -> Result { } } - Ok(repl_session.worker.get_exit_code()) + Ok(repl_session.worker.exit_code()) } diff --git a/cli/tools/vendor/test.rs b/cli/tools/vendor/test.rs index 61c885731d..7171b84632 100644 --- a/cli/tools/vendor/test.rs +++ b/cli/tools/vendor/test.rs @@ -242,7 +242,7 @@ impl VendorTestBuilder { let import_map = files.remove(&output_dir.join("import_map.json")); let mut files = files .iter() - .map(|(path, text)| (path_to_string(path), text.clone())) + .map(|(path, text)| (path_to_string(path), text.to_string())) .collect::>(); files.sort_by(|a, b| a.0.cmp(&b.0)); @@ -293,7 +293,11 @@ fn make_path(text: &str) -> PathBuf { } } -fn path_to_string(path: &Path) -> String { +fn path_to_string

(path: P) -> String +where + P: AsRef, +{ + let path = path.as_ref(); // inverse of the function above let path = path.to_string_lossy(); if cfg!(windows) { diff --git a/cli/worker.rs b/cli/worker.rs index 0b991fdd68..ea50966f4f 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -100,7 +100,7 @@ impl CliMainWorker { .await?; } - Ok(self.worker.get_exit_code()) + Ok(self.worker.exit_code()) } pub async fn run_for_watcher(self) -> Result<(), AnyError> { diff --git a/core/async_cancel.rs b/core/async_cancel.rs index a282194f56..5573e543df 100644 --- a/core/async_cancel.rs +++ b/core/async_cancel.rs @@ -1,13 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -use crate::RcLike; -use crate::Resource; -use futures::future::FusedFuture; -use futures::future::Future; -use futures::future::TryFuture; -use futures::task::Context; -use futures::task::Poll; -use pin_project::pin_project; use std::any::type_name; use std::borrow::Cow; use std::error::Error; @@ -18,6 +10,16 @@ use std::io; use std::pin::Pin; use std::rc::Rc; +use futures::future::FusedFuture; +use futures::future::Future; +use futures::future::TryFuture; +use futures::task::Context; +use futures::task::Poll; +use pin_project::pin_project; + +use crate::RcLike; +use crate::Resource; + use self::internal as i; #[derive(Debug, Default)] diff --git a/core/bindings.rs b/core/bindings.rs index 191538bd2c..07ad136ac0 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -1,5 +1,12 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +use std::option::Option; +use std::os::raw::c_void; + +use log::debug; +use v8::fast_api::FastFunction; +use v8::MapFnTo; + use crate::error::is_instance_of_error; use crate::modules::get_asserted_module_type_from_assertions; use crate::modules::parse_import_assertions; @@ -9,11 +16,6 @@ use crate::modules::ModuleMap; use crate::ops::OpCtx; use crate::runtime::SnapshotOptions; use crate::JsRuntime; -use log::debug; -use std::option::Option; -use std::os::raw::c_void; -use v8::fast_api::FastFunction; -use v8::MapFnTo; pub fn external_references( ops: &[OpCtx], diff --git a/core/error.rs b/core/error.rs index d788e14b50..02ed95ef75 100644 --- a/core/error.rs +++ b/core/error.rs @@ -1,18 +1,20 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::collections::HashSet; +use std::fmt; +use std::fmt::Debug; +use std::fmt::Display; +use std::fmt::Formatter; + +use anyhow::Error; + use crate::runtime::GetErrorClassFn; use crate::runtime::JsRealm; use crate::runtime::JsRuntime; use crate::source_map::apply_source_map; use crate::source_map::get_source_line; use crate::url::Url; -use anyhow::Error; -use std::borrow::Cow; -use std::collections::HashSet; -use std::fmt; -use std::fmt::Debug; -use std::fmt::Display; -use std::fmt::Formatter; /// A generic wrapper that can encapsulate any concrete error type. // TODO(ry) Deprecate AnyError and encourage deno_core::anyhow::Error instead. diff --git a/core/examples/fs_module_loader.rs b/core/examples/fs_module_loader.rs index 0fe122238d..620204c601 100644 --- a/core/examples/fs_module_loader.rs +++ b/core/examples/fs_module_loader.rs @@ -12,7 +12,7 @@ fn main() -> Result<(), Error> { println!("Usage: target/examples/debug/fs_module_loader "); std::process::exit(1); } - let main_url = args[1].clone(); + let main_url = &args[1]; println!("Run {}", main_url); let mut js_runtime = JsRuntime::new(RuntimeOptions { @@ -24,7 +24,7 @@ fn main() -> Result<(), Error> { .enable_all() .build()?; - let main_module = deno_core::resolve_path(&main_url)?; + let main_module = deno_core::resolve_path(main_url)?; let future = async move { let mod_id = js_runtime.load_main_module(&main_module, None).await?; diff --git a/core/examples/ts_module_loader.rs b/core/examples/ts_module_loader.rs index 5493029a41..d9b32d5be2 100644 --- a/core/examples/ts_module_loader.rs +++ b/core/examples/ts_module_loader.rs @@ -97,7 +97,7 @@ fn main() -> Result<(), Error> { println!("Usage: target/examples/debug/ts_module_loader "); std::process::exit(1); } - let main_url = args[1].clone(); + let main_url = &args[1]; println!("Run {}", main_url); let mut js_runtime = JsRuntime::new(RuntimeOptions { @@ -105,7 +105,7 @@ fn main() -> Result<(), Error> { ..Default::default() }); - let main_module = resolve_path(&main_url)?; + let main_module = resolve_path(main_url)?; let future = async move { let mod_id = js_runtime.load_main_module(&main_module, None).await?; diff --git a/ext/napi/lib.rs b/ext/napi/lib.rs index 24d7c7c11a..b281fb9f2f 100644 --- a/ext/napi/lib.rs +++ b/ext/napi/lib.rs @@ -529,7 +529,7 @@ where let exports = v8::Object::new(scope); let mut env_shared = EnvShared::new(napi_wrap); - let cstr = CString::new(path.clone()).unwrap(); + let cstr = CString::new(&*path).unwrap(); env_shared.filename = cstr.as_ptr(); std::mem::forget(cstr); diff --git a/ext/webstorage/lib.rs b/ext/webstorage/lib.rs index 736bea4b59..5425edc04b 100644 --- a/ext/webstorage/lib.rs +++ b/ext/webstorage/lib.rs @@ -2,6 +2,9 @@ // NOTE to all: use **cached** prepared statements when interfacing with SQLite. +use std::fmt; +use std::path::PathBuf; + use deno_core::error::AnyError; use deno_core::include_js_files; use deno_core::op; @@ -10,8 +13,6 @@ use deno_core::OpState; use rusqlite::params; use rusqlite::Connection; use rusqlite::OptionalExtension; -use std::fmt; -use std::path::PathBuf; pub use rusqlite; diff --git a/runtime/inspector_server.rs b/runtime/inspector_server.rs index de49d375e2..3567b964d3 100644 --- a/runtime/inspector_server.rs +++ b/runtime/inspector_server.rs @@ -266,16 +266,16 @@ async fn server( future::ready({ match (req.method(), req.uri().path()) { (&http::Method::GET, path) if path.starts_with("/ws/") => { - handle_ws_request(req, inspector_map.clone()) + handle_ws_request(req, Rc::clone(&inspector_map)) } (&http::Method::GET, "/json/version") => { handle_json_version_request(json_version_response.clone()) } (&http::Method::GET, "/json") => { - handle_json_request(inspector_map.clone()) + handle_json_request(Rc::clone(&inspector_map)) } (&http::Method::GET, "/json/list") => { - handle_json_request(inspector_map.clone()) + handle_json_request(Rc::clone(&inspector_map)) } _ => http::Response::builder() .status(http::StatusCode::NOT_FOUND) diff --git a/runtime/ops/fs.rs b/runtime/ops/fs.rs index a3ed09371d..12665ab045 100644 --- a/runtime/ops/fs.rs +++ b/runtime/ops/fs.rs @@ -211,7 +211,7 @@ async fn op_open_async( "Deno.open()", )?; let std_file = tokio::task::spawn_blocking(move || { - open_options.open(path.clone()).map_err(|err| { + open_options.open(&path).map_err(|err| { Error::new(err.kind(), format!("{}, open '{}'", err, path.display())) }) }) diff --git a/runtime/worker.rs b/runtime/worker.rs index 360a6b3d72..ea9f4f3e7b 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -1,11 +1,13 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -use crate::inspector_server::InspectorServer; -use crate::js; -use crate::ops; -use crate::ops::io::Stdio; -use crate::permissions::Permissions; -use crate::BootstrapOptions; +use std::pin::Pin; +use std::rc::Rc; +use std::sync::atomic::AtomicI32; +use std::sync::atomic::Ordering::Relaxed; +use std::sync::Arc; +use std::task::Context; +use std::task::Poll; + use deno_broadcast_channel::InMemoryBroadcastChannel; use deno_cache::CreateCache; use deno_cache::SqliteBackedCache; @@ -31,13 +33,13 @@ use deno_node::RequireNpmResolver; use deno_tls::rustls::RootCertStore; use deno_web::BlobStore; use log::debug; -use std::pin::Pin; -use std::rc::Rc; -use std::sync::atomic::AtomicI32; -use std::sync::atomic::Ordering::Relaxed; -use std::sync::Arc; -use std::task::Context; -use std::task::Poll; + +use crate::inspector_server::InspectorServer; +use crate::js; +use crate::ops; +use crate::ops::io::Stdio; +use crate::permissions::Permissions; +use crate::BootstrapOptions; pub type FormatJsErrorFn = dyn Fn(&JsError) -> String + Sync + Send; @@ -458,7 +460,7 @@ impl MainWorker { /// Return exit code set by the executed code (either in main worker /// or one of child web workers). - pub fn get_exit_code(&self) -> i32 { + pub fn exit_code(&self) -> i32 { self.exit_code.get() }