Skip to content

Commit 22552cf

Browse files
committed
CI: run Clippy in a separate job
1 parent 79c29da commit 22552cf

File tree

7 files changed

+110
-46
lines changed

7 files changed

+110
-46
lines changed

.github/workflows/tests.yml

-36
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,6 @@ env:
1616
RUSTFLAGS: "-Dwarnings"
1717

1818
jobs:
19-
check-doc:
20-
name: Docs, deadlinks, minimal dependencies
21-
runs-on: ubuntu-22.04
22-
steps:
23-
- uses: actions/checkout@v3
24-
- uses: dtolnay/rust-toolchain@nightly # Needed for -Z minimal-versions and doc_cfg
25-
- name: Install precompiled cargo-deadlinks
26-
run: |
27-
VERSION=0.8.1
28-
URL="https://github.com/deadlinks/cargo-deadlinks/releases/download/${VERSION}/cargo-deadlinks-linux"
29-
wget -O ~/.cargo/bin/cargo-deadlinks $URL
30-
chmod +x ~/.cargo/bin/cargo-deadlinks
31-
cargo deadlinks --version
32-
- uses: Swatinem/rust-cache@v2
33-
- name: Generate Docs
34-
env:
35-
RUSTDOCFLAGS: --cfg docsrs
36-
run: cargo deadlinks -- --features=custom,std
37-
- run: |
38-
cargo generate-lockfile -Z minimal-versions
39-
cargo test --features=custom,std
40-
4119
main-tests:
4220
name: Tier 1 Test
4321
runs-on: ${{ matrix.os }}
@@ -385,17 +363,3 @@ jobs:
385363
targets: riscv32i-unknown-none-elf
386364
- uses: Swatinem/rust-cache@v2
387365
- run: cargo build --features custom --target riscv32i-unknown-none-elf
388-
389-
clippy-fmt:
390-
name: Clippy + rustfmt
391-
runs-on: ubuntu-22.04
392-
steps:
393-
- uses: actions/checkout@v1
394-
- uses: dtolnay/rust-toolchain@stable
395-
with:
396-
components: rustfmt, clippy
397-
- uses: Swatinem/rust-cache@v2
398-
- name: clippy
399-
run: cargo clippy --all --features=custom,std
400-
- name: fmt
401-
run: cargo fmt --all -- --check

.github/workflows/workspace.yml

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Workspace
2+
3+
on:
4+
push:
5+
branches: master
6+
pull_request:
7+
branches: master
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
clippy:
14+
name: Clippy
15+
runs-on: ubuntu-latest
16+
env:
17+
RUSTFLAGS: "-Dwarnings"
18+
steps:
19+
- uses: actions/checkout@v3
20+
- uses: dtolnay/rust-toolchain@master
21+
with:
22+
# We need Nightly for -Zbuild-std.
23+
# Fixed Nigthly version is used to prevent
24+
# CI failures which are not relevant to PR changes
25+
# on introduction of new Clippy lints.
26+
toolchain: nightly-2024-06-11
27+
components: clippy,rust-src
28+
- name: std feature
29+
run: cargo clippy --features std
30+
- name: custom feature
31+
run: cargo clippy -Zbuild-std=core --target riscv32i-unknown-none-elf --features custom
32+
- name: iOS (apple-other.rs)
33+
run: cargo clippy -Zbuild-std=core --target x86_64-apple-ios
34+
- name: ESP-IDF (espidf.rs)
35+
run: cargo clippy -Zbuild-std=core --target riscv32imc-esp-espidf
36+
- name: Fuchsia (fuchsia.rs)
37+
run: cargo clippy -Zbuild-std=core --target x86_64-unknown-fuchsia
38+
- name: OpenBSD (getentropy.rs)
39+
run: cargo clippy -Zbuild-std=core --target x86_64-unknown-openbsd
40+
- name: FreeBSD (getrandom.rs)
41+
run: cargo clippy -Zbuild-std=core --target x86_64-unknown-freebsd
42+
- name: Hermit (hermit.rs)
43+
run: cargo clippy -Zbuild-std=core --target x86_64-unknown-hermit
44+
- name: Web WASM (js.rs)
45+
run: cargo clippy -Zbuild-std --target wasm32-unknown-unknown --features js
46+
- name: Linux (linux_android.rs)
47+
run: cargo clippy --target x86_64-unknown-linux-gnu --features linux_disable_fallback
48+
- name: Linux (linux_android_with_fallback.rs)
49+
run: cargo clippy --target x86_64-unknown-linux-gnu
50+
- name: NetBSD (netbsd.rs)
51+
run: cargo clippy -Zbuild-std=core --target x86_64-unknown-netbsd
52+
- name: Fortranix SGX (rdrand.rs)
53+
run: cargo clippy -Zbuild-std=core --target x86_64-fortanix-unknown-sgx
54+
- name: Solaris (solaris.rs)
55+
run: cargo clippy -Zbuild-std=core --target x86_64-pc-solaris
56+
- name: SOLID (solid.rs)
57+
run: cargo clippy -Zbuild-std=core --target aarch64-kmc-solid_asp3
58+
- name: Redox (use_file.rs)
59+
run: cargo clippy -Zbuild-std=core --target x86_64-unknown-redox
60+
- name: VxWorks (vxworks.rs)
61+
run: cargo clippy -Zbuild-std=core --target x86_64-wrs-vxworks
62+
- name: WASI (wasi.rs)
63+
run: cargo clippy -Zbuild-std=core --target wasm32-wasip2
64+
- name: Windows 7 (windows7.rs)
65+
run: cargo clippy -Zbuild-std=core --target x86_64-win7-windows-msvc
66+
- name: Windows (windows.rs)
67+
run: cargo clippy -Zbuild-std=core --target x86_64-pc-windows-msvc
68+
69+
fmt:
70+
name: rustfmt
71+
runs-on: ubuntu-latest
72+
steps:
73+
- uses: actions/checkout@v1
74+
- uses: dtolnay/rust-toolchain@stable
75+
with:
76+
components: rustfmt
77+
- uses: Swatinem/rust-cache@v2
78+
- name: fmt
79+
run: cargo fmt --all -- --check
80+
81+
check-doc:
82+
name: rustdoc
83+
runs-on: ubuntu-latest
84+
steps:
85+
- uses: actions/checkout@v3
86+
- uses: dtolnay/rust-toolchain@master
87+
with:
88+
# We need Nightly for doc_auto_cfg
89+
toolchain: nightly-2024-06-11
90+
- uses: Swatinem/rust-cache@v2
91+
- name: Generate Docs
92+
env:
93+
RUSTDOCFLAGS: "-Dwarnings --cfg docsrs"
94+
run: cargo doc --no-deps --features custom

