diff options
| author | Yukang <moorekang@gmail.com> | 2025-06-02 20:57:42 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-02 20:57:42 +0800 |
| commit | 19312727964f7304a100d940da3c69a1c5454ce4 (patch) | |
| tree | 9693c1a8b7f80dce65efb9539cb0b6d7e5cc358b | |
| parent | 05ee4a382593aa8e6a0d780861ab1e14de1693a6 (diff) | |
| parent | 7167e7ce06437ec093e80cc4ff20bf33dbf1fef5 (diff) | |
| download | rust-19312727964f7304a100d940da3c69a1c5454ce4.tar.gz rust-19312727964f7304a100d940da3c69a1c5454ce4.zip | |
Rollup merge of #141892 - chenyukang:yukang-fix-141785-extern-crate, r=petrochenkov
Fix false positive lint error from no_implicit_prelude attr Fixes rust-lang/rust#141785 r? `@petrochenkov`
| -rw-r--r-- | compiler/rustc_resolve/src/check_unused.rs | 10 | ||||
| -rw-r--r-- | tests/ui/resolve/extern-crate-lint-issue-141785.rs | 11 |
2 files changed, 21 insertions, 0 deletions
diff --git a/compiler/rustc_resolve/src/check_unused.rs b/compiler/rustc_resolve/src/check_unused.rs index 0579e91c0d6..e0b2adb3fc9 100644 --- a/compiler/rustc_resolve/src/check_unused.rs +++ b/compiler/rustc_resolve/src/check_unused.rs @@ -193,6 +193,16 @@ impl<'a, 'ra, 'tcx> UnusedImportCheckVisitor<'a, 'ra, 'tcx> { continue; } + let module = self + .r + .get_nearest_non_block_module(self.r.local_def_id(extern_crate.id).to_def_id()); + if module.no_implicit_prelude { + // If the module has `no_implicit_prelude`, then we don't suggest + // replacing the extern crate with a use, as it would not be + // inserted into the prelude. User writes `extern` style deliberately. + continue; + } + let vis_span = extern_crate .vis_span .find_ancestor_inside(extern_crate.span) diff --git a/tests/ui/resolve/extern-crate-lint-issue-141785.rs b/tests/ui/resolve/extern-crate-lint-issue-141785.rs new file mode 100644 index 00000000000..8d044d666df --- /dev/null +++ b/tests/ui/resolve/extern-crate-lint-issue-141785.rs @@ -0,0 +1,11 @@ +//@ check-pass +//@ edition:2018 + +#![no_implicit_prelude] +#![warn(unused_extern_crates)] + +extern crate std; +fn main() { + let r = 1u16..10; + std::println!("{:?}", r.is_empty()); +} |
