diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/build.rs | 5 | ||||
-rw-r--r-- | runtime/fmt_errors.rs | 12 | ||||
-rw-r--r-- | runtime/inspector_server.rs | 6 | ||||
-rw-r--r-- | runtime/ops/fs.rs | 6 | ||||
-rw-r--r-- | runtime/ops/mod.rs | 3 | ||||
-rw-r--r-- | runtime/ops/os/mod.rs | 16 | ||||
-rw-r--r-- | runtime/ops/permissions.rs | 8 | ||||
-rw-r--r-- | runtime/ops/process.rs | 2 | ||||
-rw-r--r-- | runtime/ops/signal.rs | 7 | ||||
-rw-r--r-- | runtime/ops/utils.rs | 2 | ||||
-rw-r--r-- | runtime/ops/web_worker/sync_fetch.rs | 6 | ||||
-rw-r--r-- | runtime/ops/worker_host.rs | 3 | ||||
-rw-r--r-- | runtime/permissions/mod.rs | 47 | ||||
-rw-r--r-- | runtime/permissions/prompter.rs | 18 | ||||
-rw-r--r-- | runtime/worker_bootstrap.rs | 2 |
15 files changed, 67 insertions, 76 deletions
diff --git a/runtime/build.rs b/runtime/build.rs index 3be20ad97..10490a871 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -1,12 +1,14 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use std::env; -use std::path::Path; + use std::path::PathBuf; // This is a shim that allows to generate documentation on docs.rs #[cfg(not(feature = "docsrs"))] mod not_docs { + use std::path::Path; + use super::*; use deno_cache::SqliteBackedCache; use deno_core::snapshot_util::*; @@ -198,7 +200,6 @@ fn main() { if env::var_os("DOCS_RS").is_some() { let snapshot_slice = &[]; std::fs::write(&runtime_snapshot_path, snapshot_slice).unwrap(); - return; } #[cfg(not(feature = "docsrs"))] diff --git a/runtime/fmt_errors.rs b/runtime/fmt_errors.rs index e8c316290..62764965d 100644 --- a/runtime/fmt_errors.rs +++ b/runtime/fmt_errors.rs @@ -93,18 +93,18 @@ fn format_frame(frame: &JsStackFrame) -> String { if let Some(function_name) = &frame.function_name { if let Some(type_name) = &frame.type_name { if !function_name.starts_with(type_name) { - write!(formatted_method, "{}.", type_name).unwrap(); + write!(formatted_method, "{type_name}.").unwrap(); } } formatted_method += function_name; if let Some(method_name) = &frame.method_name { if !function_name.ends_with(method_name) { - write!(formatted_method, " [as {}]", method_name).unwrap(); + write!(formatted_method, " [as {method_name}]").unwrap(); } } } else { if let Some(type_name) = &frame.type_name { - write!(formatted_method, "{}.", type_name).unwrap(); + write!(formatted_method, "{type_name}.").unwrap(); } if let Some(method_name) = &frame.method_name { formatted_method += method_name @@ -149,7 +149,7 @@ fn format_maybe_source_line( return "".to_string(); } if source_line.contains("Couldn't format source line: ") { - return format!("\n{}", source_line); + return format!("\n{source_line}"); } let mut s = String::new(); @@ -178,7 +178,7 @@ fn format_maybe_source_line( let indent = format!("{:indent$}", "", indent = level); - format!("\n{}{}\n{}{}", indent, source_line, indent, color_underline) + format!("\n{indent}{source_line}\n{indent}{color_underline}") } fn find_recursive_cause(js_error: &JsError) -> Option<ErrorReference> { @@ -227,7 +227,7 @@ fn format_aggregated_error( ); for line in error_string.trim_start_matches("Uncaught ").lines() { - write!(s, "\n {}", line).unwrap(); + write!(s, "\n {line}").unwrap(); } } diff --git a/runtime/inspector_server.rs b/runtime/inspector_server.rs index 3567b964d..a959bb8d4 100644 --- a/runtime/inspector_server.rs +++ b/runtime/inspector_server.rs @@ -289,7 +289,7 @@ async fn server( // Create the server manually so it can use the Local Executor let server_handler = hyper::server::Builder::new( hyper::server::conn::AddrIncoming::bind(&host).unwrap_or_else(|e| { - eprintln!("Cannot start inspector server: {}.", e); + eprintln!("Cannot start inspector server: {e}."); process::exit(1); }), hyper::server::conn::Http::new().with_executor(LocalExecutor), @@ -299,7 +299,7 @@ async fn server( shutdown_server_rx.await.ok(); }) .unwrap_or_else(|err| { - eprintln!("Cannot start inspector server: {}.", err); + eprintln!("Cannot start inspector server: {err}."); process::exit(1); }) .fuse(); @@ -422,7 +422,7 @@ impl InspectorInfo { self .thread_name .as_ref() - .map(|n| format!(" - {}", n)) + .map(|n| format!(" - {n}")) .unwrap_or_default(), process::id(), ) diff --git a/runtime/ops/fs.rs b/runtime/ops/fs.rs index 342b0e35d..f6b9a58eb 100644 --- a/runtime/ops/fs.rs +++ b/runtime/ops/fs.rs @@ -337,7 +337,7 @@ fn seek_helper(args: SeekArgs) -> Result<(u32, SeekFrom), AnyError> { 1 => SeekFrom::Current(offset), 2 => SeekFrom::End(offset), _ => { - return Err(type_error(format!("Invalid seek mode: {}", whence))); + return Err(type_error(format!("Invalid seek mode: {whence}"))); } }; @@ -542,7 +542,7 @@ fn op_chdir(state: &mut OpState, directory: String) -> Result<(), AnyError> { .borrow_mut::<PermissionsContainer>() .check_read(&d, "Deno.chdir()")?; set_current_dir(&d).map_err(|err| { - Error::new(err.kind(), format!("{}, chdir '{}'", err, directory)) + Error::new(err.kind(), format!("{err}, chdir '{directory}'")) })?; Ok(()) } @@ -1747,7 +1747,7 @@ fn make_temp( let mut rng = thread_rng(); loop { let unique = rng.gen::<u32>(); - buf.set_file_name(format!("{}{:08x}{}", prefix_, unique, suffix_)); + buf.set_file_name(format!("{prefix_}{unique:08x}{suffix_}")); let r = if is_dir { #[allow(unused_mut)] let mut builder = std::fs::DirBuilder::new(); diff --git a/runtime/ops/mod.rs b/runtime/ops/mod.rs index e42f61a7b..ce7c52d64 100644 --- a/runtime/ops/mod.rs +++ b/runtime/ops/mod.rs @@ -36,8 +36,7 @@ impl UnstableChecker { pub fn check_unstable(&self, api_name: &str) { if !self.unstable { eprintln!( - "Unstable API '{}'. The --unstable flag must be provided.", - api_name + "Unstable API '{api_name}'. The --unstable flag must be provided." ); std::process::exit(70); } diff --git a/runtime/ops/os/mod.rs b/runtime/ops/os/mod.rs index c35d4fc9e..f970c318b 100644 --- a/runtime/ops/os/mod.rs +++ b/runtime/ops/os/mod.rs @@ -92,14 +92,12 @@ fn op_set_env( } if key.contains(&['=', '\0'] as &[char]) { return Err(type_error(format!( - "Key contains invalid characters: {:?}", - key + "Key contains invalid characters: {key:?}" ))); } if value.contains('\0') { return Err(type_error(format!( - "Value contains invalid characters: {:?}", - value + "Value contains invalid characters: {value:?}" ))); } env::set_var(key, value); @@ -129,8 +127,7 @@ fn op_get_env( if key.contains(&['=', '\0'] as &[char]) { return Err(type_error(format!( - "Key contains invalid characters: {:?}", - key + "Key contains invalid characters: {key:?}" ))); } @@ -215,7 +212,7 @@ impl From<netif::Interface> for NetworkInterface { }; let (address, range) = ifa.cidr(); - let cidr = format!("{:?}/{}", address, range); + let cidr = format!("{address:?}/{range}"); let name = ifa.name().to_owned(); let address = format!("{:?}", ifa.address()); @@ -223,10 +220,7 @@ impl From<netif::Interface> for NetworkInterface { let scopeid = ifa.scope_id(); let [b0, b1, b2, b3, b4, b5] = ifa.mac(); - let mac = format!( - "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", - b0, b1, b2, b3, b4, b5 - ); + let mac = format!("{b0:02x}:{b1:02x}:{b2:02x}:{b3:02x}:{b4:02x}:{b5:02x}"); Self { family, diff --git a/runtime/ops/permissions.rs b/runtime/ops/permissions.rs index 2b01da0a9..3c48c1e8d 100644 --- a/runtime/ops/permissions.rs +++ b/runtime/ops/permissions.rs @@ -59,7 +59,7 @@ pub fn op_query_permission( n => { return Err(custom_error( "ReferenceError", - format!("No such permission name: {}", n), + format!("No such permission name: {n}"), )) } }; @@ -93,7 +93,7 @@ pub fn op_revoke_permission( n => { return Err(custom_error( "ReferenceError", - format!("No such permission name: {}", n), + format!("No such permission name: {n}"), )) } }; @@ -127,7 +127,7 @@ pub fn op_request_permission( n => { return Err(custom_error( "ReferenceError", - format!("No such permission name: {}", n), + format!("No such permission name: {n}"), )) } }; @@ -135,7 +135,7 @@ pub fn op_request_permission( } fn parse_host(host_str: &str) -> Result<(String, Option<u16>), AnyError> { - let url = url::Url::parse(&format!("http://{}/", host_str)) + let url = url::Url::parse(&format!("http://{host_str}/")) .map_err(|_| uri_error("Invalid host"))?; if url.path() != "/" { return Err(uri_error("Invalid host")); diff --git a/runtime/ops/process.rs b/runtime/ops/process.rs index eebf7e7af..9c7a3243a 100644 --- a/runtime/ops/process.rs +++ b/runtime/ops/process.rs @@ -317,7 +317,7 @@ pub fn kill(pid: i32, signal: &str) -> Result<(), AnyError> { use winapi::um::winnt::PROCESS_TERMINATE; if !matches!(signal, "SIGKILL" | "SIGTERM") { - Err(type_error(format!("Invalid signal: {}", signal))) + Err(type_error(format!("Invalid signal: {signal}"))) } else if pid <= 0 { Err(type_error("Invalid pid")) } else { diff --git a/runtime/ops/signal.rs b/runtime/ops/signal.rs index ddee1fb5d..f88d87058 100644 --- a/runtime/ops/signal.rs +++ b/runtime/ops/signal.rs @@ -222,7 +222,7 @@ pub fn signal_str_to_int(s: &str) -> Result<libc::c_int, AnyError> { "SIGIO" => Ok(29), "SIGPWR" => Ok(30), "SIGSYS" => Ok(31), - _ => Err(type_error(format!("Invalid signal : {}", s))), + _ => Err(type_error(format!("Invalid signal : {s}"))), } } @@ -260,7 +260,7 @@ pub fn signal_int_to_str(s: libc::c_int) -> Result<&'static str, AnyError> { 29 => Ok("SIGIO"), 30 => Ok("SIGPWR"), 31 => Ok("SIGSYS"), - _ => Err(type_error(format!("Invalid signal : {}", s))), + _ => Err(type_error(format!("Invalid signal : {s}"))), } } @@ -468,8 +468,7 @@ fn op_signal_bind( let signo = signal_str_to_int(&sig)?; if signal_hook_registry::FORBIDDEN.contains(&signo) { return Err(type_error(format!( - "Binding to signal '{}' is not allowed", - sig + "Binding to signal '{sig}' is not allowed", ))); } let resource = SignalStreamResource { diff --git a/runtime/ops/utils.rs b/runtime/ops/utils.rs index 29cbaab91..bdbe7f6d0 100644 --- a/runtime/ops/utils.rs +++ b/runtime/ops/utils.rs @@ -13,7 +13,7 @@ use std::sync::Arc; /// A utility function to map OsStrings to Strings pub fn into_string(s: std::ffi::OsString) -> Result<String, AnyError> { s.into_string().map_err(|s| { - let message = format!("File name or path {:?} is not valid UTF-8", s); + let message = format!("File name or path {s:?} is not valid UTF-8"); custom_error("InvalidData", message) }) } diff --git a/runtime/ops/web_worker/sync_fetch.rs b/runtime/ops/web_worker/sync_fetch.rs index a9a893572..2049d5ab8 100644 --- a/runtime/ops/web_worker/sync_fetch.rs +++ b/runtime/ops/web_worker/sync_fetch.rs @@ -92,7 +92,7 @@ pub fn op_worker_sync_fetch( } "data" => { let data_url = DataUrl::process(&script) - .map_err(|e| type_error(format!("{:?}", e)))?; + .map_err(|e| type_error(format!("{e:?}")))?; let mime_type = { let mime = data_url.mime_type(); @@ -101,7 +101,7 @@ pub fn op_worker_sync_fetch( let (body, _) = data_url .decode_to_vec() - .map_err(|e| type_error(format!("{:?}", e)))?; + .map_err(|e| type_error(format!("{e:?}")))?; (Bytes::from(body), Some(mime_type), script) } @@ -132,7 +132,7 @@ pub fn op_worker_sync_fetch( Some(mime_type) => { return Err( DomExceptionNetworkError { - msg: format!("Invalid MIME type {:?}.", mime_type), + msg: format!("Invalid MIME type {mime_type:?}."), } .into(), ) diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs index 8945ff1cc..71009be8f 100644 --- a/runtime/ops/worker_host.rs +++ b/runtime/ops/worker_host.rs @@ -193,8 +193,7 @@ fn op_create_worker( >(1); // Setup new thread - let thread_builder = - std::thread::Builder::new().name(format!("{}", worker_id)); + let thread_builder = std::thread::Builder::new().name(format!("{worker_id}")); // Spawn it thread_builder.spawn(move || { diff --git a/runtime/permissions/mod.rs b/runtime/permissions/mod.rs index 494e603a3..298146312 100644 --- a/runtime/permissions/mod.rs +++ b/runtime/permissions/mod.rs @@ -67,7 +67,7 @@ impl PermissionState { format!( "{} access{}", name, - info().map_or(String::new(), |info| { format!(" to {}", info) }), + info().map_or(String::new(), |info| { format!(" to {info}") }), ) } @@ -111,7 +111,7 @@ impl PermissionState { let msg = format!( "{} access{}", name, - info().map_or(String::new(), |info| { format!(" to {}", info) }), + info().map_or(String::new(), |info| { format!(" to {info}") }), ); if PromptResponse::Allow == permission_prompt(&msg, name, api_name) { Self::log_perm_access(name, info); @@ -314,7 +314,7 @@ pub fn parse_sys_kind(kind: &str) -> Result<&str, AnyError> { match kind { "hostname" | "osRelease" | "osUptime" | "loadavg" | "networkInterfaces" | "systemMemoryInfo" | "uid" | "gid" => Ok(kind), - _ => Err(type_error(format!("unknown system info kind \"{}\"", kind))), + _ => Err(type_error(format!("unknown system info kind \"{kind}\""))), } } @@ -451,7 +451,7 @@ impl UnaryPermission<ReadDescriptor> { let (result, prompted) = self.query(Some(&resolved_path)).check( self.name, Some(api_name), - Some(&format!("<{}>", display)), + Some(&format!("<{display}>")), self.prompt, ); if prompted { @@ -687,7 +687,7 @@ impl UnaryPermission<NetDescriptor> { if state == PermissionState::Prompt { if PromptResponse::Allow == permission_prompt( - &format!("network access to \"{}\"", host), + &format!("network access to \"{host}\""), self.name, Some("Deno.permissions.query()"), ) @@ -759,7 +759,7 @@ impl UnaryPermission<NetDescriptor> { let (result, prompted) = self.query(Some(host)).check( self.name, api_name, - Some(&format!("\"{}\"", new_host)), + Some(&format!("\"{new_host}\"")), self.prompt, ); if prompted { @@ -784,13 +784,13 @@ impl UnaryPermission<NetDescriptor> { .to_string(); let display_host = match url.port() { None => hostname.clone(), - Some(port) => format!("{}:{}", hostname, port), + Some(port) => format!("{hostname}:{port}"), }; let host = &(&hostname, url.port_or_known_default()); let (result, prompted) = self.query(Some(host)).check( self.name, api_name, - Some(&format!("\"{}\"", display_host)), + Some(&format!("\"{display_host}\"")), self.prompt, ); if prompted { @@ -861,7 +861,7 @@ impl UnaryPermission<EnvDescriptor> { if state == PermissionState::Prompt { if PromptResponse::Allow == permission_prompt( - &format!("env access to \"{}\"", env), + &format!("env access to \"{env}\""), self.name, Some("Deno.permissions.query()"), ) @@ -918,7 +918,7 @@ impl UnaryPermission<EnvDescriptor> { let (result, prompted) = self.query(Some(env)).check( self.name, None, - Some(&format!("\"{}\"", env)), + Some(&format!("\"{env}\"")), self.prompt, ); if prompted { @@ -995,7 +995,7 @@ impl UnaryPermission<SysDescriptor> { let desc = SysDescriptor(kind.to_string()); if PromptResponse::Allow == permission_prompt( - &format!("sys access to \"{}\"", kind), + &format!("sys access to \"{kind}\""), self.name, Some("Deno.permissions.query()"), ) @@ -1044,7 +1044,7 @@ impl UnaryPermission<SysDescriptor> { let (result, prompted) = self.query(Some(kind)).check( self.name, api_name, - Some(&format!("\"{}\"", kind)), + Some(&format!("\"{kind}\"")), self.prompt, ); if prompted { @@ -1118,7 +1118,7 @@ impl UnaryPermission<RunDescriptor> { if state == PermissionState::Prompt { if PromptResponse::Allow == permission_prompt( - &format!("run access to \"{}\"", cmd), + &format!("run access to \"{cmd}\""), self.name, Some("Deno.permissions.query()"), ) @@ -1187,7 +1187,7 @@ impl UnaryPermission<RunDescriptor> { let (result, prompted) = self.query(Some(cmd)).check( self.name, api_name, - Some(&format!("\"{}\"", cmd)), + Some(&format!("\"{cmd}\"")), self.prompt, ); if prompted { @@ -1606,8 +1606,7 @@ impl Permissions { "file" => match specifier.to_file_path() { Ok(path) => self.read.check(&path, Some("import()")), Err(_) => Err(uri_error(format!( - "Invalid file path.\n Specifier: {}", - specifier + "Invalid file path.\n Specifier: {specifier}" ))), }, "data" => Ok(()), @@ -2121,42 +2120,42 @@ impl<'de> Deserialize<'de> for ChildPermissionsArg { if key == "env" { let arg = serde_json::from_value::<ChildUnaryPermissionArg>(value); child_permissions_arg.env = arg.map_err(|e| { - de::Error::custom(format!("(deno.permissions.env) {}", e)) + de::Error::custom(format!("(deno.permissions.env) {e}")) })?; } else if key == "hrtime" { let arg = serde_json::from_value::<ChildUnitPermissionArg>(value); child_permissions_arg.hrtime = arg.map_err(|e| { - de::Error::custom(format!("(deno.permissions.hrtime) {}", e)) + de::Error::custom(format!("(deno.permissions.hrtime) {e}")) })?; } else if key == "net" { let arg = serde_json::from_value::<ChildUnaryPermissionArg>(value); child_permissions_arg.net = arg.map_err(|e| { - de::Error::custom(format!("(deno.permissions.net) {}", e)) + de::Error::custom(format!("(deno.permissions.net) {e}")) })?; } else if key == "ffi" { let arg = serde_json::from_value::<ChildUnaryPermissionArg>(value); child_permissions_arg.ffi = arg.map_err(|e| { - de::Error::custom(format!("(deno.permissions.ffi) {}", e)) + de::Error::custom(format!("(deno.permissions.ffi) {e}")) })?; } else if key == "read" { let arg = serde_json::from_value::<ChildUnaryPermissionArg>(value); child_permissions_arg.read = arg.map_err(|e| { - de::Error::custom(format!("(deno.permissions.read) {}", e)) + de::Error::custom(format!("(deno.permissions.read) {e}")) })?; } else if key == "run" { let arg = serde_json::from_value::<ChildUnaryPermissionArg>(value); child_permissions_arg.run = arg.map_err(|e| { - de::Error::custom(format!("(deno.permissions.run) {}", e)) + de::Error::custom(format!("(deno.permissions.run) {e}")) })?; } else if key == "sys" { let arg = serde_json::from_value::<ChildUnaryPermissionArg>(value); child_permissions_arg.sys = arg.map_err(|e| { - de::Error::custom(format!("(deno.permissions.sys) {}", e)) + de::Error::custom(format!("(deno.permissions.sys) {e}")) })?; } else if key == "write" { let arg = serde_json::from_value::<ChildUnaryPermissionArg>(value); child_permissions_arg.write = arg.map_err(|e| { - de::Error::custom(format!("(deno.permissions.write) {}", e)) + de::Error::custom(format!("(deno.permissions.write) {e}")) })?; } else { return Err(de::Error::custom("unknown permission name")); diff --git a/runtime/permissions/prompter.rs b/runtime/permissions/prompter.rs index ae07e004c..e311bc978 100644 --- a/runtime/permissions/prompter.rs +++ b/runtime/permissions/prompter.rs @@ -182,13 +182,13 @@ impl PermissionPrompter for TtyPrompter { // Clear n-lines in terminal and move cursor to the beginning of the line. fn clear_n_lines(n: usize) { - eprint!("\x1B[{}A\x1B[0J", n); + eprint!("\x1B[{n}A\x1B[0J"); } // For security reasons we must consume everything in stdin so that previously // buffered data cannot effect the prompt. if let Err(err) = clear_stdin() { - eprintln!("Error clearing stdin for permission prompt. {:#}", err); + eprintln!("Error clearing stdin for permission prompt. {err:#}"); return PromptResponse::Deny; // don't grant permission if this fails } @@ -199,17 +199,17 @@ impl PermissionPrompter for TtyPrompter { // print to stderr so that if stdout is piped this is still displayed. const OPTS: &str = "[y/n] (y = yes, allow; n = no, deny)"; - eprint!("{} ┌ ", PERMISSION_EMOJI); + eprint!("{PERMISSION_EMOJI} ┌ "); eprint!("{}", colors::bold("Deno requests ")); eprint!("{}", colors::bold(message)); eprintln!("{}", colors::bold(".")); if let Some(api_name) = api_name { - eprintln!(" ├ Requested by `{}` API", api_name); + eprintln!(" ├ Requested by `{api_name}` API"); } - let msg = format!("Run again with --allow-{} to bypass this prompt.", name); + let msg = format!("Run again with --allow-{name} to bypass this prompt."); eprintln!(" ├ {}", colors::italic(&msg)); eprint!(" └ {}", colors::bold("Allow?")); - eprint!(" {} > ", OPTS); + eprint!(" {OPTS} > "); let value = loop { let mut input = String::new(); let stdin = std::io::stdin(); @@ -224,13 +224,13 @@ impl PermissionPrompter for TtyPrompter { match ch.to_ascii_lowercase() { 'y' => { clear_n_lines(if api_name.is_some() { 4 } else { 3 }); - let msg = format!("Granted {}.", message); + let msg = format!("Granted {message}."); eprintln!("✅ {}", colors::bold(&msg)); break PromptResponse::Allow; } 'n' => { clear_n_lines(if api_name.is_some() { 4 } else { 3 }); - let msg = format!("Denied {}.", message); + let msg = format!("Denied {message}."); eprintln!("❌ {}", colors::bold(&msg)); break PromptResponse::Deny; } @@ -238,7 +238,7 @@ impl PermissionPrompter for TtyPrompter { // If we don't get a recognized option try again. clear_n_lines(1); eprint!(" └ {}", colors::bold("Unrecognized option. Allow?")); - eprint!(" {} > ", OPTS); + eprint!(" {OPTS} > "); } }; }; diff --git a/runtime/worker_bootstrap.rs b/runtime/worker_bootstrap.rs index 17aa8a85b..5563b6ead 100644 --- a/runtime/worker_bootstrap.rs +++ b/runtime/worker_bootstrap.rs @@ -37,7 +37,7 @@ impl Default for BootstrapOptions { .unwrap_or(1); let runtime_version = env!("CARGO_PKG_VERSION").into(); - let user_agent = format!("Deno/{}", runtime_version); + let user_agent = format!("Deno/{runtime_version}"); Self { runtime_version, |