Rollup merge of #103575 - Xiretza:suggestions-style-attr, r=davidtwco

Change #[suggestion_*] attributes to use style="..."

As discussed [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20tool_only_span_suggestion), this changes `#[(multipart_)suggestion_{short,verbose,hidden}(...)]` attributes to plain `#[(multipart_)suggestion(...)]` attributes with a `style = "{short,verbose,hidden}"` parameter.

It also adds a new style, `tool-only`, that corresponds to `tool_only_span_suggestion`/`tool_only_multipart_suggestion` and causes the suggestion to not be shown in human-readable output at all.

Best reviewed commit-by-commit, there's a bit of noise in there.

cc #100717 `@compiler-errors`
r? `@davidtwco`
This commit is contained in:
Manish Goregaokar 2022-11-01 20:00:38 -04:00 committed by GitHub
commit 69e705564d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 405 additions and 135 deletions

View File

@ -277,8 +277,9 @@ pub struct RegisterConflict<'a> {
pub struct SubTupleBinding<'a> { pub struct SubTupleBinding<'a> {
#[primary_span] #[primary_span]
#[label] #[label]
#[suggestion_verbose( #[suggestion(
ast_lowering_sub_tuple_binding_suggestion, ast_lowering_sub_tuple_binding_suggestion,
style = "verbose",
code = "..", code = "..",
applicability = "maybe-incorrect" applicability = "maybe-incorrect"
)] )]

View File

@ -49,7 +49,7 @@ pub(crate) struct GenericDoesNotLiveLongEnough {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(borrowck_var_does_not_need_mut)] #[diag(borrowck_var_does_not_need_mut)]
pub(crate) struct VarNeedNotMut { pub(crate) struct VarNeedNotMut {
#[suggestion_short(applicability = "machine-applicable", code = "")] #[suggestion(style = "short", applicability = "machine-applicable", code = "")]
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]

View File

@ -120,7 +120,7 @@ pub struct TypeofReservedKeywordUsed<'tcx> {
#[primary_span] #[primary_span]
#[label] #[label]
pub span: Span, pub span: Span,
#[suggestion_verbose(code = "{ty}")] #[suggestion(style = "verbose", code = "{ty}")]
pub opt_sugg: Option<(Span, Applicability)>, pub opt_sugg: Option<(Span, Applicability)>,
} }
@ -239,7 +239,11 @@ pub struct UnusedExternCrate {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(hir_analysis_extern_crate_not_idiomatic)] #[diag(hir_analysis_extern_crate_not_idiomatic)]
pub struct ExternCrateNotIdiomatic { pub struct ExternCrateNotIdiomatic {
#[suggestion_short(applicability = "machine-applicable", code = "{suggestion_code}")] #[suggestion(
style = "short",
applicability = "machine-applicable",
code = "{suggestion_code}"
)]
pub span: Span, pub span: Span,
pub msg_code: String, pub msg_code: String,
pub suggestion_code: String, pub suggestion_code: String,

View File

@ -113,8 +113,9 @@ pub struct MissingParentheseInRange {
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[multipart_suggestion_verbose( #[multipart_suggestion(
hir_analysis_add_missing_parentheses_in_range, hir_analysis_add_missing_parentheses_in_range,
style = "verbose",
applicability = "maybe-incorrect" applicability = "maybe-incorrect"
)] )]
pub struct AddMissingParenthesesInRange { pub struct AddMissingParenthesesInRange {

View File

@ -109,8 +109,9 @@ pub struct InferenceBadError<'a> {
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub enum SourceKindSubdiag<'a> { pub enum SourceKindSubdiag<'a> {
#[suggestion_verbose( #[suggestion(
infer_source_kind_subdiag_let, infer_source_kind_subdiag_let,
style = "verbose",
code = ": {type_name}", code = ": {type_name}",
applicability = "has-placeholders" applicability = "has-placeholders"
)] )]
@ -135,8 +136,9 @@ pub enum SourceKindSubdiag<'a> {
parent_prefix: String, parent_prefix: String,
parent_name: String, parent_name: String,
}, },
#[suggestion_verbose( #[suggestion(
infer_source_kind_subdiag_generic_suggestion, infer_source_kind_subdiag_generic_suggestion,
style = "verbose",
code = "::<{args}>", code = "::<{args}>",
applicability = "has-placeholders" applicability = "has-placeholders"
)] )]
@ -150,8 +152,9 @@ pub enum SourceKindSubdiag<'a> {
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub enum SourceKindMultiSuggestion<'a> { pub enum SourceKindMultiSuggestion<'a> {
#[multipart_suggestion_verbose( #[multipart_suggestion(
infer_source_kind_fully_qualified, infer_source_kind_fully_qualified,
style = "verbose",
applicability = "has-placeholders" applicability = "has-placeholders"
)] )]
FullyQualified { FullyQualified {
@ -163,8 +166,9 @@ pub enum SourceKindMultiSuggestion<'a> {
adjustment: &'a str, adjustment: &'a str,
successor_pos: &'a str, successor_pos: &'a str,
}, },
#[multipart_suggestion_verbose( #[multipart_suggestion(
infer_source_kind_closure_return, infer_source_kind_closure_return,
style = "verbose",
applicability = "has-placeholders" applicability = "has-placeholders"
)] )]
ClosureReturn { ClosureReturn {
@ -478,8 +482,9 @@ pub enum ImplicitStaticLifetimeSubdiag {
#[primary_span] #[primary_span]
span: Span, span: Span,
}, },
#[suggestion_verbose( #[suggestion(
infer_implicit_static_lifetime_suggestion, infer_implicit_static_lifetime_suggestion,
style = "verbose",
code = " + '_", code = " + '_",
applicability = "maybe-incorrect" applicability = "maybe-incorrect"
)] )]

View File

@ -83,7 +83,7 @@ pub struct UnknownToolInScopedLint {
pub struct BuiltinEllpisisInclusiveRangePatterns { pub struct BuiltinEllpisisInclusiveRangePatterns {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
#[suggestion_short(code = "{replace}", applicability = "machine-applicable")] #[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")]
pub suggestion: Span, pub suggestion: Span,
pub replace: String, pub replace: String,
} }

View File

@ -150,8 +150,9 @@ struct OpaqueHiddenInferredBoundLint<'tcx> {
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion_verbose( #[suggestion(
lint_opaque_hidden_inferred_bound_sugg, lint_opaque_hidden_inferred_bound_sugg,
style = "verbose",
applicability = "machine-applicable", applicability = "machine-applicable",
code = " + {trait_ref}" code = " + {trait_ref}"
)] )]

View File

