From 82135e07a784ebb955eab890a4d9d840f09aa4cd Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Fri, 25 Sep 2026 18:34:38 -0700 Subject: [PATCH] Stricter linting rule (#582) --- Cargo.toml | 4 ++ build.rs | 125 ++++++++++++++++++++++++++++------------------------- src/lib.rs | 7 ++- 3 files changed, 74 insertions(+), 62 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4f7401c..b86618b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,3 +28,7 @@ dbg_macro = "deny" missing_const_for_fn = "deny" std_instead_of_alloc = "deny" std_instead_of_core = "deny" + +[lints.rust] +missing_docs = "deny" +warnings = "deny" diff --git a/build.rs b/build.rs index b9e37e8..2118225 100644 --- a/build.rs +++ b/build.rs @@ -1,71 +1,76 @@ +//! A build script. + const LIB_ATOMIC_OPS_DIR: &str = "vendor/libatomic_ops"; const LIB_GC_DIR: &str = "vendor/bdwgc"; -#[cfg(feature = "autotools")] -fn main() { - for dir in &[LIB_ATOMIC_OPS_DIR, LIB_GC_DIR] { - std::process::Command::new("sh") - .arg("-c") - .arg(format!("cd {dir} && ./autogen.sh")) - .output() - .unwrap(); +cfg_select! { + feature = "cmake" => { + fn main() { + use cmake::Config; + use std::path::Path; + + let libatomic_include_path = Path::new(LIB_ATOMIC_OPS_DIR) + .join("src") + .canonicalize() + .unwrap() + .display() + .to_string() + .replace(r"\\?\", ""); + + let dst = Config::new(LIB_GC_DIR) + .profile("Release") + .define("GC_BUILD_SHARED_LIBS", "FALSE") + .cflag(format!("-I{}", libatomic_include_path)) + .build(); + + println!( + "cargo:rustc-link-search=native={}", + dst.join("lib").display() + ); + println!("cargo:rustc-link-lib=static=gc"); + } } + feature = "autotools" => { + fn main() { + for dir in &[LIB_ATOMIC_OPS_DIR, LIB_GC_DIR] { + std::process::Command::new("sh") + .arg("-c") + .arg(format!("cd {dir} && ./autogen.sh")) + .output() + .unwrap(); + } - let dst = autotools::Config::new(LIB_ATOMIC_OPS_DIR) - .cflag("-fPIC") - .build(); + let dst = autotools::Config::new(LIB_ATOMIC_OPS_DIR) + .cflag("-fPIC") + .build(); - println!( - "cargo:rustc-link-search=native={}", - dst.join("lib").display() - ); - println!("cargo:rustc-link-lib=static=atomic_ops"); + println!( + "cargo:rustc-link-search=native={}", + dst.join("lib").display() + ); + println!("cargo:rustc-link-lib=static=atomic_ops"); - let dst = autotools::Config::new(LIB_GC_DIR) - .cflag(format!( - // spell-checker: disable-next-line - "-I{} -L/lib/x86_64-linux-gnu -lpthread -fPIC", - dst.join("include").display() - )) - .build(); + let dst = autotools::Config::new(LIB_GC_DIR) + .cflag(format!( + // spell-checker: disable-next-line + "-I{} -L/lib/x86_64-linux-gnu -lpthread -fPIC", + dst.join("include").display() + )) + .build(); - println!( - "cargo:rustc-link-search=native={}", - dst.join("lib").display() - ); - println!("cargo:rustc-link-lib=static=gc"); + println!( + "cargo:rustc-link-search=native={}", + dst.join("lib").display() + ); + println!("cargo:rustc-link-lib=static=gc"); - for dir in &[LIB_ATOMIC_OPS_DIR, LIB_GC_DIR] { - std::process::Command::new("sh") - .arg("-c") - .arg(format!("cd {dir} && git clean -dfx")) - .output() - .unwrap(); + for dir in &[LIB_ATOMIC_OPS_DIR, LIB_GC_DIR] { + std::process::Command::new("sh") + .arg("-c") + .arg(format!("cd {dir} && git clean -dfx")) + .output() + .unwrap(); + } + } } } - -#[cfg(feature = "cmake")] -fn main() { - use cmake::Config; - use std::path::Path; - - let libatomic_include_path = Path::new(LIB_ATOMIC_OPS_DIR) - .join("src") - .canonicalize() - .unwrap() - .display() - .to_string() - .replace(r"\\?\", ""); - - let dst = Config::new(LIB_GC_DIR) - .profile("Release") - .define("GC_BUILD_SHARED_LIBS", "FALSE") - .cflag(format!("-I{}", libatomic_include_path)) - .build(); - - println!( - "cargo:rustc-link-search=native={}", - dst.join("lib").display() - ); - println!("cargo:rustc-link-lib=static=gc"); -} diff --git a/src/lib.rs b/src/lib.rs index c767328..144c0ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,8 +3,10 @@ mod error; -use core::alloc::{GlobalAlloc, Layout}; -use core::ptr::null; +use core::{ + alloc::{GlobalAlloc, Layout}, + ptr::null, +}; use libc::{c_int, c_void, size_t}; const GC_SUCCESS: c_int = 0; @@ -38,6 +40,7 @@ unsafe extern "C" { ) -> *mut c_void; } +/// An allocator. pub struct Allocator; impl Allocator {