Skip to content

Commit 9d5bb70

Browse files
committed
Fix false positive lint error from no_implicit_prelude attr
1 parent 91fad92 commit 9d5bb70

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

compiler/rustc_resolve/src/check_unused.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ impl<'a, 'ra, 'tcx> UnusedImportCheckVisitor<'a, 'ra, 'tcx> {
193193
continue;
194194
}
195195

196+
let module = self
197+
.r
198+
.get_nearest_non_block_module(self.r.local_def_id(extern_crate.id).to_def_id());
199+
if module.no_implicit_prelude {
200+
// If the module has `no_implicit_prelude`, then we don't suggest
201+
// replacing the extern crate with a use, as it would not be
202+
// inserted into the prelude. User writes `extern` style deliberately.
203+
continue;
204+
}
205+
196206
let vis_span = extern_crate
197207
.vis_span
198208
.find_ancestor_inside(extern_crate.span)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ edition:2018
2+
3+
//@ check-pass
4+
5+
#![no_implicit_prelude]
6+
#![warn(unused_extern_crates)]
7+
8+
extern crate std;
9+
fn main() {
10+
let r = 1u16..10;
11+
std::println!("r: {:?}", r.is_empty());
12+
}

0 commit comments

Comments
 (0)