Convert some impl Subdiagnostics to derives
This commit is contained in:
parent
635dcd819a
commit
ab4891ce74
3 changed files with 14 additions and 36 deletions
|
|
@ -3,7 +3,7 @@
|
|||
use rustc_abi::ExternAbi;
|
||||
use rustc_ast::ParamKindOrd;
|
||||
use rustc_errors::codes::*;
|
||||
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic, inline_fluent};
|
||||
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic};
|
||||
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
||||
use rustc_span::{Ident, Span, Symbol};
|
||||
|
||||
|
|
@ -927,19 +927,15 @@ pub(crate) struct FeatureOnNonNightly {
|
|||
pub sugg: Option<Span>,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[help(
|
||||
"the feature `{$name}` has been stable since `{$since}` and no longer requires an attribute to enable"
|
||||
)]
|
||||
pub(crate) struct StableFeature {
|
||||
pub name: Symbol,
|
||||
pub since: Symbol,
|
||||
}
|
||||
|
||||
impl Subdiagnostic for StableFeature {
|
||||
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
||||
diag.arg("name", self.name);
|
||||
diag.arg("since", self.since);
|
||||
diag.help(inline_fluent!("the feature `{$name}` has been stable since `{$since}` and no longer requires an attribute to enable"));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag("`{$f1}` and `{$f2}` are incompatible, using them at the same time is not allowed")]
|
||||
#[help("remove one of these features")]
|
||||
|
|
|
|||
|
|
@ -1975,27 +1975,17 @@ pub(crate) struct OverflowingBinHex<'a> {
|
|||
pub sign_bit_sub: Option<OverflowingBinHexSignBitSub<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub(crate) enum OverflowingBinHexSign {
|
||||
#[note(
|
||||
"the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}` and will become `{$actually}{$ty}`"
|
||||
)]
|
||||
Positive,
|
||||
#[note("the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}`")]
|
||||
#[note("and the value `-{$lit}` will become `{$actually}{$ty}`")]
|
||||
Negative,
|
||||
}
|
||||
|
||||
impl Subdiagnostic for OverflowingBinHexSign {
|
||||
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
||||
match self {
|
||||
OverflowingBinHexSign::Positive => {
|
||||
diag.note(inline_fluent!("the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}` and will become `{$actually}{$ty}`"));
|
||||
}
|
||||
OverflowingBinHexSign::Negative => {
|
||||
diag.note(inline_fluent!(
|
||||
"the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}`"
|
||||
));
|
||||
diag.note(inline_fluent!("and the value `-{$lit}` will become `{$actually}{$ty}`"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub(crate) enum OverflowingBinHexSub<'a> {
|
||||
#[suggestion(
|
||||
|
|
|
|||
|
|
@ -56,22 +56,14 @@ pub struct OverlappingRangeEndpoints {
|
|||
pub overlap: Vec<Overlap>,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[label("this range overlaps on `{$range}`...")]
|
||||
pub struct Overlap {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub range: String, // a printed pattern
|
||||
}
|
||||
|
||||
impl Subdiagnostic for Overlap {
|
||||
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
||||
let Overlap { span, range } = self;
|
||||
|
||||
// FIXME(mejrs) unfortunately `#[derive(LintDiagnostic)]`
|
||||
// does not support `#[subdiagnostic(eager)]`...
|
||||
let message = format!("this range overlaps on `{range}`...");
|
||||
diag.span_label(span, message);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag("exclusive range missing `{$max}`")]
|
||||
pub struct ExclusiveRangeMissingMax {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue