Skip to content
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

Run clippy in the CI with warnings disallowed; address most warnings #1412

Merged
merged 4 commits into from
Jun 15, 2022

Conversation

MarijnS95
Copy link
Member

@MarijnS95 MarijnS95 commented May 28, 2022

Depends on #1413 + #1408.

This is a draft mainly to look at how cargo clippy --fix and myself have addressed warnings for most issues. There are still a few remaining, and clippy found some odd/fishy things we should look into.

  • Tested on all platforms changed
    • Android + EGL;
    • Wayland + EGL;
    • Wayland + EGL on sharing example (doesn't run at all, but has nontrivial clippy warnings);
    • Windows.
  • Compilation warnings were addressed
  • cargo fmt has been run on this branch
  • cargo doc builds successfully
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality

glutin/src/api/glx/mod.rs Outdated Show resolved Hide resolved
glutin/src/api/egl/mod.rs Outdated Show resolved Hide resolved
@MarijnS95 MarijnS95 force-pushed the clippy branch 2 times, most recently from 6ca97fc to f077c8e Compare May 28, 2022 17:47
@MarijnS95 MarijnS95 force-pushed the clippy branch 4 times, most recently from 07b83e6 to 2d3236c Compare June 5, 2022 15:30
@MarijnS95
Copy link
Member Author

Looks like nightly clippy is throwing some false-positives on objc::msg_send![]'s return-type annotation https://docs.rs/objc/latest/objc/#messaging-objects.

That raises the question: is it desired to run nightly clippy? I'm personally all in favour of having clippy in the CI (some call it low signal-to-noise ratio, I find it making the code more pleasant to read), but nightly clippy is a bit overzealous. It has a high amount of false-positives compared to the actual future-proofing one might get; better wait for the stabilized version.

So for now this PR will only run stable clippy :)

@MarijnS95 MarijnS95 marked this pull request as ready for review June 5, 2022 15:30
@kchibisov
Copy link
Member

Running on nightly doesn't make much sense, except if the target requires nightly for whatever reason. Just stable is enough, I guess.

@MarijnS95
Copy link
Member Author

Doing that now, and all checks succeed 🎉 - what's your thought about getting the other PRs and this one in?

@MarijnS95 MarijnS95 mentioned this pull request Jun 5, 2022
glutin/src/api/ios/mod.rs Outdated Show resolved Hide resolved
@MarijnS95 MarijnS95 force-pushed the clippy branch 2 times, most recently from 11f0fd9 to 9a62def Compare June 7, 2022 18:20
Copy link
Member

@kchibisov kchibisov left a comment

Choose a reason for hiding this comment

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

Actually, could you add into lib.rs of each crate.

#![deny(clippy::all)
#![cfg_attr(feature = "cargo-clippy", deny(warnings))]

Instead of denying on CI?

@MarijnS95
Copy link
Member Author

@kchibisov What would be the advantage of those annotations? I personally don't like disallowing all clippy warnings during development, it doesn't allow contributors to compile code when perhaps having one or two testing variables / functions commented out.

Secondly, what's the advantage of disallowing normal rustc warnings through a cargo-clippy feature? I don't think I've seen such a setup yet.

@kchibisov
Copy link
Member

kchibisov commented Jun 7, 2022

@kchibisov What would be the advantage of those annotations?

I mean that with those two you can compile normally, but when you run clippy everything errors out. The intention is to error out on clippy, while allowing checks/builds to throw warnings as usual.

Secondly, what's the advantage of disallowing normal rustc warnings through a cargo-clippy feature? I don't think I've seen such a setup yet.

That's what we're using in alacritty for years. Basically it means: "when running clippy, treat all rustc warnings as errors".

@MarijnS95
Copy link
Member Author

MarijnS95 commented Jun 8, 2022

I mean that with those two you can compile normally, but when you run clippy everything errors out. The intention is to error out on clippy, while allowing checks/builds to throw warnings as usual.

Right, yes. I use clippy in rust-analyzer (to see clippy lints directly in my editor, instead of only rustc warnings) and it typically stops linting on the first crate that encounters errors (deny, -Dwarnings) meaning it was not working on glutin_examples until #1408/#1413 were addressed (both are deny lints).

Strangely enough it seems to be fine now, without those commits 🤷

That's what we're using in alacritty for years. Basically it means: "when running clippy, treat all rustc warnings as errors".

Ack, understood. I have previously seen but forgot that cargo-clippy is an actual feature (not cfg) that's enabled inside crates when "compiling" code under clippy.

Do you mind if I leave deny(clippy::all) out? That group consists of warn/deny lints only, and is already unambiguously covered by #![cfg_attr(feature = "cargo-clippy", deny(warnings))]. For example:

note: `#[deny(clippy::missing_safety_doc)]` implied by `#[deny(warnings)]`

Instead of denying on CI?

Do you mind if I leave this? In the hypothetical case that a new crate is added? Otherwise this should also be added to every binary (test/example) target.

I think that's the downside of this approach: having to add it to every target and not forgetting it on new targets. IMHO it's fine for users to push and open a PR, and address remaining lints after the fact. They usually won't (be able to) test/lint against every target / feature combination anyway. If they run clippy on their own accord at all :)

@kchibisov
Copy link
Member

Do you mind if I leave deny(clippy::all) out? That group consists of warn/deny lints only, and is already unambiguously covered by #![cfg_attr(feature = "cargo-clippy", deny(warnings))]. For example:

That's fine. You can go ahead.

@MarijnS95
Copy link
Member Author

@kchibisov I think I did that in the last push, would you mind re-reviewing this now? What's your suggestion on the sharing example, the drop-changes seem trivial yet against intended usage, but I can't test it on my machine.

@kchibisov
Copy link
Member

@MarijnS95 sharing is also failing for me. It could be failing that way for a long time on Wayland, and I won't be surprised. Not sure that we should bother with it here since it's not something new.

@MarijnS95
Copy link
Member Author

@kchibisov Perfect, let's go for it then. If you can review this once more and approve it, I'll fix the conflict and re-push!

Copy link
Member

@kchibisov kchibisov left a comment

Choose a reason for hiding this comment

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

Just a small nits I've found after re-review.

glutin/src/api/egl/mod.rs Outdated Show resolved Hide resolved
glutin/src/api/egl/mod.rs Outdated Show resolved Hide resolved
@MarijnS95 MarijnS95 requested a review from kchibisov June 10, 2022 11:15
@MarijnS95
Copy link
Member Author

Nice catch, I hadn't spotted that one in the automatic clippy --fix diff :)

@MarijnS95 MarijnS95 merged commit 4e55db7 into rust-windowing:master Jun 15, 2022
@MarijnS95 MarijnS95 deleted the clippy branch June 15, 2022 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants