rustc: Move features
from Session
to GlobalCtxt
Removes two pieces of mutable state. Follow up to #114622.
This commit is contained in:
parent
a07bc13e14
commit
7353c96be8
30 changed files with 130 additions and 93 deletions
|
@ -2237,7 +2237,7 @@ declare_lint_pass!(
|
|||
|
||||
impl EarlyLintPass for IncompleteInternalFeatures {
|
||||
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) {
|
||||
let features = cx.sess().features_untracked();
|
||||
let features = cx.builder.features();
|
||||
features
|
||||
.declared_lang_features
|
||||
.iter()
|
||||
|
|
|
@ -27,6 +27,7 @@ use rustc_data_structures::fx::FxHashMap;
|
|||
use rustc_data_structures::sync;
|
||||
use rustc_errors::{add_elided_lifetime_in_path_suggestion, DiagnosticBuilder, DiagnosticMessage};
|
||||
use rustc_errors::{Applicability, DecorateLint, MultiSpan, SuggestionStyle};
|
||||
use rustc_feature::Features;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::def_id::{CrateNum, DefId};
|
||||
|
@ -1071,6 +1072,7 @@ pub trait LintContext: Sized {
|
|||
impl<'a> EarlyContext<'a> {
|
||||
pub(crate) fn new(
|
||||
sess: &'a Session,
|
||||
features: &'a Features,
|
||||
warn_about_weird_lints: bool,
|
||||
lint_store: &'a LintStore,
|
||||
registered_tools: &'a RegisteredTools,
|
||||
|
@ -1079,6 +1081,7 @@ impl<'a> EarlyContext<'a> {
|
|||
EarlyContext {
|
||||
builder: LintLevelsBuilder::new(
|
||||
sess,
|
||||
features,
|
||||
warn_about_weird_lints,
|
||||
lint_store,
|
||||
registered_tools,
|
||||
|
|
|
@ -20,6 +20,7 @@ use rustc_ast::ptr::P;
|
|||
use rustc_ast::visit::{self as ast_visit, Visitor};
|
||||
use rustc_ast::{self as ast, walk_list, HasAttrs};
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_feature::Features;
|
||||
use rustc_middle::ty::RegisteredTools;
|
||||
use rustc_session::lint::{BufferedEarlyLint, LintBuffer, LintPass};
|
||||
use rustc_session::Session;
|
||||
|
@ -381,6 +382,7 @@ impl<'a> EarlyCheckNode<'a> for (ast::NodeId, &'a [ast::Attribute], &'a [P<ast::
|
|||
|
||||
pub fn check_ast_node<'a>(
|
||||
sess: &Session,
|
||||
features: &Features,
|
||||
pre_expansion: bool,
|
||||
lint_store: &LintStore,
|
||||
registered_tools: &RegisteredTools,
|
||||
|
@ -390,6 +392,7 @@ pub fn check_ast_node<'a>(
|
|||
) {
|
||||
let context = EarlyContext::new(
|
||||
sess,
|
||||
features,
|
||||
!pre_expansion,
|
||||
lint_store,
|
||||
registered_tools,
|
||||
|
|
|
@ -12,6 +12,7 @@ use rustc_ast as ast;
|
|||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::{DecorateLint, DiagnosticBuilder, DiagnosticMessage, MultiSpan};
|
||||
use rustc_feature::Features;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::HirId;
|
||||
|
@ -119,6 +120,7 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
|
|||
|
||||
let mut builder = LintLevelsBuilder {
|
||||
sess: tcx.sess,
|
||||
features: tcx.features(),
|
||||
provider: QueryMapExpectationsWrapper {
|
||||
tcx,
|
||||
cur: hir::CRATE_HIR_ID,
|
||||
|
@ -148,6 +150,7 @@ fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLe
|
|||
|
||||
let mut levels = LintLevelsBuilder {
|
||||
sess: tcx.sess,
|
||||
features: tcx.features(),
|
||||
provider: LintLevelQueryMap {
|
||||
tcx,
|
||||
cur: owner.into(),
|
||||
|
@ -435,6 +438,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, QueryMapExpectationsWrapper<'
|
|||
|
||||
pub struct LintLevelsBuilder<'s, P> {
|
||||
sess: &'s Session,
|
||||
features: &'s Features,
|
||||
provider: P,
|
||||
warn_about_weird_lints: bool,
|
||||
store: &'s LintStore,
|
||||
|
@ -448,12 +452,14 @@ pub(crate) struct BuilderPush {
|
|||
impl<'s> LintLevelsBuilder<'s, TopDown> {
|
||||
pub(crate) fn new(
|
||||
sess: &'s Session,
|
||||
features: &'s Features,
|
||||
warn_about_weird_lints: bool,
|
||||
store: &'s LintStore,
|
||||
registered_tools: &'s RegisteredTools,
|
||||
) -> Self {
|
||||
let mut builder = LintLevelsBuilder {
|
||||
sess,
|
||||
features,
|
||||
provider: TopDown { sets: LintLevelSets::new(), cur: COMMAND_LINE },
|
||||
warn_about_weird_lints,
|
||||
store,
|
||||
|
@ -526,6 +532,10 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
|||
self.sess
|
||||
}
|
||||
|
||||
pub(crate) fn features(&self) -> &Features {
|
||||
self.features
|
||||
}
|
||||
|
||||
pub(crate) fn lint_store(&self) -> &LintStore {
|
||||
self.store
|
||||
}
|
||||
|
@ -716,7 +726,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
|||
ast::MetaItemKind::NameValue(ref name_value) => {
|
||||
if item.path == sym::reason {
|
||||
if let ast::LitKind::Str(rationale, _) = name_value.kind {
|
||||
if !self.sess.features_untracked().lint_reasons {
|
||||
if !self.features.lint_reasons {
|
||||
feature_err(
|
||||
&self.sess.parse_sess,
|
||||
sym::lint_reasons,
|
||||
|
@ -992,7 +1002,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
|||
#[track_caller]
|
||||
fn check_gated_lint(&self, lint_id: LintId, span: Span) -> bool {
|
||||
if let Some(feature) = lint_id.lint.feature_gate {
|
||||
if !self.sess.features_untracked().enabled(feature) {
|
||||
if !self.features.enabled(feature) {
|
||||
let lint = builtin::UNKNOWN_LINTS;
|
||||
let (level, src) = self.lint_level(builtin::UNKNOWN_LINTS);
|
||||
struct_lint_level(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue