From b522f2b9b53fcca95f32d325d476111798c381a0 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Thu, 29 May 2025 13:53:27 +0200 Subject: [PATCH 1/3] uucore: Use next_back on PathBuf's DoubleEndedIterator As recommended by clippy, last() needlessly goes through the whole path while next_back() is available. --- src/uucore/src/lib/features/proc_info.rs | 2 +- src/uucore/src/lib/features/tty.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uucore/src/lib/features/proc_info.rs b/src/uucore/src/lib/features/proc_info.rs index 7ea54a85a..3f5334d10 100644 --- a/src/uucore/src/lib/features/proc_info.rs +++ b/src/uucore/src/lib/features/proc_info.rs @@ -164,7 +164,7 @@ impl ProcessInformation { let pid = { value .iter() - .last() + .next_back() .ok_or(io::ErrorKind::Other)? .to_str() .ok_or(io::ErrorKind::InvalidData)? diff --git a/src/uucore/src/lib/features/tty.rs b/src/uucore/src/lib/features/tty.rs index 6854ba164..221ee442d 100644 --- a/src/uucore/src/lib/features/tty.rs +++ b/src/uucore/src/lib/features/tty.rs @@ -73,7 +73,7 @@ impl TryFrom for Teletype { let f = |prefix: &str| { value .iter() - .last()? + .next_back()? .to_str()? .strip_prefix(prefix)? .parse::() From 7854efc8021d8a66dd93f757a0e16d4c28c8f127 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Thu, 29 May 2025 13:35:25 +0200 Subject: [PATCH 2/3] code-quality.yml: Clippy with --all-features and --workspace on ubuntu Without this, some uucore packages are not properly tested. --- .github/workflows/code-quality.yml | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 6323d2d78..a5bbf42af 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -78,7 +78,7 @@ jobs: fail-fast: false matrix: job: - - { os: ubuntu-latest , features: feat_os_unix } + - { os: ubuntu-latest , features: all , workspace: true } - { os: macos-latest , features: feat_os_macos } - { os: windows-latest , features: feat_os_windows } steps: @@ -104,6 +104,16 @@ jobs: *) FAIL_ON_FAULT=true ; FAULT_TYPE=error ;; esac; outputs FAIL_ON_FAULT FAULT_TYPE + - name: Install/setup prerequisites + shell: bash + run: | + ## Install/setup prerequisites + case '${{ matrix.job.os }}' in + ubuntu-*) + # selinux headers needed to enable all features + sudo apt-get -y install libselinux1-dev + ;; + esac - name: "`cargo clippy` lint testing" uses: nick-fields/retry@v3 with: @@ -117,7 +127,17 @@ jobs: fault_type="${{ steps.vars.outputs.FAULT_TYPE }}" fault_prefix=$(echo "$fault_type" | tr '[:lower:]' '[:upper:]') # * convert any warnings to GHA UI annotations; ref: - S=$(cargo clippy --all-targets --features ${{ matrix.job.features }} --tests -pcoreutils -- -D warnings 2>&1) && printf "%s\n" "$S" || { printf "%s\n" "$S" ; printf "%s" "$S" | sed -E -n -e '/^error:/{' -e "N; s/^error:[[:space:]]+(.*)\\n[[:space:]]+-->[[:space:]]+(.*):([0-9]+):([0-9]+).*$/::${fault_type} file=\2,line=\3,col=\4::${fault_prefix}: \`cargo clippy\`: \1 (file:'\2', line:\3)/p;" -e '}' ; fault=true ; } + if [[ "${{ matrix.job.features }}" == "all" ]]; then + extra="--all-features" + else + extra="--features ${{ matrix.job.features }}" + fi + case '${{ matrix.job.workspace-tests }}' in + 1|t|true|y|yes) + extra="${extra} --workspace" + ;; + esac + S=$(cargo clippy --all-targets $extra --tests -pcoreutils -- -D warnings 2>&1) && printf "%s\n" "$S" || { printf "%s\n" "$S" ; printf "%s" "$S" | sed -E -n -e '/^error:/{' -e "N; s/^error:[[:space:]]+(.*)\\n[[:space:]]+-->[[:space:]]+(.*):([0-9]+):([0-9]+).*$/::${fault_type} file=\2,line=\3,col=\4::${fault_prefix}: \`cargo clippy\`: \1 (file:'\2', line:\3)/p;" -e '}' ; fault=true ; } if [ -n "${{ steps.vars.outputs.FAIL_ON_FAULT }}" ] && [ -n "$fault" ]; then exit 1 ; fi style_spellcheck: From 7f05fca1aebbead5e95ba9b2f431ae24ee8d3e76 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Thu, 29 May 2025 13:34:51 +0200 Subject: [PATCH 3/3] .pre-commit-config.yaml: Match config in CI We need to enable -D warnings to get the same behaviour. --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 53e879d09..b840b9ed3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: - id: rust-clippy name: Rust clippy description: Run cargo clippy on files included in the commit. - entry: cargo +stable clippy --workspace --all-targets --all-features -- + entry: cargo +stable clippy --workspace --all-targets --all-features -- -D warnings pass_filenames: false types: [file, rust] language: system