src/lazy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(crate) struct LazyUsize(AtomicUsize);
2626

2727
impl LazyUsize {
2828
// The initialization is not completed.
29-
const UNINIT: usize = usize::max_value();
29+
const UNINIT: usize = usize::MAX;
3030

3131
pub const fn new() -> Self {
3232
Self(AtomicUsize::new(Self::UNINIT))

src/use_file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use core::{
1717
/// - On AIX, /dev/urandom will "provide cryptographically secure output".
1818
/// - On Haiku and QNX Neutrino they are identical.
1919
const FILE_PATH: &[u8] = b"/dev/urandom\0";
20-
const FD_UNINIT: usize = usize::max_value();
20+
const FD_UNINIT: usize = usize::MAX;
2121

2222
// Do not inline this when it is the fallback implementation, but don't mark it
2323
// `#[cold]` because it is hot when it is actually used.

src/vxworks.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Implementation for VxWorks
22
use crate::{util_libc::last_os_error, Error};
33
use core::{
4+
cmp::Ordering::{Equal, Greater, Less},
45
mem::MaybeUninit,
56
sync::atomic::{AtomicBool, Ordering::Relaxed},
67
};
@@ -9,17 +10,21 @@ pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
910
static RNG_INIT: AtomicBool = AtomicBool::new(false);
1011
while !RNG_INIT.load(Relaxed) {
1112
let ret = unsafe { libc::randSecure() };
12-
if ret < 0 {
13-
return Err(Error::VXWORKS_RAND_SECURE);
14-
} else if ret > 0 {
15-
RNG_INIT.store(true, Relaxed);
16-
break;
13+
match ret.cmp(&0) {
14+
Greater => {
15+
RNG_INIT.store(true, Relaxed);
16+
break;
17+
}
18+
Equal => unsafe {
19+
libc::usleep(10);
20+
},
21+
Less => return Err(Error::VXWORKS_RAND_SECURE),
1722
}
18-
unsafe { libc::usleep(10) };
1923
}
2024

2125
// Prevent overflow of i32
22-
for chunk in dest.chunks_mut(i32::max_value() as usize) {
26+
let chunk_size = usize::try_from(i32::MAX).expect("VxWorks does not support 16-bit targets");
27+
for chunk in dest.chunks_mut(chunk_size) {
2328
let ret = unsafe { libc::randABytes(chunk.as_mut_ptr().cast::<u8>(), chunk.len() as i32) };
2429
if ret != 0 {
2530
return Err(last_os_error());

src/windows.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
//! - Requires advapi32.dll (in addition to bcryptprimitives.dll)
1919
//! - Requires using name "SystemFunction036"
2020
//! - Thin wrapper around ProcessPrng
21+
//!
2122
//! For more information see the Windows RNG Whitepaper: https://aka.ms/win10rng
2223
use crate::Error;
2324
use core::mem::MaybeUninit;

src/windows7.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const TRUE: BOOLEAN = 1u8;
2525

2626
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
2727
// Prevent overflow of u32
28-
for chunk in dest.chunks_mut(u32::max_value() as usize) {
28+
for chunk in dest.chunks_mut(u32::MAX as usize) {
2929
let ret = unsafe { RtlGenRandom(chunk.as_mut_ptr().cast::<c_void>(), chunk.len() as u32) };
3030
if ret != TRUE {
3131
return Err(Error::WINDOWS_RTL_GEN_RANDOM);

0 commit comments

Comments
 (0)