Skip to content

False positive unused_extern_crates #141785

Closed
@matthiaskrgr

Description

@matthiaskrgr

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.L-unused_extern_cratesLint: unused_extern_cratesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions