Skip to content

Commit

Permalink
Rollup merge of #105200 - cjgillot:issue-104562, r=compiler-errors
Browse files Browse the repository at this point in the history
Remove useless filter in unused extern crate check.

Fixes #104562
  • Loading branch information
matthiaskrgr authored Dec 3, 2022
2 parents ed9a21e + 59cc6cd commit b1e6806
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
19 changes: 0 additions & 19 deletions compiler/rustc_hir_analysis/src/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,6 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
let unused_extern_crates: FxHashMap<LocalDefId, Span> = tcx
.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)
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/attributes/unused-item-in-attr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[w = { extern crate alloc; }]
//~^ ERROR unexpected expression: `{
//~| ERROR cannot find attribute `w` in this scope
fn f() {}

fn main() {}
16 changes: 16 additions & 0 deletions src/test/ui/attributes/unused-item-in-attr.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b1e6806

Please sign in to comment.