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.
This commit is contained in:
bors 2023-07-20 18:45:09 +00:00
commit 1554942cdc
4 changed files with 15 additions and 5 deletions

View file

@ -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.

View file

@ -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(()) }
}