From a59119347f8c1a89d6f646a6e8e71ce4ed66bca8 Mon Sep 17 00:00:00 2001 From: Constantine Evans Date: Sun, 30 Nov 2025 12:22:18 -0500 Subject: [PATCH] coverage(off) instead of no_coverage (rust-lang/rust PR 114656) --- src/ffi.rs | 6 +++--- src/lib.rs | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/ffi.rs b/src/ffi.rs index 8a9a6ee..c87d0ec 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -115,7 +115,7 @@ impl Xlib { } /// Load the Xlib library at runtime. - #[cfg_attr(coverage, no_coverage)] + #[cfg_attr(coverage, coverage(off))] #[cfg(not(feature = "dlopen"))] pub(crate) fn load() -> Result { #[link(name = "X11", kind = "dylib")] @@ -143,7 +143,7 @@ impl Xlib { } /// Load the Xlib library at runtime. - #[cfg_attr(coverage, no_coverage)] + #[cfg_attr(coverage, coverage(off))] #[cfg(feature = "dlopen")] pub(crate) fn load() -> Result { let xlib_library = unsafe { load_library(XLIB_LIBDIR, &["libX11.so.6", "libX11.so"]) }?; @@ -178,7 +178,7 @@ impl Xlib { } #[cfg(feature = "dlopen")] -#[cfg_attr(coverage, no_coverage)] +#[cfg_attr(coverage, coverage(off))] unsafe fn load_library( prefix: Option<&str>, names: &[&str], diff --git a/src/lib.rs b/src/lib.rs index 3d36a71..4a415b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -118,7 +118,7 @@ //! [`libloading`]: https://crates.io/crates/libloading #![allow(unused_unsafe)] -#![cfg_attr(coverage, feature(no_coverage))] +#![cfg_attr(coverage, feature(coverage_attribute))] mod ffi; @@ -135,7 +135,7 @@ use std::sync::{Mutex, MutexGuard, Once, PoisonError}; macro_rules! lock { ($e:expr) => {{ // Make sure this isn't flagged with coverage. - #[cfg_attr(coverage, no_coverage)] + #[cfg_attr(coverage, coverage(off))] fn unwrapper(guard: PoisonError>) -> MutexGuard<'_, T> { guard.into_inner() } @@ -146,7 +146,7 @@ macro_rules! lock { ctor_lite::ctor! { unsafe static XLIB: io::Result = { - #[cfg_attr(coverage, no_coverage)] + #[cfg_attr(coverage, coverage(off))] unsafe fn load_xlib_with_error_hook() -> io::Result { // Here's a puzzle: how do you *safely* add an error hook to Xlib? Like signal handling, there // is a single global error hook. Therefore, we need to make sure that we economize on the @@ -163,14 +163,14 @@ ctor_lite::ctor! { // sets the error hook to a dummy function, reads the resulting error hook into a static // variable, and then resets the error hook to the default function. This allows us to read // the default error hook and compare it to the one that we're setting. - #[cfg_attr(coverage, no_coverage)] + #[cfg_attr(coverage, coverage(off))] fn error(e: impl std::error::Error) -> io::Error { io::Error::new(io::ErrorKind::Other, format!("failed to load Xlib: {}", e)) } let xlib = ffi::Xlib::load().map_err(error)?; // Dummy function we use to set the error hook. - #[cfg_attr(coverage, no_coverage)] + #[cfg_attr(coverage, coverage(off))] unsafe extern "C" fn dummy( _display: *mut ffi::Display, _error: *mut ffi::XErrorEvent, @@ -199,7 +199,7 @@ ctor_lite::ctor! { #[inline] fn get_xlib(sym: &io::Result) -> io::Result<&ffi::Xlib> { // Eat coverage on the error branch. - #[cfg_attr(coverage, no_coverage)] + #[cfg_attr(coverage, coverage(off))] fn error(e: &io::Error) -> io::Error { io::Error::new(e.kind(), e.to_string()) } @@ -224,7 +224,7 @@ unsafe extern "C" fn error_handler( // Abort the program if the error hook panics. struct AbortOnPanic; impl Drop for AbortOnPanic { - #[cfg_attr(coverage, no_coverage)] + #[cfg_attr(coverage, coverage(off))] #[cold] #[inline(never)] fn drop(&mut self) { @@ -501,7 +501,7 @@ enum Slot { impl HandlerList { /// Create a new handler list. - #[cfg_attr(coverage, no_coverage)] + #[cfg_attr(coverage, coverage(off))] const fn new() -> Self { Self { slots: vec![], @@ -516,7 +516,7 @@ impl HandlerList { /// Returns the index of the handler. fn insert(&mut self, handler: ErrorHook) -> usize { // Eat the coverage for the unreachable branch. - #[cfg_attr(coverage, no_coverage)] + #[cfg_attr(coverage, coverage(off))] #[inline(always)] fn unwrapper(slot: &Slot) -> usize { match slot { @@ -570,7 +570,7 @@ struct ErrorHookSlot(Cell>); unsafe impl Sync for ErrorHookSlot {} impl ErrorHookSlot { - #[cfg_attr(coverage, no_coverage)] + #[cfg_attr(coverage, coverage(off))] const fn new() -> Self { Self(Cell::new(None)) } @@ -579,7 +579,7 @@ impl ErrorHookSlot { self.0.get() } - #[cfg_attr(coverage, no_coverage)] + #[cfg_attr(coverage, coverage(off))] unsafe fn set(&self, hook: ffi::XErrorHook) { self.0.set(Some(hook)); }