1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

Upgrades rust to 1.40.0 (#3542)

This commit is contained in:
Axetroy 2019-12-23 22:59:44 +08:00 committed by Ry Dahl
parent e88c801e76
commit 3bb15ceaea
17 changed files with 71 additions and 103 deletions

View file

@ -45,7 +45,7 @@ jobs:
- name: Install rust
uses: hecrj/setup-rust-action@v1
with:
rust-version: "1.39.0"
rust-version: "1.40.0"
- name: Install clippy and rustfmt
if: matrix.kind == 'lint'

View file

@ -60,20 +60,15 @@ impl CompilerConfig {
// Convert the PathBuf to a canonicalized string. This is needed by the
// compiler to properly deal with the configuration.
let config_path = match &config_file {
Some(config_file) => Some(
config_file
.canonicalize()
.map_err(|_| {
io::Error::new(
io::ErrorKind::InvalidInput,
format!(
"Could not find the config file: {}",
config_file.to_string_lossy()
),
)
})?
.to_owned(),
),
Some(config_file) => Some(config_file.canonicalize().map_err(|_| {
io::Error::new(
io::ErrorKind::InvalidInput,
format!(
"Could not find the config file: {}",
config_file.to_string_lossy()
),
)
})),
_ => None,
};
@ -102,7 +97,7 @@ impl CompilerConfig {
};
let ts_config = Self {
path: config_path,
path: config_path.unwrap_or_else(|| Ok(PathBuf::new())).ok(),
content: config,
hash: config_hash,
compile_js,
@ -261,7 +256,7 @@ impl TsCompiler {
module_name
);
let root_names = vec![module_name.clone()];
let root_names = vec![module_name];
let req_msg = req(
msg::CompilerRequestType::Bundle,
root_names,
@ -269,7 +264,7 @@ impl TsCompiler {
out_file,
);
let worker = TsCompiler::setup_worker(global_state.clone());
let worker = TsCompiler::setup_worker(global_state);
let worker_ = worker.clone();
async move {
@ -368,7 +363,7 @@ impl TsCompiler {
let compiling_job = global_state
.progress
.add("Compile", &module_url.to_string());
let global_state_ = global_state.clone();
let global_state_ = global_state;
async move {
worker.post_message(req_msg).await?;
@ -390,7 +385,7 @@ impl TsCompiler {
debug!(">>>>> compile_sync END");
Ok(compiled_module)
}
.boxed()
.boxed()
}
/// Get associated `CompiledFileMetadata` for given module if it exists.
@ -483,7 +478,7 @@ impl TsCompiler {
);
let compiled_file_metadata = CompiledFileMetadata {
source_path: source_file.filename.to_owned(),
source_path: source_file.filename,
version_hash,
};
let meta_key = self
@ -618,8 +613,7 @@ mod tests {
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.join("tests/002_hello.ts")
.to_owned();
.join("tests/002_hello.ts");
let specifier =
ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap();
@ -658,8 +652,7 @@ mod tests {
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.join("tests/002_hello.ts")
.to_owned();
.join("tests/002_hello.ts");
use deno::ModuleSpecifier;
let module_name = ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap())
.unwrap()
@ -717,25 +710,16 @@ mod tests {
let test_cases = vec![
// valid JSON
(
r#"{ "compilerOptions": { "checkJs": true } } "#,
true,
),
(r#"{ "compilerOptions": { "checkJs": true } } "#, true),
// JSON with comment
(
r#"{ "compilerOptions": { // force .js file compilation by Deno "checkJs": true } } "#,
true,
),
// invalid JSON
(
r#"{ "compilerOptions": { "checkJs": true },{ } "#,
true,
),
(r#"{ "compilerOptions": { "checkJs": true },{ } "#, true),
// without content
(
"",
false,
),
("", false),
];
let path = temp_dir_path.join("tsconfig.json");
@ -754,7 +738,7 @@ mod tests {
let temp_dir_path = temp_dir.path();
let path = temp_dir_path.join("doesnotexist.json");
let path_str = path.to_str().unwrap().to_string();
let res = CompilerConfig::load(Some(path_str.clone()));
let res = CompilerConfig::load(Some(path_str));
assert!(res.is_err());
}
}

View file

@ -76,13 +76,13 @@ impl WasmCompiler {
let cache = self.cache.clone();
let maybe_cached = { cache.lock().unwrap().get(&source_file.url).cloned() };
if let Some(m) = maybe_cached {
return futures::future::ok(m.clone()).boxed();
return futures::future::ok(m).boxed();
}
let cache_ = self.cache.clone();
debug!(">>>>> wasm_compile_async START");
let base64_data = base64::encode(&source_file.source_code);
let worker = WasmCompiler::setup_worker(global_state.clone());
let worker = WasmCompiler::setup_worker(global_state);
let worker_ = worker.clone();
let url = source_file.url.clone();

View file

@ -819,10 +819,7 @@ mod tests {
let headers = fetcher.get_source_code_headers(&url);
assert_eq!(headers.mime_type.clone().unwrap(), "text/javascript");
assert_eq!(
headers.redirect_to.clone().unwrap(),
"http://example.com/a.js"
);
assert_eq!(headers.redirect_to.unwrap(), "http://example.com/a.js");
let _ = fetcher.save_source_code_headers(
&url,
@ -831,10 +828,7 @@ mod tests {
);
let headers2 = fetcher.get_source_code_headers(&url);
assert_eq!(headers2.mime_type.clone().unwrap(), "text/typescript");
assert_eq!(
headers2.redirect_to.clone().unwrap(),
"http://deno.land/a.js"
);
assert_eq!(headers2.redirect_to.unwrap(), "http://deno.land/a.js");
}
#[test]
@ -868,7 +862,7 @@ mod tests {
);
let headers_file_name_1 = headers_file_name.clone();
let headers_file_name_2 = headers_file_name.clone();
let headers_file_name_3 = headers_file_name.clone();
let headers_file_name_3 = headers_file_name;
let fut = fetcher
.get_source_file_async(&module_url, true, false, false)
@ -1128,7 +1122,7 @@ mod tests {
assert!(redirect_target_headers.redirect_to.is_none());
// Examine the meta result.
assert_eq!(mod_meta.url.clone(), target_module_url);
assert_eq!(mod_meta.url, target_module_url);
futures::future::ok(())
});
@ -1195,7 +1189,7 @@ mod tests {
assert!(redirect_target_headers.redirect_to.is_none());
// Examine the meta result.
assert_eq!(mod_meta.url.clone(), target_url);
assert_eq!(mod_meta.url, target_url);
futures::future::ok(())
});
@ -1507,9 +1501,8 @@ mod tests {
},
));
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("js/main.ts")
.to_owned();
let p =
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("js/main.ts");
let specifier =
ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap();
tokio_util::run(fetcher.fetch_source_file_async(&specifier, None).then(
@ -1535,9 +1528,8 @@ mod tests {
},
));
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("js/main.ts")
.to_owned();
let p =
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("js/main.ts");
let specifier =
ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap();
tokio_util::run(fetcher.fetch_source_file_async(&specifier, None).then(

View file

@ -66,7 +66,7 @@ pub fn format_maybe_source_line(
assert!(end_column.is_some());
let line = (1 + line_number.unwrap()).to_string();
let line_color = colors::black_on_white(line.to_string());
let line_len = line.clone().len();
let line_len = line.len();
let line_padding =
colors::black_on_white(format!("{:indent$}", "", indent = line_len))
.to_string();

View file

@ -255,14 +255,10 @@ impl ImportMap {
}
// Sort in longest and alphabetical order.
normalized_map.sort_by(|k1, _v1, k2, _v2| {
if k1.len() > k2.len() {
return Ordering::Less;
} else if k2.len() > k1.len() {
return Ordering::Greater;
}
k2.cmp(k1)
normalized_map.sort_by(|k1, _v1, k2, _v2| match k1.cmp(&k2) {
Ordering::Greater => Ordering::Less,
Ordering::Less => Ordering::Greater,
Ordering::Equal => k2.cmp(k1),
});
normalized_map
@ -313,14 +309,10 @@ impl ImportMap {
}
// Sort in longest and alphabetical order.
normalized_map.sort_by(|k1, _v1, k2, _v2| {
if k1.len() > k2.len() {
return Ordering::Less;
} else if k2.len() > k1.len() {
return Ordering::Greater;
}
k2.cmp(k1)
normalized_map.sort_by(|k1, _v1, k2, _v2| match k1.cmp(&k2) {
Ordering::Greater => Ordering::Less,
Ordering::Less => Ordering::Greater,
Ordering::Equal => k2.cmp(k1),
});
Ok(normalized_map)

View file

@ -61,7 +61,7 @@ fn op_apply_source_map(
);
Ok(JsonOp::Sync(json!({
"filename": orig_filename.to_string(),
"filename": orig_filename,
"line": orig_line as u32,
"column": orig_column as u32,
})))

View file

@ -9,7 +9,7 @@ use std::ffi::OsStr;
use std::sync::Arc;
pub fn init(i: &mut Isolate, s: &ThreadSafeState, r: Arc<deno::OpRegistry>) {
let r_ = r.clone();
let r_ = r;
i.register_op(
"open_plugin",
s.core_op(json_op(s.stateful_op(move |state, args, zero_copy| {

View file

@ -81,7 +81,7 @@ fn op_worker_get_message(
debug!("op_worker_get_message");
futures::future::ok(json!({
"data": maybe_buf.map(|buf| buf.to_owned())
"data": maybe_buf.map(|buf| buf)
}))
});
@ -261,7 +261,7 @@ fn op_host_get_message(
.map_err(move |_| -> ErrBox { unimplemented!() })
.and_then(move |maybe_buf| {
futures::future::ok(json!({
"data": maybe_buf.map(|buf| buf.to_owned())
"data": maybe_buf.map(|buf| buf)
}))
});

View file

@ -394,7 +394,7 @@ mod tests {
let perms = DenoPermissions::from_flags(&DenoFlags {
read_whitelist: whitelist.clone(),
write_whitelist: whitelist.clone(),
write_whitelist: whitelist,
..Default::default()
});
@ -555,7 +555,7 @@ mod tests {
);
let mut perms2 = DenoPermissions::from_flags(&DenoFlags {
read_whitelist: whitelist.clone(),
read_whitelist: whitelist,
..Default::default()
});
set_prompt_result(false);
@ -591,7 +591,7 @@ mod tests {
);
let mut perms2 = DenoPermissions::from_flags(&DenoFlags {
write_whitelist: whitelist.clone(),
write_whitelist: whitelist,
..Default::default()
});
set_prompt_result(false);
@ -644,7 +644,7 @@ mod tests {
);
let mut perms3 = DenoPermissions::from_flags(&DenoFlags {
net_whitelist: whitelist.clone(),
net_whitelist: whitelist,
..Default::default()
});
set_prompt_result(true);

View file

@ -260,8 +260,12 @@ mod tests {
impl SourceMapGetter for MockSourceMapGetter {
fn get_source_map(&self, script_name: &str) -> Option<Vec<u8>> {
let s = match script_name {
"foo_bar.ts" => r#"{"sources": ["foo_bar.ts"], "mappings":";;;IAIA,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjD,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAE3C,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC"}"#,
"bar_baz.ts" => r#"{"sources": ["bar_baz.ts"], "mappings":";;;IAEA,CAAC,KAAK,IAAI,EAAE;QACV,MAAM,GAAG,GAAG,sDAAa,OAAO,2BAAC,CAAC;QAClC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC,CAAC,EAAE,CAAC;IAEQ,QAAA,GAAG,GAAG,KAAK,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC"}"#,
"foo_bar.ts" => {
r#"{"sources": ["foo_bar.ts"], "mappings":";;;IAIA,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjD,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAE3C,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC"}"#
}
"bar_baz.ts" => {
r#"{"sources": ["bar_baz.ts"], "mappings":";;;IAEA,CAAC,KAAK,IAAI,EAAE;QACV,MAAM,GAAG,GAAG,sDAAa,OAAO,2BAAC,CAAC;QAClC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC,CAAC,EAAE,CAAC;IAEQ,QAAA,GAAG,GAAG,KAAK,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC"}"#
}
_ => return None,
};
Some(s.as_bytes().to_owned())

View file

@ -104,7 +104,7 @@ impl ThreadSafeState {
Op::Async(fut) => {
let state = state.clone();
let result_fut = fut.map_ok(move |buf: Buf| {
state.clone().metrics_op_completed(buf.len());
state.metrics_op_completed(buf.len());
buf
});
Op::Async(result_fut.boxed())

View file

@ -243,8 +243,7 @@ mod tests {
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.join("tests/esm_imports_a.js")
.to_owned();
.join("tests/esm_imports_a.js");
let module_specifier =
ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap();
let global_state = ThreadSafeGlobalState::new(
@ -288,8 +287,7 @@ mod tests {
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.join("tests/circular1.ts")
.to_owned();
.join("tests/circular1.ts");
let module_specifier =
ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap();
let global_state = ThreadSafeGlobalState::new(
@ -335,8 +333,7 @@ mod tests {
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.join("cli/tests/006_url_imports.ts")
.to_owned();
.join("cli/tests/006_url_imports.ts");
let module_specifier =
ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap();
let mut flags = flags::DenoFlags::default();
@ -353,7 +350,7 @@ mod tests {
int,
)
.unwrap();
let global_state_ = global_state.clone();
let global_state_ = global_state;
let state_ = state.clone();
tokio_util::run(async move {
let mut worker = Worker::new(
@ -501,8 +498,7 @@ mod tests {
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.join("tests/002_hello.ts")
.to_owned();
.join("tests/002_hello.ts");
let module_specifier =
ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap();
let result =

View file

@ -117,7 +117,7 @@ fn http_op(
let record = Record::from(control);
let is_sync = record.promise_id == 0;
let op = handler(record.clone(), zero_copy_buf);
let mut record_a = record.clone();
let mut record_a = record;
let fut = async move {
match op.await {

View file

@ -402,7 +402,7 @@ mod tests {
);
tests.extend(vec![
(r"/deno/tests/006_url_imports.ts", expected_url.to_string()),
(r"\deno\tests\006_url_imports.ts", expected_url.to_string()),
(r"\deno\tests\006_url_imports.ts", expected_url),
]);
// Relative local path.
@ -413,8 +413,8 @@ mod tests {
tests.extend(vec![
(r"tests/006_url_imports.ts", expected_url.to_string()),
(r"tests\006_url_imports.ts", expected_url.to_string()),
(r"./tests/006_url_imports.ts", expected_url.to_string()),
(r".\tests\006_url_imports.ts", expected_url.to_string()),
(r"./tests/006_url_imports.ts", (*expected_url).to_string()),
(r".\tests\006_url_imports.ts", (*expected_url).to_string()),
]);
// UNC network path.
@ -437,7 +437,7 @@ mod tests {
let expected_url = format!("file://{}/tests/006_url_imports.ts", cwd_str);
tests.extend(vec![
("tests/006_url_imports.ts", expected_url.to_string()),
("./tests/006_url_imports.ts", expected_url.to_string()),
("./tests/006_url_imports.ts", expected_url),
]);
}

View file

@ -186,7 +186,7 @@ impl<L: Loader + Unpin> RecursiveLoad<L> {
{
let fut = self
.loader
.load(&module_specifier, Some(referrer_specifier.clone()));
.load(&module_specifier, Some(referrer_specifier));
self.pending.push(fut.boxed());
self.is_pending.insert(module_specifier);
}
@ -879,7 +879,7 @@ mod tests {
let loads = loader.loads.clone();
let recursive_load =
RecursiveLoad::main("/circular1.js", None, loader, modules);
let mut load_fut = recursive_load.get_future(isolate.clone()).boxed();
let mut load_fut = recursive_load.get_future(isolate).boxed();
let result = Pin::new(&mut load_fut).poll(&mut cx);
assert!(result.is_ready());
if let Poll::Ready(Ok(circular1_id)) = result {
@ -951,7 +951,7 @@ mod tests {
let loads = loader.loads.clone();
let recursive_load =
RecursiveLoad::main("/redirect1.js", None, loader, modules);
let mut load_fut = recursive_load.get_future(isolate.clone()).boxed();
let mut load_fut = recursive_load.get_future(isolate).boxed();
let result = Pin::new(&mut load_fut).poll(&mut cx);
println!(">> result {:?}", result);
assert!(result.is_ready());

View file

@ -115,7 +115,7 @@ impl TSIsolate {
let source =
&format!("main({:?}, {})", config_json.to_string(), root_names_json);
self.isolate.execute("<anon>", source)?;
Ok(self.state.clone())
Ok(self.state)
}
}