Skip to content

Commit 6f1a79c

Browse files
committed
GlobalCtxt: Erase LintStore type.
1 parent c151782 commit 6f1a79c

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

src/librustc/ty/context.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::hir::map as hir_map;
88
use crate::hir::map::DefPathHash;
99
use crate::ich::{NodeIdHashingMode, StableHashingContext};
1010
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
11-
use crate::lint::{maybe_lint_level_root, struct_lint_level, LintSource, LintStore};
11+
use crate::lint::{maybe_lint_level_root, struct_lint_level, LintSource};
1212
use crate::middle;
1313
use crate::middle::cstore::CrateStoreDyn;
1414
use crate::middle::cstore::EncodedMetadata;
@@ -947,7 +947,11 @@ pub struct GlobalCtxt<'tcx> {
947947

948948
pub sess: &'tcx Session,
949949

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

952956
pub dep_graph: DepGraph,
953957

@@ -1116,7 +1120,7 @@ impl<'tcx> TyCtxt<'tcx> {
11161120
/// reference to the context, to allow formatting values that need it.
11171121
pub fn create_global_ctxt(
11181122
s: &'tcx Session,
1119-
lint_store: Lrc<LintStore>,
1123+
lint_store: Lrc<dyn Any>,
11201124
local_providers: ty::query::Providers<'tcx>,
11211125
extern_providers: ty::query::Providers<'tcx>,
11221126
arenas: &'tcx AllArenas,

src/librustc_lint/late.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
//! for all lint attributes.
1616
1717
use rustc::hir::map::Map;
18-
use rustc::lint::LateContext;
19-
use rustc::lint::{LateLintPass, LateLintPassObject};
18+
use rustc::lint::{LateContext, LateLintPass, LateLintPassObject, LintStore};
2019
use rustc::ty::{self, TyCtxt};
2120
use rustc_data_structures::sync::{join, par_iter, ParallelIterator};
2221
use rustc_hir as hir;
@@ -31,6 +30,12 @@ use syntax::walk_list;
3130
use log::debug;
3231
use std::slice;
3332

33+
/// Extract the `LintStore` from the query context.
34+
/// This function exists because we've erased `LintStore` as `dyn Any` in the context.
35+
crate fn unerased_lint_store<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx LintStore {
36+
tcx.lint_store.downcast_ref().unwrap()
37+
}
38+
3439
macro_rules! lint_callback { ($cx:expr, $f:ident, $($args:expr),*) => ({
3540
$cx.pass.$f(&$cx.context, $($args),*);
3641
}) }
@@ -356,7 +361,7 @@ fn late_lint_mod_pass<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
356361
tables: &ty::TypeckTables::empty(None),
357362
param_env: ty::ParamEnv::empty(),
358363
access_levels,
359-
lint_store: &tcx.lint_store,
364+
lint_store: unerased_lint_store(tcx),
360365
last_node_with_lint_attrs: tcx.hir().as_local_hir_id(module_def_id).unwrap(),
361366
generics: None,
362367
only_module: true,
@@ -386,7 +391,7 @@ pub fn late_lint_mod<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
386391
late_lint_mod_pass(tcx, module_def_id, builtin_lints);
387392

388393
let mut passes: Vec<_> =
389-
tcx.lint_store.late_module_passes.iter().map(|pass| (pass)()).collect();
394+
unerased_lint_store(tcx).late_module_passes.iter().map(|pass| (pass)()).collect();
390395

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

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

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

445450
let mut passes: Vec<_> =
446-
tcx.lint_store.late_module_passes.iter().map(|pass| (pass)()).collect();
451+
unerased_lint_store(tcx).late_module_passes.iter().map(|pass| (pass)()).collect();
447452

448453
for pass in &mut passes {
449454
tcx.sess

src/librustc_lint/levels.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::late::unerased_lint_store;
12
use rustc::hir::map::Map;
23
use rustc::lint::{LintLevelMap, LintLevelSets, LintLevelsBuilder, LintStore};
34
use rustc::ty::query::Providers;
@@ -11,11 +12,11 @@ pub use rustc_session::lint::{FutureIncompatibleInfo, Level, Lint, LintId};
1112

1213
fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> &LintLevelMap {
1314
assert_eq!(cnum, LOCAL_CRATE);
14-
let store = &tcx.lint_store;
15+
let store = unerased_lint_store(tcx);
1516
let mut builder = LintLevelMapBuilder {
1617
levels: LintLevelSets::builder(tcx.sess, false, &store),
1718
tcx: tcx,
18-
store: store,
19+
store,
1920
};
2021
let krate = tcx.hir().krate();
2122

src/librustc_lint/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#![feature(bool_to_option)]
1515
#![feature(box_patterns)]
1616
#![feature(box_syntax)]
17+
#![feature(crate_visibility_modifier)]
1718
#![feature(nll)]
1819
#![recursion_limit = "256"]
1920

0 commit comments

Comments
 (0)