Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions compiler/rustc_attr_parsing/src/attributes/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ pub(crate) fn parse_name_value<S: Stage>(
}
};

match cx.sess.psess.check_config.expecteds.get(&name) {
match cx.sess.check_config.expecteds.get(&name) {
Some(ExpectedValues::Some(values)) if !values.contains(&value.map(|(v, _)| v)) => cx
.emit_lint_with_sess(
UNEXPECTED_CFGS,
Expand All @@ -232,7 +232,7 @@ pub(crate) fn parse_name_value<S: Stage>(
},
span,
),
None if cx.sess.psess.check_config.exhaustive_names => cx.emit_lint_with_sess(
None if cx.sess.check_config.exhaustive_names => cx.emit_lint_with_sess(
UNEXPECTED_CFGS,
move |dcx, level, sess| {
check_cfg::unexpected_cfg_name(sess, (name, name_span), value).into_diag(dcx, level)
Expand Down Expand Up @@ -280,7 +280,7 @@ pub fn eval_config_entry(sess: &Session, cfg_entry: &CfgEntry) -> EvalConfigResu
}
}
CfgEntry::NameValue { name, value, span } => {
if sess.psess.config.contains(&(*name, *value)) {
if sess.config.contains(&(*name, *value)) {
EvalConfigResult::True
} else {
EvalConfigResult::False { reason: cfg_entry.clone(), reason_span: *span }
Expand All @@ -294,7 +294,7 @@ pub fn eval_config_entry(sess: &Session, cfg_entry: &CfgEntry) -> EvalConfigResu
};
};
// See https://github.com/rust-lang/rust/issues/64796#issuecomment-640851454 for details
let min_version_ok = if sess.psess.assume_incomplete_release {
let min_version_ok = if sess.opts.unstable_opts.assume_incomplete_release {
RustcVersion::current_overridable() > *min_version
} else {
RustcVersion::current_overridable() >= *min_version
Expand Down
24 changes: 10 additions & 14 deletions compiler/rustc_attr_parsing/src/attributes/diagnostic/check_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ fn sort_and_truncate_possibilities(
} else {
match filter_well_known_names {
FilterWellKnownNames::Yes => {
possibilities.retain(|cfg_name| {
!sess.psess.check_config.well_known_names.contains(cfg_name)
});
possibilities
.retain(|cfg_name| !sess.check_config.well_known_names.contains(cfg_name));
}
FilterWellKnownNames::No => {}
};
Expand Down Expand Up @@ -105,13 +104,12 @@ pub(crate) fn unexpected_cfg_name(
value: Option<(Symbol, Span)>,
) -> errors::UnexpectedCfgName {
#[allow(rustc::potential_query_instability)]
let possibilities: Vec<Symbol> = sess.psess.check_config.expecteds.keys().copied().collect();
let possibilities: Vec<Symbol> = sess.check_config.expecteds.keys().copied().collect();

let mut names_possibilities: Vec<_> = if value.is_none() {
// We later sort and display all the possibilities, so the order here does not matter.
#[allow(rustc::potential_query_instability)]
sess.psess
.check_config
sess.check_config
.expecteds
.iter()
.filter_map(|(k, v)| match v {
Expand Down Expand Up @@ -167,7 +165,7 @@ pub(crate) fn unexpected_cfg_name(
is_feature_cfg |= best_match == sym::feature;

if let Some(ExpectedValues::Some(best_match_values)) =
sess.psess.check_config.expecteds.get(&best_match)
sess.check_config.expecteds.get(&best_match)
{
// We will soon sort, so the initial order does not matter.
#[allow(rustc::potential_query_instability)]
Expand Down Expand Up @@ -285,7 +283,7 @@ pub(crate) fn unexpected_cfg_value(
(name, name_span): (Symbol, Span),
value: Option<(Symbol, Span)>,
) -> errors::UnexpectedCfgValue {
let Some(ExpectedValues::Some(values)) = &sess.psess.check_config.expecteds.get(&name) else {
let Some(ExpectedValues::Some(values)) = &sess.check_config.expecteds.get(&name) else {
panic!(
"it shouldn't be possible to have a diagnostic on a value whose name is not in values"
);
Expand All @@ -305,7 +303,7 @@ pub(crate) fn unexpected_cfg_value(
let is_from_external_macro = name_span.in_external_macro(sess.source_map());

let code_sugg = if let Some((value, _)) = value
&& sess.psess.check_config.well_known_names.contains(&name)
&& sess.check_config.well_known_names.contains(&name)
&& let valid_names = possible_well_known_names_for_cfg_value(sess, value)
&& !valid_names.is_empty()
{
Expand Down Expand Up @@ -378,12 +376,12 @@ pub(crate) fn unexpected_cfg_value(
// We don't want to encourage people to add values to a well-known names, as these are
// defined by rustc/Rust itself. Users can still do this if they wish, but should not be
// encouraged to do so.
let can_suggest_adding_value = !sess.psess.check_config.well_known_names.contains(&name)
let can_suggest_adding_value = !sess.check_config.well_known_names.contains(&name)
// Except when working on rustc or the standard library itself, in which case we want to
// suggest adding these cfgs to the "normal" place because of bootstrapping reasons. As a
// basic heuristic, we use the "cheat" unstable feature enable method and the
// non-ui-testing enabled option.
|| (matches!(sess.psess.unstable_features, rustc_feature::UnstableFeatures::Cheat)
|| (matches!(sess.unstable_features, rustc_feature::UnstableFeatures::Cheat)
&& !sess.opts.unstable_opts.ui_testing);

let inst = |escape_quotes| {
Expand Down Expand Up @@ -429,13 +427,11 @@ pub(crate) fn unexpected_cfg_value(
fn possible_well_known_names_for_cfg_value(sess: &Session, value: Symbol) -> Vec<Symbol> {
#[allow(rustc::potential_query_instability)]
let mut names = sess
.psess
.check_config
.well_known_names
.iter()
.filter(|name| {
sess.psess
.check_config
sess.check_config
.expecteds
.get(*name)
.map(|expected_values| expected_values.contains(&Some(value)))
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/assert_module_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl<'tcx> AssertModuleSource<'tcx> {
/// Scan for a `cfg="foo"` attribute and check whether we have a
/// cfg flag called `foo`.
fn check_config(&self, value: Symbol) -> bool {
let config = &self.tcx.sess.psess.config;
let config = &self.tcx.sess.config;
debug!("check_config(config={:?}, value={:?})", config, value);
if config.iter().any(|&(name, _)| name == value) {
debug!("check_config: matched");
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,6 @@ fn print_crate_info(
}
Cfg => {
let mut cfgs = sess
.psess
.config
.iter()
.filter_map(|&(name, value)| {
Expand Down Expand Up @@ -763,7 +762,7 @@ fn print_crate_info(

// INSTABILITY: We are sorting the output below.
#[allow(rustc::potential_query_instability)]
for (name, expected_values) in &sess.psess.check_config.expecteds {
for (name, expected_values) in &sess.check_config.expecteds {
use crate::config::ExpectedValues;
match expected_values {
ExpectedValues::Any => {
Expand Down Expand Up @@ -791,9 +790,7 @@ fn print_crate_info(
}

check_cfgs.sort_unstable();
if !sess.psess.check_config.exhaustive_names
&& sess.psess.check_config.exhaustive_values
{
if !sess.check_config.exhaustive_names && sess.check_config.exhaustive_values {
println_info!("cfg(any())");
}
for check_cfg in check_cfgs {
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_expand/src/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use rustc_proc_macro::bridge::{
DelimSpan, Diagnostic, ExpnGlobals, Group, Ident, LitKind, Literal, Punct, TokenTree, server,
};
use rustc_proc_macro::{Delimiter, Level};
use rustc_session::Session;
use rustc_session::parse::ParseSess;
use rustc_span::def_id::CrateNum;
use rustc_span::{BytePos, FileName, Pos, Span, Symbol, sym};
Expand Down Expand Up @@ -440,6 +441,10 @@ impl<'a, 'b> Rustc<'a, 'b> {
}
}

fn sess(&self) -> &Session {
&self.ecx.sess
}

fn psess(&self) -> &ParseSess {
self.ecx.psess()
}
Expand Down Expand Up @@ -825,7 +830,7 @@ impl server::Server for Rustc<'_, '_> {
/// since we've loaded `my_proc_macro` from disk in order to execute it).
/// In this way, we have obtained a span pointing into `my_proc_macro`
fn span_save_span(&mut self, span: Self::Span) -> usize {
self.psess().save_proc_macro_span(span)
self.sess().save_proc_macro_span(span)
}

fn span_recover_proc_macro_span(&mut self, id: usize) -> Self::Span {
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_incremental/src/persist/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,7 @@ impl<'tcx> CleanVisitor<'tcx> {
item_id: LocalDefId,
attr: &RustcCleanAttribute,
) -> Option<Assertion> {
self.tcx
.sess
.psess
.config
.contains(&(attr.cfg, None))
.then(|| self.assertion_auto(item_id, attr))
self.tcx.sess.config.contains(&(attr.cfg, None)).then(|| self.assertion_auto(item_id, attr))
}

/// Gets the "auto" assertion on pre-validated attr, along with the `except` labels.
Expand Down Expand Up @@ -406,7 +401,7 @@ struct FindAllAttrs<'tcx> {

impl<'tcx> FindAllAttrs<'tcx> {
fn is_active_attr(&self, attr: &RustcCleanAttribute) -> bool {
self.tcx.sess.psess.config.contains(&(attr.cfg, None))
self.tcx.sess.config.contains(&(attr.cfg, None))
}

fn report_unchecked_attrs(&self, mut checked_attrs: FxHashSet<Span>) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,11 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
let cfg = parse_cfg(sess.dcx(), config.crate_cfg);
let mut cfg = config::build_configuration(&sess, cfg);
util::add_configuration(&mut cfg, &mut sess, &*codegen_backend);
sess.psess.config = cfg;
sess.config = cfg;

let mut check_cfg = parse_check_cfg(sess.dcx(), config.crate_check_cfg);
check_cfg.fill_well_known(&sess.target);
sess.psess.check_config = check_cfg;
sess.check_config = check_cfg;

if let Some(psess_created) = config.psess_created {
psess_created(&mut sess.psess);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/dependency_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ fn add_library(
// This error is probably a little obscure, but I imagine that it
// can be refined over time.
if link2 != link || link == RequireStatic {
let linking_to_rustc_driver = tcx.sess.psess.unstable_features.is_nightly_build()
let linking_to_rustc_driver = tcx.sess.unstable_features.is_nightly_build()
&& tcx.crates(()).iter().any(|&cnum| tcx.crate_name(cnum) == sym::rustc_driver);
tcx.dcx().emit_err(CrateDepMultiple {
crate_name: tcx.crate_name(cnum),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let stability = tcx.lookup_stability(CRATE_DEF_ID);
let macros =
self.lazy_array(tcx.resolutions(()).proc_macros.iter().map(|p| p.local_def_index));
for (i, span) in self.tcx.sess.psess.proc_macro_quoted_spans() {
for (i, span) in self.tcx.sess.proc_macro_quoted_spans() {
let span = self.lazy(span);
self.tables.proc_macro_quoted_spans.set_some(i, span);
}
Expand Down
30 changes: 3 additions & 27 deletions compiler/rustc_session/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ use rustc_errors::{
BufferedEarlyLint, ColorConfig, DecorateDiagCompat, Diag, DiagCtxt, DiagCtxtHandle,
DiagMessage, EmissionGuarantee, Level, MultiSpan, StashKey,
};
use rustc_feature::{GateIssue, UnstableFeatures, find_feature_issue};
use rustc_feature::{GateIssue, find_feature_issue};
use rustc_span::edition::Edition;
use rustc_span::hygiene::ExpnId;
use rustc_span::source_map::{FilePathMapping, SourceMap};
use rustc_span::{Span, Symbol, sym};

use crate::Session;
use crate::config::{Cfg, CheckCfg};
use crate::errors::{
CliFeatureDiagnosticHelp, FeatureDiagnosticForIssue, FeatureDiagnosticHelp,
FeatureDiagnosticSuggestion, FeatureGateError, SuggestUpgradeCompiler,
Expand Down Expand Up @@ -182,7 +181,7 @@ pub fn add_feature_diagnostics_for_issue<G: EmissionGuarantee>(
}

// #23973: do not suggest `#![feature(...)]` if we are in beta/stable
if sess.psess.unstable_features.is_nightly_build() {
if sess.unstable_features.is_nightly_build() {
if feature_from_cli {
err.subdiagnostic(CliFeatureDiagnosticHelp { feature });
} else if let Some(span) = inject_span {
Expand Down Expand Up @@ -226,7 +225,7 @@ pub fn feature_err_unstable_feature_bound(
let mut err = sess.dcx().create_err(FeatureGateError { span, explain: explain.into() });

// #23973: do not suggest `#![feature(...)]` if we are in beta/stable
if sess.psess.unstable_features.is_nightly_build() {
if sess.unstable_features.is_nightly_build() {
err.subdiagnostic(FeatureDiagnosticHelp { feature });

if feature == sym::rustc_attrs {
Expand All @@ -245,9 +244,6 @@ pub fn feature_err_unstable_feature_bound(
/// Info about a parsing session.
pub struct ParseSess {
dcx: DiagCtxt,
pub unstable_features: UnstableFeatures,
pub config: Cfg,
pub check_config: CheckCfg,
pub edition: Edition,
/// Places where raw identifiers were used. This is used to avoid complaining about idents
/// clashing with keywords in new editions.
Expand All @@ -264,11 +260,6 @@ pub struct ParseSess {
pub ambiguous_block_expr_parse: Lock<FxIndexMap<Span, Span>>,
pub gated_spans: GatedSpans,
pub symbol_gallery: SymbolGallery,
/// Whether cfg(version) should treat the current release as incomplete
pub assume_incomplete_release: bool,
/// Spans passed to `proc_macro::quote_span`. Each span has a numerical
/// identifier represented by its position in the vector.
proc_macro_quoted_spans: AppendOnlyVec<Span>,
/// Used to generate new `AttrId`s. Every `AttrId` is unique.
pub attr_id_generator: AttrIdGenerator,
}
Expand All @@ -288,9 +279,6 @@ impl ParseSess {
pub fn with_dcx(dcx: DiagCtxt, source_map: Arc<SourceMap>) -> Self {
Self {
dcx,
unstable_features: UnstableFeatures::from_environment(None),
config: Cfg::default(),
check_config: CheckCfg::default(),
edition: ExpnId::root().expn_data().edition,
raw_identifier_spans: Default::default(),
bad_unicode_identifiers: Lock::new(Default::default()),
Expand All @@ -299,8 +287,6 @@ impl ParseSess {
ambiguous_block_expr_parse: Lock::new(Default::default()),
gated_spans: GatedSpans::default(),
symbol_gallery: SymbolGallery::default(),
assume_incomplete_release: false,
proc_macro_quoted_spans: Default::default(),
attr_id_generator: AttrIdGenerator::new(),
}
}
Expand Down Expand Up @@ -388,16 +374,6 @@ impl ParseSess {
});
}

pub fn save_proc_macro_span(&self, span: Span) -> usize {
self.proc_macro_quoted_spans.push(span)
}

pub fn proc_macro_quoted_spans(&self) -> impl Iterator<Item = (usize, Span)> {
// This is equivalent to `.iter().copied().enumerate()`, but that isn't possible for
// AppendOnlyVec, so we resort to this scheme.
self.proc_macro_quoted_spans.iter_enumerated()
}

pub fn dcx(&self) -> DiagCtxtHandle<'_> {
self.dcx.handle()
}
Expand Down
Loading
Loading