Skip to content

Commit adeba3d

Browse files
committed
ruff_db: simplify lifetimes on DiagnosticDisplay
I initially split the lifetime out into three distinct lifetimes on near-instinct because I moved the struct into the public API. But because they are all shared borrows, and because there are no other APIs on `DisplayDiagnostic` to access individual fields (and probably never will be), it's probably fine to just specify one lifetime. Because of subtyping, the one lifetime will be the shorter of the three. There's also the point that `ruff_db` isn't _really_ a public API, since it isn't a library that others depend on. So my instinct is probably a bit off there.
1 parent af988bf commit adeba3d

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

crates/ruff_db/src/diagnostic/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ impl Diagnostic {
106106
///
107107
/// Note that this `Display` impl includes a trailing line terminator, so
108108
/// callers should prefer using this with `write!` instead of `writeln!`.
109-
pub fn display<'c, 'db, 'd>(
110-
&'d self,
111-
db: &'db dyn Db,
112-
config: &'c DisplayDiagnosticConfig,
113-
) -> DisplayDiagnostic<'c, 'db, 'd> {
109+
pub fn display<'a>(
110+
&'a self,
111+
db: &'a dyn Db,
112+
config: &'a DisplayDiagnosticConfig,
113+
) -> DisplayDiagnostic<'a> {
114114
let resolver = FileResolver::new(db);
115115
DisplayDiagnostic::new(resolver, config, self)
116116
}

crates/ruff_db/src/diagnostic/render.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ use super::{
2121
///
2222
/// It is created via [`Diagnostic::display`].
2323
///
24-
/// The lifetime parameters are:
24+
/// The lifetime parameter, `'a`, refers to the shorter of:
2525
///
26-
/// * `'c` is the lifetime of the rendering configuration.
27-
/// * `'r` is the lifetime of the resolver used to load the contents of `Span`
26+
/// * The lifetime of the rendering configuration.
27+
/// * The lifetime of the resolver used to load the contents of `Span`
2828
/// values. When using Salsa, this most commonly corresponds to the lifetime
2929
/// of a Salsa `Db`.
30-
/// * `'d` is the lifetime of the diagnostic being rendered.
30+
/// * The lifetime of the diagnostic being rendered.
3131
#[derive(Debug)]
32-
pub struct DisplayDiagnostic<'c, 'r, 'd> {
33-
config: &'c DisplayDiagnosticConfig,
34-
resolver: FileResolver<'r>,
32+
pub struct DisplayDiagnostic<'a> {
33+
config: &'a DisplayDiagnosticConfig,
34+
resolver: FileResolver<'a>,
3535
annotate_renderer: AnnotateRenderer,
36-
diag: &'d Diagnostic,
36+
diag: &'a Diagnostic,
3737
}
3838

39-
impl<'c, 'r, 'd> DisplayDiagnostic<'c, 'r, 'd> {
39+
impl<'a> DisplayDiagnostic<'a> {
4040
pub(crate) fn new(
41-
resolver: FileResolver<'r>,
42-
config: &'c DisplayDiagnosticConfig,
43-
diag: &'d Diagnostic,
44-
) -> DisplayDiagnostic<'c, 'r, 'd> {
41+
resolver: FileResolver<'a>,
42+
config: &'a DisplayDiagnosticConfig,
43+
diag: &'a Diagnostic,
44+
) -> DisplayDiagnostic<'a> {
4545
let annotate_renderer = if config.color {
4646
AnnotateRenderer::styled()
4747
} else {
@@ -56,7 +56,7 @@ impl<'c, 'r, 'd> DisplayDiagnostic<'c, 'r, 'd> {
5656
}
5757
}
5858

59-
impl std::fmt::Display for DisplayDiagnostic<'_, '_, '_> {
59+
impl std::fmt::Display for DisplayDiagnostic<'_> {
6060
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
6161
if matches!(self.config.format, DiagnosticFormat::Concise) {
6262
match self.diag.severity() {

0 commit comments

Comments
 (0)