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
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ fn print_target_cpus(sess: &Session, tm: &llvm::TargetMachine, out: &mut String)
};
let mut cpus = cpu_names
.lines()
.filter(|cpu_name| {
!sess.target.unsupported_cpus.contains(&std::borrow::Cow::Borrowed(*cpu_name))
})
.map(|cpu_name| Cpu { cpu_name, remark: make_remark(cpu_name) })
.collect::<VecDeque<_>>();

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: 7 additions & 0 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,13 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
tcx.dcx().emit_fatal(errors::CpuRequired);
}

if let Some(target_cpu) = &tcx.sess.opts.cg.target_cpu
&& tcx.sess.target.unsupported_cpus.contains(&target_cpu.into())
{
// The target cpu is explicitly listed as an unsupported cpu
tcx.dcx().emit_fatal(errors::CpuUnsupported { target_cpu: target_cpu.clone() });
}

let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);

// Run the monomorphization collector and partition the collected items into
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_codegen_ssa/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,12 @@ pub(crate) struct InsufficientVSCodeProduct;
#[diag("target requires explicitly specifying a cpu with `-C target-cpu`")]
pub(crate) struct CpuRequired;

#[derive(Diagnostic)]
#[diag("target cpu `{$target_cpu}` is known but unsupported")]
pub(crate) struct CpuUnsupported {
pub target_cpu: String,
}

#[derive(Diagnostic)]
#[diag("processing debug info with `dsymutil` failed: {$status}")]
#[note("{$output}")]
Expand Down
14 changes: 13 additions & 1 deletion compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,20 @@ pub fn target_spec_to_backend_features<'a>(
sess: &'a Session,
mut extend_backend_features: impl FnMut(&'a str, /* enable */ bool),
) {
// Compute implied features
let mut rust_features = vec![];

// This check handles SM versions that defaults (by LLVM) to unsupported (by Rust) PTX ISA versions.
// sm_70, sm_72 and sm_75 defaults to PTX ISA versions with major version 6, while sm_80 default to 7.0
if sess.target.arch == Arch::Nvptx64
&& matches!(
sess.opts.cg.target_cpu.as_deref(),
None | Some("sm_70") | Some("sm_72") | Some("sm_75")
)
{
rust_features.push((true, "ptx70"));
}

// Compute implied features
parse_rust_feature_list(
sess,
&sess.target.features,
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
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for CoerceVisitor<'_, 'tcx> {
ControlFlow::Break(())
}
}
Ok(Certainty::Maybe { .. }) => {
Ok(Certainty::Maybe(_)) => {
// FIXME: structurally normalize?
if self.fcx.tcx.is_lang_item(pred.def_id(), LangItem::Unsize)
&& let ty::Dynamic(..) = pred.skip_binder().trait_ref.args.type_at(1).kind()
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
20 changes: 11 additions & 9 deletions compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use derive_where::derive_where;
use rustc_type_ir::inherent::*;
use rustc_type_ir::lang_items::SolverTraitLangItem;
use rustc_type_ir::search_graph::CandidateHeadUsages;
use rustc_type_ir::solve::{AliasBoundKind, SizedTraitKind};
use rustc_type_ir::solve::{AliasBoundKind, MaybeInfo, SizedTraitKind, StalledOnCoroutines};
use rustc_type_ir::{
self as ty, AliasTy, Interner, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable,
TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Unnormalized,
Expand Down Expand Up @@ -501,7 +501,7 @@ where

pub(super) fn forced_ambiguity(
&mut self,
cause: MaybeCause,
maybe: MaybeInfo,
) -> Result<Candidate<I>, NoSolution> {
// This may fail if `try_evaluate_added_goals` overflows because it
// fails to reach a fixpoint but ends up getting an error after
Expand All @@ -512,7 +512,7 @@ where
// created a minimization for an ICE in typenum, but that one no
// longer fails here. cc trait-system-refactor-initiative#105.
let source = CandidateSource::BuiltinImpl(BuiltinImplSource::Misc);
let certainty = Certainty::Maybe { cause, opaque_types_jank: OpaqueTypesJank::AllGood };
let certainty = Certainty::Maybe(maybe);
self.probe_trait_candidate(source)
.enter(|this| this.evaluate_added_goals_and_make_canonical_response(certainty))
}
Expand Down Expand Up @@ -1031,7 +1031,7 @@ where
};

if opaque_types.is_empty() {
candidates.extend(self.forced_ambiguity(MaybeCause::Ambiguity));
candidates.extend(self.forced_ambiguity(MaybeInfo::AMBIGUOUS));
return;
}

Expand Down Expand Up @@ -1122,10 +1122,11 @@ where

if candidates.is_empty() {
let source = CandidateSource::BuiltinImpl(BuiltinImplSource::Misc);
let certainty = Certainty::Maybe {
let certainty = Certainty::Maybe(MaybeInfo {
cause: MaybeCause::Ambiguity,
opaque_types_jank: OpaqueTypesJank::ErrorIfRigidSelfTy,
};
stalled_on_coroutines: StalledOnCoroutines::No,
});
candidates
.extend(self.probe_trait_candidate(source).enter(|this| {
this.evaluate_added_goals_and_make_canonical_response(certainty)
Expand Down Expand Up @@ -1178,7 +1179,7 @@ where
//
// We use `forced_ambiguity` here over `make_ambiguous_response_no_constraints`
// because the former will also record a built-in candidate in the inspector.
return self.forced_ambiguity(MaybeCause::Ambiguity).map(|cand| cand.result);
return self.forced_ambiguity(MaybeInfo::AMBIGUOUS).map(|cand| cand.result);
};

match proven_via {
Expand Down Expand Up @@ -1326,13 +1327,14 @@ where
{
self.recursion_depth += 1;
if self.recursion_depth > self.ecx.cx().recursion_limit() {
return ControlFlow::Break(Ok(Certainty::Maybe {
return ControlFlow::Break(Ok(Certainty::Maybe(MaybeInfo {
cause: MaybeCause::Overflow {
suggest_increasing_limit: true,
keep_constraints: false,
},
opaque_types_jank: OpaqueTypesJank::AllGood,
}));
stalled_on_coroutines: StalledOnCoroutines::No,
})));
}
let result = ty.super_visit_with(self);
self.recursion_depth -= 1;
Expand Down
Loading
Loading