Skip to content

False positive unused_extern_crates #141785

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

Open
matthiaskrgr opened this issue May 30, 2025 · 1 comment
Open

False positive unused_extern_crates #141785

matthiaskrgr opened this issue May 30, 2025 · 1 comment
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. L-unused_extern_crates Lint: unused_extern_crates T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

I tried this code:
(edition 2024)

#![warn(unused_extern_crates)]

#![no_implicit_prelude]
extern crate std;
fn main() {
    let r = 1u16..10;
    std::println!("{:?}", r.is_empty());
}

=>

warning: `extern crate` is not idiomatic in the new edition
 --> src/main.rs:4:1
  |
4 | extern crate std;
  | ^^^^^^^^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(unused_extern_crates)]
  |         ^^^^^^^^^^^^^^^^^^^^
help: convert it to a `use`
  |
4 - extern crate std;
4 + use std;

the suggested code

#![warn(unused_extern_crates)]

#![no_implicit_prelude]
use std;
fn main() {
    let r = 1u16..10;
    std::println!("{:?}", r.is_empty());
}

does not compile:

error[E0432]: unresolved import `std`
 --> src/main.rs:4:5
  |
4 | use std;
  |     ^^^ no external crate `std`

For more information about this error, try `rustc --explain E0432`.
@matthiaskrgr matthiaskrgr added the C-bug Category: This is a bug. label May 30, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 30, 2025
@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels May 30, 2025
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 30, 2025
@jieyouxu jieyouxu added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. L-unused_extern_crates Lint: unused_extern_crates and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 30, 2025
@Noratrieb Noratrieb changed the title FP unused_extern_crates False positive unused_extern_crates May 30, 2025
@chenyukang

This comment has been minimized.

@chenyukang chenyukang self-assigned this Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. L-unused_extern_crates Lint: unused_extern_crates T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants