Skip to content

Commit 9376482

Browse files
authored
Rollup merge of #152495 - JonathanBrouwer:remove-empty-subdiags, r=lqd
Clean up some subdiagnostics Just a nice minor cleanup :) * Removes some empty subdiagnostics which could just be subdiagnostic attributes * Convert some manual implementation of `Subdiagnostic` to derives
2 parents 5822878 + ab4891c commit 9376482

12 files changed

Lines changed: 36 additions & 90 deletions

File tree

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use rustc_abi::ExternAbi;
44
use rustc_ast::ParamKindOrd;
55
use rustc_errors::codes::*;
6-
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic, inline_fluent};
6+
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic};
77
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
88
use rustc_span::{Ident, Span, Symbol};
99

@@ -927,19 +927,15 @@ pub(crate) struct FeatureOnNonNightly {
927927
pub sugg: Option<Span>,
928928
}
929929

930+
#[derive(Subdiagnostic)]
931+
#[help(
932+
"the feature `{$name}` has been stable since `{$since}` and no longer requires an attribute to enable"
933+
)]
930934
pub(crate) struct StableFeature {
931935
pub name: Symbol,
932936
pub since: Symbol,
933937
}
934938

935-
impl Subdiagnostic for StableFeature {
936-
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
937-
diag.arg("name", self.name);
938-
diag.arg("since", self.since);
939-
diag.help(inline_fluent!("the feature `{$name}` has been stable since `{$since}` and no longer requires an attribute to enable"));
940-
}
941-
}
942-
943939
#[derive(Diagnostic)]
944940
#[diag("`{$f1}` and `{$f2}` are incompatible, using them at the same time is not allowed")]
945941
#[help("remove one of these features")]

compiler/rustc_lint/src/lints.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,27 +1975,17 @@ pub(crate) struct OverflowingBinHex<'a> {
19751975
pub sign_bit_sub: Option<OverflowingBinHexSignBitSub<'a>>,
19761976
}
19771977

1978+
#[derive(Subdiagnostic)]
19781979
pub(crate) enum OverflowingBinHexSign {
1980+
#[note(
1981+
"the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}` and will become `{$actually}{$ty}`"
1982+
)]
19791983
Positive,
1984+
#[note("the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}`")]
1985+
#[note("and the value `-{$lit}` will become `{$actually}{$ty}`")]
19801986
Negative,
19811987
}
19821988

1983-
impl Subdiagnostic for OverflowingBinHexSign {
1984-
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1985-
match self {
1986-
OverflowingBinHexSign::Positive => {
1987-
diag.note(inline_fluent!("the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}` and will become `{$actually}{$ty}`"));
1988-
}
1989-
OverflowingBinHexSign::Negative => {
1990-
diag.note(inline_fluent!(
1991-
"the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}`"
1992-
));
1993-
diag.note(inline_fluent!("and the value `-{$lit}` will become `{$actually}{$ty}`"));
1994-
}
1995-
}
1996-
}
1997-
}
1998-
19991989
#[derive(Subdiagnostic)]
20001990
pub(crate) enum OverflowingBinHexSub<'a> {
20011991
#[suggestion(

compiler/rustc_metadata/src/dependency_format.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ use crate::creader::CStore;
6868
use crate::errors::{
6969
BadPanicStrategy, CrateDepMultiple, IncompatiblePanicInDropStrategy,
7070
IncompatibleWithImmediateAbort, IncompatibleWithImmediateAbortCore, LibRequired,
71-
NonStaticCrateDep, RequiredPanicStrategy, RlibRequired, RustcDriverHelp, RustcLibRequired,
72-
TwoPanicRuntimes,
71+
NonStaticCrateDep, RequiredPanicStrategy, RlibRequired, RustcLibRequired, TwoPanicRuntimes,
7372
};
7473

7574
pub(crate) fn calculate(tcx: TyCtxt<'_>) -> Dependencies {
@@ -318,7 +317,7 @@ fn add_library(
318317
.drain(..)
319318
.map(|cnum| NonStaticCrateDep { crate_name_: tcx.crate_name(cnum) })
320319
.collect(),
321-
rustc_driver_help: linking_to_rustc_driver.then_some(RustcDriverHelp),
320+
rustc_driver_help: linking_to_rustc_driver,
322321
});
323322
}
324323
}

compiler/rustc_metadata/src/errors.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ pub struct CrateDepMultiple {
4343
pub crate_name: Symbol,
4444
#[subdiagnostic]
4545
pub non_static_deps: Vec<NonStaticCrateDep>,
46-
#[subdiagnostic]
47-
pub rustc_driver_help: Option<RustcDriverHelp>,
46+
#[help("`feature(rustc_private)` is needed to link to the compiler's `rustc_driver` library")]
47+
pub rustc_driver_help: bool,
4848
}
4949

5050
#[derive(Subdiagnostic)]
@@ -54,10 +54,6 @@ pub struct NonStaticCrateDep {
5454
pub crate_name_: Symbol,
5555
}
5656

