From 50901b4f20955ec95972e62793ddb1c5d0134766 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 30 Jul 2023 08:34:45 +0200 Subject: [PATCH 1/2] Use <[u8]>::escape_ascii() Rust 1.60 added the escape_ascii() function on slices of u8. This produces an iterator with items u8 that provides escapement in the style of std::ascii::escape_default(). The returned iterator implements Display, thus we can just pass it directly to write!() to get the resulting escaped string. The above allows to simplify some hand-written version doing the same. Signed-off-by: Uli Schlachter --- x11rb/src/errors.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/x11rb/src/errors.rs b/x11rb/src/errors.rs index 49643c20..9bae2b1e 100644 --- a/x11rb/src/errors.rs +++ b/x11rb/src/errors.rs @@ -26,11 +26,7 @@ impl std::fmt::Display for LibxcbLoadError { LibxcbLoadError::GetSymbolError(symbol, e) => write!( f, "failed to get symbol \"{}\": {}", - symbol - .iter() - .flat_map(|&c| std::ascii::escape_default(c)) - .map(char::from) - .collect::(), + symbol.escape_ascii(), e, ), } From dac5e1c60e392f5580a7296da71fbc939c69a1c6 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 30 Jul 2023 08:45:12 +0200 Subject: [PATCH 2/2] Only use cfg(target_has_atomic) Commit 72d70aac234a2693 added a fallback for older Rust versions that did not yet have cfg(target_has_atomic), which was stabilised in Rust 1.61. Now that our MSRV is above that, we can remove the extra code. Signed-off-by: Uli Schlachter --- x11rb/build.rs | 55 --------------------------------- x11rb/src/xcb_ffi/atomic_u64.rs | 8 ++--- 2 files changed, 4 insertions(+), 59 deletions(-) delete mode 100644 x11rb/build.rs diff --git a/x11rb/build.rs b/x11rb/build.rs deleted file mode 100644 index 94f0df13..00000000 --- a/x11rb/build.rs +++ /dev/null @@ -1,55 +0,0 @@ -// The build constants emitted by this script are NOT public API. - -fn main() { - // Get the current Rust version. - let rust_version = Version::get(); - - // If we in a version prior to Rust 1.61, we can't use the "target_has_atomic" feature. - // - // This feature was stabilized in Rust 1.60, but some nightlies will claim to be 1.60 - // but not have the feature. Rust 1.61 lets us safely target nightlies without this feature. - // - // We use a negative implementation of the cfg guard, rather than emitting, say, a - // "x11rb_has_target_has_atomic" cfg guard. This is because some non-Cargo build systems - // will not run the build script. In this case, it is best to assume that we are targeting - // the latest stable version of Rust, where this feature is available. In this case, the absence - // of this cfg guard will indicate the available feature. - // - // TODO(notgull): Once the MSRV is raised to 1.60 or higher, this entire build script can be deleted. - if rust_version.major < 1 || (rust_version.major == 1 && rust_version.minor < 61) { - println!("cargo:rustc-cfg=x11rb_no_target_has_atomic"); - } -} - -struct Version { - major: usize, - minor: usize, -} - -impl Version { - fn get() -> Self { - let rustc = std::env::var_os("RUSTC").unwrap_or_else(|| "rustc".into()); - let output = std::process::Command::new(rustc) - .args(["--version", "--verbose"]) - .output() - .expect("failed to execute rustc"); - - let stdout = std::str::from_utf8(&output.stdout).expect("rustc stdout is not utf8"); - - // Find the line with the "release" tag - let release = stdout - .lines() - .find_map(|line| line.strip_prefix("release: ")) - .expect("rustc output does not contain release tag"); - - // Strip off the extra channel info. - let release = release.split('-').next().unwrap(); - - // Split into semver components. - let mut release = release.splitn(3, '.'); - let major = release.next().unwrap().parse().unwrap(); - let minor = release.next().unwrap().parse().unwrap(); - - Version { major, minor } - } -} diff --git a/x11rb/src/xcb_ffi/atomic_u64.rs b/x11rb/src/xcb_ffi/atomic_u64.rs index 89bff9ec..9ce37d5e 100644 --- a/x11rb/src/xcb_ffi/atomic_u64.rs +++ b/x11rb/src/xcb_ffi/atomic_u64.rs @@ -1,11 +1,11 @@ //! Either `AtomicU64` or emulating `AtomicU64` through a `Mutex`. // Use the `AtomicU64` from the standard library if we're on a platform that supports atomic -// 64-bit operations. If we can't tell, just fall back to the `Mutex` implementation anyways. -#[cfg(all(not(x11rb_no_target_has_atomic), target_has_atomic = "64"))] +// 64-bit operations. +#[cfg(target_has_atomic = "64")] pub(crate) use std::sync::atomic::AtomicU64; -#[cfg(any(x11rb_no_target_has_atomic, not(target_has_atomic = "64")))] +#[cfg(not(target_has_atomic = "64"))] mod impl_ { use std::sync::atomic::Ordering; use std::sync::Mutex; @@ -31,5 +31,5 @@ mod impl_ { } } -#[cfg(any(x11rb_no_target_has_atomic, not(target_has_atomic = "64")))] +#[cfg(not(target_has_atomic = "64"))] pub(crate) use self::impl_::AtomicU64;