Skip to content

Commit 1cb7f4d

Browse files
authored
Merge pull request RustPython#4214 from youknowone/platform-clippy
Add platform-dependent clippy running to CI
2 parents ef887ad + 185e0cb commit 1cb7f4d

File tree

5 files changed

+23
-17
lines changed

5 files changed

+23
-17
lines changed

.github/workflows/ci.yaml

+6-2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ jobs:
118118
path: compiler/parser/python.rs
119119
key: lalrpop-${{ hashFiles('compiler/parser/python.lalrpop') }}
120120
- uses: dtolnay/rust-toolchain@stable
121+
with:
122+
components: clippy
121123
- name: Set up the Windows environment
122124
shell: bash
123125
run: |
@@ -128,6 +130,10 @@ jobs:
128130
run: brew install autoconf automake libtool
129131
if: runner.os == 'macOS'
130132
- uses: Swatinem/rust-cache@v1
133+
134+
- name: run clippy
135+
run: cargo clippy ${{ env.CARGO_ARGS }} ${{ env.NON_WASM_PACKAGES }} -- -Dwarnings
136+
131137
- name: run rust tests
132138
run: cargo test --workspace --exclude rustpython_wasm --verbose --features threading ${{ env.CARGO_ARGS }} ${{ env.NON_WASM_PACKAGES }}
133139
- name: check compilation without threading
@@ -331,8 +337,6 @@ jobs:
331337
components: rustfmt, clippy
332338
- name: run rustfmt
333339
run: cargo fmt --all -- --check
334-
- name: run clippy
335-
run: cargo clippy ${{ env.CARGO_ARGS }} ${{ env.NON_WASM_PACKAGES }} -- -Dwarnings
336340
- name: run clippy on wasm
337341
run: cargo clippy --manifest-path=wasm/lib/Cargo.toml -- -Dwarnings
338342
- uses: actions/setup-python@v2

stdlib/src/fcntl.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,24 @@ mod fcntl {
163163
whence: OptionalArg<i32>,
164164
vm: &VirtualMachine,
165165
) -> PyResult {
166+
macro_rules! try_into_l_type {
167+
($l_type:path) => {
168+
$l_type
169+
.try_into()
170+
.map_err(|e| vm.new_overflow_error(format!("{e}")))
171+
};
172+
}
173+
166174
let mut l: libc::flock = unsafe { std::mem::zeroed() };
167-
if cmd == libc::LOCK_UN {
168-
l.l_type = libc::F_UNLCK
169-
.try_into()
170-
.map_err(|e| vm.new_overflow_error(format!("{e}")))?;
175+
l.l_type = if cmd == libc::LOCK_UN {
176+
try_into_l_type!(libc::F_UNLCK)
171177
} else if (cmd & libc::LOCK_SH) != 0 {
172-
l.l_type = libc::F_RDLCK
173-
.try_into()
174-
.map_err(|e| vm.new_overflow_error(format!("{e}")))?;
178+
try_into_l_type!(libc::F_RDLCK)
175179
} else if (cmd & libc::LOCK_EX) != 0 {
176-
l.l_type = libc::F_WRLCK
177-
.try_into()
178-
.map_err(|e| vm.new_overflow_error(format!("{e}")))?;
180+
try_into_l_type!(libc::F_WRLCK)
179181
} else {
180182
return Err(vm.new_value_error("unrecognized lockf argument".to_owned()));
181-
}
183+
}?;
182184
l.l_start = match start {
183185
OptionalArg::Present(s) => s.try_to_primitive(vm)?,
184186
OptionalArg::Missing => 0,

stdlib/src/ssl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ mod windows {
14451445
.iter()
14461446
.filter_map(|open| open(store_name.as_str()).ok())
14471447
.collect::<Vec<_>>();
1448-
let certs = stores.iter().map(|s| s.certs()).flatten().map(|c| {
1448+
let certs = stores.iter().flat_map(|s| s.certs()).map(|c| {
14491449
let cert = vm.ctx.new_bytes(c.to_der().to_owned());
14501450
let enc_type = unsafe {
14511451
let ptr = c.as_ptr() as wincrypt::PCCERT_CONTEXT;

vm/src/stdlib/winapi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,6 @@ mod _winapi {
431431
}
432432

433433
let (path, _) = path.split_at(length as usize);
434-
Ok(String::from_utf16(&path).unwrap())
434+
Ok(String::from_utf16(path).unwrap())
435435
}
436436
}

vm/src/stdlib/winreg.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ mod winreg {
191191
key.with_key(|k| k.get_raw_value(subkey))
192192
.map_err(|e| e.to_pyexception(vm))
193193
.and_then(|regval| {
194-
let ty = regval.vtype.clone() as usize;
194+
let ty = regval.vtype as usize;
195195
Ok((reg_to_py(regval, vm)?, ty))
196196
})
197197
}
@@ -221,7 +221,7 @@ mod winreg {
221221
})
222222
.map_err(|e| e.to_pyexception(vm))
223223
.and_then(|(name, value)| {
224-
let ty = value.vtype.clone() as usize;
224+
let ty = value.vtype as usize;
225225
Ok((name, reg_to_py(value, vm)?, ty))
226226
})
227227
}

0 commit comments

Comments
 (0)