Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
5 changes: 3 additions & 2 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use rustc_attr_parsing::AttributeParser;
use rustc_errors::msg;
use rustc_feature::{DependentFeature, Features};
use rustc_session::Session;
use rustc_session::config::NextSolverConfig;
use rustc_session::diagnostics::{feature_err, feature_warn};
use rustc_span::{Span, Spanned, sym};

Expand Down Expand Up @@ -698,7 +699,7 @@ fn check_dependent_features(sess: &Session, features: &Features) {
}

fn warn_next_solver_and_gce(sess: &Session, features: &Features) {
if !sess.opts.unstable_opts.next_solver.globally {
if sess.opts.unstable_opts.next_solver != NextSolverConfig::Globally {
return;
}

Expand All @@ -716,7 +717,7 @@ fn warn_next_solver_and_gce(sess: &Session, features: &Features) {
}

fn check_features_requiring_new_solver(sess: &Session, features: &Features) {
if sess.opts.unstable_opts.next_solver.globally {
if sess.opts.unstable_opts.next_solver == NextSolverConfig::Globally {
return;
}

Expand Down
43 changes: 41 additions & 2 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_ast::{AttrStyle, MetaItemLit, Safety};
use rustc_attr_ir::target::Target;
use rustc_attr_ir::{AttrPath, Attribute, AttributeKind};
use rustc_data_structures::sync::{DynSend, DynSync};
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level, MultiSpan};
use rustc_errors::{Diag, DiagCtxtHandle, DiagLocation, Diagnostic, Level, MultiSpan};
use rustc_feature::AttributeStability;
use rustc_lint_defs::builtin::UNUSED_ATTRIBUTES;
use rustc_lint_defs::{Lint, LintId};
Expand Down Expand Up @@ -408,22 +408,29 @@ pub struct AcceptContext<'f, 'sess> {
}

impl<'f, 'sess: 'f> SharedContext<'f, 'sess> {
#[track_caller]
pub(crate) fn emit_err(&self, diag: impl for<'x> Diagnostic<'x>) -> ErrorGuaranteed {
self.cx.emit_err(diag)
}

/// Emit a lint. This method is somewhat special, since lints emitted during attribute parsing
/// must be delayed until after HIR is built. This method will take care of the details of
/// that.
#[track_caller]
pub(crate) fn emit_lint(
&mut self,
lint: &'static Lint,
diagnostic: impl for<'x> Diagnostic<'x> + DynSend + DynSync + 'static,
span: impl Into<MultiSpan>,
) {
let emitted_at = DiagLocation::caller();
self.emit_lint_inner(
lint,
EmitAttribute(Box::new(move |dcx, level, _| diagnostic.into_diag(dcx, level))),
EmitAttribute(Box::new(move |dcx, level, _| {
let mut diag = diagnostic.into_diag(dcx, level);
diag.emitted_at = emitted_at;
diag
})),
span,
);
}
Expand Down Expand Up @@ -497,6 +504,7 @@ impl<'f, 'sess: 'f> AcceptContext<'f, 'sess> {
///
/// The provided span is used as a fallback for diagnostic generation in case `arg` does not
/// contain any. It should be the span of the node that contains `arg`.
#[track_caller]
pub(crate) fn expect_single_element_list<'arg>(
&mut self,
arg: &'arg ArgParser,
Expand Down Expand Up @@ -529,6 +537,7 @@ impl<'f, 'sess: 'f> AcceptContext<'f, 'sess> {
///
/// - You want to emit your own diagnostics (for instance, with [`SharedContext::emit_err`]).
/// - The attribute can be parsed in multiple ways and it does not make sense to emit an error.
#[track_caller]
pub(crate) fn expect_list<'arg>(
&mut self,
args: &'arg ArgParser,
Expand All @@ -550,6 +559,7 @@ impl<'f, 'sess: 'f> AcceptContext<'f, 'sess> {
///
/// - You want to emit your own diagnostics (for instance, with [`SharedContext::emit_err`]).
/// - The attribute can be parsed in multiple ways and it does not make sense to emit an error.
#[track_caller]
pub(crate) fn expect_single<'arg>(
&mut self,
list: &'arg MetaItemListParser,
Expand Down Expand Up @@ -589,6 +599,7 @@ impl<'f, 'sess: 'f> AcceptContext<'f, 'sess> {
///
/// - You want to emit your own diagnostics (for instance, with [`SharedContext::emit_err`]).
/// - The attribute can be parsed in multiple ways and it does not make sense to emit an error.
#[track_caller]
pub(crate) fn expect_name_value<'arg, Arg>(
&mut self,
arg: &'arg Arg,
Expand All @@ -609,6 +620,7 @@ impl<'f, 'sess: 'f> AcceptContext<'f, 'sess> {
///
/// - You want to emit your own diagnostics (for instance, with [`SharedContext::emit_err`]).
/// - The attribute can be parsed in multiple ways and it does not make sense to emit an error.
#[track_caller]
pub(crate) fn expect_no_args<'arg>(&mut self, arg: &'arg ArgParser) -> Option<()> {
if let Err(span) = arg.as_no_args() {
self.adcx().expected_no_args(span);
Expand All @@ -631,6 +643,7 @@ impl<'f, 'sess: 'f> AcceptContext<'f, 'sess> {
///
/// - You want to emit your own diagnostics (for instance, with [`SharedContext::emit_err`]).
/// - The attribute can be parsed in multiple ways and it does not make sense to emit an error.
#[track_caller]
pub(crate) fn expect_string_literal<'arg, Arg>(&mut self, arg: &'arg Arg) -> Option<Symbol>
where
Arg: ExpectStringLiteral,
Expand All @@ -644,6 +657,7 @@ pub(crate) trait ExpectNameValue {
where
Self: 'a;

#[track_caller]
fn expect_name_value<'a, 'f, 'sess>(
&'a self,
cx: &mut AcceptContext<'f, 'sess>,
Expand All @@ -655,6 +669,7 @@ pub(crate) trait ExpectNameValue {
impl ExpectNameValue for MetaItemOrLitParser {
type Output<'a> = (Ident, &'a NameValueParser);

#[track_caller]
fn expect_name_value<'a, 'f, 'sess>(
&'a self,
cx: &mut AcceptContext<'f, 'sess>,
Expand All @@ -673,6 +688,7 @@ impl ExpectNameValue for MetaItemOrLitParser {
impl ExpectNameValue for MetaItemParser {
type Output<'a> = (Ident, &'a NameValueParser);

#[track_caller]
fn expect_name_value<'a, 'f, 'sess>(
&'a self,
cx: &mut AcceptContext<'f, 'sess>,
Expand All @@ -697,6 +713,7 @@ impl ExpectNameValue for MetaItemParser {
impl ExpectNameValue for ArgParser {
type Output<'a> = &'a NameValueParser;

#[track_caller]
fn expect_name_value<'a, 'f, 'sess>(
&'a self,
cx: &mut AcceptContext<'f, 'sess>,
Expand All @@ -713,11 +730,13 @@ impl ExpectNameValue for ArgParser {
}

pub(crate) trait ExpectStringLiteral {
#[track_caller]
fn expect_string_literal<'f, 'sess>(&self, cx: &mut AcceptContext<'f, 'sess>)
-> Option<Symbol>;
}

impl ExpectStringLiteral for NameValueParser {
#[track_caller]
fn expect_string_literal<'f, 'sess>(
&self,
cx: &mut AcceptContext<'f, 'sess>,
Expand All @@ -731,6 +750,7 @@ impl ExpectStringLiteral for NameValueParser {
}

impl ExpectStringLiteral for MetaItemOrLitParser {
#[track_caller]
fn expect_string_literal<'f, 'sess>(
&self,
cx: &mut AcceptContext<'f, 'sess>,
Expand Down Expand Up @@ -893,6 +913,7 @@ pub enum ShouldEmit {
}

impl ShouldEmit {
#[track_caller]
pub(crate) fn emit_err(self, diag: Diag<'_>) -> ErrorGuaranteed {
match self {
ShouldEmit::EarlyFatal { .. } if diag.level() == Level::DelayedBug => diag.emit_err(),
Expand All @@ -912,6 +933,7 @@ pub(crate) struct AttributeDiagnosticContext<'a, 'f, 'sess> {
}

impl<'a, 'f, 'sess: 'f> AttributeDiagnosticContext<'a, 'f, 'sess> {
#[track_caller]
fn emit_parse_error(
&mut self,
mut span: Span,
Expand Down Expand Up @@ -950,6 +972,7 @@ impl<'a, 'f, 'sess: 'f> AttributeDiagnosticContext<'a, 'f, 'sess> {

/// Helpers that can be used to generate errors during attribute parsing.
impl<'a, 'f, 'sess: 'f> AttributeDiagnosticContext<'a, 'f, 'sess> {
#[track_caller]
pub(crate) fn expected_integer_literal_in_range(
&mut self,
span: Span,
Expand All @@ -964,6 +987,7 @@ impl<'a, 'f, 'sess: 'f> AttributeDiagnosticContext<'a, 'f, 'sess> {

/// The provided span is used as a fallback in case `args` does not contain any. It should be
/// the span of the node that contains `args`.
#[track_caller]
pub(crate) fn expected_list(&mut self, span: Span, args: &ArgParser) -> ErrorGuaranteed {
let span = match args {
ArgParser::NoArgs => span,
Expand All @@ -973,6 +997,7 @@ impl<'a, 'f, 'sess: 'f> AttributeDiagnosticContext<'a, 'f, 'sess> {
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedList)
}

#[track_caller]
pub(crate) fn expected_list_with_num_args_or_more(
&mut self,
args: usize,
Expand All @@ -984,45 +1009,54 @@ impl<'a, 'f, 'sess: 'f> AttributeDiagnosticContext<'a, 'f, 'sess> {
)
}

#[track_caller]
pub(crate) fn expected_list_or_no_args(&mut self, span: Span) -> ErrorGuaranteed {
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedListOrNoArgs)
}

#[track_caller]
pub(crate) fn expected_nv_or_no_args(&mut self, span: Span) -> ErrorGuaranteed {
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedNameValueOrNoArgs)
}

#[track_caller]
pub(crate) fn expected_non_empty_string_literal(&mut self, span: Span) -> ErrorGuaranteed {
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedNonEmptyStringLiteral)
}

#[track_caller]
pub(crate) fn expected_no_args(&mut self, span: Span) -> ErrorGuaranteed {
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedNoArgs)
}

/// Emit an error that a `name` was expected here
#[track_caller]
pub(crate) fn expected_identifier(&mut self, span: Span) -> ErrorGuaranteed {
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedIdentifier)
}

/// Emit an error that a `name = value` pair was expected at this span. The symbol can be given for
/// a nicer error message talking about the specific name that was found lacking a value.
#[track_caller]
fn expected_name_value(&mut self, span: Span, name: Option<Symbol>) -> ErrorGuaranteed {
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedNameValue(name))
}

/// Emit an error that a `name = value` argument is missing in a list of name-value pairs.
#[track_caller]
pub(crate) fn missing_name_value(&mut self, span: Span, name: Symbol) -> ErrorGuaranteed {
self.emit_parse_error(span, AttributeParseErrorReason::MissingNameValue(name))
}

/// Emit an error that a `name = value` pair was found where that name was already seen.
#[track_caller]
pub(crate) fn duplicate_key(&mut self, span: Span, key: Symbol) -> ErrorGuaranteed {
self.emit_parse_error(span, AttributeParseErrorReason::DuplicateKey(key))
}

/// An error that should be emitted when a [`MetaItemOrLitParser`]
/// was expected *not* to be a literal, but instead a meta item.
#[track_caller]
pub(crate) fn expected_not_literal(&mut self, span: Span) -> ErrorGuaranteed {
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedNotLiteral)
}
Expand All @@ -1031,6 +1065,7 @@ impl<'a, 'f, 'sess: 'f> AttributeDiagnosticContext<'a, 'f, 'sess> {
/// The `provided_arguments` argument allows distinguishing between "expected an argument here"
/// (when zero arguments are provided) and "expect a single argument here" (when two or more
/// arguments are provided).
#[track_caller]
pub(crate) fn expected_single_argument(
&mut self,
span: Span,
Expand All @@ -1045,11 +1080,13 @@ impl<'a, 'f, 'sess: 'f> AttributeDiagnosticContext<'a, 'f, 'sess> {
self.emit_parse_error(span, reason)
}

#[track_caller]
pub(crate) fn expected_at_least_one_argument(&mut self, span: Span) -> ErrorGuaranteed {
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedAtLeastOneArgument)
}

/// Produces an error along the lines of `expected one of [foo, meow]`
#[track_caller]
pub(crate) fn expected_specific_argument(
&mut self,
span: Span,
Expand All @@ -1067,6 +1104,7 @@ impl<'a, 'f, 'sess: 'f> AttributeDiagnosticContext<'a, 'f, 'sess> {

/// Produces an error along the lines of `expected one of [foo, meow] as an argument`.
/// i.e. slightly different wording to [`expected_specific_argument`](Self::expected_specific_argument).
#[track_caller]
pub(crate) fn expected_specific_argument_and_list(
&mut self,
span: Span,
Expand All @@ -1083,6 +1121,7 @@ impl<'a, 'f, 'sess: 'f> AttributeDiagnosticContext<'a, 'f, 'sess> {
}

/// produces an error along the lines of `expected one of ["foo", "meow"]`
#[track_caller]
pub(crate) fn expected_specific_argument_strings(
&mut self,
span: Span,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_attr_parsing/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ impl<'sess> AttributeParser<'sess> {
self.sess().dcx()
}

#[track_caller]
pub(crate) fn emit_err(&self, diag: impl for<'x> Diagnostic<'x>) -> ErrorGuaranteed {
self.should_emit.emit_err(self.sess.dcx().create_err(diag))
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,10 @@ declare_features! (
(unstable, mips_target_feature, "1.27.0", Some(150253)),
/// Allows qualified paths in struct expressions, struct patterns and tuple struct patterns.
(unstable, more_qualified_paths, "1.54.0", Some(86935)),
/// The `movdir64b` target feature on x86.
(unstable, movdir64b_target_feature, "CURRENT_RUSTC_VERSION", Some(163741)),
/// The `movdiri` target feature on x86.
(unstable, movdiri_target_feature, "CURRENT_RUSTC_VERSION", Some(163741)),
/// Allows `move(expr)` in closures.
(incomplete, move_expr, "1.97.0", Some(155050)),
/// The `movrs` target feature on x86.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ fn orphan_check<'tcx>(
// (1) Instantiate all generic params with fresh inference vars.
let infcx = tcx
.infer_ctxt()
.with_next_trait_solver(tcx.next_trait_solver_in_coherence())
.with_next_trait_solver(true)
.enable_next_solver_overflow_fcw(false)
.build(TypingMode::Coherence);
let cause = traits::ObligationCause::dummy();
Expand Down
16 changes: 2 additions & 14 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ fn test_unstable_options_tracking_hash() {
// tidy-alphabetical-end
// FIXME(#160895): We don't test this when the next-solver is enabled by default.
if option_env!("CFG_DEFAULT_NEXT_SOLVER_GLOBALLY").is_none() {
tracked!(next_solver, NextSolverConfig { coherence: true, globally: true });
tracked!(next_solver, NextSolverConfig::Globally);
}
// tidy-alphabetical-start
tracked!(no_generate_arange_section, true);
Expand Down Expand Up @@ -948,7 +948,7 @@ fn test_edition_parsing() {

#[test]
fn test_assumptions_on_binders_enables_next_solver_globally() {
let globally = NextSolverConfig { coherence: true, globally: true };
let globally = NextSolverConfig::Globally;
let mut early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());

// `-Zassumptions-on-binders` alone enables the next solver globally.
Expand All @@ -957,18 +957,6 @@ fn test_assumptions_on_binders_enables_next_solver_globally() {
assert!(opts.unstable_opts.assumptions_on_binders);
assert_eq!(opts.unstable_opts.next_solver, globally);

// Flag order must not matter when both `-Zassumptions-on-binders` and `-Znext-solver`
// are present.
for args in [
["-Zassumptions-on-binders".to_string(), "-Znext-solver=coherence".to_string()],
["-Znext-solver=coherence".to_string(), "-Zassumptions-on-binders".to_string()],
] {
let matches = optgroups().parse(&args).unwrap();
let opts = build_session_options(&mut early_dcx, &matches, false);
assert!(opts.unstable_opts.assumptions_on_binders);
assert_eq!(opts.unstable_opts.next_solver, globally);
}

// `-Zassumptions-on-binders` overrides `-Znext-solver=no` regardless of order, since
// the assumptions implementation requires the next solver. This also emits an early
// warning (covered by the UI test `next-solver-no-overridden`).
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::cmp::min;

use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_errors::{Diag, DiagLocation, Diagnostic, EmissionOverride, MultiSpan};
use rustc_errors::{Diag, Diagnostic, EmissionOverride, MultiSpan};
use rustc_hir::{HirId, ItemLocalId};
use rustc_lint_defs::{
EditionFcw, FutureIncompatibilityReason, Level, Lint, LintExpectationId, LintId,
Expand Down Expand Up @@ -494,8 +494,6 @@ pub fn emit_lint_base<'a, D: Diagnostic<'a> + 'a>(
} else {
Diag::new(sess.dcx(), err_level, "")
};
// FIXME: Find a nicer way to expose the `DiagLocation`
err.emitted_at = DiagLocation::caller();

if let Some(span) = span
&& err.span.primary_span().is_none()
Expand Down
Loading
Loading