Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Rust to 1.51.0 #9895

Merged
merged 2 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
- name: Install rust
uses: hecrj/setup-rust-action@v1
with:
rust-version: 1.50.0
rust-version: 1.51.0

- name: Install clippy and rustfmt
if: matrix.kind == 'lint'
Expand Down
24 changes: 12 additions & 12 deletions cli/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,27 @@ pub struct Location {
pub col: usize,
}

impl Into<Location> for swc_common::Loc {
fn into(self) -> Location {
impl From<swc_common::Loc> for Location {
fn from(swc_loc: swc_common::Loc) -> Self {
use swc_common::FileName::*;

let filename = match &self.file.name {
let filename = match &swc_loc.file.name {
Real(path_buf) => path_buf.to_string_lossy().to_string(),
Custom(str_) => str_.to_string(),
_ => panic!("invalid filename"),
};

Location {
filename,
line: self.line,
col: self.col_display,
line: swc_loc.line,
col: swc_loc.col_display,
}
}
}

impl Into<ModuleSpecifier> for Location {
fn into(self) -> ModuleSpecifier {
resolve_url_or_path(&self.filename).unwrap()
impl From<Location> for ModuleSpecifier {
fn from(loc: Location) -> Self {
resolve_url_or_path(&loc.filename).unwrap()
}
}

Expand Down Expand Up @@ -174,10 +174,10 @@ fn get_ts_config(tsx: bool, dts: bool) -> TsConfig {
pub fn get_syntax(media_type: &MediaType) -> Syntax {
match media_type {
MediaType::JavaScript => Syntax::Es(get_es_config(false)),
MediaType::JSX => Syntax::Es(get_es_config(true)),
MediaType::Jsx => Syntax::Es(get_es_config(true)),
MediaType::TypeScript => Syntax::Typescript(get_ts_config(false, false)),
MediaType::Dts => Syntax::Typescript(get_ts_config(false, true)),
MediaType::TSX => Syntax::Typescript(get_ts_config(true, false)),
MediaType::Tsx => Syntax::Typescript(get_ts_config(true, false)),
_ => Syntax::Es(get_es_config(false)),
}
}
Expand Down Expand Up @@ -429,10 +429,10 @@ pub fn parse_with_source_map(
comments.with_leading(module.span.lo, |comments| comments.to_vec());

Ok(ParsedModule {
comments,
leading_comments,
module,
source_map,
comments,
source_file,
})
}
Expand Down Expand Up @@ -711,7 +711,7 @@ mod tests {
}
}
"#;
let module = parse(specifier.as_str(), source, &MediaType::TSX)
let module = parse(specifier.as_str(), source, &MediaType::Tsx)
.expect("could not parse module");
let (code, _) = module
.transpile(&EmitOptions::default())
Expand Down
6 changes: 2 additions & 4 deletions cli/bench/http.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.

use super::Result;
use std::{
collections::HashMap, path::PathBuf, process::Command, time::Duration,
};
use std::{collections::HashMap, path::Path, process::Command, time::Duration};
pub use test_util::{parse_wrk_output, WrkOutput as HttpBenchmarkResult};

// Some of the benchmarks in this file have been renamed. In case the history
Expand All @@ -15,7 +13,7 @@ pub use test_util::{parse_wrk_output, WrkOutput as HttpBenchmarkResult};
const DURATION: &str = "20s";

pub(crate) fn benchmark(
target_path: &PathBuf,
target_path: &Path,
) -> Result<HashMap<String, HttpBenchmarkResult>> {
let deno_exe = test_util::deno_exe_path();
let deno_exe = deno_exe.to_str().unwrap();
Expand Down
10 changes: 5 additions & 5 deletions cli/bench/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::collections::HashMap;
use std::io::BufRead;
use std::io::Read;
use std::io::Write;
use std::path::PathBuf;
use std::path::Path;
use std::process::ChildStdin;
use std::process::ChildStdout;
use std::process::Command;
Expand Down Expand Up @@ -135,7 +135,7 @@ impl Drop for LspClient {
}

impl LspClient {
fn new(deno_exe: &PathBuf) -> Result<Self, AnyError> {
fn new(deno_exe: &Path) -> Result<Self, AnyError> {
let mut child = Command::new(deno_exe)
.arg("lsp")
.stdin(Stdio::piped())
Expand Down Expand Up @@ -244,7 +244,7 @@ impl LspClient {
/// A benchmark that opens a 8000+ line TypeScript document, adds a function to
/// the end of the document and does a level of hovering and gets quick fix
/// code actions.
fn bench_big_file_edits(deno_exe: &PathBuf) -> Result<Duration, AnyError> {
fn bench_big_file_edits(deno_exe: &Path) -> Result<Duration, AnyError> {
let mut client = LspClient::new(deno_exe)?;

let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON)?;
Expand Down Expand Up @@ -302,7 +302,7 @@ fn bench_big_file_edits(deno_exe: &PathBuf) -> Result<Duration, AnyError> {
}

/// A test that starts up the LSP, opens a single line document, and exits.
fn bench_startup_shutdown(deno_exe: &PathBuf) -> Result<Duration, AnyError> {
fn bench_startup_shutdown(deno_exe: &Path) -> Result<Duration, AnyError> {
let mut client = LspClient::new(deno_exe)?;

let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON)?;
Expand Down Expand Up @@ -338,7 +338,7 @@ fn bench_startup_shutdown(deno_exe: &PathBuf) -> Result<Duration, AnyError> {

/// Generate benchmarks for the LSP server.
pub(crate) fn benchmarks(
deno_exe: &PathBuf,
deno_exe: &Path,
) -> Result<HashMap<String, u64>, AnyError> {
println!("-> Start benchmarking lsp");
let mut exec_times = HashMap::new();
Expand Down
17 changes: 9 additions & 8 deletions cli/bench/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::collections::HashMap;
use std::convert::From;
use std::env;
use std::fs;
use std::path::Path;
use std::path::PathBuf;
use std::process::Command;
use std::process::Stdio;
Expand Down Expand Up @@ -126,8 +127,8 @@ const EXEC_TIME_BENCHMARKS: &[(&str, &[&str], Option<i32>)] = &[
const RESULT_KEYS: &[&str] =
&["mean", "stddev", "user", "system", "min", "max"];
fn run_exec_time(
deno_exe: &PathBuf,
target_dir: &PathBuf,
deno_exe: &Path,
target_dir: &Path,
) -> Result<HashMap<String, HashMap<String, f64>>> {
let hyperfine_exe = test_util::prebuilt_tool_path("hyperfine");

Expand Down Expand Up @@ -218,7 +219,7 @@ fn rlib_size(target_dir: &std::path::Path, prefix: &str) -> u64 {

const BINARY_TARGET_FILES: &[&str] =
&["CLI_SNAPSHOT.bin", "COMPILER_SNAPSHOT.bin"];
fn get_binary_sizes(target_dir: &PathBuf) -> Result<HashMap<String, u64>> {
fn get_binary_sizes(target_dir: &Path) -> Result<HashMap<String, u64>> {
let mut sizes = HashMap::<String, u64>::new();
let mut mtimes = HashMap::<String, SystemTime>::new();

Expand Down Expand Up @@ -276,7 +277,7 @@ const BUNDLES: &[(&str, &str)] = &[
("file_server", "./test_util/std/http/file_server.ts"),
("gist", "./test_util/std/examples/gist.ts"),
];
fn bundle_benchmark(deno_exe: &PathBuf) -> Result<HashMap<String, u64>> {
fn bundle_benchmark(deno_exe: &Path) -> Result<HashMap<String, u64>> {
let mut sizes = HashMap::<String, u64>::new();

for (name, url) in BUNDLES {
Expand Down Expand Up @@ -304,7 +305,7 @@ fn bundle_benchmark(deno_exe: &PathBuf) -> Result<HashMap<String, u64>> {
Ok(sizes)
}

fn run_throughput(deno_exe: &PathBuf) -> Result<HashMap<String, f64>> {
fn run_throughput(deno_exe: &Path) -> Result<HashMap<String, f64>> {
let mut m = HashMap::<String, f64>::new();

m.insert("100M_tcp".to_string(), throughput::tcp(deno_exe, 100)?);
Expand All @@ -315,7 +316,7 @@ fn run_throughput(deno_exe: &PathBuf) -> Result<HashMap<String, f64>> {
Ok(m)
}

fn run_http(target_dir: &PathBuf, new_data: &mut BenchResult) -> Result<()> {
fn run_http(target_dir: &Path, new_data: &mut BenchResult) -> Result<()> {
let stats = http::benchmark(target_dir)?;

new_data.req_per_sec = stats
Expand All @@ -332,7 +333,7 @@ fn run_http(target_dir: &PathBuf, new_data: &mut BenchResult) -> Result<()> {
}

fn run_strace_benchmarks(
deno_exe: &PathBuf,
deno_exe: &Path,
new_data: &mut BenchResult,
) -> Result<()> {
use std::io::Read;
Expand Down Expand Up @@ -372,7 +373,7 @@ fn run_strace_benchmarks(
Ok(())
}

fn run_max_mem_benchmark(deno_exe: &PathBuf) -> Result<HashMap<String, u64>> {
fn run_max_mem_benchmark(deno_exe: &Path) -> Result<HashMap<String, u64>> {
let mut results = HashMap::<String, u64>::new();

for (name, args, return_code) in EXEC_TIME_BENCHMARKS {
Expand Down
6 changes: 3 additions & 3 deletions cli/bench/throughput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use super::Result;
use std::{
path::PathBuf,
path::Path,
process::Command,
time::{Duration, Instant},
};
Expand All @@ -11,7 +11,7 @@ const MB: usize = 1024 * 1024;
const SERVER_ADDR: &str = "0.0.0.0:4544";
const CLIENT_ADDR: &str = "127.0.0.1 4544";

pub(crate) fn cat(deno_exe: &PathBuf, megs: usize) -> f64 {
pub(crate) fn cat(deno_exe: &Path, megs: usize) -> f64 {
let size = megs * MB;
let shell_cmd = format!(
"{} run --allow-read cli/tests/cat.ts /dev/zero | head -c {}",
Expand All @@ -28,7 +28,7 @@ pub(crate) fn cat(deno_exe: &PathBuf, megs: usize) -> f64 {
(end - start).as_secs_f64()
}

pub(crate) fn tcp(deno_exe: &PathBuf, megs: usize) -> Result<f64> {
pub(crate) fn tcp(deno_exe: &Path, megs: usize) -> Result<f64> {
let size = megs * MB;

// The GNU flavor of `nc` requires the `-N` flag to shutdown the network socket after EOF on stdin
Expand Down
28 changes: 14 additions & 14 deletions cli/file_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ pub fn map_content_type(
| "application/node" => {
map_js_like_extension(specifier, MediaType::JavaScript)
}
"text/jsx" => MediaType::JSX,
"text/tsx" => MediaType::TSX,
"text/jsx" => MediaType::Jsx,
"text/tsx" => MediaType::Tsx,
"application/json" | "text/json" => MediaType::Json,
"application/wasm" => MediaType::Wasm,
// Handle plain and possibly webassembly
Expand Down Expand Up @@ -264,8 +264,8 @@ fn map_js_like_extension(
None => default,
Some(os_str) => match os_str.to_str() {
None => default,
Some("jsx") => MediaType::JSX,
Some("tsx") => MediaType::TSX,
Some("jsx") => MediaType::Jsx,
Some("tsx") => MediaType::Tsx,
// Because DTS files do not have a separate media type, or a unique
// extension, we have to "guess" at those things that we consider that
// look like TypeScript, and end with `.d.ts` are DTS files.
Expand Down Expand Up @@ -685,8 +685,8 @@ mod tests {
("data:text/plain,Hello%2C%20Deno!", true, MediaType::Unknown, "text/plain", "Hello, Deno!"),
("data:,Hello%2C%20Deno!", true, MediaType::Unknown, "", "Hello, Deno!"),
("data:application/javascript,console.log(\"Hello, Deno!\");%0A", true, MediaType::JavaScript, "application/javascript", "console.log(\"Hello, Deno!\");\n"),
("data:text/jsx;base64,ZXhwb3J0IGRlZmF1bHQgZnVuY3Rpb24oKSB7CiAgcmV0dXJuIDxkaXY+SGVsbG8gRGVubyE8L2Rpdj4KfQo=", true, MediaType::JSX, "text/jsx;base64", "export default function() {\n return <div>Hello Deno!</div>\n}\n"),
("data:text/tsx;base64,ZXhwb3J0IGRlZmF1bHQgZnVuY3Rpb24oKSB7CiAgcmV0dXJuIDxkaXY+SGVsbG8gRGVubyE8L2Rpdj4KfQo=", true, MediaType::TSX, "text/tsx;base64", "export default function() {\n return <div>Hello Deno!</div>\n}\n"),
("data:text/jsx;base64,ZXhwb3J0IGRlZmF1bHQgZnVuY3Rpb24oKSB7CiAgcmV0dXJuIDxkaXY+SGVsbG8gRGVubyE8L2Rpdj4KfQo=", true, MediaType::Jsx, "text/jsx;base64", "export default function() {\n return <div>Hello Deno!</div>\n}\n"),
("data:text/tsx;base64,ZXhwb3J0IGRlZmF1bHQgZnVuY3Rpb24oKSB7CiAgcmV0dXJuIDxkaXY+SGVsbG8gRGVubyE8L2Rpdj4KfQo=", true, MediaType::Tsx, "text/tsx;base64", "export default function() {\n return <div>Hello Deno!</div>\n}\n"),
];

for (
Expand Down Expand Up @@ -744,10 +744,10 @@ mod tests {
let fixtures = vec![
// Extension only
(file_url!("/foo/bar.ts"), None, MediaType::TypeScript, None),
(file_url!("/foo/bar.tsx"), None, MediaType::TSX, None),
(file_url!("/foo/bar.tsx"), None, MediaType::Tsx, None),
(file_url!("/foo/bar.d.ts"), None, MediaType::Dts, None),
(file_url!("/foo/bar.js"), None, MediaType::JavaScript, None),
(file_url!("/foo/bar.jsx"), None, MediaType::JSX, None),
(file_url!("/foo/bar.jsx"), None, MediaType::Jsx, None),
(file_url!("/foo/bar.json"), None, MediaType::Json, None),
(file_url!("/foo/bar.wasm"), None, MediaType::Wasm, None),
(file_url!("/foo/bar.cjs"), None, MediaType::JavaScript, None),
Expand Down Expand Up @@ -823,13 +823,13 @@ mod tests {
(
"https://deno.land/x/mod",
Some("text/jsx".to_string()),
MediaType::JSX,
MediaType::Jsx,
None,
),
(
"https://deno.land/x/mod",
Some("text/tsx".to_string()),
MediaType::TSX,
MediaType::Tsx,
None,
),
(
Expand Down Expand Up @@ -860,25 +860,25 @@ mod tests {
(
"https://deno.land/x/mod.tsx",
Some("application/typescript".to_string()),
MediaType::TSX,
MediaType::Tsx,
None,
),
(
"https://deno.land/x/mod.tsx",
Some("application/javascript".to_string()),
MediaType::TSX,
MediaType::Tsx,
None,
),
(
"https://deno.land/x/mod.jsx",
Some("application/javascript".to_string()),
MediaType::JSX,
MediaType::Jsx,
None,
),
(
"https://deno.land/x/mod.jsx",
Some("application/x-typescript".to_string()),
MediaType::JSX,
MediaType::Jsx,
None,
),
(
Expand Down
2 changes: 1 addition & 1 deletion cli/fs_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ mod tests {

#[test]
fn test_collect_files() {
fn create_files(dir_path: &PathBuf, files: &[&str]) {
fn create_files(dir_path: &Path, files: &[&str]) {
std::fs::create_dir(dir_path).expect("Failed to create directory");
for f in files {
let path = dir_path.join(f);
Expand Down
8 changes: 2 additions & 6 deletions cli/lsp/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ pub fn analyze_dependencies(
let resolved_import =
resolve_import(&import, specifier, maybe_import_map);
if media_type == &MediaType::JavaScript
|| media_type == &MediaType::JSX
|| media_type == &MediaType::Jsx
{
maybe_type = Some(resolved_import)
} else {
Expand All @@ -297,11 +297,7 @@ pub fn analyze_dependencies(
let maybe_resolved_type_dependency =
// Check for `@deno-types` pragmas that affect the import
if let Some(comment) = desc.leading_comments.last() {
if let Some(deno_types) = parse_deno_types(&comment.text).as_ref() {
Some(resolve_import(deno_types, specifier, maybe_import_map))
} else {
None
}
parse_deno_types(&comment.text).as_ref().map(|deno_types| resolve_import(deno_types, specifier, maybe_import_map))
} else {
None
};
Expand Down
Loading