diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5b2877083..7d440fcd9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -118,6 +118,8 @@ jobs: path: compiler/parser/python.rs key: lalrpop-${{ hashFiles('compiler/parser/python.lalrpop') }} - uses: dtolnay/rust-toolchain@stable + with: + components: clippy - name: Set up the Windows environment shell: bash run: | @@ -128,6 +130,10 @@ jobs: run: brew install autoconf automake libtool if: runner.os == 'macOS' - uses: Swatinem/rust-cache@v1 + + - name: run clippy + run: cargo clippy ${{ env.CARGO_ARGS }} ${{ env.NON_WASM_PACKAGES }} -- -Dwarnings + - name: run rust tests run: cargo test --workspace --exclude rustpython_wasm --verbose --features threading ${{ env.CARGO_ARGS }} ${{ env.NON_WASM_PACKAGES }} - name: check compilation without threading @@ -331,8 +337,6 @@ jobs: components: rustfmt, clippy - name: run rustfmt run: cargo fmt --all -- --check - - name: run clippy - run: cargo clippy ${{ env.CARGO_ARGS }} ${{ env.NON_WASM_PACKAGES }} -- -Dwarnings - name: run clippy on wasm run: cargo clippy --manifest-path=wasm/lib/Cargo.toml -- -Dwarnings - uses: actions/setup-python@v2 diff --git a/stdlib/src/fcntl.rs b/stdlib/src/fcntl.rs index 795b57031..ee73e5039 100644 --- a/stdlib/src/fcntl.rs +++ b/stdlib/src/fcntl.rs @@ -163,22 +163,24 @@ mod fcntl { whence: OptionalArg, vm: &VirtualMachine, ) -> PyResult { + macro_rules! try_into_l_type { + ($l_type:path) => { + $l_type + .try_into() + .map_err(|e| vm.new_overflow_error(format!("{e}"))) + }; + } + let mut l: libc::flock = unsafe { std::mem::zeroed() }; - if cmd == libc::LOCK_UN { - l.l_type = libc::F_UNLCK - .try_into() - .map_err(|e| vm.new_overflow_error(format!("{e}")))?; + l.l_type = if cmd == libc::LOCK_UN { + try_into_l_type!(libc::F_UNLCK) } else if (cmd & libc::LOCK_SH) != 0 { - l.l_type = libc::F_RDLCK - .try_into() - .map_err(|e| vm.new_overflow_error(format!("{e}")))?; + try_into_l_type!(libc::F_RDLCK) } else if (cmd & libc::LOCK_EX) != 0 { - l.l_type = libc::F_WRLCK - .try_into() - .map_err(|e| vm.new_overflow_error(format!("{e}")))?; + try_into_l_type!(libc::F_WRLCK) } else { return Err(vm.new_value_error("unrecognized lockf argument".to_owned())); - } + }?; l.l_start = match start { OptionalArg::Present(s) => s.try_to_primitive(vm)?, OptionalArg::Missing => 0, diff --git a/stdlib/src/ssl.rs b/stdlib/src/ssl.rs index 73c3296d2..19316e4e2 100644 --- a/stdlib/src/ssl.rs +++ b/stdlib/src/ssl.rs @@ -1445,7 +1445,7 @@ mod windows { .iter() .filter_map(|open| open(store_name.as_str()).ok()) .collect::>(); - let certs = stores.iter().map(|s| s.certs()).flatten().map(|c| { + let certs = stores.iter().flat_map(|s| s.certs()).map(|c| { let cert = vm.ctx.new_bytes(c.to_der().to_owned()); let enc_type = unsafe { let ptr = c.as_ptr() as wincrypt::PCCERT_CONTEXT; diff --git a/vm/src/stdlib/winapi.rs b/vm/src/stdlib/winapi.rs index e9eceb0f2..68d6f5125 100644 --- a/vm/src/stdlib/winapi.rs +++ b/vm/src/stdlib/winapi.rs @@ -431,6 +431,6 @@ mod _winapi { } let (path, _) = path.split_at(length as usize); - Ok(String::from_utf16(&path).unwrap()) + Ok(String::from_utf16(path).unwrap()) } } diff --git a/vm/src/stdlib/winreg.rs b/vm/src/stdlib/winreg.rs index 71bdec42a..48b347c5f 100644 --- a/vm/src/stdlib/winreg.rs +++ b/vm/src/stdlib/winreg.rs @@ -191,7 +191,7 @@ mod winreg { key.with_key(|k| k.get_raw_value(subkey)) .map_err(|e| e.to_pyexception(vm)) .and_then(|regval| { - let ty = regval.vtype.clone() as usize; + let ty = regval.vtype as usize; Ok((reg_to_py(regval, vm)?, ty)) }) } @@ -221,7 +221,7 @@ mod winreg { }) .map_err(|e| e.to_pyexception(vm)) .and_then(|(name, value)| { - let ty = value.vtype.clone() as usize; + let ty = value.vtype as usize; Ok((name, reg_to_py(value, vm)?, ty)) }) }