Skip to content

Commit 1554942

Browse files
committed
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.
2 parents 092e4f4 + a4a5e5b commit 1554942

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

compiler/rustc_hir_analysis/src/check_unused.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
use rustc_data_structures::unord::{ExtendUnord, UnordSet};
22
use rustc_hir::def::DefKind;
33
use rustc_hir::def_id::LocalDefId;
4+
use rustc_middle::query::Providers;
45
use rustc_middle::ty::TyCtxt;
56
use rustc_session::lint;
67

7-
pub fn check_crate(tcx: TyCtxt<'_>) {
8-
let mut used_trait_imports: UnordSet<LocalDefId> = Default::default();
8+
pub fn provide(providers: &mut Providers) {
9+
*providers = Providers { check_unused_traits, ..*providers };
10+
}
11+
12+
fn check_unused_traits(tcx: TyCtxt<'_>, (): ()) {
13+
let mut used_trait_imports = UnordSet::<LocalDefId>::default();
914

1015
// FIXME: Use `tcx.hir().par_body_owners()` when we implement creating `DefId`s
1116
// for anon constants during their parents' typeck.

compiler/rustc_hir_analysis/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ pub fn provide(providers: &mut Providers) {
177177
collect::provide(providers);
178178
coherence::provide(providers);
179179
check::provide(providers);
180+
check_unused::provide(providers);
180181
variance::provide(providers);
181182
outlives::provide(providers);
182183
impl_wf_check::provide(providers);
@@ -247,7 +248,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
247248
}
248249
});
249250

250-
check_unused::check_crate(tcx);
251+
tcx.ensure().check_unused_traits(());
251252

252253
if let Some(reported) = tcx.sess.has_errors() { Err(reported) } else { Ok(()) }
253254
}

compiler/rustc_middle/src/query/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,10 @@ rustc_queries! {
898898
desc { |tcx| "linting {}", describe_as_module(key, tcx) }
899899
}
900900

901+
query check_unused_traits(_: ()) -> () {
902+
desc { "checking unused trait imports in crate" }
903+
}
904+
901905
/// Checks the attributes in the module.
902906
query check_mod_attrs(key: LocalDefId) -> () {
903907
desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }

tests/incremental/hashes/trait_defs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -420,13 +420,13 @@ trait TraitAddExternModifier {
420420
// -------------------------
421421
// --------------------------------------------------------------------
422422
// -------------------------
423-
fn method() ;
423+
fn method();
424424
}
425425

426426
#[cfg(not(any(cfail1,cfail4)))]
427427
#[rustc_clean(cfg="cfail2")]
428428
#[rustc_clean(cfg="cfail3")]
429-
#[rustc_clean(except="hir_owner", cfg="cfail5")]
429+
#[rustc_clean(cfg="cfail5")]
430430
#[rustc_clean(cfg="cfail6")]
431431
trait TraitAddExternModifier {
432432
#[rustc_clean(except="hir_owner,hir_owner_nodes,fn_sig", cfg="cfail2")]

0 commit comments

Comments
 (0)