diff options
| author | bors <bors@rust-lang.org> | 2023-07-20 18:45:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-07-20 18:45:09 +0000 |
| commit | 1554942cdc0099e081d5cd673d45f8a09cfd0eb0 (patch) | |
| tree | ae16e2a99a1b565ca2d6a8e95daa08b6a373f76b | |
| parent | 092e4f46be168ab24d53e4141086b2cf04822b8e (diff) | |
| parent | a4a5e5b4ae2431c09b228bfb3e2930a1c38b9e45 (diff) | |
| download | rust-1554942cdc0099e081d5cd673d45f8a09cfd0eb0.tar.gz rust-1554942cdc0099e081d5cd673d45f8a09cfd0eb0.zip | |
Auto merge of #113546 - cjgillot:unused-query, r=compiler-errors
Querify unused trait check. This code transitively loads information for all bodies, and from resolutions. As it does not return a value, it should be beneficial to have it as a query.
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check_unused.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/lib.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/query/mod.rs | 4 | ||||
| -rw-r--r-- | tests/incremental/hashes/trait_defs.rs | 4 |
4 files changed, 15 insertions, 5 deletions
diff --git a/compiler/rustc_hir_analysis/src/check_unused.rs b/compiler/rustc_hir_analysis/src/check_unused.rs index 5318e637fc7..d10bc5b34ea 100644 --- a/compiler/rustc_hir_analysis/src/check_unused.rs +++ b/compiler/rustc_hir_analysis/src/check_unused.rs @@ -1,11 +1,16 @@ use rustc_data_structures::unord::{ExtendUnord, UnordSet}; use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalDefId; +use rustc_middle::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_session::lint; -pub fn check_crate(tcx: TyCtxt<'_>) { - let mut used_trait_imports: UnordSet<LocalDefId> = Default::default(); +pub fn provide(providers: &mut Providers) { + *providers = Providers { check_unused_traits, ..*providers }; +} + +fn check_unused_traits(tcx: TyCtxt<'_>, (): ()) { + let mut used_trait_imports = UnordSet::<LocalDefId>::default(); // FIXME: Use `tcx.hir().par_body_owners()` when we implement creating `DefId`s // for anon constants during their parents' typeck. diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index d7e62457f36..4f95174f869 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -177,6 +177,7 @@ pub fn provide(providers: &mut Providers) { collect::provide(providers); coherence::provide(providers); check::provide(providers); + check_unused::provide(providers); variance::provide(providers); outlives::provide(providers); impl_wf_check::provide(providers); @@ -247,7 +248,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> { } }); - check_unused::check_crate(tcx); + tcx.ensure().check_unused_traits(()); if let Some(reported) = tcx.sess.has_errors() { Err(reported) } else { Ok(()) } } diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 062adc9ec54..b36f0df78f1 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -898,6 +898,10 @@ rustc_queries! { desc { |tcx| "linting {}", describe_as_module(key, tcx) } } + query check_unused_traits(_: ()) -> () { + desc { "checking unused trait imports in crate" } + } + /// Checks the attributes in the module. query check_mod_attrs(key: LocalDefId) -> () { desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) } diff --git a/tests/incremental/hashes/trait_defs.rs b/tests/incremental/hashes/trait_defs.rs index b583bee2f24..7b8c6245d2d 100644 --- a/tests/incremental/hashes/trait_defs.rs +++ b/tests/incremental/hashes/trait_defs.rs @@ -420,13 +420,13 @@ trait TraitAddExternModifier { // ------------------------- // -------------------------------------------------------------------- // ------------------------- - fn method() ; + fn method(); } #[cfg(not(any(cfail1,cfail4)))] #[rustc_clean(cfg="cfail2")] #[rustc_clean(cfg="cfail3")] -#[rustc_clean(except="hir_owner", cfg="cfail5")] +#[rustc_clean(cfg="cfail5")] #[rustc_clean(cfg="cfail6")] trait TraitAddExternModifier { #[rustc_clean(except="hir_owner,hir_owner_nodes,fn_sig", cfg="cfail2")] |
