From 13e958082070831bb71535389b78d3502d6d22b3 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Fri, 22 Nov 2024 01:47:20 +0900 Subject: [PATCH] Apply unqualified_local_imports lint --- bench/benches/bench.rs | 2 +- build.rs | 2 +- portable-atomic-util/build.rs | 2 +- portable-atomic-util/src/lib.rs | 2 +- src/cfgs.rs | 2 +- src/imp/atomic128/aarch64.rs | 18 +++++++++--------- src/imp/atomic128/intrinsics.rs | 2 +- src/imp/atomic128/powerpc64.rs | 8 ++++---- src/imp/atomic128/riscv64.rs | 6 +++--- src/imp/atomic128/s390x.rs | 2 +- src/imp/atomic128/x86_64.rs | 4 ++-- src/imp/atomic64/riscv32.rs | 6 +++--- src/imp/detect/auxv.rs | 4 ++-- src/imp/fallback/mod.rs | 8 +++++--- src/imp/interrupt/mod.rs | 2 +- src/lib.rs | 22 +++++++++++----------- src/tests/mod.rs | 2 +- tools/build.sh | 4 +++- 18 files changed, 51 insertions(+), 47 deletions(-) diff --git a/bench/benches/bench.rs b/bench/benches/bench.rs index 5f2b470d..21d78252 100644 --- a/bench/benches/bench.rs +++ b/bench/benches/bench.rs @@ -47,7 +47,7 @@ mod intrinsics; #[path = "../../src/imp/fallback/mod.rs"] mod seqlock_fallback; #[allow(unused_imports)] -use seqlock_fallback as fallback; +use self::seqlock_fallback as fallback; #[allow(dead_code, unused_imports)] #[path = "imp/spinlock_fallback.rs"] mod spinlock_fallback; diff --git a/build.rs b/build.rs index c7ae1064..4b5c2fea 100644 --- a/build.rs +++ b/build.rs @@ -6,7 +6,7 @@ #[path = "version.rs"] mod version; -use version::{rustc_version, Version}; +use self::version::{rustc_version, Version}; use std::{env, str}; diff --git a/portable-atomic-util/build.rs b/portable-atomic-util/build.rs index a8b95f37..b0638d1e 100644 --- a/portable-atomic-util/build.rs +++ b/portable-atomic-util/build.rs @@ -6,7 +6,7 @@ #[allow(dead_code)] #[path = "version.rs"] mod version; -use version::{rustc_version, Version}; +use self::version::{rustc_version, Version}; use std::env; diff --git a/portable-atomic-util/src/lib.rs b/portable-atomic-util/src/lib.rs index 3d0292d4..02a2c29d 100644 --- a/portable-atomic-util/src/lib.rs +++ b/portable-atomic-util/src/lib.rs @@ -72,7 +72,7 @@ extern crate std as alloc; #[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))] mod arc; #[cfg(any(all(feature = "alloc", not(portable_atomic_no_alloc)), feature = "std"))] -pub use arc::{Arc, Weak}; +pub use self::arc::{Arc, Weak}; #[cfg(not(portable_atomic_no_futures_api))] #[cfg(any(all(feature = "alloc", not(portable_atomic_no_alloc)), feature = "std"))] diff --git a/src/cfgs.rs b/src/cfgs.rs index 25eb534a..a30afe7f 100644 --- a/src/cfgs.rs +++ b/src/cfgs.rs @@ -626,7 +626,7 @@ mod check { crate::cfg_has_atomic_cas! { type __AtomicPtr = (); } crate::cfg_no_atomic_cas! { type __AtomicPtr = (); } #[allow(unused_imports)] - use { + use self::{ _Atomic128 as _, _Atomic16 as _, _Atomic32 as _, _Atomic64 as _, _Atomic8 as _, _AtomicPtr as _, __AtomicPtr as _, }; diff --git a/src/imp/atomic128/aarch64.rs b/src/imp/atomic128/aarch64.rs index a650a49d..3081cfc4 100644 --- a/src/imp/atomic128/aarch64.rs +++ b/src/imp/atomic128/aarch64.rs @@ -483,7 +483,7 @@ Note: // if compile_time(FEAT_LSE2) => ldp: // cfg guarantee that the CPU supports FEAT_LSE2. #[cfg(any(target_feature = "lse2", portable_atomic_target_feature = "lse2"))] -use _atomic_load_ldp as atomic_load; +use self::_atomic_load_ldp as atomic_load; #[cfg(not(any(target_feature = "lse2", portable_atomic_target_feature = "lse2")))] #[inline] unsafe fn atomic_load(src: *mut u128, order: Ordering) -> u128 { @@ -883,7 +883,7 @@ Note: // if compile_time(FEAT_LSE2) => stp: // cfg guarantee that the CPU supports FEAT_LSE2. #[cfg(any(target_feature = "lse2", portable_atomic_target_feature = "lse2"))] -use _atomic_store_stp as atomic_store; +use self::_atomic_store_stp as atomic_store; #[cfg(not(any(target_feature = "lse2", portable_atomic_target_feature = "lse2")))] #[inline] unsafe fn atomic_store(dst: *mut u128, val: u128, order: Ordering) { @@ -1579,15 +1579,15 @@ Note: any(target_feature = "lse", portable_atomic_target_feature = "lse"), not(portable_atomic_ll_sc_rmw), ))] -use _atomic_swap_casp as atomic_swap; +use self::_atomic_swap_casp as atomic_swap; #[cfg(not(any(target_feature = "lse128", portable_atomic_target_feature = "lse128")))] #[cfg(not(all( any(target_feature = "lse", portable_atomic_target_feature = "lse"), not(portable_atomic_ll_sc_rmw), )))] -use _atomic_swap_ldxp_stxp as atomic_swap; +use self::_atomic_swap_ldxp_stxp as atomic_swap; #[cfg(any(target_feature = "lse128", portable_atomic_target_feature = "lse128"))] -use _atomic_swap_swpp as atomic_swap; +use self::_atomic_swap_swpp as atomic_swap; #[cfg(any( target_feature = "lse128", portable_atomic_target_feature = "lse128", @@ -1750,7 +1750,7 @@ macro_rules! atomic_rmw_ll_sc_3 { any(target_feature = "lse", portable_atomic_target_feature = "lse"), not(portable_atomic_ll_sc_rmw), )))] - use $name as $reexport_name; + use self::$name as $reexport_name; #[cfg(any( test, not(all( @@ -1808,7 +1808,7 @@ macro_rules! atomic_rmw_cas_3 { any(target_feature = "lse", portable_atomic_target_feature = "lse"), not(portable_atomic_ll_sc_rmw), ))] - use $name as $reexport_name; + use self::$name as $reexport_name; #[cfg(any(test, not(portable_atomic_ll_sc_rmw)))] #[cfg(any(target_feature = "lse", portable_atomic_target_feature = "lse"))] #[inline] @@ -1876,7 +1876,7 @@ macro_rules! atomic_rmw_ll_sc_2 { any(target_feature = "lse", portable_atomic_target_feature = "lse"), not(portable_atomic_ll_sc_rmw), )))] - use $name as $reexport_name; + use self::$name as $reexport_name; #[cfg(any( test, not(all( @@ -1930,7 +1930,7 @@ macro_rules! atomic_rmw_cas_2 { any(target_feature = "lse", portable_atomic_target_feature = "lse"), not(portable_atomic_ll_sc_rmw), ))] - use $name as $reexport_name; + use self::$name as $reexport_name; #[cfg(any(test, not(portable_atomic_ll_sc_rmw)))] #[cfg(any(target_feature = "lse", portable_atomic_target_feature = "lse"))] #[inline] diff --git a/src/imp/atomic128/intrinsics.rs b/src/imp/atomic128/intrinsics.rs index 0341e0f4..8ae815b9 100644 --- a/src/imp/atomic128/intrinsics.rs +++ b/src/imp/atomic128/intrinsics.rs @@ -186,7 +186,7 @@ unsafe fn atomic_compare_exchange( } #[cfg(target_arch = "x86_64")] -use atomic_compare_exchange as atomic_compare_exchange_weak; +use self::atomic_compare_exchange as atomic_compare_exchange_weak; #[cfg(not(target_arch = "x86_64"))] #[inline] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces diff --git a/src/imp/atomic128/powerpc64.rs b/src/imp/atomic128/powerpc64.rs index 6e2e0a24..b87d1011 100644 --- a/src/imp/atomic128/powerpc64.rs +++ b/src/imp/atomic128/powerpc64.rs @@ -138,7 +138,7 @@ fn extract_cr0(r: u64) -> bool { target_feature = "quadword-atomics", portable_atomic_target_feature = "quadword-atomics", ))] -use atomic_load_pwr8 as atomic_load; +use self::atomic_load_pwr8 as atomic_load; // Otherwise, we need to do run-time detection and can use pwr8_fn only if quadword-atomics is available. #[cfg(not(any( target_feature = "quadword-atomics", @@ -250,7 +250,7 @@ unsafe fn atomic_load_pwr8(src: *mut u128, order: Ordering) -> u128 { target_feature = "quadword-atomics", portable_atomic_target_feature = "quadword-atomics", ))] -use atomic_store_pwr8 as atomic_store; +use self::atomic_store_pwr8 as atomic_store; // Otherwise, we need to do run-time detection and can use pwr8_fn only if quadword-atomics is available. #[cfg(not(any( target_feature = "quadword-atomics", @@ -428,7 +428,7 @@ unsafe fn atomic_compare_exchange_pwr8( target_feature = "quadword-atomics", portable_atomic_target_feature = "quadword-atomics", )))] -use atomic_compare_exchange as atomic_compare_exchange_weak; +use self::atomic_compare_exchange as atomic_compare_exchange_weak; #[cfg(any( target_feature = "quadword-atomics", portable_atomic_target_feature = "quadword-atomics", @@ -747,7 +747,7 @@ macro_rules! select_atomic_rmw { target_feature = "quadword-atomics", portable_atomic_target_feature = "quadword-atomics", ))] - use $pwr8_fn as $name; + use self::$pwr8_fn as $name; // Otherwise, we need to do run-time detection and can use pwr8_fn only if quadword-atomics is available. #[cfg(not(any( target_feature = "quadword-atomics", diff --git a/src/imp/atomic128/riscv64.rs b/src/imp/atomic128/riscv64.rs index 00c558c8..74fda982 100644 --- a/src/imp/atomic128/riscv64.rs +++ b/src/imp/atomic128/riscv64.rs @@ -111,7 +111,7 @@ macro_rules! atomic_rmw_amocas_order_insn { target_feature = "experimental-zacas", portable_atomic_target_feature = "experimental-zacas", ))] -use atomic_load_zacas as atomic_load; +use self::atomic_load_zacas as atomic_load; // Otherwise, we need to do run-time detection and can use zacas_fn only if zacas is available. #[cfg(not(any( target_feature = "experimental-zacas", @@ -367,7 +367,7 @@ unsafe fn atomic_compare_exchange_zacas( } // amocas is always strong. -use atomic_compare_exchange as atomic_compare_exchange_weak; +use self::atomic_compare_exchange as atomic_compare_exchange_weak; // 128-bit atomic load by two 64-bit atomic loads. (see arm_linux.rs for more) #[inline] @@ -424,7 +424,7 @@ macro_rules! select_atomic_rmw { target_feature = "experimental-zacas", portable_atomic_target_feature = "experimental-zacas", ))] - use $zacas_fn as $name; + use self::$zacas_fn as $name; // Otherwise, we need to do run-time detection and can use zacas_fn only if zacas is available. #[cfg(not(any( target_feature = "experimental-zacas", diff --git a/src/imp/atomic128/s390x.rs b/src/imp/atomic128/s390x.rs index ce1328eb..d77db40f 100644 --- a/src/imp/atomic128/s390x.rs +++ b/src/imp/atomic128/s390x.rs @@ -180,7 +180,7 @@ unsafe fn atomic_compare_exchange( } // cdsg is always strong. -use atomic_compare_exchange as atomic_compare_exchange_weak; +use self::atomic_compare_exchange as atomic_compare_exchange_weak; #[cfg(not(any( target_feature = "load-store-on-cond", diff --git a/src/imp/atomic128/x86_64.rs b/src/imp/atomic128/x86_64.rs index 4c80d1a5..5fc92a88 100644 --- a/src/imp/atomic128/x86_64.rs +++ b/src/imp/atomic128/x86_64.rs @@ -438,7 +438,7 @@ unsafe fn atomic_compare_exchange( } // cmpxchg16b is always strong. -use atomic_compare_exchange as atomic_compare_exchange_weak; +use self::atomic_compare_exchange as atomic_compare_exchange_weak; // See cmpxchg16b() for target_feature(enable). #[cfg_attr( @@ -747,7 +747,7 @@ macro_rules! select_atomic_rmw { ) => { // If cmpxchg16b is available at compile-time, we can always use cmpxchg16b_fn. #[cfg(any(target_feature = "cmpxchg16b", portable_atomic_target_feature = "cmpxchg16b"))] - use $cmpxchg16b_fn as $name; + use self::$cmpxchg16b_fn as $name; // Otherwise, we need to do run-time detection and can use cmpxchg16b_fn only if cmpxchg16b is available. #[cfg(not(any( target_feature = "cmpxchg16b", diff --git a/src/imp/atomic64/riscv32.rs b/src/imp/atomic64/riscv32.rs index 0db6b484..8e3084f8 100644 --- a/src/imp/atomic64/riscv32.rs +++ b/src/imp/atomic64/riscv32.rs @@ -113,7 +113,7 @@ macro_rules! atomic_rmw_amocas_order_insn { target_feature = "experimental-zacas", portable_atomic_target_feature = "experimental-zacas", ))] -use atomic_load_zacas as atomic_load; +use self::atomic_load_zacas as atomic_load; // Otherwise, we need to do run-time detection and can use zacas_fn only if zacas is available. #[cfg(not(any( target_feature = "experimental-zacas", @@ -369,7 +369,7 @@ unsafe fn atomic_compare_exchange_zacas( } // amocas is always strong. -use atomic_compare_exchange as atomic_compare_exchange_weak; +use self::atomic_compare_exchange as atomic_compare_exchange_weak; // 64-bit atomic load by two 32-bit atomic loads. (see arm_linux.rs for more) #[inline] @@ -426,7 +426,7 @@ macro_rules! select_atomic_rmw { target_feature = "experimental-zacas", portable_atomic_target_feature = "experimental-zacas", ))] - use $zacas_fn as $name; + use self::$zacas_fn as $name; // Otherwise, we need to do run-time detection and can use zacas_fn only if zacas is available. #[cfg(not(any( target_feature = "experimental-zacas", diff --git a/src/imp/detect/auxv.rs b/src/imp/detect/auxv.rs index b4e85a70..08e3b995 100644 --- a/src/imp/detect/auxv.rs +++ b/src/imp/detect/auxv.rs @@ -110,7 +110,7 @@ so we use it (see aarch64_aa64reg.rs). include!("common.rs"); -use os::ffi; +use self::os::ffi; #[cfg(any(target_os = "linux", target_os = "android"))] mod os { // core::ffi::c_* (except c_void) requires Rust 1.64, libc requires Rust 1.63 @@ -409,7 +409,7 @@ mod os { // Basically, Linux/FreeBSD/OpenBSD use the same hwcap values. // FreeBSD and OpenBSD usually support a subset of the hwcap values supported by Linux. -use arch::_detect; +use self::arch::_detect; #[cfg(target_arch = "aarch64")] mod arch { use super::{ffi, os, CpuInfo}; diff --git a/src/imp/fallback/mod.rs b/src/imp/fallback/mod.rs index 87202914..c2286d0e 100644 --- a/src/imp/fallback/mod.rs +++ b/src/imp/fallback/mod.rs @@ -108,13 +108,15 @@ cfg_no_fast_atomic_64! { use core::{cell::UnsafeCell, mem, sync::atomic::Ordering}; -use seq_lock::{SeqLock, SeqLockWriteGuard}; -use utils::CachePadded; +use self::{ + seq_lock::{SeqLock, SeqLockWriteGuard}, + utils::CachePadded, +}; // Some 64-bit architectures have ABI with 32-bit pointer width (e.g., x86_64 X32 ABI, // AArch64 ILP32 ABI, mips64 N32 ABI). On those targets, AtomicU64 is fast, // so use it to reduce chunks of byte-wise atomic memcpy. -use seq_lock::{AtomicChunk, Chunk}; +use self::seq_lock::{AtomicChunk, Chunk}; // Adapted from https://github.com/crossbeam-rs/crossbeam/blob/crossbeam-utils-0.8.7/crossbeam-utils/src/atomic/atomic_cell.rs#L969-L1016. #[inline] diff --git a/src/imp/interrupt/mod.rs b/src/imp/interrupt/mod.rs index 5db1846b..94fc4b76 100644 --- a/src/imp/interrupt/mod.rs +++ b/src/imp/interrupt/mod.rs @@ -42,7 +42,7 @@ See also README.md of this directory. // called while interrupts are disabled, and since the load/store is // atomic, it is not affected by interrupts even if interrupts are enabled. #[cfg(not(any(target_arch = "avr", feature = "critical-section")))] -use arch::atomic; +use self::arch::atomic; #[cfg(not(feature = "critical-section"))] #[cfg_attr( diff --git a/src/lib.rs b/src/lib.rs index 83c5fab6..48fa4c14 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -452,13 +452,13 @@ extern crate std; #[macro_use] mod cfgs; #[cfg(target_pointer_width = "128")] -pub use {cfg_has_atomic_128 as cfg_has_atomic_ptr, cfg_no_atomic_128 as cfg_no_atomic_ptr}; +pub use self::{cfg_has_atomic_128 as cfg_has_atomic_ptr, cfg_no_atomic_128 as cfg_no_atomic_ptr}; #[cfg(target_pointer_width = "16")] -pub use {cfg_has_atomic_16 as cfg_has_atomic_ptr, cfg_no_atomic_16 as cfg_no_atomic_ptr}; +pub use self::{cfg_has_atomic_16 as cfg_has_atomic_ptr, cfg_no_atomic_16 as cfg_no_atomic_ptr}; #[cfg(target_pointer_width = "32")] -pub use {cfg_has_atomic_32 as cfg_has_atomic_ptr, cfg_no_atomic_32 as cfg_no_atomic_ptr}; +pub use self::{cfg_has_atomic_32 as cfg_has_atomic_ptr, cfg_no_atomic_32 as cfg_no_atomic_ptr}; #[cfg(target_pointer_width = "64")] -pub use {cfg_has_atomic_64 as cfg_has_atomic_ptr, cfg_no_atomic_64 as cfg_no_atomic_ptr}; +pub use self::{cfg_has_atomic_64 as cfg_has_atomic_ptr, cfg_no_atomic_64 as cfg_no_atomic_ptr}; #[macro_use] mod utils; @@ -470,12 +470,12 @@ mod tests; #[doc(no_inline)] pub use core::sync::atomic::Ordering; -#[doc(no_inline)] // LLVM doesn't support fence/compiler_fence for MSP430. +#[cfg(target_arch = "msp430")] +pub use self::imp::msp430::{compiler_fence, fence}; +#[doc(no_inline)] #[cfg(not(target_arch = "msp430"))] pub use core::sync::atomic::{compiler_fence, fence}; -#[cfg(target_arch = "msp430")] -pub use imp::msp430::{compiler_fence, fence}; mod imp; @@ -4768,17 +4768,17 @@ cfg_has_atomic_128! { cfg_no_atomic_cas! { cfg_no_atomic_cas_or_amo32! { #[cfg(feature = "float")] -use diagnostic_helper::HasFetchAbs; -use diagnostic_helper::{ +use self::diagnostic_helper::HasFetchAbs; +use self::diagnostic_helper::{ HasAnd, HasBitClear, HasBitSet, HasBitToggle, HasFetchAnd, HasFetchByteAdd, HasFetchByteSub, HasFetchNot, HasFetchOr, HasFetchPtrAdd, HasFetchPtrSub, HasFetchXor, HasNot, HasOr, HasXor, }; } // cfg_no_atomic_cas_or_amo32! cfg_no_atomic_cas_or_amo8! { -use diagnostic_helper::{HasAdd, HasSub, HasSwap}; +use self::diagnostic_helper::{HasAdd, HasSub, HasSwap}; } // cfg_no_atomic_cas_or_amo8! #[cfg_attr(not(feature = "float"), allow(unused_imports))] -use diagnostic_helper::{ +use self::diagnostic_helper::{ HasCompareExchange, HasCompareExchangeWeak, HasFetchAdd, HasFetchMax, HasFetchMin, HasFetchNand, HasFetchNeg, HasFetchSub, HasFetchUpdate, HasNeg, }; diff --git a/src/tests/mod.rs b/src/tests/mod.rs index f4b6f02f..baee6821 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -196,7 +196,7 @@ fn test_is_lock_free() { // test version parsing code used in the build script. #[test] fn test_rustc_version() { - use version::Version; + use self::version::Version; // rustc 1.34 (rustup) let v = Version::parse( diff --git a/tools/build.sh b/tools/build.sh index 2c1b3621..15e7889c 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -236,6 +236,7 @@ else base_args=(hack "${subcmd}") fi nightly='' +base_rustflags="${RUSTFLAGS:-}" if [[ "${rustc_version}" =~ nightly|dev ]]; then nightly=1 if [[ -z "${is_custom_toolchain}" ]]; then @@ -246,6 +247,7 @@ if [[ "${rustc_version}" =~ nightly|dev ]]; then subcmd=clippy retry rustup ${pre_args[@]+"${pre_args[@]}"} component add clippy &>/dev/null base_args=(hack "${subcmd}") + base_rustflags+=' -Z crate-attr=feature(unqualified_local_imports) -W unqualified_local_imports' fi fi export CARGO_TARGET_DIR="${target_dir}" @@ -262,7 +264,7 @@ build() { local target="$1" shift local args=("${base_args[@]}") - local target_rustflags="${RUSTFLAGS:-}" + local target_rustflags="${base_rustflags}" if ! grep -Eq "^${target}$" <<<"${rustc_target_list}" || [[ -f "target-specs/${target}.json" ]]; then if [[ ! -f "target-specs/${target}.json" ]]; then printf '%s\n' "target '${target}' not available on ${rustc_version} (skipped all checks)"