Closed
Description
The following code
#![feature(rust_2018_preview)]
#![deny(unnecessary_extern_crate)]
#![allow(unused_imports)]
extern crate libc;
mod foo {
use crate::libc;
}
fn main() {}
generates an error:
error: `extern crate` is unnecessary in the new edition
--> src/main.rs:5:1
|
5 | extern crate libc;
| ^^^^^^^^^^^^^^^^^^ help: remove it
|
note: lint level defined here
--> src/main.rs:2:9
|
2 | #![deny(unnecessary_extern_crate)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
error: Could not compile `playground`.
but if the extern crate libc;
is removed it no longer compiles!
This situation has come up on two occasions so far:
- In attempting to fix 2018 compatibility lint isn't firing for all imports that need to be rewritten #50660 the lint started firing for
use libc;
and rustfix rewrote it touse crate::libc;
. This worked in the 2015 edition becauseextern crate libc;
was declared at the top. Later thisunnecessary_extern_crate
lint ended up showing the error above. - Discovered in rustc: Fix
crate
lint for single-item paths #50665 theuse *;
statement is entirely disallowed in the 2018 edition, so we instead recommend the replacementuse crate::*;
. This, however, will also break if one of the identifiers used is anextern crate
as the lint currently suggests removingextern crate