Skip to content

Commit

Permalink
Clippy fixes (denoland#2009)
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus authored and ry committed Mar 28, 2019
1 parent 1fec34b commit da1b98b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
8 changes: 2 additions & 6 deletions cli/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions cli/deno_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
(
Expand All @@ -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);
Expand All @@ -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")
);
}

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion cli/js_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<u8>> {
fn builtin_source_map(_: &str) -> Option<Vec<u8>> {
None
}

Expand Down
4 changes: 2 additions & 2 deletions cli/startup_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -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.");
Expand Down
12 changes: 5 additions & 7 deletions core/isolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,10 @@ impl<B: Behavior> Isolate<B> {
};

// 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
Expand Down Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit da1b98b

Please sign in to comment.