57-
#[derive(Subdiagnostic)]
58-
#[help("`feature(rustc_private)` is needed to link to the compiler's `rustc_driver` library")]
59-
pub struct RustcDriverHelp;
60-
6157
#[derive(Diagnostic)]
6258
#[diag("cannot link together two panic runtimes: {$prev_name} and {$cur_name}")]
6359
pub struct TwoPanicRuntimes {

compiler/rustc_parse/src/errors.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,12 +2786,14 @@ pub(crate) struct UnknownTokenStart {
27862786
pub escaped: String,
27872787
#[subdiagnostic]
27882788
pub sugg: Option<TokenSubstitution>,
2789-
#[subdiagnostic]
2790-
pub null: Option<UnknownTokenNull>,
2789+
#[help(
2790+
"source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used"
2791+
)]
2792+
pub null: bool,
27912793
#[subdiagnostic]
27922794
pub repeat: Option<UnknownTokenRepeat>,
2793-
#[subdiagnostic]
2794-
pub invisible: Option<InvisibleCharacter>,
2795+
#[help("invisible characters like '{$escaped}' are not usually visible in text editors")]
2796+
pub invisible: bool,
27952797
}
27962798

27972799
#[derive(Subdiagnostic)]
@@ -2837,16 +2839,6 @@ pub(crate) struct UnknownTokenRepeat {
28372839
pub repeats: usize,
28382840
}
28392841

2840-
#[derive(Subdiagnostic)]
2841-
#[help("invisible characters like '{$escaped}' are not usually visible in text editors")]
2842-
pub(crate) struct InvisibleCharacter;
2843-
2844-
#[derive(Subdiagnostic)]
2845-
#[help(
2846-
"source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used"
2847-
)]
2848-
pub(crate) struct UnknownTokenNull;
2849-
28502842
#[derive(Diagnostic)]
28512843
pub(crate) enum UnescapeError {
28522844
#[diag("invalid unicode character escape")]

compiler/rustc_parse/src/lexer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,8 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
459459
span: self.mk_sp(start, self.pos + Pos::from_usize(repeats * c.len_utf8())),
460460
escaped: escaped_char(c),
461461
sugg,
462-
null: if c == '\x00' { Some(errors::UnknownTokenNull) } else { None },
463-
invisible: if INVISIBLE_CHARACTERS.contains(&c) { Some(errors::InvisibleCharacter) } else { None },
462+
null: c == '\x00',
463+
invisible: INVISIBLE_CHARACTERS.contains(&c),
464464
repeat: if repeats > 0 {
465465
swallow_next_invalid = repeats;
466466
Some(errors::UnknownTokenRepeat { repeats })

compiler/rustc_pattern_analysis/src/errors.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,14 @@ pub struct OverlappingRangeEndpoints {
5656
pub overlap: Vec<Overlap>,
5757
}
5858

59+
#[derive(Subdiagnostic)]
60+
#[label("this range overlaps on `{$range}`...")]
5961
pub struct Overlap {
62+
#[primary_span]
6063
pub span: Span,
6164
pub range: String, // a printed pattern
6265
}
6366

64-
impl Subdiagnostic for Overlap {
65-
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
66-
let Overlap { span, range } = self;
67-
68-
// FIXME(mejrs) unfortunately `#[derive(LintDiagnostic)]`
69-
// does not support `#[subdiagnostic(eager)]`...
70-
let message = format!("this range overlaps on `{range}`...");
71-
diag.span_label(span, message);
72-
}
73-
}
74-
7567
#[derive(LintDiagnostic)]
7668
#[diag("exclusive range missing `{$max}`")]
7769
pub struct ExclusiveRangeMissingMax {

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,11 +1015,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10151015
span,
10161016
name,
10171017
param_kind: is_type,
1018-
help: self
1019-
.tcx
1020-
.sess
1021-
.is_nightly_build()
1022-
.then_some(errs::ParamInNonTrivialAnonConstHelp),
1018+
help: self.tcx.sess.is_nightly_build(),
10231019
})
10241020
}
10251021
ResolutionError::ParamInEnumDiscriminant { name, param_kind: is_type } => self

compiler/rustc_resolve/src/errors.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,14 +429,10 @@ pub(crate) struct ParamInNonTrivialAnonConst {
429429
pub(crate) name: Symbol,
430430
#[subdiagnostic]
431431
pub(crate) param_kind: ParamKindInNonTrivialAnonConst,
432-
#[subdiagnostic]
433-
pub(crate) help: Option<ParamInNonTrivialAnonConstHelp>,
432+
#[help("add `#![feature(generic_const_exprs)]` to allow generic const expressions")]
433+
pub(crate) help: bool,
434434
}
435435

436-
#[derive(Subdiagnostic)]
437-
#[help("add `#![feature(generic_const_exprs)]` to allow generic const expressions")]
438-
pub(crate) struct ParamInNonTrivialAnonConstHelp;
439-
440436
#[derive(Debug)]
441437
#[derive(Subdiagnostic)]
442438
pub(crate) enum ParamKindInNonTrivialAnonConst {

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3510,12 +3510,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
35103510
span: lifetime_ref.ident.span,
35113511
name: lifetime_ref.ident.name,
35123512
param_kind: errors::ParamKindInNonTrivialAnonConst::Lifetime,
3513-
help: self
3514-
.r
3515-
.tcx
3516-
.sess
3517-
.is_nightly_build()
3518-
.then_some(errors::ParamInNonTrivialAnonConstHelp),
3513+
help: self.r.tcx.sess.is_nightly_build(),
35193514
})
35203515
.emit();
35213516
}

0 commit comments

Comments
 (0)