From 64dfd8eaed38f3bceef94029ed881ebfd17f68c7 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Mon, 3 Jan 2022 14:59:11 -0800 Subject: fix(windows-kernel-build): harsh clippy stuff --- crates/windows-kernel-build/src/lib.rs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/crates/windows-kernel-build/src/lib.rs b/crates/windows-kernel-build/src/lib.rs index f2f4680..29ca151 100644 --- a/crates/windows-kernel-build/src/lib.rs +++ b/crates/windows-kernel-build/src/lib.rs @@ -1,3 +1,12 @@ +#![deny( + warnings, + nonstandard_style, + unused, + future_incompatible, + rust_2018_idioms +)] +#![deny(clippy::all, clippy::nursery, clippy::pedantic)] + use std::path::PathBuf; use thiserror::Error; @@ -18,6 +27,9 @@ pub enum DirectoryType { /// Retrieves the path to the Windows Kits directory. The default should be /// `C:\Program Files (x86)\Windows Kits\10`. +/// +/// # Errors +/// if a key cannot be found. pub fn get_windows_kits_dir() -> Result { let hklm = RegKey::predef(HKEY_LOCAL_MACHINE); let key = r"SOFTWARE\Microsoft\Windows Kits\Installed Roots"; @@ -28,7 +40,10 @@ pub fn get_windows_kits_dir() -> Result { /// Retrieves the path to the kernel mode libraries. The path may look something /// like: `C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\km`. -pub fn get_km_dir(dir_type: DirectoryType) -> Result { +/// +/// # Errors +/// if a directory cannot be found. +pub fn get_km_dir(dir_type: &DirectoryType) -> Result { // We first append lib to the path and read the directory.. let dir = get_windows_kits_dir()? .join(match dir_type { @@ -40,27 +55,32 @@ pub fn get_km_dir(dir_type: DirectoryType) -> Result { // In the lib directory we may have one or more directories named after the // version of Windows, we will be looking for the highest version number. let dir = dir - .filter_map(|dir| dir.ok()) + .filter_map(std::result::Result::ok) .map(|dir| dir.path()) .filter(|dir| { dir .components() .last() .and_then(|c| c.as_os_str().to_str()) - .map(|c| c.starts_with("10.") && dir.join("km").is_dir()) - .unwrap_or(false) + .map_or(false, |c| c.starts_with("10.") && dir.join("km").is_dir()) }) .max() - // .ok_or_else(|| Error::DirectoryNotFound)?; .ok_or(Error::DirectoryNotFound)?; // Finally append km to the path to get the path to the kernel mode libraries. Ok(dir.join("km")) } +/// # Panics +/// if the `target` is currently not supported. +/// +/// # Errors +/// - if the kernel libraries cannot be found +/// - if the `TARGET` environment variable is not present +/// - if the link path cannot be converted to a &str pub fn build() -> Result<(), Error> { // Get the path to the kernel libraries. - let dir = get_km_dir(DirectoryType::Library).unwrap(); + let dir = get_km_dir(&DirectoryType::Library).unwrap(); // Append the architecture based on our target. let target = std::env::var("TARGET").unwrap(); -- cgit v1.2.3