summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
author林炳权 <695601626@qq.com>2023-10-06 02:49:09 +0800
committerGitHub <noreply@github.com>2023-10-05 14:49:09 -0400
commit7a01799f490739612be27725f1584a995f6b1491 (patch)
treef7861a6db6d055ed109281533786046ad44c4eb8 /cli
parentab3c9d41e483e5a7e6a326c66af7052a51301f91 (diff)
chore: update to Rust 1.73 (#20781)
Diffstat (limited to 'cli')
-rw-r--r--cli/errors.rs6
-rw-r--r--cli/tools/bench/mitata.rs3
-rw-r--r--cli/tools/bench/mod.rs1
-rw-r--r--cli/tools/coverage/merge.rs22
-rw-r--r--cli/tools/jupyter/server.rs4
-rw-r--r--cli/util/fs.rs8
6 files changed, 18 insertions, 26 deletions
diff --git a/cli/errors.rs b/cli/errors.rs
index 4ea0e000a..f867ebbcc 100644
--- a/cli/errors.rs
+++ b/cli/errors.rs
@@ -15,6 +15,7 @@ use deno_graph::ModuleError;
use deno_graph::ModuleGraphError;
use deno_graph::ResolutionError;
use import_map::ImportMapError;
+use std::fmt::Write;
fn get_import_map_error_class(_: &ImportMapError) -> &'static str {
"URIError"
@@ -70,7 +71,10 @@ pub fn get_error_class_name(e: &AnyError) -> &'static str {
log::warn!(
"Error '{}' contains boxed error of unknown type:{}",
e,
- e.chain().map(|e| format!("\n {e:?}")).collect::<String>()
+ e.chain().fold(String::new(), |mut output, e| {
+ let _ = write!(output, "\n {e:?}");
+ output
+ })
);
}
"Error"
diff --git a/cli/tools/bench/mitata.rs b/cli/tools/bench/mitata.rs
index 1e20e4016..7ddea6f82 100644
--- a/cli/tools/bench/mitata.rs
+++ b/cli/tools/bench/mitata.rs
@@ -149,8 +149,7 @@ pub mod cpu {
}
pub fn linux() -> String {
- let info =
- std::fs::read_to_string("/proc/cpuinfo").unwrap_or(String::new());
+ let info = std::fs::read_to_string("/proc/cpuinfo").unwrap_or_default();
for line in info.lines() {
let mut iter = line.split(':');
diff --git a/cli/tools/bench/mod.rs b/cli/tools/bench/mod.rs
index 1c44c8b3c..454a97126 100644
--- a/cli/tools/bench/mod.rs
+++ b/cli/tools/bench/mod.rs
@@ -244,7 +244,6 @@ async fn bench_specifiers(
let join_handles = specifiers.into_iter().map(move |specifier| {
let worker_factory = worker_factory.clone();
let permissions = permissions.clone();
- let specifier = specifier;
let sender = sender.clone();
let options = option_for_handles.clone();
spawn_blocking(move || {
diff --git a/cli/tools/coverage/merge.rs b/cli/tools/coverage/merge.rs
index 0a436acfb..c7f9b1524 100644
--- a/cli/tools/coverage/merge.rs
+++ b/cli/tools/coverage/merge.rs
@@ -26,7 +26,7 @@ pub fn merge_processes(
for script_cov in process_cov.result {
url_to_scripts
.entry(script_cov.url.clone())
- .or_insert_with(Vec::new)
+ .or_default()
.push(script_cov);
}
}
@@ -66,10 +66,7 @@ pub fn merge_scripts(
end: root_range_cov.end_char_offset,
}
};
- range_to_funcs
- .entry(root_range)
- .or_insert_with(Vec::new)
- .push(func_cov);
+ range_to_funcs.entry(root_range).or_default().push(func_cov);
}
}
@@ -103,11 +100,7 @@ impl Ord for CharRange {
impl PartialOrd for CharRange {
fn partial_cmp(&self, other: &Self) -> Option<::std::cmp::Ordering> {
- if self.start != other.start {
- self.start.partial_cmp(&other.start)
- } else {
- other.end.partial_cmp(&self.end)
- }
+ Some(self.cmp(other))
}
}
@@ -167,7 +160,7 @@ fn into_start_events<'a>(trees: Vec<&'a mut RangeTree<'a>>) -> Vec<StartEvent> {
for child in tree.children.drain(..) {
result
.entry(child.start)
- .or_insert_with(Vec::new)
+ .or_default()
.push((parent_index, child));
}
}
@@ -294,7 +287,7 @@ fn merge_range_tree_children<'a>(
};
parent_to_nested
.entry(parent_index)
- .or_insert_with(Vec::new)
+ .or_default()
.push(child);
}
}
@@ -312,10 +305,7 @@ fn merge_range_tree_children<'a>(
flat_children[parent_index].push(tree);
continue;
}
- parent_to_nested
- .entry(parent_index)
- .or_insert_with(Vec::new)
- .push(tree);
+ parent_to_nested.entry(parent_index).or_default().push(tree);
}
start_event_queue.set_pending_offset(open_range_end);
open_range = Some(CharRange {
diff --git a/cli/tools/jupyter/server.rs b/cli/tools/jupyter/server.rs
index 0b8d25c3e..391d202fd 100644
--- a/cli/tools/jupyter/server.rs
+++ b/cli/tools/jupyter/server.rs
@@ -416,9 +416,7 @@ impl JupyterServer {
// Otherwise, executing multiple cells one-by-one might lead to output
// from various cells be grouped together in another cell result.
tokio::time::sleep(std::time::Duration::from_millis(5)).await;
- } else {
- let exception_details = exception_details.unwrap();
-
+ } else if let Some(exception_details) = exception_details {
// Determine the exception value and name
let (name, message, stack) =
if let Some(exception) = exception_details.exception {
diff --git a/cli/util/fs.rs b/cli/util/fs.rs
index 93403659a..9aeeb62cc 100644
--- a/cli/util/fs.rs
+++ b/cli/util/fs.rs
@@ -9,6 +9,7 @@ use deno_runtime::deno_crypto::rand;
use deno_runtime::deno_node::PathClean;
use std::borrow::Cow;
use std::env::current_dir;
+use std::fmt::Write as FmtWrite;
use std::fs::OpenOptions;
use std::io::Error;
use std::io::ErrorKind;
@@ -57,9 +58,10 @@ pub fn atomic_write_file<T: AsRef<[u8]>>(
fn inner(file_path: &Path, data: &[u8], mode: u32) -> std::io::Result<()> {
let temp_file_path = {
- let rand: String = (0..4)
- .map(|_| format!("{:02x}", rand::random::<u8>()))
- .collect();
+ let rand: String = (0..4).fold(String::new(), |mut output, _| {
+ let _ = write!(output, "{:02x}", rand::random::<u8>());
+ output
+ });
let extension = format!("{rand}.tmp");
file_path.with_extension(extension)
};