about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_hir/src/hir.rs45
1 files changed, 13 insertions, 32 deletions
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs
index 751c379b21a..b91fb41cb4d 100644
--- a/compiler/rustc_hir/src/hir.rs
+++ b/compiler/rustc_hir/src/hir.rs
@@ -139,19 +139,6 @@ impl fmt::Display for Lifetime {
     }
 }
 
-pub enum LifetimeSuggestionPosition {
-    /// The user wrote `'a` or `'_`.
-    Normal,
-    /// The user wrote `&type` or `&mut type`.
-    Ampersand,
-    /// The user wrote `Path` and omitted the `<'_>`.
-    ElidedPath,
-    /// The user wrote `Path<T>`, and omitted the `'_,`.
-    ElidedPathArgument,
-    /// The user wrote `dyn Trait` and omitted the `+ '_`.
-    ObjectDefault,
-}
-
 impl Lifetime {
     pub fn is_elided(&self) -> bool {
         self.res.is_elided()
@@ -161,34 +148,28 @@ impl Lifetime {
         self.ident.name == kw::Empty || self.ident.name == kw::UnderscoreLifetime
     }
 
-    pub fn suggestion_position(&self) -> (LifetimeSuggestionPosition, Span) {
+    pub fn suggestion(&self, new_lifetime: &str) -> (Span, String) {
+        debug_assert!(new_lifetime.starts_with('\''));
+
         if self.ident.name == kw::Empty {
             if self.ident.span.is_empty() {
-                (LifetimeSuggestionPosition::ElidedPathArgument, self.ident.span)
+                // The user wrote `Path<T>`, and omitted the `'_,`.
+                (self.ident.span, format!("{new_lifetime}, "))
             } else {
-                (LifetimeSuggestionPosition::ElidedPath, self.ident.span.shrink_to_hi())
+                // The user wrote `Path` and omitted the `<'_>`.
+                (self.ident.span.shrink_to_hi(), format!("<{new_lifetime}>"))
             }
         } else if self.res == LifetimeName::ImplicitObjectLifetimeDefault {
-            (LifetimeSuggestionPosition::ObjectDefault, self.ident.span)
+            // The user wrote `dyn Trait` and omitted the `+ '_`.
+            (self.ident.span, format!("+ {new_lifetime}"))
         } else if self.ident.span.is_empty() {
-            (LifetimeSuggestionPosition::Ampersand, self.ident.span)
+            // The user wrote `&type` or `&mut type`.
+            (self.ident.span, format!("{new_lifetime} "))
         } else {
-            (LifetimeSuggestionPosition::Normal, self.ident.span)
+            // The user wrote `'a` or `'_`.
+            (self.ident.span, format!("{new_lifetime}"))
         }
     }
-
-    pub fn suggestion(&self, new_lifetime: &str) -> (Span, String) {
-        debug_assert!(new_lifetime.starts_with('\''));
-        let (pos, span) = self.suggestion_position();
-        let code = match pos {
-            LifetimeSuggestionPosition::Normal => format!("{new_lifetime}"),
-            LifetimeSuggestionPosition::Ampersand => format!("{new_lifetime} "),
-            LifetimeSuggestionPosition::ElidedPath => format!("<{new_lifetime}>"),
-            LifetimeSuggestionPosition::ElidedPathArgument => format!("{new_lifetime}, "),
-            LifetimeSuggestionPosition::ObjectDefault => format!("+ {new_lifetime}"),
-        };
-        (span, code)
-    }
 }
 
 /// A `Path` is essentially Rust's notion of a name; for instance,