Skip to content

Commit

Permalink
Move diagnostic_items queries to librustc_passes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Dec 29, 2019
1 parent 2a14d16 commit fd4d50d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ pub mod lint;
pub mod middle {
pub mod cstore;
pub mod dependency_format;
pub mod diagnostic_items;
pub mod exported_symbols;
pub mod free_region;
pub mod lang_items;
Expand Down
8 changes: 0 additions & 8 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2759,14 +2759,6 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
assert_eq!(id, LOCAL_CRATE);
tcx.arena.alloc(middle::lang_items::collect(tcx))
};
providers.diagnostic_items = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
middle::diagnostic_items::collect(tcx)
};
providers.all_diagnostic_items = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
middle::diagnostic_items::collect_all(tcx)
};
providers.maybe_unused_trait_import = |tcx, id| tcx.maybe_unused_trait_imports.contains(&id);
providers.maybe_unused_extern_crates = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
Expand Down
26 changes: 19 additions & 7 deletions src/librustc_passes/diagnostic_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
//!
//! * Compiler internal types like `Ty` and `TyCtxt`
use crate::hir::def_id::{DefId, LOCAL_CRATE};
use crate::ty::TyCtxt;
use crate::util::nodemap::FxHashMap;
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
use rustc::ty::query::Providers;
use rustc::ty::TyCtxt;
use rustc::util::nodemap::FxHashMap;

use crate::hir;
use crate::hir::itemlikevisit::ItemLikeVisitor;
use rustc::hir;
use rustc::hir::itemlikevisit::ItemLikeVisitor;
use syntax::ast;
use syntax::symbol::{sym, Symbol};

Expand Down Expand Up @@ -93,7 +94,7 @@ fn extract(attrs: &[ast::Attribute]) -> Option<Symbol> {
}

/// Traverse and collect the diagnostic items in the current
pub fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
// Initialize the collector.
let mut collector = DiagnosticItemCollector::new(tcx);

Expand All @@ -104,7 +105,7 @@ pub fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
}

/// Traverse and collect all the diagnostic items in all crates.
pub fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
// Initialize the collector.
let mut collector = FxHashMap::default();

Expand All @@ -117,3 +118,14 @@ pub fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {

tcx.arena.alloc(collector)
}

pub fn provide(providers: &mut Providers<'_>) {
providers.diagnostic_items = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
collect(tcx)
};
providers.all_diagnostic_items = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
collect_all(tcx)
};
}
2 changes: 2 additions & 0 deletions src/librustc_passes/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use rustc::ty::query::Providers;
pub mod ast_validation;
mod check_const;
pub mod dead;
mod diagnostic_items;
pub mod entry;
pub mod hir_stats;
mod intrinsicck;
Expand All @@ -32,6 +33,7 @@ mod reachable;

pub fn provide(providers: &mut Providers<'_>) {
check_const::provide(providers);
diagnostic_items::provide(providers);
entry::provide(providers);
loops::provide(providers);
liveness::provide(providers);
Expand Down

0 comments on commit fd4d50d

Please sign in to comment.