Skip to content

Commit

Permalink
chore: use Rust 1.62.0 (denoland#15028)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju committed Jul 1, 2022
1 parent 77c25be commit b8b82c3
Show file tree
Hide file tree
Showing 20 changed files with 105 additions and 76 deletions.
13 changes: 9 additions & 4 deletions cli/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -113,25 +114,29 @@ 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');
}

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');
Expand Down
25 changes: 14 additions & 11 deletions cli/fmt_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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();
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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();
}
}
}
Expand All @@ -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
}
Expand Down
13 changes: 9 additions & 4 deletions cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 9 additions & 8 deletions cli/lsp/path_to_regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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('$');
}
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -753,7 +754,7 @@ impl Compiler {
}
}
}
path.push_str(&format!("{}{}{}", prefix, segment, suffix));
write!(path, "{}{}{}", prefix, segment, suffix).unwrap();
}
}
}
Expand All @@ -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 {
Expand Down
26 changes: 13 additions & 13 deletions cli/tests/integration/vendor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -530,20 +531,19 @@ 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!(
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>"` "#,
"entry to a deno.json file.",
),
if dir != "vendor/" {
format!("{}{}", dir.trim_end_matches('/'), if cfg!(windows) { '\\' } else {'/'})
} else {
dir.to_string()
}
)
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>"` "#,
"entry to a deno.json file.",
),
if dir != "vendor/" {
format!("{}{}", dir.trim_end_matches('/'), if cfg!(windows) { '\\' } else {'/'})
} else {
dir.to_string()
}
);
write!(text, "{}", f).unwrap();
}
text
}
Expand Down
27 changes: 17 additions & 10 deletions cli/tools/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion cli/tools/vendor/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 14 additions & 7 deletions cli/tools/vendor/build.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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();
}
}

Expand Down
Loading

0 comments on commit b8b82c3

Please sign in to comment.