diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1d5071a115c024..b43dda3bf66994 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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' diff --git a/cli/compilers/ts.rs b/cli/compilers/ts.rs index 0e3e0b95dd2889..c6528dd5b44177 100644 --- a/cli/compilers/ts.rs +++ b/cli/compilers/ts.rs @@ -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()); } } diff --git a/cli/compilers/wasm.rs b/cli/compilers/wasm.rs index 22ec6526c9444d..f2c0403fab7100 100644 --- a/cli/compilers/wasm.rs +++ b/cli/compilers/wasm.rs @@ -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(); diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index 1e147ab3233897..0d89ab26021407 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -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( diff --git a/cli/fmt_errors.rs b/cli/fmt_errors.rs index 84fcf5b430baaf..8b28d7bb4d7e87 100644 --- a/cli/fmt_errors.rs +++ b/cli/fmt_errors.rs @@ -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(); diff --git a/cli/import_map.rs b/cli/import_map.rs index d2916c19814d2f..26f1dd86a14d77 100644 --- a/cli/import_map.rs +++ b/cli/import_map.rs @@ -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) diff --git a/cli/ops/errors.rs b/cli/ops/errors.rs index 3d94c05c48a8fc..4ef9129162e910 100644 --- a/cli/ops/errors.rs +++ b/cli/ops/errors.rs @@ -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, }))) diff --git a/cli/ops/plugins.rs b/cli/ops/plugins.rs index 258cd27646883d..eb52b07171be20 100644 --- a/cli/ops/plugins.rs +++ b/cli/ops/plugins.rs @@ -9,7 +9,7 @@ use std::ffi::OsStr; use std::sync::Arc; pub fn init(i: &mut Isolate, s: &ThreadSafeState, r: Arc) { - 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| { diff --git a/cli/ops/workers.rs b/cli/ops/workers.rs index 2b4d11e75ede4c..467d0bfb2ed4ff 100644 --- a/cli/ops/workers.rs +++ b/cli/ops/workers.rs @@ -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) })) }); diff --git a/cli/permissions.rs b/cli/permissions.rs index 72a1a928acc09d..8d476c234decbc 100644 --- a/cli/permissions.rs +++ b/cli/permissions.rs @@ -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); diff --git a/cli/source_maps.rs b/cli/source_maps.rs index 95df48a313b496..aea9f087cae618 100644 --- a/cli/source_maps.rs +++ b/cli/source_maps.rs @@ -260,8 +260,12 @@ mod tests { impl SourceMapGetter for MockSourceMapGetter { fn get_source_map(&self, script_name: &str) -> Option> { 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()) diff --git a/cli/state.rs b/cli/state.rs index d31f667b52c744..2657ae747f12a3 100644 --- a/cli/state.rs +++ b/cli/state.rs @@ -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()) diff --git a/cli/worker.rs b/cli/worker.rs index e35458d39e17a1..410d6ee4455803 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -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 = diff --git a/core/examples/http_bench.rs b/core/examples/http_bench.rs index c08c5b6e143d87..a79e3fc20e3d95 100644 --- a/core/examples/http_bench.rs +++ b/core/examples/http_bench.rs @@ -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 { diff --git a/core/module_specifier.rs b/core/module_specifier.rs index ad24616ff38dd1..dd5347a33db3c9 100644 --- a/core/module_specifier.rs +++ b/core/module_specifier.rs @@ -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), ]); } diff --git a/core/modules.rs b/core/modules.rs index 3f431d36d69d56..722fa2cbeaab43 100644 --- a/core/modules.rs +++ b/core/modules.rs @@ -186,7 +186,7 @@ impl RecursiveLoad { { 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()); diff --git a/deno_typescript/lib.rs b/deno_typescript/lib.rs index c410c870fb63b4..3d27149c527846 100644 --- a/deno_typescript/lib.rs +++ b/deno_typescript/lib.rs @@ -115,7 +115,7 @@ impl TSIsolate { let source = &format!("main({:?}, {})", config_json.to_string(), root_names_json); self.isolate.execute("", source)?; - Ok(self.state.clone()) + Ok(self.state) } }