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

unused-extern-crate false positive with sysroot crates #69304

Closed
nagisa opened this issue Feb 20, 2020 · 5 comments
Closed

unused-extern-crate false positive with sysroot crates #69304

nagisa opened this issue Feb 20, 2020 · 5 comments
Labels
A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-cargo Relevant to the cargo team, which will review and decide on the PR/issue.

Comments

@nagisa
Copy link
Member

nagisa commented Feb 20, 2020

To use certain crates such as proc_macro it is required to include it with extern crate proc_macro. Similar thing applies to other sysroot crates.

Denying the unused group of lints will prevent code from compiling properly with an error like this:

error: `extern crate` is not idiomatic in the new edition
 --> src/lib.rs:3:1
  |
3 | extern crate proc_macro;
  | ^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `use`
  |
  = note: `-D unused-extern-crates` implied by `-D unused`
@nagisa nagisa added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. A-edition-2018-lints labels Feb 20, 2020
@nagisa
Copy link
Member Author

nagisa commented Feb 20, 2020

Might be reproducible only when cargo checking a proc_macro crate. I am having trouble in quickly minimizing this.

@nagisa
Copy link
Member Author

nagisa commented Feb 20, 2020

Note that at least the "convert to use" suggestion is not applicable, because use-ing a sysroot crate does not work cc @estebank

@ehuss
Copy link
Contributor

ehuss commented Feb 20, 2020

Hm, this is an unexpected consequence due to rust-lang/cargo#7700. As of beta (1.42), extern crate proc_macro; isn't necessary.

I can see how that might be problematic for people who use deny(warnings) or deny(unused). I'm not sure what the policy is for that. For now you can either remove the extern crate proc_macro, or if you need compatibility with older versions, add an explicit allow.

@jonas-schievink jonas-schievink added the T-cargo Relevant to the cargo team, which will review and decide on the PR/issue. label Feb 20, 2020
@Mark-Simulacrum
Copy link
Member

Generally speaking, we're free to break deny(warnings). Where possible, I think we usually try to phase new warnings in such that the nightly that introduces the warning has a previously released stable which supports some fix for it (e.g., deprecation issued as a "use this" would start warning once the replacement lands in stable).

@nagisa
Copy link
Member Author

nagisa commented Feb 20, 2020

Ah, I see why this is happening, now.

What we do is we run nightly cargo clippy, which, I presume, does add the --extern proc_macro but we compile actual code with plain rustc and we do not add the flag (yet). Hence the disconnect between what the lint is saying and the behaviour we are seeing when compiling code.

Closing as not-a-bug.

@nagisa nagisa closed this as completed Feb 20, 2020
@fmease fmease added A-edition-2018 Area: The 2018 edition and removed A-edition-2018-lints labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-cargo Relevant to the cargo team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants