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
22 changes: 11 additions & 11 deletions compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(crate) mod on_move;
pub(crate) mod on_type_error;
pub(crate) mod on_unimplemented;
pub(crate) mod on_unknown;
pub(crate) mod on_unmatch_args;
pub(crate) mod on_unmatched_args;

#[derive(Copy, Clone)]
pub(crate) enum Mode {
Expand All @@ -41,8 +41,8 @@ pub(crate) enum Mode {
DiagnosticOnMove,
/// `#[diagnostic::on_unknown]`
DiagnosticOnUnknown,
/// `#[diagnostic::on_unmatch_args]`
DiagnosticOnUnmatchArgs,
/// `#[diagnostic::on_unmatched_args]`
DiagnosticOnUnmatchedArgs,
/// `#[diagnostic::on_type_error]`
DiagnosticOnTypeError,
}
Expand All @@ -55,7 +55,7 @@ impl Mode {
Self::DiagnosticOnConst => "diagnostic::on_const",
Self::DiagnosticOnMove => "diagnostic::on_move",
Self::DiagnosticOnUnknown => "diagnostic::on_unknown",
Self::DiagnosticOnUnmatchArgs => "diagnostic::on_unmatch_args",
Self::DiagnosticOnUnmatchedArgs => "diagnostic::on_unmatched_args",
Self::DiagnosticOnTypeError => "diagnostic::on_type_error",
}
}
Expand All @@ -73,7 +73,7 @@ impl Mode {
Self::DiagnosticOnConst => DEFAULT,
Self::DiagnosticOnMove => DEFAULT,
Self::DiagnosticOnUnknown => DEFAULT,
Self::DiagnosticOnUnmatchArgs => DEFAULT,
Self::DiagnosticOnUnmatchedArgs => DEFAULT,
Self::DiagnosticOnTypeError => DIAGNOSTIC_ON_TYPE_ERROR_EXPECTED_OPTIONS,
}
}
Expand All @@ -90,7 +90,7 @@ impl Mode {
Self::DiagnosticOnConst => DEFAULT,
Self::DiagnosticOnMove => DEFAULT,
Self::DiagnosticOnUnknown => DEFAULT,
Self::DiagnosticOnUnmatchArgs => DEFAULT,
Self::DiagnosticOnUnmatchedArgs => DEFAULT,
Self::DiagnosticOnTypeError => DIAGNOSTIC_ON_TYPE_ERROR_ALLOWED_OPTIONS,
}
}
Expand All @@ -112,7 +112,7 @@ impl Mode {
Self::DiagnosticOnUnknown => {
"only `This` is allowed as a format argument, referring to the failed import"
}
Self::DiagnosticOnUnmatchArgs => {
Self::DiagnosticOnUnmatchedArgs => {
"only `This` is allowed as a format argument, referring to the macro's name"
}
Self::DiagnosticOnTypeError => {
Expand Down Expand Up @@ -313,7 +313,7 @@ fn parse_directive_items<'p>(
| Mode::DiagnosticOnConst
| Mode::DiagnosticOnMove
| Mode::DiagnosticOnUnknown
| Mode::DiagnosticOnUnmatchArgs,
| Mode::DiagnosticOnUnmatchedArgs,
sym::message,
) => {
let value = or_malformed!(value?);
Expand All @@ -329,7 +329,7 @@ fn parse_directive_items<'p>(
| Mode::DiagnosticOnConst
| Mode::DiagnosticOnMove
| Mode::DiagnosticOnUnknown
| Mode::DiagnosticOnUnmatchArgs,
| Mode::DiagnosticOnUnmatchedArgs,
sym::label,
) => {
let value = or_malformed!(value?);
Expand Down Expand Up @@ -469,7 +469,7 @@ fn parse_arg(
(
Mode::DiagnosticOnUnknown
| Mode::DiagnosticOnMove
| Mode::DiagnosticOnUnmatchArgs
| Mode::DiagnosticOnUnmatchedArgs
| Mode::DiagnosticOnTypeError,
sym::This,
) => FormatArg::This,
Expand Down Expand Up @@ -502,7 +502,7 @@ fn parse_arg(
) => FormatArg::GenericParam { generic_param, span },

// Generics are explicitly not allowed, we print those back as is.
(Mode::DiagnosticOnUnknown | Mode::DiagnosticOnUnmatchArgs, as_is) => {
(Mode::DiagnosticOnUnknown | Mode::DiagnosticOnUnmatchedArgs, as_is) => {
warnings.push(FormatWarning::DisallowedPlaceholder {
span,
attr: mode.as_str(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ use rustc_session::lint::builtin::MISPLACED_DIAGNOSTIC_ATTRIBUTES;

use crate::attributes::diagnostic::*;
use crate::attributes::prelude::*;
use crate::diagnostics::DiagnosticOnUnmatchArgsOnlyForMacros;
use crate::diagnostics::DiagnosticOnUnmatchedArgsOnlyForMacros;

#[derive(Default)]
pub(crate) struct OnUnmatchArgsParser {
pub(crate) struct OnUnmatchedArgsParser {
span: Option<Span>,
directive: Option<(Span, Directive)>,
}

impl AttributeParser for OnUnmatchArgsParser {
impl AttributeParser for OnUnmatchedArgsParser {
const ATTRIBUTES: AcceptMapping<Self> = &[(
&[sym::diagnostic, sym::on_unmatch_args],
&[sym::diagnostic, sym::on_unmatched_args],
template!(List: &[r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#]),
AttributeStability::Stable, // Unstable, stability checked manually in the parser
|this, cx, args| {
if !cx.features().diagnostic_on_unmatch_args() {
if !cx.features().diagnostic_on_unmatched_args() {
return;
}

Expand All @@ -28,13 +28,13 @@ impl AttributeParser for OnUnmatchArgsParser {
if !matches!(cx.target, Target::MacroDef) {
cx.emit_lint(
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
DiagnosticOnUnmatchArgsOnlyForMacros,
DiagnosticOnUnmatchedArgsOnlyForMacros,
span,
);
return;
}

let mode = Mode::DiagnosticOnUnmatchArgs;
let mode = Mode::DiagnosticOnUnmatchedArgs;
let Some(items) = parse_list(cx, args, mode) else { return };

let Some(directive) = parse_directive_items(cx, mode, items.mixed(), true) else {
Expand All @@ -48,7 +48,9 @@ impl AttributeParser for OnUnmatchArgsParser {

fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
if let Some(_span) = self.span {
Some(AttributeKind::OnUnmatchArgs { directive: self.directive.map(|d| Box::new(d.1)) })
Some(AttributeKind::OnUnmatchedArgs {
directive: self.directive.map(|d| Box::new(d.1)),
})
} else {
None
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::attributes::diagnostic::on_move::*;
use crate::attributes::diagnostic::on_type_error::*;
use crate::attributes::diagnostic::on_unimplemented::*;
use crate::attributes::diagnostic::on_unknown::*;
use crate::attributes::diagnostic::on_unmatch_args::*;
use crate::attributes::diagnostic::on_unmatched_args::*;
use crate::attributes::doc::*;
use crate::attributes::dummy::*;
use crate::attributes::inline::*;
Expand Down Expand Up @@ -149,7 +149,7 @@ attribute_parsers!(
OnTypeErrorParser,
OnUnimplementedParser,
OnUnknownParser,
OnUnmatchArgsParser,
OnUnmatchedArgsParser,
RustcAlignParser,
RustcAlignStaticParser,
RustcCguTestAttributeParser,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ pub(crate) struct DiagnosticOnUnknownOnlyForImports {
}

#[derive(Diagnostic)]
#[diag("`#[diagnostic::on_unmatch_args]` can only be applied to macro definitions")]
pub(crate) struct DiagnosticOnUnmatchArgsOnlyForMacros;
#[diag("`#[diagnostic::on_unmatched_args]` can only be applied to macro definitions")]
pub(crate) struct DiagnosticOnUnmatchedArgsOnlyForMacros;

#[derive(Diagnostic)]
#[diag("`#[diagnostic::on_type_error]` can only be applied to enums, structs or unions")]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use rustc_middle::ty::{
Unnormalized,
};
use rustc_span::Span;
use rustc_trait_selection::diagnostics::impl_trait_overcapture_suggestion;
use rustc_trait_selection::error_reporting::infer::region::unexpected_hidden_region_diagnostic;
use rustc_trait_selection::errors::impl_trait_overcapture_suggestion;

use crate::MirBorrowckCtxt;
use crate::borrow_set::BorrowData;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_expand/src/mbe/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(super) fn failed_to_match_macro(
args: FailedMacro<'_>,
body: &TokenStream,
rules: &[MacroRule],
on_unmatch_args: Option<&Directive>,
on_unmatched_args: Option<&Directive>,
) -> (Span, ErrorGuaranteed) {
debug!("failed to match macro");
let def_head_span = if !def_span.is_dummy() && !psess.source_map().is_imported(def_span) {
Expand Down Expand Up @@ -77,7 +77,7 @@ pub(super) fn failed_to_match_macro(
let CustomDiagnostic {
message: custom_message, label: custom_label, notes: custom_notes, ..
} = {
on_unmatch_args
on_unmatched_args
.map(|directive| directive.eval(None, &FormatArgs { this: name.to_string(), .. }))
.unwrap_or_default()
};
Expand Down
26 changes: 13 additions & 13 deletions compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub struct MacroRulesMacroExpander {
node_id: NodeId,
name: Ident,
span: Span,
on_unmatch_args: Option<Directive>,
on_unmatched_args: Option<Directive>,
transparency: Transparency,
kinds: MacroKinds,
rules: Vec<MacroRule>,
Expand Down Expand Up @@ -249,7 +249,7 @@ impl MacroRulesMacroExpander {
FailedMacro::Derive,
body,
rules,
self.on_unmatch_args.as_ref(),
self.on_unmatched_args.as_ref(),
);
cx.macro_error_and_trace_macros_diag();
Err(guar)
Expand All @@ -274,7 +274,7 @@ impl TTMacroExpander for MacroRulesMacroExpander {
self.transparency,
input,
&self.rules,
self.on_unmatch_args.as_ref(),
self.on_unmatched_args.as_ref(),
))
}
}
Expand Down Expand Up @@ -309,7 +309,7 @@ impl AttrProcMacro for MacroRulesMacroExpander {
args,
body,
&self.rules,
self.on_unmatch_args.as_ref(),
self.on_unmatched_args.as_ref(),
)
}
}
Expand Down Expand Up @@ -371,7 +371,7 @@ impl<'matcher> Tracker<'matcher> for NoopTracker {
}

/// Expands the rules based macro defined by `rules` for a given input `arg`.
#[instrument(skip(cx, transparency, arg, rules, on_unmatch_args))]
#[instrument(skip(cx, transparency, arg, rules, on_unmatched_args))]
fn expand_macro<'cx, 'a: 'cx>(
cx: &'cx mut ExtCtxt<'_>,
sp: Span,
Expand All @@ -381,7 +381,7 @@ fn expand_macro<'cx, 'a: 'cx>(
transparency: Transparency,
arg: TokenStream,
rules: &'a [MacroRule],
on_unmatch_args: Option<&Directive>,
on_unmatched_args: Option<&Directive>,
) -> Box<dyn MacResult + 'cx> {
let psess = &cx.sess.psess;

Expand Down Expand Up @@ -440,7 +440,7 @@ fn expand_macro<'cx, 'a: 'cx>(
FailedMacro::Func,
&arg,
rules,
on_unmatch_args,
on_unmatched_args,
);
cx.macro_error_and_trace_macros_diag();
DummyResult::any(span, guar)
Expand All @@ -449,7 +449,7 @@ fn expand_macro<'cx, 'a: 'cx>(
}

/// Expands the rules based macro defined by `rules` for a given attribute `args` and `body`.
#[instrument(skip(cx, transparency, args, body, rules, on_unmatch_args))]
#[instrument(skip(cx, transparency, args, body, rules, on_unmatched_args))]
fn expand_macro_attr(
cx: &mut ExtCtxt<'_>,
sp: Span,
Expand All @@ -461,7 +461,7 @@ fn expand_macro_attr(
args: TokenStream,
body: TokenStream,
rules: &[MacroRule],
on_unmatch_args: Option<&Directive>,
on_unmatched_args: Option<&Directive>,
) -> Result<TokenStream, ErrorGuaranteed> {
let psess = &cx.sess.psess;
// Macros defined in the current crate have a real node id,
Expand Down Expand Up @@ -526,7 +526,7 @@ fn expand_macro_attr(
FailedMacro::Attr(&args),
&body,
rules,
on_unmatch_args,
on_unmatched_args,
);
cx.trace_macros_diag();
Err(guar)
Expand Down Expand Up @@ -865,9 +865,9 @@ pub fn compile_declarative_macro(
return dummy_syn_ext(guar);
}

let on_unmatch_args = find_attr!(
let on_unmatched_args = find_attr!(
attrs,
OnUnmatchArgs { directive, .. } => directive.clone()
OnUnmatchedArgs { directive, .. } => directive.clone()
)
.flatten()
.map(|directive| *directive);
Expand All @@ -877,7 +877,7 @@ pub fn compile_declarative_macro(
kinds,
span,
node_id,
on_unmatch_args,
on_unmatched_args,
transparency,
rules,
macro_rules,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ declare_features! (
(removed, deprecated_safe, "1.95.0", Some(94978), Some("never properly implemented, in the way of attribute refactor"), 152554),
/// Allows deriving traits as per `SmartPointer` specification
(removed, derive_smart_pointer, "1.84.0", Some(123430), Some("replaced by `CoercePointee`"), 131284),
/// Allows macros to customize macro argument matcher diagnostics.
(removed, diagnostic_on_unmatch_args, "CURRENT_RUSTC_VERSION", Some(155642), Some("renamed to `diagnostic_on_unmatched_args`"), 157887),
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
(removed, doc_auto_cfg, "1.92.0", Some(43781), Some("merged into `doc_cfg`"), 138907),
/// Allows `#[doc(cfg_hide(...))]`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ declare_features! (
/// Allows giving unresolved imports a custom diagnostic message
(unstable, diagnostic_on_unknown, "1.96.0", Some(152900)),
/// Allows macros to customize macro argument matcher diagnostics.
(unstable, diagnostic_on_unmatch_args, "1.97.0", Some(155642)),
(unstable, diagnostic_on_unmatched_args, "1.97.0", Some(155642)),
/// Allows `#[doc(cfg(...))]`.
(unstable, doc_cfg, "1.21.0", Some(43781)),
/// Allows `#[doc(masked)]`.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir/src/attrs/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,8 +1191,8 @@ pub enum AttributeKind {
directive: Option<Box<Directive>>,
},

/// Represents `#[diagnostic::on_unmatch_args]`.
OnUnmatchArgs {
/// Represents `#[diagnostic::on_unmatched_args]`.
OnUnmatchedArgs {
/// None if the directive was malformed in some way.
directive: Option<Box<Directive>>,
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/attrs/encode_cross_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl AttributeKind {
OnTypeError { .. } => Yes,
OnUnimplemented { .. } => Yes,
OnUnknown { .. } => Yes,
OnUnmatchArgs { .. } => Yes,
OnUnmatchedArgs { .. } => Yes,
Optimize(..) => No,
PanicRuntime => No,
PatchableFunctionEntry { .. } => Yes,
Expand Down
Loading
Loading