Move lint_store
from GlobalCtxt
to Session
.
This was made possible by the removal of plugin support, which simplified lint store creation. This simplifies the places in rustc and rustdoc that call `describe_lints`, which are early on. The lint store is now built before those places, so they don't have to create their own lint store for temporary use, they can just use the main one.
This commit is contained in:
parent
73c1fc5bc0
commit
a3b4961d5f
10 changed files with 59 additions and 64 deletions
|
@ -17,22 +17,25 @@
|
|||
use crate::{passes::LateLintPassObject, LateContext, LateLintPass, LintStore};
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_data_structures::sync::join;
|
||||
use rustc_data_structures::sync::{join, Lrc};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
|
||||
use rustc_hir::intravisit as hir_visit;
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_session::lint::LintPass;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::Span;
|
||||
|
||||
use std::any::Any;
|
||||
use std::cell::Cell;
|
||||
|
||||
/// Extract the `LintStore` from the query context.
|
||||
/// This function exists because we've erased `LintStore` as `dyn Any` in the context.
|
||||
pub fn unerased_lint_store(tcx: TyCtxt<'_>) -> &LintStore {
|
||||
let store: &dyn Any = &*tcx.lint_store;
|
||||
/// This function exists because we've erased `LintStore` as `dyn Any` in the session.
|
||||
pub fn unerased_lint_store(sess: &Session) -> &LintStore {
|
||||
assert!(sess.lint_store.is_some());
|
||||
let store: &Lrc<_> = sess.lint_store.as_ref().unwrap();
|
||||
let store: &dyn Any = &**store;
|
||||
store.downcast_ref().unwrap()
|
||||
}
|
||||
|
||||
|
@ -361,8 +364,11 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
|
|||
// Note: `passes` is often empty. In that case, it's faster to run
|
||||
// `builtin_lints` directly rather than bundling it up into the
|
||||
// `RuntimeCombinedLateLintPass`.
|
||||
let mut passes: Vec<_> =
|
||||
unerased_lint_store(tcx).late_module_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
|
||||
let mut passes: Vec<_> = unerased_lint_store(&tcx.sess)
|
||||
.late_module_passes
|
||||
.iter()
|
||||
.map(|mk_pass| (mk_pass)(tcx))
|
||||
.collect();
|
||||
if passes.is_empty() {
|
||||
late_lint_mod_inner(tcx, module_def_id, context, builtin_lints);
|
||||
} else {
|
||||
|
@ -399,7 +405,7 @@ fn late_lint_mod_inner<'tcx, T: LateLintPass<'tcx>>(
|
|||
fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
|
||||
// Note: `passes` is often empty.
|
||||
let mut passes: Vec<_> =
|
||||
unerased_lint_store(tcx).late_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
|
||||
unerased_lint_store(&tcx.sess).late_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
|
||||
|
||||
if passes.is_empty() {
|
||||
return;
|
||||
|
|
|
@ -123,7 +123,7 @@ impl LintLevelSets {
|
|||
}
|
||||
|
||||
fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExpectation)> {
|
||||
let store = unerased_lint_store(tcx);
|
||||
let store = unerased_lint_store(&tcx.sess);
|
||||
|
||||
let mut builder = LintLevelsBuilder {
|
||||
sess: tcx.sess,
|
||||
|
@ -152,7 +152,7 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
|
|||
|
||||
#[instrument(level = "trace", skip(tcx), ret)]
|
||||
fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLevelMap {
|
||||
let store = unerased_lint_store(tcx);
|
||||
let store = unerased_lint_store(&tcx.sess);
|
||||
let attrs = tcx.hir_attrs(owner);
|
||||
|
||||
let mut levels = LintLevelsBuilder {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue