Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b3db6fa

Browse files
committedMar 26, 2025
Remove ImplicitObjectLifetimeDefault case from suggestion.
It has no effect on anything in the test suite. This means it can also be rewritten as a neater pairwise `match`.
1 parent 4b10974 commit b3db6fa

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed
 

‎compiler/rustc_hir/src/hir.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,18 @@ impl Lifetime {
151151
pub fn suggestion(&self, new_lifetime: &str) -> (Span, String) {
152152
debug_assert!(new_lifetime.starts_with('\''));
153153

154-
if self.ident.name == kw::Empty {
155-
if self.ident.span.is_empty() {
156-
// The user wrote `Path<T>`, and omitted the `'_,`.
157-
(self.ident.span, format!("{new_lifetime}, "))
158-
} else {
159-
// The user wrote `Path` and omitted the `<'_>`.
160-
(self.ident.span.shrink_to_hi(), format!("<{new_lifetime}>"))
161-
}
162-
} else if self.res == LifetimeName::ImplicitObjectLifetimeDefault {
163-
// The user wrote `dyn Trait` and omitted the `+ '_`.
164-
(self.ident.span, format!("+ {new_lifetime}"))
165-
} else if self.ident.span.is_empty() {
154+
match (self.ident.name.is_empty(), self.ident.span.is_empty()) {
155+
// The user wrote `Path<T>`, and omitted the `'_,`.
156+
(true, true) => (self.ident.span, format!("{new_lifetime}, ")),
157+
158+
// The user wrote `Path` and omitted the `<'_>`.
159+
(true, false) => (self.ident.span.shrink_to_hi(), format!("<{new_lifetime}>")),
160+
166161
// The user wrote `&type` or `&mut type`.
167-
(self.ident.span, format!("{new_lifetime} "))
168-
} else {
162+
(false, true) => (self.ident.span, format!("{new_lifetime} ")),
163+
169164
// The user wrote `'a` or `'_`.
170-
(self.ident.span, format!("{new_lifetime}"))
165+
(false, false) => (self.ident.span, format!("{new_lifetime}")),
171166
}
172167
}
173168
}

0 commit comments

Comments
 (0)
Please sign in to comment.