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

Deny rust_2018_idioms and unused_qualifications in crate roots #2739

Closed
MarijnS95 opened this issue Dec 12, 2023 · 10 comments · Fixed by #2741 or #2743
Closed

Deny rust_2018_idioms and unused_qualifications in crate roots #2739

MarijnS95 opened this issue Dec 12, 2023 · 10 comments · Fixed by #2741 or #2743
Labels
enhancement New feature or request

Comments

@MarijnS95
Copy link
Contributor

Suggestion

When using a local path reference to the windows-rs crate, from a project that denies a bunch of lints globally (via rustflags in .cargo/config.toml until workspace lints get implicit/forced inheritance), there are quite a few warnings from the windows crate which would be trivial and neat to resolve.

Most/all originate from the rust_2018_idioms lint (and a few more like unused_qualifications, I think https://github.com/ash-rs/ash/blob/e6d80badc389d94e2a747f442e5ed4189b66d7d3/ash/src/lib.rs#L1-L8 might be a good starting point). This lint isn't enabled by default despite windows already setting edition = "2021", and certain things like extern crate might be nice to clear out.

Some samples:

warning: unused extern crate
  --> windows-rs\crates\libs\windows\src\lib.rs:11:1
   |
11 | extern crate self as windows;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it
   |
   = note: `-W unused-extern-crates` implied by `-W rust-2018-idioms`
   = help: to override `-W rust-2018-idioms` add `#[allow(unused_extern_crates)]`
warning: unnecessary qualification
  --> windows-rs\crates\libs\core\src\strings\bstr.rs:87:21
   |
87 |     fn from(value: &std::string::String) -> Self {
   |                     ^^^^^^^^^^^^^^^^^^^
   |
help: remove the unnecessary path segments
   |
87 -     fn from(value: &std::string::String) -> Self {
87 +     fn from(value: &String) -> Self {
   |
warning: hidden lifetime parameters in types are deprecated
   --> windows-rs\crates\libs\implement\src\lib.rs:241:34
    |
241 |     fn parse(cursor: syn::parse::ParseStream) -> syn::parse::Result<Self> {
    |                      ------------^^^^^^^^^^^
    |                      |
    |                      expected lifetime parameter
    |
    = note: `-W elided-lifetimes-in-paths` implied by `-W rust-2018-idioms`
    = help: to override `-W rust-2018-idioms` add `#[allow(elided_lifetimes_in_paths)]`
help: indicate the anonymous lifetime
    |
241 |     fn parse(cursor: syn::parse::ParseStream<'_>) -> syn::parse::Result<Self> {
    |                                             ++++
@MarijnS95 MarijnS95 added the enhancement New feature or request label Dec 12, 2023
@kennykerr
Copy link
Collaborator

Happy to tighten this up if there's a way to do so without adding more attributes to the various crates. Perhaps with a clippy config file, like rustfmt.toml, or through the yml workflows.

Note that the warning about the "unused extern crate" is a false positive and it is in fact needed.

@MarijnS95 MarijnS95 changed the title Deny rust_2018_idioms in crate roots Deny rust_2018_idioms and unused_qualifications in crate roots Dec 12, 2023
@MarijnS95
Copy link
Contributor Author

Note that the warning about the "unused extern crate" is a false positive and it is in fact needed.

Most are valid, especially in the custom .rs files for strings (self::convert::From, self::string::String etc), they're all part of the prelude and not shadowed.

@MarijnS95
Copy link
Contributor Author

MarijnS95 commented Dec 12, 2023

Happy to tighten this up if there's a way to do so without adding more attributes to the various crates. Perhaps with a clippy config file, like rustfmt.toml, or through the yml workflows.

Exactly that exists in the latest 1.74 Rust release: https://blog.rust-lang.org/2023/11/16/Rust-1.74.0.html#lint-configuration-through-cargo

It has one fatal flaw, which is having to opt-in every crate manually. That might work for windows-rs as there are not many crates and it's relatively easy to audit (and you probably don't care about having strict linting on most crates, like tools and tests. EDIT: On the other hand it improves readability, especially when tests are taken as examples).

@ChrisDenton
Copy link
Collaborator

Lints set in a workspace will be inherited by every crate.

@MarijnS95
Copy link
Contributor Author

@ChrisDenton
Copy link
Collaborator

Right you need to add workspace = true to the crate's lints table but that's more annoying than a "fatal flaw", imho.

@MarijnS95
Copy link
Contributor Author

For a workspace split across over 200 crates, with new ones being added on a weekly basis?

@ChrisDenton
Copy link
Collaborator

Tbh, in that case I'd be minded to automate it. There's probably a bunch of boiler plate stuff you need in any case.

But I admit I find that to be an unusual workflow, unless you're doing some kind of monorepo-like thing.

@kennykerr
Copy link
Collaborator

Thanks, workspace lints works nicely - I'll roll that into #2740.

@kennykerr
Copy link
Collaborator

Both rust_2018_idioms and unused_qualifications are now enforced as of #2741 and #2743.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants