Rust-clippy: option to only disable lint -> clippy::lint deprecation warnings

Created on 10 Sep 2018  路  14Comments  路  Source: rust-lang/rust-clippy

Some crates require to be compatible with stable.
They might have old-style clippy lint attributes.
Until the tool_lints features is available in stable, there will be a lot of
``` warning: lint nameif_not_elseis deprecated and may not have an effect in the future. Alsocfg_attr(cargo-clippy)won't be necessary anymore --> src/main.rs:16:52 | 16 | #![cfg_attr(feature = "cargo-clippy", deny(clippy, if_not_else, enum_glob_use, wrong_pub_self_convention))] | ^^^^^^^^^^^ help: change it to:clippy::if_not_else`

``` spam, so it would be cool to have a way to disable thelint->clippy::linttransition warning explicitly untiltool_lintshits stable, unless I am missing something and there already is a way to do that? renamed_and_removed_lints` implies that removed/unknown lints is still warned about which we still want warnings about in this case I think?

Most helpful comment

Yes I also think this is weird for nightly users... But I guess there is no good alternative. We can't just add a feature into stable and just hope that it works. And we _really_ want to move to tool_lints, because the whole cfg_attr thingies are pretty ugly IMO (and others), just to enable/disable a lint. So I guess a warning is the best thing to do.


@mati865 Will there be a clippy-preview on stable channel soon? Oh yeah it is in the beta.15... Yes we should disable this warning for the beta and later stable toolchain, until tool_lints are stable.

All 14 comments

Well, I kind of waited for this issue to come up :smile:

The only way is currently to #[allow(renamed_and_removed_lints)]. This is because this warning will only exist for a temporary time in the compiler (while the transition to tool_lints is made) and I didn't want to introduce a new lint in the compiler for that.

I think tool_lints are nearly ready to be stabilized, the only thing that I don't currently like is the renamed/removed behavior of tool_lints. But I'll try to get this straight ASAP.

Until that point we can try to do two thinks

  • create a new lint in the compiler explicitly for this warning (I'm not a fan of this)
  • test in the compiler if the crate is compiled with stable toolchain and don't emit the warning in this case (not sure if this is possible, but I think it should be)

Why not continue to use cfg_attr with the new lint names for the time being? That way stuff still compiles.

Oh yeah you're right that would be the best solution:

#![cfg_attr(feature="cargo-clippy", feature(tool_lints))]

#[cfg_attr(feature="cargo-clippy", warn(clippy::if_not_else))]
fn main() {
    if !true {
        println!("Hi, World!");
    } else {
        println!("Hello, World!");
    }
}

Playground compiles without errors or warnings and the Clippy warnings are emitted when using Clippy

When using the above trick, I start to get a warning in RLS in VSCode:

[rustc] #![feature] may not be used on the beta release channel

I can silence the RLS warning by changing the setting of the Rust extension to use RLS from stable instead of beta, but I'm not sure if the warning wouldn't just pop up again with the next stable...

I run clippy like that: cargo +nightly clippy, so I tried changing the [cfg_attr(feature = "cargo-clippy", ...] to [cfg_attr(all(feature = "nightly", feature = "cargo-clippy"), ...] but that didn't work. (Or rather, it silenced the RLS warning, but the disabling of the clippy lint didn't work anymore..)

Any hints on how to solve this properly?

@df5602 your VS Code/Project is configured to use beta Rust.
That trick works for me in VS Code with nightly toolchain.

Can confirm. So that trick works in stable and nightly, but not beta?

(About the other thing with feature = "nightly": The blog where I copied this from defined this as a custom feature, but I used it assuming it was a built-in feature, similar to compilation target, etc.. So it's clear why that didn't work...)

P.S. my installed toolchains:

$ rustup update
info: syncing channel updates for 'stable-x86_64-apple-darwin'
info: syncing channel updates for 'beta-x86_64-apple-darwin'
info: syncing channel updates for 'nightly-x86_64-apple-darwin'
info: checking for self-updates

   stable-x86_64-apple-darwin unchanged - rustc 1.28.0 (9634041f0 2018-07-30)
     beta-x86_64-apple-darwin unchanged - rustc 1.29.0-beta.15 (6fdf1dbb9 2018-09-10)
  nightly-x86_64-apple-darwin unchanged - rustc 1.30.0-nightly (551244f05 2018-09-10)

@df5602 features are considered unstable and can be used only with nightly toolchain.

Hmm, if I change the RLS toolchain in VS Code and restart, I get a warning only in beta. Stable and nightly are fine. Maybe that's a bug in RLS?

If I add "rust.clippy_preference": "off" to my VSCode settings (default: 'opt-in'), the warning disappears. So it appears that I need to opt-out from opting-in or use nightly... (And using stable doesn't result in a warning because clippy hasn't made it there yet...)

@df5602 there is no clippy-preview for stable toolchain. Something that doesn't exist cannot produce error :wink:

Exactly ;-) I wasn't aware that RLS automatically used --feature="cargo-clippy" (on beta and nightly) behind the scenes. Now it all makes sense. Hopefully this is useful to know for others as well...

@flip1995 this will become more problematic because you cannot use features there.
I think deprecation notice should be disabled for beta branch once it's branched. Otherwise Clippy users with Rust 1.31 (when it comes out) will get get warning saying they should do something that is not possible on stable/beta.

Even for nightly users, it's weird that code that used to work suddenly gives warnings, and those warnings require enabling a whole new feature to silence.

Yes I also think this is weird for nightly users... But I guess there is no good alternative. We can't just add a feature into stable and just hope that it works. And we _really_ want to move to tool_lints, because the whole cfg_attr thingies are pretty ugly IMO (and others), just to enable/disable a lint. So I guess a warning is the best thing to do.


@mati865 Will there be a clippy-preview on stable channel soon? Oh yeah it is in the beta.15... Yes we should disable this warning for the beta and later stable toolchain, until tool_lints are stable.

Going to close this as tool lints are on stable now :tada:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

f-fr picture f-fr  路  3Comments

phansch picture phansch  路  3Comments

matthiaskrgr picture matthiaskrgr  路  3Comments

taiki-e picture taiki-e  路  3Comments

vitorenesduarte picture vitorenesduarte  路  3Comments