+ pub(crate) fn maybe_report_lifetime_uses(
+ &mut self,
+ generics_span: Span,
+ params: &[ast::GenericParam],
+ ) {
+ for (param_index, param) in params.iter().enumerate() {
+ let GenericParamKind::Lifetime = param.kind else { continue };
+
+ let def_id = self.r.local_def_id(param.id);
+
+ let use_set = self.lifetime_uses.remove(&def_id);
+ debug!(
+ "Use set for {:?}({:?} at {:?}) is {:?}",
+ def_id, param.ident, param.ident.span, use_set
+ );
+
+ let deletion_span = || {
+ if params.len() == 1 {
+ // if sole lifetime, remove the entire `<>` brackets
+ generics_span
+ } else if param_index == 0 {
+ // if removing within `<>` brackets, we also want to
+ // delete a leading or trailing comma as appropriate
+ param.span().to(params[param_index + 1].span().shrink_to_lo())
+ } else {
+ // if removing within `<>` brackets, we also want to
+ // delete a leading or trailing comma as appropriate
+ params[param_index - 1].span().shrink_to_hi().to(param.span())
+ }
+ };
+ match use_set {
+ Some(LifetimeUseSet::Many) => {}
+ Some(LifetimeUseSet::One { use_span, use_ctxt }) => {
+ debug!(?param.ident, ?param.ident.span, ?use_span);
+
+ let elidable = matches!(use_ctxt, LifetimeCtxt::Rptr);
+
+ let deletion_span = deletion_span();
+ self.r.lint_buffer.buffer_lint_with_diagnostic(
+ lint::builtin::SINGLE_USE_LIFETIMES,
+ param.id,
+ param.ident.span,
+ &format!("lifetime parameter `{}` only used once", param.ident),
+ lint::BuiltinLintDiagnostics::SingleUseLifetime {
+ param_span: param.ident.span,
+ use_span: Some((use_span, elidable)),
+ deletion_span,
+ },
+ );
+ }
+ None => {
+ debug!(?param.ident, ?param.ident.span);
+
+ let deletion_span = deletion_span();
+ self.r.lint_buffer.buffer_lint_with_diagnostic(
+ lint::builtin::UNUSED_LIFETIMES,
+ param.id,
+ param.ident.span,
+ &format!("lifetime parameter `{}` never used", param.ident),
+ lint::BuiltinLintDiagnostics::SingleUseLifetime {
+ param_span: param.ident.span,
+ use_span: None,
+ deletion_span,
+ },
+ );
+ }
+ }
+ }
+ }
+
+ pub(crate) fn emit_undeclared_lifetime_error(