Add "tool-only" suggestion style
This commit is contained in:
parent
29334b951a
commit
20f2958b8a
3 changed files with 24 additions and 14 deletions
|
@ -474,14 +474,11 @@ pub(super) fn build_suggestion_code(
|
||||||
/// Possible styles for suggestion subdiagnostics.
|
/// Possible styles for suggestion subdiagnostics.
|
||||||
#[derive(Clone, Copy, PartialEq)]
|
#[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 {
|
||||||
|
@ -493,6 +490,7 @@ impl FromStr for SuggestionKind {
|
||||||
"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(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -513,6 +511,9 @@ impl SuggestionKind {
|
||||||
SuggestionKind::Verbose => {
|
SuggestionKind::Verbose => {
|
||||||
quote! { rustc_errors::SuggestionStyle::ShowAlways }
|
quote! { rustc_errors::SuggestionStyle::ShowAlways }
|
||||||
}
|
}
|
||||||
|
SuggestionKind::ToolOnly => {
|
||||||
|
quote! { rustc_errors::SuggestionStyle::CompletelyHidden }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -583,6 +584,8 @@ impl SubdiagnosticKind {
|
||||||
"help" => SubdiagnosticKind::Help,
|
"help" => SubdiagnosticKind::Help,
|
||||||
"warning" => SubdiagnosticKind::Warn,
|
"warning" => SubdiagnosticKind::Warn,
|
||||||
_ => {
|
_ => {
|
||||||
|
// FIXME(#100717): remove #[suggestion_{short,verbose,hidden}] attributes, use
|
||||||
|
// #[suggestion(style = "...")] instead
|
||||||
if let Some(suggestion_kind) =
|
if let Some(suggestion_kind) =
|
||||||
name.strip_prefix("suggestion").and_then(SuggestionKind::from_suffix)
|
name.strip_prefix("suggestion").and_then(SuggestionKind::from_suffix)
|
||||||
{
|
{
|
||||||
|
@ -719,7 +722,7 @@ impl SubdiagnosticKind {
|
||||||
|
|
||||||
let value = value.value().parse().unwrap_or_else(|()| {
|
let value = value.value().parse().unwrap_or_else(|()| {
|
||||||
span_err(value.span().unwrap(), "invalid suggestion style")
|
span_err(value.span().unwrap(), "invalid suggestion style")
|
||||||
.help("valid styles are `normal`, `short`, `hidden` and `verbose`")
|
.help("valid styles are `normal`, `short`, `hidden`, `verbose` and `tool-only`")
|
||||||
.emit();
|
.emit();
|
||||||
SuggestionKind::Normal
|
SuggestionKind::Normal
|
||||||
});
|
});
|
||||||
|
|
|
@ -735,6 +735,13 @@ struct SuggestionStyleVerbose {
|
||||||
sub: Span,
|
sub: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Subdiagnostic)]
|
||||||
|
#[suggestion(parser_add_paren, code = "", style = "tool-only")]
|
||||||
|
struct SuggestionStyleToolOnly {
|
||||||
|
#[primary_span]
|
||||||
|
sub: Span,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
#[suggestion(parser_add_paren, code = "", style = "hidden", style = "normal")]
|
#[suggestion(parser_add_paren, code = "", style = "hidden", style = "normal")]
|
||||||
//~^ ERROR specified multiple times
|
//~^ ERROR specified multiple times
|
||||||
|
|
|
@ -446,45 +446,45 @@ LL | #[suggestion_part(code = 3)]
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
|
||||||
error: specified multiple times
|
error: specified multiple times
|
||||||
--> $DIR/subdiagnostic-derive.rs:739:61
|
--> $DIR/subdiagnostic-derive.rs:746:61
|
||||||
|
|
|
|
||||||
LL | #[suggestion(parser_add_paren, code = "", style = "hidden", style = "normal")]
|
LL | #[suggestion(parser_add_paren, code = "", style = "hidden", style = "normal")]
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
note: previously specified here
|
note: previously specified here
|
||||||
--> $DIR/subdiagnostic-derive.rs:739:43
|
--> $DIR/subdiagnostic-derive.rs:746:43
|
||||||
|
|
|
|
||||||
LL | #[suggestion(parser_add_paren, code = "", style = "hidden", style = "normal")]
|
LL | #[suggestion(parser_add_paren, code = "", style = "hidden", style = "normal")]
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: specified multiple times
|
error: specified multiple times
|
||||||
--> $DIR/subdiagnostic-derive.rs:748:50
|
--> $DIR/subdiagnostic-derive.rs:755:50
|
||||||
|
|
|
|
||||||
LL | #[suggestion_hidden(parser_add_paren, code = "", style = "normal")]
|
LL | #[suggestion_hidden(parser_add_paren, code = "", style = "normal")]
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
note: previously specified here
|
note: previously specified here
|
||||||
--> $DIR/subdiagnostic-derive.rs:748:3
|
--> $DIR/subdiagnostic-derive.rs:755:3
|
||||||
|
|
|
|
||||||
LL | #[suggestion_hidden(parser_add_paren, code = "", style = "normal")]
|
LL | #[suggestion_hidden(parser_add_paren, code = "", style = "normal")]
|
||||||
| ^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: invalid suggestion style
|
error: invalid suggestion style
|
||||||
--> $DIR/subdiagnostic-derive.rs:757:51
|
--> $DIR/subdiagnostic-derive.rs:764:51
|
||||||
|
|
|
|
||||||
LL | #[suggestion(parser_add_paren, code = "", style = "foo")]
|
LL | #[suggestion(parser_add_paren, code = "", style = "foo")]
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
|
|
||||||
= help: valid styles are `normal`, `short`, `hidden` and `verbose`
|
= help: valid styles are `normal`, `short`, `hidden`, `verbose` and `tool-only`
|
||||||
|
|
||||||
error: `#[suggestion(style = ...)]` is not a valid attribute
|
error: `#[suggestion(style = ...)]` is not a valid attribute
|
||||||
--> $DIR/subdiagnostic-derive.rs:765:43
|
--> $DIR/subdiagnostic-derive.rs:772:43
|
||||||
|
|
|
|
||||||
LL | #[suggestion(parser_add_paren, code = "", style = 42)]
|
LL | #[suggestion(parser_add_paren, code = "", style = 42)]
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|
||||||
error: `#[suggestion(style)]` is not a valid attribute
|
error: `#[suggestion(style)]` is not a valid attribute
|
||||||
--> $DIR/subdiagnostic-derive.rs:773:43
|
--> $DIR/subdiagnostic-derive.rs:780:43
|
||||||
|
|
|
|
||||||
LL | #[suggestion(parser_add_paren, code = "", style)]
|
LL | #[suggestion(parser_add_paren, code = "", style)]
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
@ -492,7 +492,7 @@ LL | #[suggestion(parser_add_paren, code = "", style)]
|
||||||
= 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: `#[suggestion(style(...))]` is not a valid attribute
|
error: `#[suggestion(style(...))]` is not a valid attribute
|
||||||
--> $DIR/subdiagnostic-derive.rs:781:43
|
--> $DIR/subdiagnostic-derive.rs:788:43
|
||||||
|
|
|
|
||||||
LL | #[suggestion(parser_add_paren, code = "", style("foo"))]
|
LL | #[suggestion(parser_add_paren, code = "", style("foo"))]
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue