diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2022-12-03 09:23:03 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2022-12-03 09:23:03 +0000 |
| commit | 59cc6cd4acd2e9ccbdbc8e78c26d2ac9e0b00f89 (patch) | |
| tree | 87751554430b23a2fa06411b147388a129e164dd | |
| parent | 24f2704e96c9d3a4f887d2d0a7d79ecffd79bd65 (diff) | |
| download | rust-59cc6cd4acd2e9ccbdbc8e78c26d2ac9e0b00f89.tar.gz rust-59cc6cd4acd2e9ccbdbc8e78c26d2ac9e0b00f89.zip | |
Remove useless filter in unused extern crate check.
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check_unused.rs | 19 | ||||
| -rw-r--r-- | src/test/ui/attributes/unused-item-in-attr.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/attributes/unused-item-in-attr.stderr | 16 |
3 files changed, 22 insertions, 19 deletions
diff --git a/compiler/rustc_hir_analysis/src/check_unused.rs b/compiler/rustc_hir_analysis/src/check_unused.rs index d0c31733481..5749b04783c 100644 --- a/compiler/rustc_hir_analysis/src/check_unused.rs +++ b/compiler/rustc_hir_analysis/src/check_unused.rs @@ -57,25 +57,6 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) { .maybe_unused_extern_crates(()) .iter() .filter(|&&(def_id, _)| { - // The `def_id` here actually was calculated during resolution (at least - // at the time of this writing) and is being shipped to us via a side - // channel of the tcx. There may have been extra expansion phases, - // however, which ended up removing the `def_id` *after* expansion. - // - // As a result we need to verify that `def_id` is indeed still valid for - // our AST and actually present in the HIR map. If it's not there then - // there's safely nothing to warn about, and otherwise we carry on with - // our execution. - // - // Note that if we carry through to the `extern_mod_stmt_cnum` query - // below it'll cause a panic because `def_id` is actually bogus at this - // point in time otherwise. - if tcx.hir().find(tcx.hir().local_def_id_to_hir_id(def_id)).is_none() { - return false; - } - true - }) - .filter(|&&(def_id, _)| { tcx.extern_mod_stmt_cnum(def_id).map_or(true, |cnum| { !tcx.is_compiler_builtins(cnum) && !tcx.is_panic_runtime(cnum) diff --git a/src/test/ui/attributes/unused-item-in-attr.rs b/src/test/ui/attributes/unused-item-in-attr.rs new file mode 100644 index 00000000000..70dcd5413f1 --- /dev/null +++ b/src/test/ui/attributes/unused-item-in-attr.rs @@ -0,0 +1,6 @@ +#[w = { extern crate alloc; }] +//~^ ERROR unexpected expression: `{ +//~| ERROR cannot find attribute `w` in this scope +fn f() {} + +fn main() {} diff --git a/src/test/ui/attributes/unused-item-in-attr.stderr b/src/test/ui/attributes/unused-item-in-attr.stderr new file mode 100644 index 00000000000..92a8f585821 --- /dev/null +++ b/src/test/ui/attributes/unused-item-in-attr.stderr @@ -0,0 +1,16 @@ +error: unexpected expression: `{ + extern crate alloc; + }` + --> $DIR/unused-item-in-attr.rs:1:7 + | +LL | #[w = { extern crate alloc; }] + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: cannot find attribute `w` in this scope + --> $DIR/unused-item-in-attr.rs:1:3 + | +LL | #[w = { extern crate alloc; }] + | ^ + +error: aborting due to 2 previous errors + |
