Skip to content

Move more of rustc::lint into rustc_lint #68045

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 14 commits into from
Jan 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::hir::map as hir_map;
use crate::hir::map::DefPathHash;
use crate::ich::{NodeIdHashingMode, StableHashingContext};
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
use crate::lint::{maybe_lint_level_root, struct_lint_level, LintSource, LintStore};
use crate::lint::{maybe_lint_level_root, struct_lint_level, LintSource};
use crate::middle;
use crate::middle::cstore::CrateStoreDyn;
use crate::middle::cstore::EncodedMetadata;
Expand Down Expand Up @@ -947,7 +947,11 @@ pub struct GlobalCtxt<'tcx> {

pub sess: &'tcx Session,

pub lint_store: Lrc<LintStore>,
/// This only ever stores a `LintStore` but we don't want a dependency on that type here.
///
/// FIXME(Centril): consider `dyn LintStoreMarker` once
/// we can upcast to `Any` for some additional type safety.
pub lint_store: Lrc<dyn Any>,

pub dep_graph: DepGraph,

Expand Down Expand Up @@ -1116,7 +1120,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// reference to the context, to allow formatting values that need it.
pub fn create_global_ctxt(
s: &'tcx Session,
lint_store: Lrc<LintStore>,
lint_store: Lrc<dyn Any>,
local_providers: ty::query::Providers<'tcx>,
extern_providers: ty::query::Providers<'tcx>,
arenas: &'tcx AllArenas,
Expand Down
19 changes: 12 additions & 7 deletions src/librustc_lint/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
//! for all lint attributes.

use rustc::hir::map::Map;
use rustc::lint::LateContext;
use rustc::lint::{LateLintPass, LateLintPassObject};
use rustc::lint::{LateContext, LateLintPass, LateLintPassObject, LintStore};
use rustc::ty::{self, TyCtxt};
use rustc_data_structures::sync::{join, par_iter, ParallelIterator};
use rustc_hir as hir;
Expand All @@ -31,6 +30,12 @@ use syntax::walk_list;
use log::debug;
use std::slice;

/// Extract the `LintStore` from the query context.
/// This function exists because we've erased `LintStore` as `dyn Any` in the context.
crate fn unerased_lint_store<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx LintStore {
tcx.lint_store.downcast_ref().unwrap()
}

macro_rules! lint_callback { ($cx:expr, $f:ident, $($args:expr),*) => ({
$cx.pass.$f(&$cx.context, $($args),*);
}) }
Expand Down Expand Up @@ -356,7 +361,7 @@ fn late_lint_mod_pass<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
tables: &ty::TypeckTables::empty(None),
param_env: ty::ParamEnv::empty(),
access_levels,
lint_store: &tcx.lint_store,
lint_store: unerased_lint_store(tcx),
last_node_with_lint_attrs: tcx.hir().as_local_hir_id(module_def_id).unwrap(),
generics: None,
only_module: true,
Expand Down Expand Up @@ -386,7 +391,7 @@ pub fn late_lint_mod<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
late_lint_mod_pass(tcx, module_def_id, builtin_lints);

let mut passes: Vec<_> =
tcx.lint_store.late_module_passes.iter().map(|pass| (pass)()).collect();
unerased_lint_store(tcx).late_module_passes.iter().map(|pass| (pass)()).collect();

if !passes.is_empty() {
late_lint_mod_pass(tcx, module_def_id, LateLintPassObjects { lints: &mut passes[..] });
Expand All @@ -403,7 +408,7 @@ fn late_lint_pass_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(tcx: TyCtxt<'tc
tables: &ty::TypeckTables::empty(None),
param_env: ty::ParamEnv::empty(),
access_levels,
lint_store: &tcx.lint_store,
lint_store: unerased_lint_store(tcx),
last_node_with_lint_attrs: hir::CRATE_HIR_ID,
generics: None,
only_module: false,
Expand All @@ -424,7 +429,7 @@ fn late_lint_pass_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(tcx: TyCtxt<'tc
}

fn late_lint_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(tcx: TyCtxt<'tcx>, builtin_lints: T) {
let mut passes = tcx.lint_store.late_passes.iter().map(|p| (p)()).collect::<Vec<_>>();
let mut passes = unerased_lint_store(tcx).late_passes.iter().map(|p| (p)()).collect::<Vec<_>>();

if !tcx.sess.opts.debugging_opts.no_interleave_lints {
if !passes.is_empty() {
Expand All @@ -443,7 +448,7 @@ fn late_lint_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(tcx: TyCtxt<'tcx>, b
}

let mut passes: Vec<_> =
tcx.lint_store.late_module_passes.iter().map(|pass| (pass)()).collect();
unerased_lint_store(tcx).late_module_passes.iter().map(|pass| (pass)()).collect();

for pass in &mut passes {
tcx.sess
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_lint/levels.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::late::unerased_lint_store;
use rustc::hir::map::Map;
use rustc::lint::{LintLevelMap, LintLevelSets, LintLevelsBuilder, LintStore};
use rustc::ty::query::Providers;
Expand All @@ -11,11 +12,11 @@ pub use rustc_session::lint::{FutureIncompatibleInfo, Level, Lint, LintId};

fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> &LintLevelMap {
assert_eq!(cnum, LOCAL_CRATE);
let store = &tcx.lint_store;
let store = unerased_lint_store(tcx);
let mut builder = LintLevelMapBuilder {
levels: LintLevelSets::builder(tcx.sess, false, &store),
tcx: tcx,
store: store,
store,
};
let krate = tcx.hir().krate();

Expand Down
1 change: 1 addition & 0 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(crate_visibility_modifier)]
#![feature(nll)]
#![recursion_limit = "256"]

Expand Down