Skip to content

Commit 9c3b62d

Browse files
committed
Remove LifetimeSuggestionPosition and Lifetime::suggestion_position.
They both are only used in `Lifetime::suggestion`. This commit inlines and removes them.
1 parent 001f6fb commit 9c3b62d

File tree

1 file changed

+13
-32
lines changed

1 file changed

+13
-32
lines changed

compiler/rustc_hir/src/hir.rs

+13-32
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,6 @@ impl fmt::Display for Lifetime {
139139
}
140140
}
141141

142-
pub enum LifetimeSuggestionPosition {
143-
/// The user wrote `'a` or `'_`.
144-
Normal,
145-
/// The user wrote `&type` or `&mut type`.
146-
Ampersand,
147-
/// The user wrote `Path` and omitted the `<'_>`.
148-
ElidedPath,
149-
/// The user wrote `Path<T>`, and omitted the `'_,`.
150-
ElidedPathArgument,
151-
/// The user wrote `dyn Trait` and omitted the `+ '_`.
152-
ObjectDefault,
153-
}
154-
155142
impl Lifetime {
156143
pub fn is_elided(&self) -> bool {
157144
self.res.is_elided()
@@ -161,34 +148,28 @@ impl Lifetime {
161148
self.ident.name == kw::Empty || self.ident.name == kw::UnderscoreLifetime
162149
}
163150

164-
pub fn suggestion_position(&self) -> (LifetimeSuggestionPosition, Span) {
151+
pub fn suggestion(&self, new_lifetime: &str) -> (Span, String) {
152+
debug_assert!(new_lifetime.starts_with('\''));
153+
165154
if self.ident.name == kw::Empty {
166155
if self.ident.span.is_empty() {
167-
(LifetimeSuggestionPosition::ElidedPathArgument, self.ident.span)
156+
// The user wrote `Path<T>`, and omitted the `'_,`.
157+
(self.ident.span, format!("{new_lifetime}, "))
168158
} else {
169-
(LifetimeSuggestionPosition::ElidedPath, self.ident.span.shrink_to_hi())
159+
// The user wrote `Path` and omitted the `<'_>`.
160+
(self.ident.span.shrink_to_hi(), format!("<{new_lifetime}>"))
170161
}
171162
} else if self.res == LifetimeName::ImplicitObjectLifetimeDefault {
172-
(LifetimeSuggestionPosition::ObjectDefault, self.ident.span)
163+
// The user wrote `dyn Trait` and omitted the `+ '_`.
164+
(self.ident.span, format!("+ {new_lifetime}"))
173165
} else if self.ident.span.is_empty() {
174-
(LifetimeSuggestionPosition::Ampersand, self.ident.span)
166+
// The user wrote `&type` or `&mut type`.
167+
(self.ident.span, format!("{new_lifetime} "))
175168
} else {
176-
(LifetimeSuggestionPosition::Normal, self.ident.span)
169+
// The user wrote `'a` or `'_`.
170+
(self.ident.span, format!("{new_lifetime}"))
177171
}
178172
}
179-
180-
pub fn suggestion(&self, new_lifetime: &str) -> (Span, String) {
181-
debug_assert!(new_lifetime.starts_with('\''));
182-
let (pos, span) = self.suggestion_position();
183-
let code = match pos {
184-
LifetimeSuggestionPosition::Normal => format!("{new_lifetime}"),
185-
LifetimeSuggestionPosition::Ampersand => format!("{new_lifetime} "),
186-
LifetimeSuggestionPosition::ElidedPath => format!("<{new_lifetime}>"),
187-
LifetimeSuggestionPosition::ElidedPathArgument => format!("{new_lifetime}, "),
188-
LifetimeSuggestionPosition::ObjectDefault => format!("+ {new_lifetime}"),
189-
};
190-
(span, code)
191-
}
192173
}
193174

194175
/// A `Path` is essentially Rust's notion of a name; for instance,

0 commit comments

Comments
 (0)