diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-07-15 12:30:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-15 12:30:25 -0400 |
commit | 635eed93731c3616cacf53860b9aeeeb8cfe158b (patch) | |
tree | 04509d5720189fe12b2021500c461ccea1ddfa8e /ext | |
parent | ee0c0586b318fe23908a3b9b4311b26d79c5c8a1 (diff) |
chore: fix Windows specific clippy errors (#15212)
Diffstat (limited to 'ext')
-rw-r--r-- | ext/ffi/build.rs | 7 | ||||
-rw-r--r-- | ext/ffi/lib.rs | 32 |
2 files changed, 23 insertions, 16 deletions
diff --git a/ext/ffi/build.rs b/ext/ffi/build.rs index 091dd9599..1debd6b9c 100644 --- a/ext/ffi/build.rs +++ b/ext/ffi/build.rs @@ -1,8 +1,9 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. -use std::env; - +#[cfg(not(target_os = "windows"))] fn build_tcc() { + use std::env; + { // TODO(@littledivy): Windows support for fast call. // let tcc_path = root @@ -58,6 +59,8 @@ fn main() {} #[cfg(not(target_os = "windows"))] fn main() { + use std::env; + if let Ok(tcc_path) = env::var("TCC_PATH") { println!("cargo:rustc-link-search=native={}", tcc_path); } else { diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs index 737ea9db2..ac792de44 100644 --- a/ext/ffi/lib.rs +++ b/ext/ffi/lib.rs @@ -518,8 +518,10 @@ pub(crate) fn format_error(e: dlopen::Error, path: String) -> String { let arguments = [path.as_ptr()]; loop { - unsafe { - let length = FormatMessageW( + // SAFETY: + // winapi call to format the error message + let length = unsafe { + FormatMessageW( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, std::ptr::null_mut(), err_num as DWORD, @@ -527,22 +529,24 @@ pub(crate) fn format_error(e: dlopen::Error, path: String) -> String { buf.as_mut_ptr(), buf.len() as DWORD, arguments.as_ptr() as _, - ); - - if length == 0 { - let err_num = GetLastError(); - if err_num == ERROR_INSUFFICIENT_BUFFER { - buf.resize(buf.len() * 2, 0); - continue; - } + ) + }; - // Something went wrong, just return the original error. - return e.to_string(); + if length == 0 { + // SAFETY: + // winapi call to get the last error message + let err_num = unsafe { GetLastError() }; + if err_num == ERROR_INSUFFICIENT_BUFFER { + buf.resize(buf.len() * 2, 0); + continue; } - let msg = String::from_utf16_lossy(&buf[..length as usize]); - return msg; + // Something went wrong, just return the original error. + return e.to_string(); } + + let msg = String::from_utf16_lossy(&buf[..length as usize]); + return msg; } } _ => e.to_string(), |