From da1b98b690e39ce4becf314910d046b9850f650f Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Thu, 28 Mar 2019 08:09:19 -0400 Subject: [PATCH] Clippy fixes (#2009) --- cli/compiler.rs | 8 ++------ cli/deno_dir.rs | 26 +++++++++++++------------- cli/js_errors.rs | 2 +- cli/startup_data.rs | 4 ++-- core/isolate.rs | 12 +++++------- 5 files changed, 23 insertions(+), 29 deletions(-) diff --git a/cli/compiler.rs b/cli/compiler.rs index 0452e08a95..085fcd820e 100644 --- a/cli/compiler.rs +++ b/cli/compiler.rs @@ -186,12 +186,8 @@ mod tests { maybe_source_map: None, }; - out = compile_sync( - Arc::new(IsolateState::mock()), - specifier, - &referrer, - &mut out, - ); + out = + compile_sync(Arc::new(IsolateState::mock()), specifier, &referrer, &out); assert!( out .maybe_output_code diff --git a/cli/deno_dir.rs b/cli/deno_dir.rs index 40612e9703..1055fa687a 100644 --- a/cli/deno_dir.rs +++ b/cli/deno_dir.rs @@ -692,7 +692,7 @@ mod tests { fn test_cache_path() { let (temp_dir, deno_dir) = test_setup(false, false); let filename = "hello.js"; - let source_code = "1+2".as_bytes(); + let source_code = b"1+2"; let hash = source_code_hash(filename, source_code, version::DENO); assert_eq!( ( @@ -708,9 +708,9 @@ mod tests { let (_temp_dir, deno_dir) = test_setup(false, false); let filename = "hello.js"; - let source_code = "1+2".as_bytes(); - let output_code = "1+2 // output code".as_bytes(); - let source_map = "{}".as_bytes(); + let source_code = b"1+2"; + let output_code = b"1+2 // output code"; + let source_map = b"{}"; let hash = source_code_hash(filename, source_code, version::DENO); let (cache_path, source_map_path) = deno_dir.cache_path(filename, source_code); @@ -719,41 +719,41 @@ mod tests { let out = ModuleMetaData { filename: filename.to_owned(), - source_code: source_code.to_owned(), + source_code: source_code[..].to_owned(), module_name: "hello.js".to_owned(), media_type: msg::MediaType::TypeScript, - maybe_output_code: Some(output_code.to_owned()), + maybe_output_code: Some(output_code[..].to_owned()), maybe_output_code_filename: None, - maybe_source_map: Some(source_map.to_owned()), + maybe_source_map: Some(source_map[..].to_owned()), maybe_source_map_filename: None, }; let r = deno_dir.code_cache(&out); r.expect("code_cache error"); assert!(cache_path.exists()); - assert_eq!(output_code.to_owned(), fs::read(&cache_path).unwrap()); + assert_eq!(output_code[..].to_owned(), fs::read(&cache_path).unwrap()); } #[test] fn test_source_code_hash() { assert_eq!( "7e44de2ed9e0065da09d835b76b8d70be503d276", - source_code_hash("hello.ts", "1+2".as_bytes(), "0.2.11") + source_code_hash("hello.ts", b"1+2", "0.2.11") ); // Different source_code should result in different hash. assert_eq!( "57033366cf9db1ef93deca258cdbcd9ef5f4bde1", - source_code_hash("hello.ts", "1".as_bytes(), "0.2.11") + source_code_hash("hello.ts", b"1", "0.2.11") ); // Different filename should result in different hash. assert_eq!( "19657f90b5b0540f87679e2fb362e7bd62b644b0", - source_code_hash("hi.ts", "1+2".as_bytes(), "0.2.11") + source_code_hash("hi.ts", b"1+2", "0.2.11") ); // Different version should result in different hash. assert_eq!( "e2b4b7162975a02bf2770f16836eb21d5bcb8be1", - source_code_hash("hi.ts", "1+2".as_bytes(), "0.2.0") + source_code_hash("hi.ts", b"1+2", "0.2.0") ); } @@ -1456,7 +1456,7 @@ mod tests { #[test] fn test_filter_shebang() { - assert_eq!(filter_shebang("#!".as_bytes().to_owned()), "".as_bytes()); + assert_eq!(filter_shebang(b"#!"[..].to_owned()), b""); assert_eq!( filter_shebang("#!\n\n".as_bytes().to_owned()), "\n\n".as_bytes() diff --git a/cli/js_errors.rs b/cli/js_errors.rs index 90c9f20075..1cb9cb3a19 100644 --- a/cli/js_errors.rs +++ b/cli/js_errors.rs @@ -209,7 +209,7 @@ pub fn apply_source_map( // The bundle does not get built for 'cargo check', so we don't embed the // bundle source map. #[cfg(feature = "check-only")] -fn builtin_source_map(script_name: &str) -> Option> { +fn builtin_source_map(_: &str) -> Option> { None } diff --git a/cli/startup_data.rs b/cli/startup_data.rs index 5ef74de066..6e636e5790 100644 --- a/cli/startup_data.rs +++ b/cli/startup_data.rs @@ -13,7 +13,7 @@ pub fn deno_isolate_init() -> StartupData { StartupData::Script(Script { filename: "gen/bundle/main.js".to_string(), - source: std::str::from_utf8(source_bytes).unwrap().to_string(), + source: std::str::from_utf8(&source_bytes[..]).unwrap().to_string(), }) } else { debug!("Deno isolate init with snapshots."); @@ -40,7 +40,7 @@ pub fn compiler_isolate_init() -> StartupData { StartupData::Script(Script { filename: "gen/bundle/compiler.js".to_string(), - source: std::str::from_utf8(source_bytes).unwrap().to_string(), + source: std::str::from_utf8(&source_bytes[..]).unwrap().to_string(), }) } else { debug!("Deno isolate init with snapshots."); diff --git a/core/isolate.rs b/core/isolate.rs index b28730ba68..f8ada23d46 100644 --- a/core/isolate.rs +++ b/core/isolate.rs @@ -140,11 +140,10 @@ impl Isolate { }; // If we want to use execute this has to happen here sadly. - match startup_script { - Some(s) => core_isolate + if let Some(s) = startup_script { + core_isolate .execute(s.filename.as_str(), s.source.as_str()) - .unwrap(), - None => {} + .unwrap() }; core_isolate @@ -510,9 +509,8 @@ impl IsolateHandle { /// the isolate. pub fn terminate_execution(&self) { unsafe { - match *self.shared_libdeno_isolate.lock().unwrap() { - Some(isolate) => libdeno::deno_terminate_execution(isolate), - None => (), + if let Some(isolate) = *self.shared_libdeno_isolate.lock().unwrap() { + libdeno::deno_terminate_execution(isolate) } } }