Skip to content

Make Clippy stricter #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ jobs:
toolchain: stable
profile: minimal
components: rustfmt, clippy
- run: |
- env:
CLIPPYFLAGS: --deny warnings --allow clippy::needless-lifetimes
run: |
cargo fmt --all -- --check
cargo clippy --tests
for example in examples/*; do (cd $example/; cargo clippy) || exit 1; done
cargo clippy --tests -- $CLIPPYFLAGS
for example in examples/*; do (cd $example/; cargo clippy -- $CLIPPYFLAGS) || exit 1; done

test:
name: python${{ matrix.python-version }}-${{ matrix.platform.python-architecture }} ${{ matrix.platform.os }}
Expand Down
2 changes: 1 addition & 1 deletion src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
ID: IntoDimension<Dim = D>,
{
let dims = dims.into_dimension();
let data_ptr = data_ptr.unwrap_or(boxed_slice.as_ptr());
let data_ptr = data_ptr.unwrap_or_else(|| boxed_slice.as_ptr());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have pointed out when reviewing (I thought recent clippy is OK with this...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, current nightly Clippy actually wants the version without the closure whereas current stable Clippy complains about it. I think nightly Clippy is right, as boxed_slice.as_ptr() does not cost anything that should be delayed by wrapping it in a closure. So I expect to change this again with the next stable Clippy release. But as written above, the most important thing is to have a systematic check of this stuff via the CI.

let container = SliceBox::new(boxed_slice);
let cell = pyo3::PyClassInitializer::from(container)
.create_cell(py)
Expand Down