From 2fcd8a71f70a64efaf071fbf4f3932899fdb7920 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 22 Mar 2026 20:32:22 +0100 Subject: [PATCH] Remove more `BuiltinLintDiag` in `rustc_resolve` --- compiler/rustc_lint/src/early/diagnostics.rs | 8 +++----- compiler/rustc_lint/src/lints.rs | 9 --------- compiler/rustc_lint_defs/src/lib.rs | 3 ++- compiler/rustc_resolve/src/errors.rs | 9 +++++++++ compiler/rustc_resolve/src/late/diagnostics.rs | 10 +++------- 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs index c61bb7307f60..43bb3971d7ac 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -118,13 +118,14 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> { } BuiltinLintDiag::SingleUseLifetime { param_span, - use_span: Some((use_span, elide)), + use_span, + elidable, deletion_span, ident, } => { debug!(?param_span, ?use_span, ?deletion_span); let suggestion = if let Some(deletion_span) = deletion_span { - let (use_span, replace_lt) = if elide { + let (use_span, replace_lt) = if elidable { let use_span = self.sess.source_map().span_extend_while_whitespace(use_span); (use_span, String::new()) @@ -145,9 +146,6 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> { lints::SingleUseLifetime { suggestion, param_span, use_span, ident } .into_diag(dcx, level) } - BuiltinLintDiag::SingleUseLifetime { use_span: None, deletion_span, ident, .. } => { - lints::UnusedLifetime { deletion_span, ident }.into_diag(dcx, level) - } BuiltinLintDiag::NamedArgumentUsedPositionally { position_sp_to_replace, position_sp_for_msg, diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index c66654afc9d1..c7c92356c378 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -3149,15 +3149,6 @@ pub(crate) struct SingleUseLifetimeSugg { pub replace_lt: String, } -#[derive(Diagnostic)] -#[diag("lifetime parameter `{$ident}` never used")] -pub(crate) struct UnusedLifetime { - #[suggestion("elide the unused lifetime", code = "", applicability = "machine-applicable")] - pub deletion_span: Option, - - pub ident: Ident, -} - #[derive(Diagnostic)] #[diag("named argument `{$named_arg_name}` is not used by name")] pub(crate) struct NamedArgumentUsedPositionally { diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index f3317017daab..0faa50442961 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -681,7 +681,8 @@ pub enum BuiltinLintDiag { deletion_span: Option, /// Span of the single use, or None if the lifetime is never used. /// If true, the lifetime will be fully elided. - use_span: Option<(Span, bool)>, + use_span: Span, + elidable: bool, ident: Ident, }, NamedArgumentUsedPositionally { diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index 24c923de6794..25c7c625ff93 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -1583,3 +1583,12 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> { diag } } + +#[derive(Diagnostic)] +#[diag("lifetime parameter `{$ident}` never used")] +pub(crate) struct UnusedLifetime { + #[suggestion("elide the unused lifetime", code = "", applicability = "machine-applicable")] + pub deletion_span: Option, + + pub ident: Ident, +} diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index a8ca4faf5ab0..3bc40604ac04 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -3653,7 +3653,8 @@ pub(crate) fn maybe_report_lifetime_uses( param.ident.span, lint::BuiltinLintDiag::SingleUseLifetime { param_span: param.ident.span, - use_span: Some((use_span, elidable)), + use_span, + elidable, deletion_span, ident: param.ident, }, @@ -3669,12 +3670,7 @@ pub(crate) fn maybe_report_lifetime_uses( lint::builtin::UNUSED_LIFETIMES, param.id, param.ident.span, - lint::BuiltinLintDiag::SingleUseLifetime { - param_span: param.ident.span, - use_span: None, - deletion_span, - ident: param.ident, - }, + errors::UnusedLifetime { deletion_span, ident: param.ident }, ); } }