Skip to content

Commit 1931272

Browse files
authored
Rollup merge of #141892 - chenyukang:yukang-fix-141785-extern-crate, r=petrochenkov
Fix false positive lint error from no_implicit_prelude attr Fixes #141785 r? `@petrochenkov`
2 parents 05ee4a3 + 7167e7c commit 1931272

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ check-pass
2+
//@ edition:2018
3+
4+
#![no_implicit_prelude]
5+
#![warn(unused_extern_crates)]
6+
7+
extern crate std;
8+
fn main() {
9+
let r = 1u16..10;
10+
std::println!("{:?}", r.is_empty());
11+
}

0 commit comments

Comments
 (0)