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

option to only disable lint -> clippy::lint deprecation warnings #3159

Closed
matthiaskrgr opened this issue Sep 10, 2018 · 14 comments
Closed

option to only disable lint -> clippy::lint deprecation warnings #3159

matthiaskrgr opened this issue Sep 10, 2018 · 14 comments

Comments

@matthiaskrgr
Copy link
Member

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 name `if_not_else` is deprecated and may not have an effect in the future. Also `cfg_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 the lint -> clippy::lint transition warning explicitly until tool_lints hits 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?

@flip1995
Copy link
Member

flip1995 commented Sep 10, 2018

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

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)

@Manishearth
Copy link
Member

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

@flip1995
Copy link
Member

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

@df5602
Copy link

df5602 commented Sep 11, 2018

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?

@mati865
Copy link
Contributor

mati865 commented Sep 11, 2018

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

@df5602
Copy link

df5602 commented Sep 11, 2018

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)

@mati865
Copy link
Contributor

mati865 commented Sep 11, 2018

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

@df5602
Copy link

df5602 commented Sep 11, 2018

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...)

@mati865
Copy link
Contributor

mati865 commented Sep 11, 2018

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

@df5602
Copy link

df5602 commented Sep 11, 2018

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...

@mati865
Copy link
Contributor

mati865 commented Sep 11, 2018

@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.

@Arnavion
Copy link
Contributor

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.

@flip1995
Copy link
Member

flip1995 commented Sep 12, 2018

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.

bors added a commit to rust-lang/rust that referenced this issue Oct 3, 2018
 [beta] Cancel warning for tool_lints

For the discussion about this, see: rust-lang/rust-clippy#3159

`clippy-preview` is available on stable since 1.29. So when running `cargo +beta clippy` on a crate with `#![allow(clippy_lint)]` a warning is produced, which tells the programmer to change this to `#![allow(clippy::clippy_lint)]`. But since `tool_lints` aren't stable yet, this would require a `#![feature(tool_lints)]`. Features aren't available on stable or beta, so we cannot do this. Even wrapping `cfg_attr(clippy)` around this won't help, since Clippy can also be run from stable or beta toolchain.

r? @Manishearth
@phansch
Copy link
Member

phansch commented Dec 7, 2018

Going to close this as tool lints are on stable now 🎉

@phansch phansch closed this as completed Dec 7, 2018
asomers added a commit to bfffs/bfffs that referenced this issue Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants