mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
chore: use Rust 1.62.0 (#15028)
This commit is contained in:
parent
77c25beaa5
commit
b8b82c3ea4
20 changed files with 105 additions and 76 deletions
13
cli/diff.rs
13
cli/diff.rs
|
@ -2,6 +2,7 @@
|
|||
|
||||
use crate::colors;
|
||||
use dissimilar::{diff as difference, Chunk};
|
||||
use std::fmt::Write as _;
|
||||
|
||||
/// Print diff of the same file_path, before and after formatting.
|
||||
///
|
||||
|
@ -113,12 +114,14 @@ impl DiffBuilder {
|
|||
fn write_line_diff(&mut self) {
|
||||
let split = self.orig.split('\n').enumerate();
|
||||
for (i, s) in split {
|
||||
self.output.push_str(&format!(
|
||||
write!(
|
||||
self.output,
|
||||
"{:width$}{} ",
|
||||
self.orig_line + i,
|
||||
colors::gray(" |"),
|
||||
width = self.line_number_width
|
||||
));
|
||||
)
|
||||
.unwrap();
|
||||
self.output.push_str(&fmt_rem());
|
||||
self.output.push_str(s);
|
||||
self.output.push('\n');
|
||||
|
@ -126,12 +129,14 @@ impl DiffBuilder {
|
|||
|
||||
let split = self.edit.split('\n').enumerate();
|
||||
for (i, s) in split {
|
||||
self.output.push_str(&format!(
|
||||
write!(
|
||||
self.output,
|
||||
"{:width$}{} ",
|
||||
self.edit_line + i,
|
||||
colors::gray(" |"),
|
||||
width = self.line_number_width
|
||||
));
|
||||
)
|
||||
.unwrap();
|
||||
self.output.push_str(&fmt_add());
|
||||
self.output.push_str(s);
|
||||
self.output.push('\n');
|
||||
|
|
|
@ -7,6 +7,7 @@ use crate::colors::yellow;
|
|||
use deno_core::error::format_file_name;
|
||||
use deno_core::error::JsError;
|
||||
use deno_core::error::JsStackFrame;
|
||||
use std::fmt::Write as _;
|
||||
|
||||
// Keep in sync with `/core/error.js`.
|
||||
pub fn format_location(frame: &JsStackFrame) -> String {
|
||||
|
@ -29,9 +30,9 @@ pub fn format_location(frame: &JsStackFrame) -> String {
|
|||
result += &cyan("<anonymous>").to_string();
|
||||
}
|
||||
if let Some(line_number) = frame.line_number {
|
||||
result += &format!("{}{}", ":", yellow(&line_number.to_string()));
|
||||
write!(result, ":{}", yellow(&line_number.to_string())).unwrap();
|
||||
if let Some(column_number) = frame.column_number {
|
||||
result += &format!("{}{}", ":", yellow(&column_number.to_string()));
|
||||
write!(result, ":{}", yellow(&column_number.to_string())).unwrap();
|
||||
}
|
||||
}
|
||||
result
|
||||
|
@ -61,18 +62,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) {
|
||||
formatted_method += &format!("{}.", type_name);
|
||||
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) {
|
||||
formatted_method += &format!(" [as {}]", method_name);
|
||||
write!(formatted_method, " [as {}]", method_name).unwrap();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if let Some(type_name) = &frame.type_name {
|
||||
formatted_method += &format!("{}.", type_name);
|
||||
write!(formatted_method, "{}.", type_name).unwrap();
|
||||
}
|
||||
if let Some(method_name) = &frame.method_name {
|
||||
formatted_method += method_name
|
||||
|
@ -84,7 +85,7 @@ fn format_frame(frame: &JsStackFrame) -> String {
|
|||
} else if frame.is_constructor {
|
||||
result += "new ";
|
||||
if let Some(function_name) = &frame.function_name {
|
||||
result += &italic_bold(&function_name).to_string();
|
||||
write!(result, "{}", italic_bold(&function_name)).unwrap();
|
||||
} else {
|
||||
result += &cyan("<anonymous>").to_string();
|
||||
}
|
||||
|
@ -94,7 +95,7 @@ fn format_frame(frame: &JsStackFrame) -> String {
|
|||
result += &format_location(frame);
|
||||
return result;
|
||||
}
|
||||
result += &format!(" ({})", format_location(frame));
|
||||
write!(result, " ({})", format_location(frame)).unwrap();
|
||||
result
|
||||
}
|
||||
|
||||
|
@ -156,7 +157,7 @@ fn format_js_error_inner(js_error: &JsError, is_child: bool) -> String {
|
|||
for aggregated_error in aggregated {
|
||||
let error_string = format_js_error_inner(aggregated_error, true);
|
||||
for line in error_string.trim_start_matches("Uncaught ").lines() {
|
||||
s.push_str(&format!("\n {}", line));
|
||||
write!(s, "\n {}", line).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -174,14 +175,16 @@ fn format_js_error_inner(js_error: &JsError, is_child: bool) -> String {
|
|||
0,
|
||||
));
|
||||
for frame in &js_error.frames {
|
||||
s.push_str(&format!("\n at {}", format_frame(frame)));
|
||||
write!(s, "\n at {}", format_frame(frame)).unwrap();
|
||||
}
|
||||
if let Some(cause) = &js_error.cause {
|
||||
let error_string = format_js_error_inner(cause, true);
|
||||
s.push_str(&format!(
|
||||
write!(
|
||||
s,
|
||||
"\nCaused by: {}",
|
||||
error_string.trim_start_matches("Uncaught ")
|
||||
));
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
s
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ use log::error;
|
|||
use log::warn;
|
||||
use serde_json::from_value;
|
||||
use std::env;
|
||||
use std::fmt::Write as _;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use tokio::fs;
|
||||
|
@ -2878,7 +2879,8 @@ impl Inner {
|
|||
let measures = self.performance.to_vec();
|
||||
let workspace_settings = self.config.get_workspace_settings();
|
||||
|
||||
contents.push_str(&format!(
|
||||
write!(
|
||||
contents,
|
||||
r#"# Deno Language Server Status
|
||||
|
||||
## Workspace Settings
|
||||
|
@ -2914,16 +2916,19 @@ impl Inner {
|
|||
.map(|m| m.to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n - ")
|
||||
));
|
||||
)
|
||||
.unwrap();
|
||||
contents
|
||||
.push_str("\n## Performance\n\n|Name|Duration|Count|\n|---|---|---|\n");
|
||||
let mut averages = self.performance.averages();
|
||||
averages.sort();
|
||||
for average in averages {
|
||||
contents.push_str(&format!(
|
||||
writeln!(
|
||||
contents,
|
||||
"|{}|{}ms|{}|\n",
|
||||
average.name, average.average_duration, average.count
|
||||
));
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
Some(contents)
|
||||
} else {
|
||||
|
|
|
@ -33,6 +33,7 @@ use once_cell::sync::Lazy;
|
|||
use regex::Regex;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::fmt::Write as _;
|
||||
use std::iter::Peekable;
|
||||
|
||||
static ESCAPE_STRING_RE: Lazy<Regex> =
|
||||
|
@ -268,9 +269,9 @@ impl StringOrVec {
|
|||
let mut s = String::new();
|
||||
for (i, segment) in v.iter().enumerate() {
|
||||
if omit_initial_prefix && i == 0 {
|
||||
s.push_str(&format!("{}{}", segment, suffix));
|
||||
write!(s, "{}{}", segment, suffix).unwrap();
|
||||
} else {
|
||||
s.push_str(&format!("{}{}{}", prefix, segment, suffix));
|
||||
write!(s, "{}{}{}", prefix, segment, suffix).unwrap();
|
||||
}
|
||||
}
|
||||
s
|
||||
|
@ -618,10 +619,10 @@ pub fn tokens_to_regex(
|
|||
|
||||
if end {
|
||||
if !strict {
|
||||
route.push_str(&format!(r"{}?", delimiter));
|
||||
write!(route, r"{}?", delimiter).unwrap();
|
||||
}
|
||||
if has_ends_with {
|
||||
route.push_str(&format!(r"(?={})", ends_with));
|
||||
write!(route, r"(?={})", ends_with).unwrap();
|
||||
} else {
|
||||
route.push('$');
|
||||
}
|
||||
|
@ -639,11 +640,11 @@ pub fn tokens_to_regex(
|
|||
};
|
||||
|
||||
if !strict {
|
||||
route.push_str(&format!(r"(?:{}(?={}))?", delimiter, ends_with));
|
||||
write!(route, r"(?:{}(?={}))?", delimiter, ends_with).unwrap();
|
||||
}
|
||||
|
||||
if !is_end_deliminated {
|
||||
route.push_str(&format!(r"(?={}|{})", delimiter, ends_with));
|
||||
write!(route, r"(?={}|{})", delimiter, ends_with).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -753,7 +754,7 @@ impl Compiler {
|
|||
}
|
||||
}
|
||||
}
|
||||
path.push_str(&format!("{}{}{}", prefix, segment, suffix));
|
||||
write!(path, "{}{}{}", prefix, segment, suffix).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -772,7 +773,7 @@ impl Compiler {
|
|||
}
|
||||
let prefix = k.prefix.clone().unwrap_or_default();
|
||||
let suffix = k.suffix.clone().unwrap_or_default();
|
||||
path.push_str(&format!("{}{}{}", prefix, s, suffix));
|
||||
write!(path, "{}{}{}", prefix, s, suffix).unwrap();
|
||||
}
|
||||
None => {
|
||||
if !optional {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::fmt::Write as _;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Stdio;
|
||||
use test_util as util;
|
||||
|
@ -530,8 +531,7 @@ fn update_existing_config_test() {
|
|||
fn success_text(module_count: &str, dir: &str, has_import_map: bool) -> String {
|
||||
let mut text = format!("Vendored {} into {} directory.", module_count, dir);
|
||||
if has_import_map {
|
||||
text.push_str(&
|
||||
format!(
|
||||
let f = format!(
|
||||
concat!(
|
||||
"\n\nTo use vendored modules, specify the `--import-map {}import_map.json` flag when ",
|
||||
r#"invoking Deno subcommands or add an `"importMap": "<path_to_vendored_import_map>"` "#,
|
||||
|
@ -542,8 +542,8 @@ fn success_text(module_count: &str, dir: &str, has_import_map: bool) -> String {
|
|||
} else {
|
||||
dir.to_string()
|
||||
}
|
||||
)
|
||||
);
|
||||
write!(text, "{}", f).unwrap();
|
||||
}
|
||||
text
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ use serde::Deserialize;
|
|||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt::Write as _;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::num::NonZeroUsize;
|
||||
|
@ -618,27 +619,33 @@ impl TestReporter for PrettyTestReporter {
|
|||
|
||||
let mut summary_result = String::new();
|
||||
|
||||
summary_result.push_str(&format!(
|
||||
write!(
|
||||
summary_result,
|
||||
"{} passed{} | {} failed{}",
|
||||
summary.passed,
|
||||
get_steps_text(summary.passed_steps),
|
||||
summary.failed,
|
||||
get_steps_text(summary.failed_steps + summary.pending_steps),
|
||||
));
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let ignored_steps = get_steps_text(summary.ignored_steps);
|
||||
if summary.ignored > 0 || !ignored_steps.is_empty() {
|
||||
summary_result
|
||||
.push_str(&format!(" | {} ignored{}", summary.ignored, ignored_steps))
|
||||
};
|
||||
write!(
|
||||
summary_result,
|
||||
" | {} ignored{}",
|
||||
summary.ignored, ignored_steps
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
if summary.measured > 0 {
|
||||
summary_result.push_str(&format!(" | {} measured", summary.measured,))
|
||||
};
|
||||
write!(summary_result, " | {} measured", summary.measured,).unwrap();
|
||||
}
|
||||
|
||||
if summary.filtered_out > 0 {
|
||||
summary_result
|
||||
.push_str(&format!(" | {} filtered out", summary.filtered_out,))
|
||||
write!(summary_result, " | {} filtered out", summary.filtered_out)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
println!(
|
||||
|
@ -891,7 +898,7 @@ fn extract_files_from_regex_blocks(
|
|||
let mut file_source = String::new();
|
||||
for line in lines_regex.captures_iter(text) {
|
||||
let text = line.get(1).unwrap();
|
||||
file_source.push_str(&format!("{}\n", text.as_str()));
|
||||
writeln!(file_source, "{}", text.as_str()).unwrap();
|
||||
}
|
||||
|
||||
let file_specifier = deno_core::resolve_url_or_path(&format!(
|
||||
|
|
2
cli/tools/vendor/analyze.rs
vendored
2
cli/tools/vendor/analyze.rs
vendored
|
@ -25,7 +25,7 @@ struct DefaultExportFinder {
|
|||
has_default_export: bool,
|
||||
}
|
||||
|
||||
impl<'a> Visit for DefaultExportFinder {
|
||||
impl Visit for DefaultExportFinder {
|
||||
noop_visit_type!();
|
||||
|
||||
fn visit_export_default_decl(&mut self, _: &ExportDefaultDecl) {
|
||||
|
|
21
cli/tools/vendor/build.rs
vendored
21
cli/tools/vendor/build.rs
vendored
|
@ -1,5 +1,6 @@
|
|||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use std::fmt::Write as _;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
@ -164,10 +165,14 @@ fn build_proxy_module_source(
|
|||
module: &Module,
|
||||
proxied_module: &ProxiedModule,
|
||||
) -> String {
|
||||
let mut text = format!(
|
||||
"// @deno-types=\"{}\"\n",
|
||||
let mut text = String::new();
|
||||
writeln!(
|
||||
text,
|
||||
"// @deno-types=\"{}\"",
|
||||
proxied_module.declaration_specifier
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let relative_specifier = format!(
|
||||
"./{}",
|
||||
proxied_module
|
||||
|
@ -179,15 +184,17 @@ fn build_proxy_module_source(
|
|||
|
||||
// for simplicity, always include the `export *` statement as it won't error
|
||||
// even when the module does not contain a named export
|
||||
text.push_str(&format!("export * from \"{}\";\n", relative_specifier));
|
||||
writeln!(text, "export * from \"{}\";", relative_specifier).unwrap();
|
||||
|
||||
// add a default export if one exists in the module
|
||||
if let Some(parsed_source) = module.maybe_parsed_source.as_ref() {
|
||||
if has_default_export(parsed_source) {
|
||||
text.push_str(&format!(
|
||||
"export {{ default }} from \"{}\";\n",
|
||||
writeln!(
|
||||
text,
|
||||
"export {{ default }} from \"{}\";",
|
||||
relative_specifier
|
||||
));
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1012,7 +1012,8 @@ Pending dynamic modules:\n".to_string();
|
|||
let module_info = module_map
|
||||
.get_info_by_id(&pending_evaluate.module_id)
|
||||
.unwrap();
|
||||
msg.push_str(&format!("- {}", module_info.name.as_str()));
|
||||
msg.push_str("- ");
|
||||
msg.push_str(module_info.name.as_str());
|
||||
}
|
||||
return Poll::Ready(Err(generic_error(msg)));
|
||||
} else {
|
||||
|
|
|
@ -573,9 +573,8 @@ where
|
|||
// By default, Err returned by this function does not tell
|
||||
// which symbol wasn't exported. So we'll modify the error
|
||||
// message to include the name of symbol.
|
||||
//
|
||||
// SAFETY: The obtained T symbol is the size of a pointer.
|
||||
let fn_ptr =
|
||||
// SAFETY: The obtained T symbol is the size of a pointer.
|
||||
match unsafe { resource.lib.symbol::<*const c_void>(symbol) } {
|
||||
Ok(value) => Ok(value),
|
||||
Err(err) => Err(generic_error(format!(
|
||||
|
|
|
@ -754,13 +754,14 @@ fn rdata_to_return_record(
|
|||
let mut s = String::new();
|
||||
|
||||
if let Some(name) = name {
|
||||
s.push_str(&format!("{}", name));
|
||||
s.push_str(&name.to_string());
|
||||
} else if name.is_none() && key_values.is_empty() {
|
||||
s.push(';');
|
||||
}
|
||||
|
||||
for key_value in key_values {
|
||||
s.push_str(&format!("; {}", key_value));
|
||||
s.push_str("; ");
|
||||
s.push_str(&key_value.to_string());
|
||||
}
|
||||
|
||||
s
|
||||
|
|
|
@ -152,9 +152,9 @@ pub fn op_webgpu_render_bundle_encoder_set_bind_group(
|
|||
|
||||
// Align the data
|
||||
assert!(args.dynamic_offsets_data.len() % std::mem::size_of::<u32>() == 0);
|
||||
let (prefix, dynamic_offsets_data, suffix) =
|
||||
// SAFETY: A u8 to u32 cast is safe because we asserted that the length is a
|
||||
// multiple of 4.
|
||||
let (prefix, dynamic_offsets_data, suffix) =
|
||||
unsafe { args.dynamic_offsets_data.align_to::<u32>() };
|
||||
assert!(prefix.is_empty());
|
||||
assert!(suffix.is_empty());
|
||||
|
|
|
@ -241,9 +241,9 @@ pub fn op_webgpu_compute_pass_set_bind_group(
|
|||
|
||||
// Align the data
|
||||
assert!(args.dynamic_offsets_data_start % std::mem::size_of::<u32>() == 0);
|
||||
let (prefix, dynamic_offsets_data, suffix) =
|
||||
// SAFETY: A u8 to u32 cast is safe because we asserted that the length is a
|
||||
// multiple of 4.
|
||||
let (prefix, dynamic_offsets_data, suffix) =
|
||||
unsafe { args.dynamic_offsets_data.align_to::<u32>() };
|
||||
assert!(prefix.is_empty());
|
||||
assert!(suffix.is_empty());
|
||||
|
|
|
@ -305,9 +305,9 @@ pub fn op_webgpu_render_pass_set_bind_group(
|
|||
|
||||
// Align the data
|
||||
assert!(args.dynamic_offsets_data_start % std::mem::size_of::<u32>() == 0);
|
||||
let (prefix, dynamic_offsets_data, suffix) =
|
||||
// SAFETY: A u8 to u32 cast is safe because we asserted that the length is a
|
||||
// multiple of 4.
|
||||
let (prefix, dynamic_offsets_data, suffix) =
|
||||
unsafe { args.dynamic_offsets_data.align_to::<u32>() };
|
||||
assert!(prefix.is_empty());
|
||||
assert!(suffix.is_empty());
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
[toolchain]
|
||||
channel = "1.61.0"
|
||||
channel = "1.62.0"
|
||||
components = ["rustfmt", "clippy"]
|
||||
|
|
|
@ -580,7 +580,7 @@ struct EnumAccess<'a, 'b, 's> {
|
|||
// p1: std::marker::PhantomData<&'x ()>,
|
||||
}
|
||||
|
||||
impl<'de, 'a, 'b, 's, 'x> de::EnumAccess<'de> for EnumAccess<'a, 'b, 's> {
|
||||
impl<'de, 'a, 'b, 's> de::EnumAccess<'de> for EnumAccess<'a, 'b, 's> {
|
||||
type Error = Error;
|
||||
type Variant = VariantDeserializer<'a, 'b, 's>;
|
||||
|
||||
|
|
|
@ -51,9 +51,9 @@ impl FromV8 for ByteString {
|
|||
}
|
||||
let len = v8str.length();
|
||||
let mut buffer = SmallVec::with_capacity(len);
|
||||
#[allow(clippy::uninit_vec)]
|
||||
// SAFETY: we set length == capacity (see previous line),
|
||||
// before immediately writing into that buffer and sanity check with an assert
|
||||
#[allow(clippy::uninit_vec)]
|
||||
unsafe {
|
||||
buffer.set_len(len);
|
||||
let written = v8str.write_one_byte(
|
||||
|
|
|
@ -87,11 +87,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn bytes_layout() {
|
||||
// SAFETY: ensuring layout is the same
|
||||
let u1: [usize; 4] =
|
||||
unsafe { mem::transmute(from_static(HELLO.as_bytes())) };
|
||||
// SAFETY: ensuring layout is the same
|
||||
unsafe { mem::transmute(from_static(HELLO.as_bytes())) };
|
||||
let u2: [usize; 4] =
|
||||
// SAFETY: ensuring layout is the same
|
||||
unsafe { mem::transmute(bytes::Bytes::from_static(HELLO.as_bytes())) };
|
||||
assert_eq!(u1[..3], u2[..3]); // Struct bytes are equal besides Vtables
|
||||
}
|
||||
|
|
|
@ -34,9 +34,9 @@ impl FromV8 for U16String {
|
|||
.map_err(|_| Error::ExpectedString)?;
|
||||
let len = v8str.length();
|
||||
let mut buffer = Vec::with_capacity(len);
|
||||
#[allow(clippy::uninit_vec)]
|
||||
// SAFETY: we set length == capacity (see previous line),
|
||||
// before immediately writing into that buffer and sanity check with an assert
|
||||
#[allow(clippy::uninit_vec)]
|
||||
unsafe {
|
||||
buffer.set_len(len);
|
||||
let written = v8str.write(
|
||||
|
|
|
@ -50,6 +50,7 @@ impl V8Slice {
|
|||
}
|
||||
|
||||
fn as_slice_mut(&mut self) -> &mut [u8] {
|
||||
#[allow(clippy::cast_ref_to_mut)]
|
||||
// SAFETY: v8::SharedRef<v8::BackingStore> is similar to Arc<[u8]>,
|
||||
// it points to a fixed continuous slice of bytes on the heap.
|
||||
// It's safe-ish to mutate concurrently because it can not be
|
||||
|
@ -59,7 +60,6 @@ impl V8Slice {
|
|||
// concurrent mutation is simply an accepted fact of life.
|
||||
// And in practice V8Slices also do not have overallping read/write phases.
|
||||
// TLDR: permissive interior mutability on slices of bytes is "fine"
|
||||
#[allow(clippy::cast_ref_to_mut)]
|
||||
unsafe {
|
||||
&mut *(&self.store[self.range.clone()] as *const _ as *mut [u8])
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue