Skip to content

Querify unused trait check. #113546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions compiler/rustc_hir_analysis/src/check_unused.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(()) }
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
4 changes: 2 additions & 2 deletions tests/incremental/hashes/trait_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down