Skip to content

Commit 20f2958

Browse files
committed
Add "tool-only" suggestion style
1 parent 29334b9 commit 20f2958

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

compiler/rustc_macros/src/diagnostics/utils.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,14 +474,11 @@ pub(super) fn build_suggestion_code(
474474
/// Possible styles for suggestion subdiagnostics.
475475
#[derive(Clone, Copy, PartialEq)]
476476
pub(super) enum SuggestionKind {
477-
/// `#[suggestion]`
478477
Normal,
479-
/// `#[suggestion_short]`
480478
Short,
481-
/// `#[suggestion_hidden]`
482479
Hidden,
483-
/// `#[suggestion_verbose]`
484480
Verbose,
481+
ToolOnly,
485482
}
486483

487484
impl FromStr for SuggestionKind {
@@ -493,6 +490,7 @@ impl FromStr for SuggestionKind {
493490
"short" => Ok(SuggestionKind::Short),
494491
"hidden" => Ok(SuggestionKind::Hidden),
495492
"verbose" => Ok(SuggestionKind::Verbose),
493+
"tool-only" => Ok(SuggestionKind::ToolOnly),
496494
_ => Err(()),
497495
}
498496
}
@@ -513,6 +511,9 @@ impl SuggestionKind {
513511
SuggestionKind::Verbose => {
514512
quote! { rustc_errors::SuggestionStyle::ShowAlways }
515513
}
514+
SuggestionKind::ToolOnly => {
515+
quote! { rustc_errors::SuggestionStyle::CompletelyHidden }
516+
}
516517
}
517518
}
518519

@@ -583,6 +584,8 @@ impl SubdiagnosticKind {
583584
"help" => SubdiagnosticKind::Help,
584585
"warning" => SubdiagnosticKind::Warn,
585586
_ => {
587+
// FIXME(#100717): remove #[suggestion_{short,verbose,hidden}] attributes, use
588+
// #[suggestion(style = "...")] instead
586589
if let Some(suggestion_kind) =
587590
name.strip_prefix("suggestion").and_then(SuggestionKind::from_suffix)
588591
{
@@ -719,7 +722,7 @@ impl SubdiagnosticKind {
719722

720723
let value = value.value().parse().unwrap_or_else(|()| {
721724
span_err(value.span().unwrap(), "invalid suggestion style")
722-
.help("valid styles are `normal`, `short`, `hidden` and `verbose`")
725+
.help("valid styles are `normal`, `short`, `hidden`, `verbose` and `tool-only`")
723726
.emit();
724727
SuggestionKind::Normal
725728
});

src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,13 @@ struct SuggestionStyleVerbose {
735735
sub: Span,
736736
}
737737

738+
#[derive(Subdiagnostic)]
739+
#[suggestion(parser_add_paren, code = "", style = "tool-only")]
740+
struct SuggestionStyleToolOnly {
741+
#[primary_span]
742+
sub: Span,
743+
}
744+
738745
#[derive(Subdiagnostic)]
739746
#[suggestion(parser_add_paren, code = "", style = "hidden", style = "normal")]
740747
//~^ ERROR specified multiple times

src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -446,53 +446,53 @@ LL | #[suggestion_part(code = 3)]
446446
| ^^^^^^^^
447447

448448
error: specified multiple times
449-
--> $DIR/subdiagnostic-derive.rs:739:61
449+
--> $DIR/subdiagnostic-derive.rs:746:61
450450
|
451451
LL | #[suggestion(parser_add_paren, code = "", style = "hidden", style = "normal")]
452452
| ^^^^^^^^^^^^^^^^
453453
|
454454
note: previously specified here
455-
--> $DIR/subdiagnostic-derive.rs:739:43
455+
--> $DIR/subdiagnostic-derive.rs:746:43
456456
|
457457
LL | #[suggestion(parser_add_paren, code = "", style = "hidden", style = "normal")]
458458
| ^^^^^^^^^^^^^^^^
459459

460460
error: specified multiple times
461-
--> $DIR/subdiagnostic-derive.rs:748:50
461+
--> $DIR/subdiagnostic-derive.rs:755:50
462462
|
463463
LL | #[suggestion_hidden(parser_add_paren, code = "", style = "normal")]
464464
| ^^^^^^^^^^^^^^^^
465465
|
466466
note: previously specified here
467-
--> $DIR/subdiagnostic-derive.rs:748:3
467+
--> $DIR/subdiagnostic-derive.rs:755:3
468468
|
469469
LL | #[suggestion_hidden(parser_add_paren, code = "", style = "normal")]
470470
| ^^^^^^^^^^^^^^^^^
471471

472472
error: invalid suggestion style
473-
--> $DIR/subdiagnostic-derive.rs:757:51
473+
--> $DIR/subdiagnostic-derive.rs:764:51
474474
|
475475
LL | #[suggestion(parser_add_paren, code = "", style = "foo")]
476476
| ^^^^^
477477
|
478-
= help: valid styles are `normal`, `short`, `hidden` and `verbose`
478+
= help: valid styles are `normal`, `short`, `hidden`, `verbose` and `tool-only`
479479

480480
error: `#[suggestion(style = ...)]` is not a valid attribute
481-
--> $DIR/subdiagnostic-derive.rs:765:43
481+
--> $DIR/subdiagnostic-derive.rs:772:43
482482
|
483483
LL | #[suggestion(parser_add_paren, code = "", style = 42)]
484484
| ^^^^^^^^^^
485485

486486
error: `#[suggestion(style)]` is not a valid attribute
487-
--> $DIR/subdiagnostic-derive.rs:773:43
487+
--> $DIR/subdiagnostic-derive.rs:780:43
488488
|
489489
LL | #[suggestion(parser_add_paren, code = "", style)]
490490
| ^^^^^
491491
|
492492
= help: a diagnostic slug must be the first argument to the attribute
493493

494494
error: `#[suggestion(style(...))]` is not a valid attribute
495-
--> $DIR/subdiagnostic-derive.rs:781:43
495+
--> $DIR/subdiagnostic-derive.rs:788:43
496496
|
497497
LL | #[suggestion(parser_add_paren, code = "", style("foo"))]
498498
| ^^^^^^^^^^^^

0 commit comments

Comments
 (0)