@ -129,7 +129,7 @@ pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream {
/// } /// }
/// ///
/// #[derive(Subdiagnostic)] /// #[derive(Subdiagnostic)]
/// #[suggestion_verbose(parser::raw_identifier)] /// #[suggestion(style = "verbose",parser::raw_identifier)]
/// pub struct RawIdentifierSuggestion<'tcx> { /// pub struct RawIdentifierSuggestion<'tcx> {
/// #[primary_span] /// #[primary_span]
/// span: Span, /// span: Span,

View File

@ -12,7 +12,7 @@ use syn::{spanned::Spanned, Attribute, Field, Meta, Type, TypeTuple};
use syn::{MetaList, MetaNameValue, NestedMeta, Path}; use syn::{MetaList, MetaNameValue, NestedMeta, Path};
use synstructure::{BindingInfo, VariantInfo}; use synstructure::{BindingInfo, VariantInfo};
use super::error::invalid_nested_attr; use super::error::{invalid_attr, invalid_nested_attr};
thread_local! { thread_local! {
pub static CODE_IDENT_COUNT: RefCell<u32> = RefCell::new(0); pub static CODE_IDENT_COUNT: RefCell<u32> = RefCell::new(0);
@ -472,16 +472,13 @@ pub(super) fn build_suggestion_code(
} }
/// Possible styles for suggestion subdiagnostics. /// Possible styles for suggestion subdiagnostics.
#[derive(Clone, Copy)] #[derive(Clone, Copy, PartialEq)]
pub(super) enum SuggestionKind { pub(super) enum SuggestionKind {
/// `#[suggestion]`
Normal, Normal,
/// `#[suggestion_short]`
Short, Short,
/// `#[suggestion_hidden]`
Hidden, Hidden,
/// `#[suggestion_verbose]`
Verbose, Verbose,
ToolOnly,
} }
impl FromStr for SuggestionKind { impl FromStr for SuggestionKind {
@ -489,15 +486,28 @@ impl FromStr for SuggestionKind {
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
match s { match s {
"" => Ok(SuggestionKind::Normal), "normal" => Ok(SuggestionKind::Normal),
"_short" => Ok(SuggestionKind::Short), "short" => Ok(SuggestionKind::Short),
"_hidden" => Ok(SuggestionKind::Hidden), "hidden" => Ok(SuggestionKind::Hidden),
"_verbose" => Ok(SuggestionKind::Verbose), "verbose" => Ok(SuggestionKind::Verbose),
"tool-only" => Ok(SuggestionKind::ToolOnly),
_ => Err(()), _ => Err(()),
} }
} }
} }
impl fmt::Display for SuggestionKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SuggestionKind::Normal => write!(f, "normal"),
SuggestionKind::Short => write!(f, "short"),
SuggestionKind::Hidden => write!(f, "hidden"),
SuggestionKind::Verbose => write!(f, "verbose"),
SuggestionKind::ToolOnly => write!(f, "tool-only"),
}
}
}
impl SuggestionKind { impl SuggestionKind {
pub fn to_suggestion_style(&self) -> TokenStream { pub fn to_suggestion_style(&self) -> TokenStream {
match self { match self {
@ -513,6 +523,19 @@ impl SuggestionKind {
SuggestionKind::Verbose => { SuggestionKind::Verbose => {
quote! { rustc_errors::SuggestionStyle::ShowAlways } quote! { rustc_errors::SuggestionStyle::ShowAlways }
} }
SuggestionKind::ToolOnly => {
quote! { rustc_errors::SuggestionStyle::CompletelyHidden }
}
}
}
fn from_suffix(s: &str) -> Option<Self> {
match s {
"" => Some(SuggestionKind::Normal),
"_short" => Some(SuggestionKind::Short),
"_hidden" => Some(SuggestionKind::Hidden),
"_verbose" => Some(SuggestionKind::Verbose),
_ => None,
} }
} }
} }
@ -565,25 +588,49 @@ impl SubdiagnosticKind {
let name = name.as_str(); let name = name.as_str();
let meta = attr.parse_meta()?; let meta = attr.parse_meta()?;
let mut kind = match name { let mut kind = match name {
"label" => SubdiagnosticKind::Label, "label" => SubdiagnosticKind::Label,
"note" => SubdiagnosticKind::Note, "note" => SubdiagnosticKind::Note,
"help" => SubdiagnosticKind::Help, "help" => SubdiagnosticKind::Help,
"warning" => SubdiagnosticKind::Warn, "warning" => SubdiagnosticKind::Warn,
_ => { _ => {
// Recover old `#[(multipart_)suggestion_*]` syntaxes
// FIXME(#100717): remove
if let Some(suggestion_kind) = if let Some(suggestion_kind) =
name.strip_prefix("suggestion").and_then(|s| s.parse().ok()) name.strip_prefix("suggestion").and_then(SuggestionKind::from_suffix)
{ {
if suggestion_kind != SuggestionKind::Normal {
invalid_attr(attr, &meta)
.help(format!(
r#"Use `#[suggestion(..., style = "{}")]` instead"#,
suggestion_kind
))
.emit();
}
SubdiagnosticKind::Suggestion { SubdiagnosticKind::Suggestion {
suggestion_kind, suggestion_kind: SuggestionKind::Normal,
applicability: None, applicability: None,
code_field: new_code_ident(), code_field: new_code_ident(),
code_init: TokenStream::new(), code_init: TokenStream::new(),
} }
} else if let Some(suggestion_kind) = } else if let Some(suggestion_kind) =
name.strip_prefix("multipart_suggestion").and_then(|s| s.parse().ok()) name.strip_prefix("multipart_suggestion").and_then(SuggestionKind::from_suffix)
{ {
SubdiagnosticKind::MultipartSuggestion { suggestion_kind, applicability: None } if suggestion_kind != SuggestionKind::Normal {
invalid_attr(attr, &meta)
.help(format!(
r#"Use `#[multipart_suggestion(..., style = "{}")]` instead"#,
suggestion_kind
))
.emit();
}
SubdiagnosticKind::MultipartSuggestion {
suggestion_kind: SuggestionKind::Normal,
applicability: None,
}
} else { } else {
throw_invalid_attr!(attr, &meta); throw_invalid_attr!(attr, &meta);
} }
@ -621,6 +668,7 @@ impl SubdiagnosticKind {
}; };
let mut code = None; let mut code = None;
let mut suggestion_kind = None;
let mut nested_iter = nested.into_iter().peekable(); let mut nested_iter = nested.into_iter().peekable();
@ -682,16 +730,37 @@ impl SubdiagnosticKind {
}); });
applicability.set_once(value, span); applicability.set_once(value, span);
} }
(
"style",
SubdiagnosticKind::Suggestion { .. }
| SubdiagnosticKind::MultipartSuggestion { .. },
) => {
let Some(value) = string_value else {
invalid_nested_attr(attr, &nested_attr).emit();
continue;
};
let value = value.value().parse().unwrap_or_else(|()| {
span_err(value.span().unwrap(), "invalid suggestion style")
.help("valid styles are `normal`, `short`, `hidden`, `verbose` and `tool-only`")
.emit();
SuggestionKind::Normal
});
suggestion_kind.set_once(value, span);
}
// Invalid nested attribute // Invalid nested attribute
(_, SubdiagnosticKind::Suggestion { .. }) => { (_, SubdiagnosticKind::Suggestion { .. }) => {
invalid_nested_attr(attr, &nested_attr) invalid_nested_attr(attr, &nested_attr)
.help("only `code` and `applicability` are valid nested attributes") .help(
"only `style`, `code` and `applicability` are valid nested attributes",
)
.emit(); .emit();
} }
(_, SubdiagnosticKind::MultipartSuggestion { .. }) => { (_, SubdiagnosticKind::MultipartSuggestion { .. }) => {
invalid_nested_attr(attr, &nested_attr) invalid_nested_attr(attr, &nested_attr)
.help("only `applicability` is a valid nested attributes") .help("only `style` and `applicability` are valid nested attributes")
.emit() .emit()
} }
_ => { _ => {
@ -701,7 +770,16 @@ impl SubdiagnosticKind {
} }
match kind { match kind {
SubdiagnosticKind::Suggestion { ref code_field, ref mut code_init, .. } => { SubdiagnosticKind::Suggestion {
ref code_field,
ref mut code_init,
suggestion_kind: ref mut kind_field,
..
} => {
if let Some(kind) = suggestion_kind.value() {
*kind_field = kind;
}
*code_init = if let Some(init) = code.value() { *code_init = if let Some(init) = code.value() {
init init
} else { } else {
@ -709,11 +787,17 @@ impl SubdiagnosticKind {
quote! { let #code_field = std::iter::empty(); } quote! { let #code_field = std::iter::empty(); }
}; };
} }
SubdiagnosticKind::MultipartSuggestion {
suggestion_kind: ref mut kind_field, ..
} => {
if let Some(kind) = suggestion_kind.value() {
*kind_field = kind;
}
}
SubdiagnosticKind::Label SubdiagnosticKind::Label
| SubdiagnosticKind::Note | SubdiagnosticKind::Note
| SubdiagnosticKind::Help | SubdiagnosticKind::Help
| SubdiagnosticKind::Warn | SubdiagnosticKind::Warn => {}
| SubdiagnosticKind::MultipartSuggestion { .. } => {}
} }
Ok(Some((kind, slug))) Ok(Some((kind, slug)))

View File

@ -64,7 +64,7 @@ pub(crate) struct BadQPathStage2 {
#[diag(parser_incorrect_semicolon)] #[diag(parser_incorrect_semicolon)]
pub(crate) struct IncorrectSemicolon<'a> { pub(crate) struct IncorrectSemicolon<'a> {
#[primary_span] #[primary_span]
#[suggestion_short(code = "", applicability = "machine-applicable")] #[suggestion(style = "short", code = "", applicability = "machine-applicable")]
pub span: Span, pub span: Span,
#[help] #[help]
pub opt_help: Option<()>, pub opt_help: Option<()>,
@ -136,7 +136,12 @@ pub(crate) struct InvalidComparisonOperator {
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub(crate) enum InvalidComparisonOperatorSub { pub(crate) enum InvalidComparisonOperatorSub {
#[suggestion_short(use_instead, applicability = "machine-applicable", code = "{correct}")] #[suggestion(
use_instead,
style = "short",
applicability = "machine-applicable",
code = "{correct}"
)]
Correctable { Correctable {
#[primary_span] #[primary_span]
span: Span, span: Span,
@ -160,14 +165,16 @@ pub(crate) struct InvalidLogicalOperator {
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub(crate) enum InvalidLogicalOperatorSub { pub(crate) enum InvalidLogicalOperatorSub {
#[suggestion_short( #[suggestion(
use_amp_amp_for_conjunction, use_amp_amp_for_conjunction,
style = "short",
applicability = "machine-applicable", applicability = "machine-applicable",
code = "&&" code = "&&"
)] )]
Conjunction(#[primary_span] Span), Conjunction(#[primary_span] Span),
#[suggestion_short( #[suggestion(
use_pipe_pipe_for_disjunction, use_pipe_pipe_for_disjunction,
style = "short",
applicability = "machine-applicable", applicability = "machine-applicable",
code = "||" code = "||"
)] )]
@ -178,7 +185,7 @@ pub(crate) enum InvalidLogicalOperatorSub {
#[diag(parser_tilde_is_not_unary_operator)] #[diag(parser_tilde_is_not_unary_operator)]
pub(crate) struct TildeAsUnaryOperator( pub(crate) struct TildeAsUnaryOperator(
#[primary_span] #[primary_span]
#[suggestion_short(applicability = "machine-applicable", code = "!")] #[suggestion(style = "short", applicability = "machine-applicable", code = "!")]
pub Span, pub Span,
); );
@ -194,22 +201,25 @@ pub(crate) struct NotAsNegationOperator {
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub enum NotAsNegationOperatorSub { pub enum NotAsNegationOperatorSub {
#[suggestion_short( #[suggestion(
parser_unexpected_token_after_not_default, parser_unexpected_token_after_not_default,
style = "short",
applicability = "machine-applicable", applicability = "machine-applicable",
code = "!" code = "!"
)] )]
SuggestNotDefault(#[primary_span] Span), SuggestNotDefault(#[primary_span] Span),
#[suggestion_short( #[suggestion(
parser_unexpected_token_after_not_bitwise, parser_unexpected_token_after_not_bitwise,
style = "short",
applicability = "machine-applicable", applicability = "machine-applicable",
code = "!" code = "!"
)] )]
SuggestNotBitwise(#[primary_span] Span), SuggestNotBitwise(#[primary_span] Span),
#[suggestion_short( #[suggestion(
parser_unexpected_token_after_not_logical, parser_unexpected_token_after_not_logical,
style = "short",
applicability = "machine-applicable", applicability = "machine-applicable",
code = "!" code = "!"
)] )]
@ -249,7 +259,7 @@ pub(crate) struct UnexpectedTokenAfterLabel {
#[primary_span] #[primary_span]
#[label(parser_unexpected_token_after_label)] #[label(parser_unexpected_token_after_label)]
pub span: Span, pub span: Span,
#[suggestion_verbose(suggestion_remove_label, code = "")] #[suggestion(suggestion_remove_label, style = "verbose", code = "")]
pub remove_label: Option<Span>, pub remove_label: Option<Span>,
#[subdiagnostic] #[subdiagnostic]
pub enclose_in_block: Option<UnexpectedTokenAfterLabelSugg>, pub enclose_in_block: Option<UnexpectedTokenAfterLabelSugg>,
@ -272,7 +282,7 @@ pub(crate) struct RequireColonAfterLabeledExpression {
pub span: Span, pub span: Span,
#[label] #[label]
pub label: Span, pub label: Span,
#[suggestion_short(applicability = "machine-applicable", code = ": ")] #[suggestion(style = "short", applicability = "machine-applicable", code = ": ")]
pub label_end: Span, pub label_end: Span,
} }
@ -354,7 +364,7 @@ pub(crate) struct IntLiteralTooLarge {
pub(crate) struct MissingSemicolonBeforeArray { pub(crate) struct MissingSemicolonBeforeArray {
#[primary_span] #[primary_span]
pub open_delim: Span, pub open_delim: Span,
#[suggestion_verbose(applicability = "maybe-incorrect", code = ";")] #[suggestion(style = "verbose", applicability = "maybe-incorrect", code = ";")]
pub semicolon: Span, pub semicolon: Span,
} }
@ -442,9 +452,9 @@ pub(crate) struct MissingInInForLoop {
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub(crate) enum MissingInInForLoopSub { pub(crate) enum MissingInInForLoopSub {
// Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect // Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect
#[suggestion_short(use_in_not_of, applicability = "maybe-incorrect", code = "in")] #[suggestion(use_in_not_of, style = "short", applicability = "maybe-incorrect", code = "in")]
InNotOf(#[primary_span] Span), InNotOf(#[primary_span] Span),
#[suggestion_short(add_in, applicability = "maybe-incorrect", code = " in ")] #[suggestion(add_in, style = "short", applicability = "maybe-incorrect", code = " in ")]
AddIn(#[primary_span] Span), AddIn(#[primary_span] Span),
} }
@ -470,7 +480,7 @@ pub(crate) struct CatchAfterTry {
pub(crate) struct CommaAfterBaseStruct { pub(crate) struct CommaAfterBaseStruct {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
#[suggestion_short(applicability = "machine-applicable", code = "")] #[suggestion(style = "short", applicability = "machine-applicable", code = "")]
pub comma: Span, pub comma: Span,
} }
@ -512,7 +522,7 @@ pub(crate) struct RemoveLet {
#[diag(parser_use_eq_instead)] #[diag(parser_use_eq_instead)]
pub(crate) struct UseEqInstead { pub(crate) struct UseEqInstead {
#[primary_span] #[primary_span]
#[suggestion_short(applicability = "machine-applicable", code = "=")] #[suggestion(style = "short", applicability = "machine-applicable", code = "=")]
pub span: Span, pub span: Span,
} }
@ -520,7 +530,7 @@ pub(crate) struct UseEqInstead {
#[diag(parser_use_empty_block_not_semi)] #[diag(parser_use_empty_block_not_semi)]
pub(crate) struct UseEmptyBlockNotSemi { pub(crate) struct UseEmptyBlockNotSemi {
#[primary_span] #[primary_span]
#[suggestion_hidden(applicability = "machine-applicable", code = "{{}}")] #[suggestion(style = "hidden", applicability = "machine-applicable", code = "{{}}")]
pub span: Span, pub span: Span,
} }
@ -576,7 +586,12 @@ pub(crate) struct LeadingPlusNotSupported {
#[primary_span] #[primary_span]
#[label] #[label]
pub span: Span, pub span: Span,
#[suggestion_verbose(suggestion_remove_plus, code = "", applicability = "machine-applicable")] #[suggestion(
suggestion_remove_plus,
style = "verbose",
code = "",
applicability = "machine-applicable"
)]
pub remove_plus: Option<Span>, pub remove_plus: Option<Span>,
#[subdiagnostic] #[subdiagnostic]
pub add_parentheses: Option<ExprParenthesesNeeded>, pub add_parentheses: Option<ExprParenthesesNeeded>,
@ -843,7 +858,7 @@ pub(crate) struct InvalidCurlyInLetElse {
#[help] #[help]
pub(crate) struct CompoundAssignmentExpressionInLet { pub(crate) struct CompoundAssignmentExpressionInLet {
#[primary_span] #[primary_span]
#[suggestion_short(code = "=", applicability = "maybe-incorrect")] #[suggestion(style = "short", code = "=", applicability = "maybe-incorrect")]
pub span: Span, pub span: Span,
} }
@ -864,8 +879,9 @@ pub(crate) struct InvalidMetaItem {
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion_verbose( #[suggestion(
parser_sugg_escape_to_use_as_identifier, parser_sugg_escape_to_use_as_identifier,
style = "verbose",
applicability = "maybe-incorrect", applicability = "maybe-incorrect",
code = "r#" code = "r#"
)] )]
@ -1005,7 +1021,12 @@ pub(crate) enum ExpectedSemiSugg {
applicability = "machine-applicable" applicability = "machine-applicable"
)] )]
ChangeToSemi(#[primary_span] Span), ChangeToSemi(#[primary_span] Span),
#[suggestion_short(parser_sugg_add_semi, code = ";", applicability = "machine-applicable")] #[suggestion(
parser_sugg_add_semi,
style = "short",
code = ";",
applicability = "machine-applicable"
)]
AddSemi(#[primary_span] Span), AddSemi(#[primary_span] Span),
} }
@ -1059,8 +1080,9 @@ pub(crate) struct GenericParamsWithoutAngleBracketsSugg {
pub(crate) struct ComparisonOperatorsCannotBeChained { pub(crate) struct ComparisonOperatorsCannotBeChained {
#[primary_span] #[primary_span]
pub span: Vec<Span>, pub span: Vec<Span>,
#[suggestion_verbose( #[suggestion(
parser_sugg_turbofish_syntax, parser_sugg_turbofish_syntax,
style = "verbose",
code = "::", code = "::",
applicability = "maybe-incorrect" applicability = "maybe-incorrect"
)] )]
@ -1074,8 +1096,9 @@ pub(crate) struct ComparisonOperatorsCannotBeChained {
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub(crate) enum ComparisonOperatorsCannotBeChainedSugg { pub(crate) enum ComparisonOperatorsCannotBeChainedSugg {
#[suggestion_verbose( #[suggestion(
sugg_split_comparison, sugg_split_comparison,
style = "verbose",
code = " && {middle_term}", code = " && {middle_term}",
applicability = "maybe-incorrect" applicability = "maybe-incorrect"
)] )]
@ -1217,7 +1240,7 @@ pub(crate) enum UnexpectedConstParamDeclarationSugg {
pub(crate) struct UnexpectedConstInGenericParam { pub(crate) struct UnexpectedConstInGenericParam {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
#[suggestion_verbose(code = "", applicability = "maybe-incorrect")] #[suggestion(style = "verbose", code = "", applicability = "maybe-incorrect")]
pub to_remove: Option<Span>, pub to_remove: Option<Span>,
} }
@ -1225,7 +1248,7 @@ pub(crate) struct UnexpectedConstInGenericParam {
#[diag(parser_async_move_order_incorrect)] #[diag(parser_async_move_order_incorrect)]
pub(crate) struct AsyncMoveOrderIncorrect { pub(crate) struct AsyncMoveOrderIncorrect {
#[primary_span] #[primary_span]
#[suggestion_verbose(code = "async move", applicability = "maybe-incorrect")] #[suggestion(style = "verbose", code = "async move", applicability = "maybe-incorrect")]
pub span: Span, pub span: Span,
} }

View File

@ -291,7 +291,7 @@ pub struct DocTestUnknownAny {
#[note(no_op_note)] #[note(no_op_note)]
pub struct DocTestUnknownSpotlight { pub struct DocTestUnknownSpotlight {
pub path: String, pub path: String,
#[suggestion_short(applicability = "machine-applicable", code = "notable_trait")] #[suggestion(style = "short", applicability = "machine-applicable", code = "notable_trait")]
pub span: Span, pub span: Span,
} }

View File

@ -40,9 +40,9 @@ struct HelloWarn {}
//~^ ERROR unsupported type attribute for diagnostic derive enum //~^ ERROR unsupported type attribute for diagnostic derive enum
enum DiagnosticOnEnum { enum DiagnosticOnEnum {
Foo, Foo,
//~^ ERROR diagnostic slug not specified //~^ ERROR diagnostic slug not specified
Bar, Bar,
//~^ ERROR diagnostic slug not specified //~^ ERROR diagnostic slug not specified
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
@ -211,9 +211,10 @@ struct LabelOnNonSpan {
#[diag(compiletest_example, code = "E0123")] #[diag(compiletest_example, code = "E0123")]
struct Suggest { struct Suggest {
#[suggestion(suggestion, code = "This is the suggested code")] #[suggestion(suggestion, code = "This is the suggested code")]
#[suggestion_short(suggestion, code = "This is the suggested code")] #[suggestion(suggestion, code = "This is the suggested code", style = "normal")]
#[suggestion_hidden(suggestion, code = "This is the suggested code")] #[suggestion(suggestion, code = "This is the suggested code", style = "short")]
#[suggestion_verbose(suggestion, code = "This is the suggested code")] #[suggestion(suggestion, code = "This is the suggested code", style = "hidden")]
#[suggestion(suggestion, code = "This is the suggested code", style = "verbose")]
suggestion: (Span, Applicability), suggestion: (Span, Applicability),
} }
@ -536,8 +537,7 @@ struct LabelWithTrailingList {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(compiletest_example)] #[diag(compiletest_example)]
struct LintsGood { struct LintsGood {}
}
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(compiletest_example)] #[diag(compiletest_example)]
@ -683,7 +683,7 @@ struct RawIdentDiagnosticArg {
#[diag(compiletest_example)] #[diag(compiletest_example)]
struct SubdiagnosticBad { struct SubdiagnosticBad {
#[subdiagnostic(bad)] #[subdiagnostic(bad)]
//~^ ERROR `#[subdiagnostic(bad)]` is not a valid attribute //~^ ERROR `#[subdiagnostic(bad)]` is not a valid attribute
note: Note, note: Note,
} }
@ -691,7 +691,7 @@ struct SubdiagnosticBad {
#[diag(compiletest_example)] #[diag(compiletest_example)]
struct SubdiagnosticBadStr { struct SubdiagnosticBadStr {
#[subdiagnostic = "bad"] #[subdiagnostic = "bad"]
//~^ ERROR `#[subdiagnostic = ...]` is not a valid attribute //~^ ERROR `#[subdiagnostic = ...]` is not a valid attribute
note: Note, note: Note,
} }
@ -699,7 +699,7 @@ struct SubdiagnosticBadStr {
#[diag(compiletest_example)] #[diag(compiletest_example)]
struct SubdiagnosticBadTwice { struct SubdiagnosticBadTwice {
#[subdiagnostic(bad, bad)] #[subdiagnostic(bad, bad)]
//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute //~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
note: Note, note: Note,
} }
@ -707,7 +707,7 @@ struct SubdiagnosticBadTwice {
#[diag(compiletest_example)] #[diag(compiletest_example)]
struct SubdiagnosticBadLitStr { struct SubdiagnosticBadLitStr {
#[subdiagnostic("bad")] #[subdiagnostic("bad")]
//~^ ERROR `#[subdiagnostic("...")]` is not a valid attribute //~^ ERROR `#[subdiagnostic("...")]` is not a valid attribute
note: Note, note: Note,
} }
@ -715,7 +715,7 @@ struct SubdiagnosticBadLitStr {
#[diag(compiletest_example)] #[diag(compiletest_example)]
struct SubdiagnosticEagerLint { struct SubdiagnosticEagerLint {
#[subdiagnostic(eager)] #[subdiagnostic(eager)]
//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute //~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
note: Note, note: Note,
} }
@ -731,11 +731,7 @@ struct SubdiagnosticEagerCorrect {
// after the `span_suggestion` call - which breaks eager translation. // after the `span_suggestion` call - which breaks eager translation.
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion_short( #[suggestion(use_instead, applicability = "machine-applicable", code = "{correct}")]
use_instead,
applicability = "machine-applicable",
code = "{correct}"
)]
pub(crate) struct SubdiagnosticWithSuggestion { pub(crate) struct SubdiagnosticWithSuggestion {
#[primary_span] #[primary_span]
span: Span, span: Span,
@ -796,3 +792,10 @@ struct SuggestionsInvalidLiteral {
//~^ ERROR `code = "..."`/`code(...)` must contain only string literals //~^ ERROR `code = "..."`/`code(...)` must contain only string literals
sub: Span, sub: Span,
} }
#[derive(Diagnostic)]
#[diag(compiletest_example)]
struct SuggestionStyleGood {
#[suggestion(code = "", style = "hidden")]
sub: Span,
}

View File

@ -261,41 +261,41 @@ LL | #[label(label)]
| ^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^
error: suggestion without `code = "..."` error: suggestion without `code = "..."`
--> $DIR/diagnostic-derive.rs:223:5 --> $DIR/diagnostic-derive.rs:224:5
| |
LL | #[suggestion(suggestion)] LL | #[suggestion(suggestion)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: `#[suggestion(nonsense = ...)]` is not a valid attribute error: `#[suggestion(nonsense = ...)]` is not a valid attribute
--> $DIR/diagnostic-derive.rs:231:18 --> $DIR/diagnostic-derive.rs:232:18
| |
LL | #[suggestion(nonsense = "bar")] LL | #[suggestion(nonsense = "bar")]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
| |
= help: only `code` and `applicability` are valid nested attributes = help: only `style`, `code` and `applicability` are valid nested attributes
error: suggestion without `code = "..."` error: suggestion without `code = "..."`
--> $DIR/diagnostic-derive.rs:231:5 --> $DIR/diagnostic-derive.rs:232:5
| |
LL | #[suggestion(nonsense = "bar")] LL | #[suggestion(nonsense = "bar")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: `#[suggestion(msg = ...)]` is not a valid attribute error: `#[suggestion(msg = ...)]` is not a valid attribute
--> $DIR/diagnostic-derive.rs:240:18 --> $DIR/diagnostic-derive.rs:241:18
| |
LL | #[suggestion(msg = "bar")] LL | #[suggestion(msg = "bar")]
| ^^^^^^^^^^^ | ^^^^^^^^^^^
| |
= help: only `code` and `applicability` are valid nested attributes = help: only `style`, `code` and `applicability` are valid nested attributes
error: suggestion without `code = "..."` error: suggestion without `code = "..."`
--> $DIR/diagnostic-derive.rs:240:5 --> $DIR/diagnostic-derive.rs:241:5
| |
LL | #[suggestion(msg = "bar")] LL | #[suggestion(msg = "bar")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: wrong field type for suggestion error: wrong field type for suggestion
--> $DIR/diagnostic-derive.rs:263:5 --> $DIR/diagnostic-derive.rs:264:5
| |
LL | / #[suggestion(suggestion, code = "This is suggested code")] LL | / #[suggestion(suggestion, code = "This is suggested code")]
LL | | LL | |
@ -305,55 +305,55 @@ LL | | suggestion: Applicability,
= help: `#[suggestion(...)]` should be applied to fields of type `Span` or `(Span, Applicability)` = help: `#[suggestion(...)]` should be applied to fields of type `Span` or `(Span, Applicability)`
error: specified multiple times error: specified multiple times
--> $DIR/diagnostic-derive.rs:279:24 --> $DIR/diagnostic-derive.rs:280:24
| |
LL | suggestion: (Span, Span, Applicability), LL | suggestion: (Span, Span, Applicability),
| ^^^^ | ^^^^
| |
note: previously specified here note: previously specified here
--> $DIR/diagnostic-derive.rs:279:18 --> $DIR/diagnostic-derive.rs:280:18
| |
LL | suggestion: (Span, Span, Applicability), LL | suggestion: (Span, Span, Applicability),
| ^^^^ | ^^^^
error: specified multiple times error: specified multiple times
--> $DIR/diagnostic-derive.rs:287:33 --> $DIR/diagnostic-derive.rs:288:33
| |
LL | suggestion: (Applicability, Applicability, Span), LL | suggestion: (Applicability, Applicability, Span),
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
| |
note: previously specified here note: previously specified here
--> $DIR/diagnostic-derive.rs:287:18 --> $DIR/diagnostic-derive.rs:288:18
| |
LL | suggestion: (Applicability, Applicability, Span), LL | suggestion: (Applicability, Applicability, Span),
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
error: `#[label = ...]` is not a valid attribute error: `#[label = ...]` is not a valid attribute
--> $DIR/diagnostic-derive.rs:294:5 --> $DIR/diagnostic-derive.rs:295:5
| |
LL | #[label = "bar"] LL | #[label = "bar"]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
error: specified multiple times error: specified multiple times
--> $DIR/diagnostic-derive.rs:445:44 --> $DIR/diagnostic-derive.rs:446:44
| |
LL | #[suggestion(suggestion, code = "...", applicability = "maybe-incorrect")] LL | #[suggestion(suggestion, code = "...", applicability = "maybe-incorrect")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
note: previously specified here note: previously specified here
--> $DIR/diagnostic-derive.rs:447:24 --> $DIR/diagnostic-derive.rs:448:24
| |
LL | suggestion: (Span, Applicability), LL | suggestion: (Span, Applicability),
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
error: invalid applicability error: invalid applicability
--> $DIR/diagnostic-derive.rs:453:44 --> $DIR/diagnostic-derive.rs:454:44
| |
LL | #[suggestion(suggestion, code = "...", applicability = "batman")] LL | #[suggestion(suggestion, code = "...", applicability = "batman")]
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^
error: `#[label(foo)]` is not a valid attribute error: `#[label(foo)]` is not a valid attribute
--> $DIR/diagnostic-derive.rs:516:20 --> $DIR/diagnostic-derive.rs:517:20
| |
LL | #[label(label, foo)] LL | #[label(label, foo)]
| ^^^ | ^^^
@ -361,13 +361,13 @@ LL | #[label(label, foo)]
= help: a diagnostic slug must be the first argument to the attribute = help: a diagnostic slug must be the first argument to the attribute
error: `#[label(foo = ...)]` is not a valid attribute error: `#[label(foo = ...)]` is not a valid attribute
--> $DIR/diagnostic-derive.rs:524:20 --> $DIR/diagnostic-derive.rs:525:20
| |
LL | #[label(label, foo = "...")] LL | #[label(label, foo = "...")]
| ^^^^^^^^^^^ | ^^^^^^^^^^^
error: `#[label(foo(...))]` is not a valid attribute error: `#[label(foo(...))]` is not a valid attribute
--> $DIR/diagnostic-derive.rs:532:20 --> $DIR/diagnostic-derive.rs:533:20
| |
LL | #[label(label, foo("..."))] LL | #[label(label, foo("..."))]
| ^^^^^^^^^^ | ^^^^^^^^^^
@ -574,19 +574,19 @@ LL | #[subdiagnostic(eager)]
= help: eager subdiagnostics are not supported on lints = help: eager subdiagnostics are not supported on lints
error: expected at least one string literal for `code(...)` error: expected at least one string literal for `code(...)`
--> $DIR/diagnostic-derive.rs:779:18 --> $DIR/diagnostic-derive.rs:775:18
| |
LL | #[suggestion(code())] LL | #[suggestion(code())]
| ^^^^^^ | ^^^^^^
error: `code(...)` must contain only string literals error: `code(...)` must contain only string literals
--> $DIR/diagnostic-derive.rs:787:23 --> $DIR/diagnostic-derive.rs:783:23
| |
LL | #[suggestion(code(foo))] LL | #[suggestion(code(foo))]
| ^^^ | ^^^
error: `code = "..."`/`code(...)` must contain only string literals error: `code = "..."`/`code(...)` must contain only string literals
--> $DIR/diagnostic-derive.rs:795:18 --> $DIR/diagnostic-derive.rs:791:18
| |
LL | #[suggestion(code = 3)] LL | #[suggestion(code = 3)]
| ^^^^^^^^ | ^^^^^^^^
@ -652,7 +652,7 @@ LL | #[diag(nonsense, code = "E0123")]
| ^^^^^^^^ not found in `rustc_errors::fluent` | ^^^^^^^^ not found in `rustc_errors::fluent`
error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied
--> $DIR/diagnostic-derive.rs:338:10 --> $DIR/diagnostic-derive.rs:339:10
| |
LL | #[derive(Diagnostic)] LL | #[derive(Diagnostic)]
| ^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello` | ^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello`

View File

@ -11,13 +11,13 @@
#![crate_type = "lib"] #![crate_type = "lib"]
extern crate rustc_errors; extern crate rustc_errors;
extern crate rustc_macros;
extern crate rustc_session; extern crate rustc_session;
extern crate rustc_span; extern crate rustc_span;
extern crate rustc_macros;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_span::Span;
use rustc_macros::Subdiagnostic; use rustc_macros::Subdiagnostic;
use rustc_span::Span;
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[label(parser_add_paren)] #[label(parser_add_paren)]
@ -40,7 +40,7 @@ enum B {
#[primary_span] #[primary_span]
span: Span, span: Span,
var: String, var: String,
} },
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
@ -165,7 +165,7 @@ enum P {
#[primary_span] #[primary_span]
span: Span, span: Span,
var: String, var: String,
} },
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
@ -177,7 +177,7 @@ enum Q {
#[primary_span] #[primary_span]
span: Span, span: Span,
var: String, var: String,
} },
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
@ -189,7 +189,7 @@ enum R {
#[primary_span] #[primary_span]
span: Span, span: Span,
var: String, var: String,
} },
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
@ -201,7 +201,7 @@ enum S {
#[primary_span] #[primary_span]
span: Span, span: Span,
var: String, var: String,
} },
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
@ -213,7 +213,7 @@ enum T {
#[primary_span] #[primary_span]
span: Span, span: Span,
var: String, var: String,
} },
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
@ -225,7 +225,7 @@ enum U {
#[primary_span] #[primary_span]
span: Span, span: Span,
var: String, var: String,
} },
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
@ -240,7 +240,7 @@ enum V {
#[primary_span] #[primary_span]
span: Span, span: Span,
var: String, var: String,
} },
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
@ -301,14 +301,14 @@ struct AB {
#[primary_span] #[primary_span]
span: Span, span: Span,
#[skip_arg] #[skip_arg]
z: Z z: Z,
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
union AC { union AC {
//~^ ERROR unexpected unsupported untagged union //~^ ERROR unexpected unsupported untagged union
span: u32, span: u32,
b: u64 b: u64,
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
@ -372,7 +372,7 @@ enum AI {
#[applicability] #[applicability]
applicability: Applicability, applicability: Applicability,
var: String, var: String,
} },
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
@ -427,7 +427,7 @@ struct AN {
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion(parser_add_paren, code ="...", applicability = "foo")] #[suggestion(parser_add_paren, code = "...", applicability = "foo")]
//~^ ERROR invalid applicability //~^ ERROR invalid applicability
struct AO { struct AO {
#[primary_span] #[primary_span]
@ -437,7 +437,7 @@ struct AO {
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[help(parser_add_paren)] #[help(parser_add_paren)]
struct AP { struct AP {
var: String var: String,
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
@ -452,7 +452,7 @@ struct AR {
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion(parser_add_paren, code ="...", applicability = "machine-applicable")] #[suggestion(parser_add_paren, code = "...", applicability = "machine-applicable")]
struct AS { struct AS {
#[primary_span] #[primary_span]
span: Span, span: Span,
@ -467,11 +467,11 @@ enum AT {
#[primary_span] #[primary_span]
span: Span, span: Span,
var: String, var: String,
} },
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion(parser_add_paren, code ="{var}", applicability = "machine-applicable")] #[suggestion(parser_add_paren, code = "{var}", applicability = "machine-applicable")]
struct AU { struct AU {
#[primary_span] #[primary_span]
span: Span, span: Span,
@ -479,7 +479,7 @@ struct AU {
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion(parser_add_paren, code ="{var}", applicability = "machine-applicable")] #[suggestion(parser_add_paren, code = "{var}", applicability = "machine-applicable")]
//~^ ERROR `var` doesn't refer to a field on this type //~^ ERROR `var` doesn't refer to a field on this type
struct AV { struct AV {
#[primary_span] #[primary_span]
@ -488,22 +488,22 @@ struct AV {
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
enum AW { enum AW {
#[suggestion(parser_add_paren, code ="{var}", applicability = "machine-applicable")] #[suggestion(parser_add_paren, code = "{var}", applicability = "machine-applicable")]
A { A {
#[primary_span] #[primary_span]
span: Span, span: Span,
var: String, var: String,
} },
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
enum AX { enum AX {
#[suggestion(parser_add_paren, code ="{var}", applicability = "machine-applicable")] #[suggestion(parser_add_paren, code = "{var}", applicability = "machine-applicable")]
//~^ ERROR `var` doesn't refer to a field on this type //~^ ERROR `var` doesn't refer to a field on this type
A { A {
#[primary_span] #[primary_span]
span: Span, span: Span,
} },
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
@ -659,7 +659,7 @@ enum BL {
/// ..and the field /// ..and the field
#[primary_span] #[primary_span]
span: Span, span: Span,
} },
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
@ -706,3 +706,95 @@ struct BQ {
span: Span, span: Span,
r#type: String, r#type: String,
} }
#[derive(Subdiagnostic)]
#[suggestion(parser_add_paren, code = "")]
struct SuggestionStyleDefault {
#[primary_span]
sub: Span,
}
#[derive(Subdiagnostic)]
#[suggestion(parser_add_paren, code = "", style = "short")]
struct SuggestionStyleShort {
#[primary_span]
sub: Span,
}
#[derive(Subdiagnostic)]
#[suggestion(parser_add_paren, code = "", style = "hidden")]
struct SuggestionStyleHidden {
#[primary_span]
sub: Span,
}
#[derive(Subdiagnostic)]
#[suggestion(parser_add_paren, code = "", style = "verbose")]
struct SuggestionStyleVerbose {
#[primary_span]
sub: Span,
}
#[derive(Subdiagnostic)]
#[suggestion(parser_add_paren, code = "", style = "tool-only")]
struct SuggestionStyleToolOnly {
#[primary_span]
sub: Span,
}
#[derive(Subdiagnostic)]
#[suggestion(parser_add_paren, code = "", style = "hidden", style = "normal")]
//~^ ERROR specified multiple times
//~| NOTE previously specified here
struct SuggestionStyleTwice {
#[primary_span]
sub: Span,
}
#[derive(Subdiagnostic)]
#[suggestion_hidden(parser_add_paren, code = "")]
//~^ ERROR #[suggestion_hidden(...)]` is not a valid attribute
struct SuggestionStyleOldSyntax {
#[primary_span]
sub: Span,
}
#[derive(Subdiagnostic)]
#[suggestion_hidden(parser_add_paren, code = "", style = "normal")]
//~^ ERROR #[suggestion_hidden(...)]` is not a valid attribute
struct SuggestionStyleOldAndNewSyntax {
#[primary_span]
sub: Span,
}
#[derive(Subdiagnostic)]
#[suggestion(parser_add_paren, code = "", style = "foo")]
//~^ ERROR invalid suggestion style
struct SuggestionStyleInvalid1 {
#[primary_span]
sub: Span,
}
#[derive(Subdiagnostic)]
#[suggestion(parser_add_paren, code = "", style = 42)]
//~^ ERROR `#[suggestion(style = ...)]` is not a valid attribute
struct SuggestionStyleInvalid2 {
#[primary_span]
sub: Span,
}
#[derive(Subdiagnostic)]
#[suggestion(parser_add_paren, code = "", style)]
//~^ ERROR `#[suggestion(style)]` is not a valid attribute
struct SuggestionStyleInvalid3 {
#[primary_span]
sub: Span,
}
#[derive(Subdiagnostic)]
#[suggestion(parser_add_paren, code = "", style("foo"))]
//~^ ERROR `#[suggestion(style(...))]` is not a valid attribute
struct SuggestionStyleInvalid4 {
#[primary_span]
sub: Span,
}

View File

@ -186,7 +186,7 @@ error: unexpected unsupported untagged union
LL | / union AC { LL | / union AC {
LL | | LL | |
LL | | span: u32, LL | | span: u32,
LL | | b: u64 LL | | b: u64,
LL | | } LL | | }
| |_^ | |_^
@ -253,10 +253,10 @@ LL | #[suggestion(parser_add_paren)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: invalid applicability error: invalid applicability
--> $DIR/subdiagnostic-derive.rs:430:45 --> $DIR/subdiagnostic-derive.rs:430:46
| |
LL | #[suggestion(parser_add_paren, code ="...", applicability = "foo")] LL | #[suggestion(parser_add_paren, code = "...", applicability = "foo")]
| ^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^
error: suggestion without `#[primary_span]` field error: suggestion without `#[primary_span]` field
--> $DIR/subdiagnostic-derive.rs:448:1 --> $DIR/subdiagnostic-derive.rs:448:1
@ -275,16 +275,16 @@ LL | #[label]
| ^^^^^^^^ | ^^^^^^^^
error: `var` doesn't refer to a field on this type error: `var` doesn't refer to a field on this type
--> $DIR/subdiagnostic-derive.rs:482:38 --> $DIR/subdiagnostic-derive.rs:482:39
| |
LL | #[suggestion(parser_add_paren, code ="{var}", applicability = "machine-applicable")] LL | #[suggestion(parser_add_paren, code = "{var}", applicability = "machine-applicable")]
| ^^^^^^^ | ^^^^^^^
error: `var` doesn't refer to a field on this type error: `var` doesn't refer to a field on this type
--> $DIR/subdiagnostic-derive.rs:501:42 --> $DIR/subdiagnostic-derive.rs:501:43
| |
LL | #[suggestion(parser_add_paren, code ="{var}", applicability = "machine-applicable")] LL | #[suggestion(parser_add_paren, code = "{var}", applicability = "machine-applicable")]
| ^^^^^^^ | ^^^^^^^
error: `#[suggestion_part]` is not a valid attribute error: `#[suggestion_part]` is not a valid attribute
--> $DIR/subdiagnostic-derive.rs:524:5 --> $DIR/subdiagnostic-derive.rs:524:5
@ -320,7 +320,7 @@ error: `#[multipart_suggestion(code = ...)]` is not a valid attribute
LL | #[multipart_suggestion(parser_add_paren, code = "...", applicability = "machine-applicable")] LL | #[multipart_suggestion(parser_add_paren, code = "...", applicability = "machine-applicable")]
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
| |
= help: only `applicability` is a valid nested attributes = help: only `style` and `applicability` are valid nested attributes
error: multipart suggestion without any `#[suggestion_part(...)]` fields error: multipart suggestion without any `#[suggestion_part(...)]` fields
--> $DIR/subdiagnostic-derive.rs:536:1 --> $DIR/subdiagnostic-derive.rs:536:1
@ -445,6 +445,62 @@ error: `code = "..."`/`code(...)` must contain only string literals
LL | #[suggestion_part(code = 3)] LL | #[suggestion_part(code = 3)]
| ^^^^^^^^ | ^^^^^^^^
error: specified multiple times
--> $DIR/subdiagnostic-derive.rs:746:61
|
LL | #[suggestion(parser_add_paren, code = "", style = "hidden", style = "normal")]
| ^^^^^^^^^^^^^^^^
|
note: previously specified here
--> $DIR/subdiagnostic-derive.rs:746:43
|
LL | #[suggestion(parser_add_paren, code = "", style = "hidden", style = "normal")]
| ^^^^^^^^^^^^^^^^
error: `#[suggestion_hidden(...)]` is not a valid attribute
--> $DIR/subdiagnostic-derive.rs:755:1
|
LL | #[suggestion_hidden(parser_add_paren, code = "")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: Use `#[suggestion(..., style = "hidden")]` instead
error: `#[suggestion_hidden(...)]` is not a valid attribute
--> $DIR/subdiagnostic-derive.rs:763:1
|
LL | #[suggestion_hidden(parser_add_paren, code = "", style = "normal")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: Use `#[suggestion(..., style = "hidden")]` instead
error: invalid suggestion style
--> $DIR/subdiagnostic-derive.rs:771:51
|
LL | #[suggestion(parser_add_paren, code = "", style = "foo")]
| ^^^^^
|
= help: valid styles are `normal`, `short`, `hidden`, `verbose` and `tool-only`
error: `#[suggestion(style = ...)]` is not a valid attribute
--> $DIR/subdiagnostic-derive.rs:779:43
|
LL | #[suggestion(parser_add_paren, code = "", style = 42)]
| ^^^^^^^^^^
error: `#[suggestion(style)]` is not a valid attribute
--> $DIR/subdiagnostic-derive.rs:787:43
|
LL | #[suggestion(parser_add_paren, code = "", style)]
| ^^^^^
|
= help: a diagnostic slug must be the first argument to the attribute
error: `#[suggestion(style(...))]` is not a valid attribute
--> $DIR/subdiagnostic-derive.rs:795:43
|
LL | #[suggestion(parser_add_paren, code = "", style("foo"))]
| ^^^^^^^^^^^^
error: cannot find attribute `foo` in this scope error: cannot find attribute `foo` in this scope
--> $DIR/subdiagnostic-derive.rs:63:3 --> $DIR/subdiagnostic-derive.rs:63:3
| |
@ -505,6 +561,6 @@ error[E0425]: cannot find value `slug` in module `rustc_errors::fluent`
LL | #[label(slug)] LL | #[label(slug)]
| ^^^^ not found in `rustc_errors::fluent` | ^^^^ not found in `rustc_errors::fluent`
error: aborting due to 72 previous errors error: aborting due to 79 previous errors
For more information about this error, try `rustc --explain E0425`. For more information about this error, try `rustc --explain E0425`.