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
|
@ -18,6 +18,7 @@ use rustc_errors::{
|
|||
Applicability, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, IntoDiagnostic,
|
||||
MultiSpan, PResult,
|
||||
};
|
||||
use rustc_feature::Features;
|
||||
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
|
||||
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics, RegisteredTools};
|
||||
use rustc_parse::{self, parser, MACRO_ARGUMENTS};
|
||||
|
@ -767,6 +768,7 @@ impl SyntaxExtension {
|
|||
/// and other properties converted from attributes.
|
||||
pub fn new(
|
||||
sess: &Session,
|
||||
features: &Features,
|
||||
kind: SyntaxExtensionKind,
|
||||
span: Span,
|
||||
helper_attrs: Vec<Symbol>,
|
||||
|
@ -816,7 +818,7 @@ impl SyntaxExtension {
|
|||
allow_internal_unstable: (!allow_internal_unstable.is_empty())
|
||||
.then(|| allow_internal_unstable.into()),
|
||||
stability: stability.map(|(s, _)| s),
|
||||
deprecation: attr::find_deprecation(&sess, attrs).map(|(d, _)| d),
|
||||
deprecation: attr::find_deprecation(&sess, features, attrs).map(|(d, _)| d),
|
||||
helper_attrs,
|
||||
edition,
|
||||
builtin_name,
|
||||
|
@ -957,6 +959,7 @@ pub trait LintStoreExpand {
|
|||
fn pre_expansion_lint(
|
||||
&self,
|
||||
sess: &Session,
|
||||
features: &Features,
|
||||
registered_tools: &RegisteredTools,
|
||||
node_id: NodeId,
|
||||
attrs: &[Attribute],
|
||||
|
|
|
@ -796,7 +796,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||
| Annotatable::FieldDef(..)
|
||||
| Annotatable::Variant(..) => panic!("unexpected annotatable"),
|
||||
};
|
||||
if self.cx.ecfg.proc_macro_hygiene() {
|
||||
if self.cx.ecfg.features.proc_macro_hygiene {
|
||||
return;
|
||||
}
|
||||
feature_err(
|
||||
|
@ -834,7 +834,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||
}
|
||||
}
|
||||
|
||||
if !self.cx.ecfg.proc_macro_hygiene() {
|
||||
if !self.cx.ecfg.features.proc_macro_hygiene {
|
||||
annotatable
|
||||
.visit_with(&mut GateProcMacroInput { parse_sess: &self.cx.sess.parse_sess });
|
||||
}
|
||||
|
@ -1122,6 +1122,7 @@ impl InvocationCollectorNode for P<ast::Item> {
|
|||
if let Some(lint_store) = ecx.lint_store {
|
||||
lint_store.pre_expansion_lint(
|
||||
ecx.sess,
|
||||
ecx.ecfg.features,
|
||||
ecx.resolver.registered_tools(),
|
||||
ecx.current_expansion.lint_node_id,
|
||||
&attrs,
|
||||
|
@ -1580,7 +1581,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
|
|||
fn cfg(&self) -> StripUnconfigured<'_> {
|
||||
StripUnconfigured {
|
||||
sess: &self.cx.sess,
|
||||
features: self.cx.ecfg.features,
|
||||
features: Some(self.cx.ecfg.features),
|
||||
config_tokens: false,
|
||||
lint_node_id: self.cx.current_expansion.lint_node_id,
|
||||
}
|
||||
|
@ -1676,7 +1677,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
|
|||
// Detect use of feature-gated or invalid attributes on macro invocations
|
||||
// since they will not be detected after macro expansion.
|
||||
fn check_attributes(&self, attrs: &[ast::Attribute], call: &ast::MacCall) {
|
||||
let features = self.cx.ecfg.features.unwrap();
|
||||
let features = self.cx.ecfg.features;
|
||||
let mut attrs = attrs.iter().peekable();
|
||||
let mut span: Option<Span> = None;
|
||||
while let Some(attr) = attrs.next() {
|
||||
|
@ -1976,7 +1977,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
|||
|
||||
pub struct ExpansionConfig<'feat> {
|
||||
pub crate_name: String,
|
||||
pub features: Option<&'feat Features>,
|
||||
pub features: &'feat Features,
|
||||
pub recursion_limit: Limit,
|
||||
pub trace_mac: bool,
|
||||
/// If false, strip `#[test]` nodes
|
||||
|
@ -1987,11 +1988,11 @@ pub struct ExpansionConfig<'feat> {
|
|||
pub proc_macro_backtrace: bool,
|
||||
}
|
||||
|
||||
impl<'feat> ExpansionConfig<'feat> {
|
||||
pub fn default(crate_name: String) -> ExpansionConfig<'static> {
|
||||
impl ExpansionConfig<'_> {
|
||||
pub fn default(crate_name: String, features: &Features) -> ExpansionConfig<'_> {
|
||||
ExpansionConfig {
|
||||
crate_name,
|
||||
features: None,
|
||||
features,
|
||||
recursion_limit: Limit::new(1024),
|
||||
trace_mac: false,
|
||||
should_test: false,
|
||||
|
@ -1999,8 +2000,4 @@ impl<'feat> ExpansionConfig<'feat> {
|
|||
proc_macro_backtrace: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn proc_macro_hygiene(&self) -> bool {
|
||||
self.features.is_some_and(|features| features.proc_macro_hygiene)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ use rustc_ast_pretty::pprust;
|
|||
use rustc_attr::{self as attr, TransparencyError};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
|
||||
use rustc_errors::{Applicability, ErrorGuaranteed};
|
||||
use rustc_feature::Features;
|
||||
use rustc_lint_defs::builtin::{
|
||||
RUST_2021_INCOMPATIBLE_OR_PATTERNS, SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
|
||||
};
|
||||
|
@ -375,6 +376,7 @@ pub(super) fn try_match_macro<'matcher, T: Tracker<'matcher>>(
|
|||
/// Converts a macro item into a syntax extension.
|
||||
pub fn compile_declarative_macro(
|
||||
sess: &Session,
|
||||
features: &Features,
|
||||
def: &ast::Item,
|
||||
edition: Edition,
|
||||
) -> (SyntaxExtension, Vec<(usize, Span)>) {
|
||||
|
@ -382,6 +384,7 @@ pub fn compile_declarative_macro(
|
|||
let mk_syn_ext = |expander| {
|
||||
SyntaxExtension::new(
|
||||
sess,
|
||||
features,
|
||||
SyntaxExtensionKind::LegacyBang(expander),
|
||||
def.span,
|
||||
Vec::new(),
|
||||
|
@ -503,7 +506,7 @@ pub fn compile_declarative_macro(
|
|||
true,
|
||||
&sess.parse_sess,
|
||||
def.id,
|
||||
sess.features_untracked(),
|
||||
features,
|
||||
edition,
|
||||
)
|
||||
.pop()
|
||||
|
@ -527,7 +530,7 @@ pub fn compile_declarative_macro(
|
|||
false,
|
||||
&sess.parse_sess,
|
||||
def.id,
|
||||
sess.features_untracked(),
|
||||
features,
|
||||
edition,
|
||||
)
|
||||
.pop()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue