]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/hir/mod.rs
rustc: always include elidable lifetimes in HIR types.
[rust.git] / src / librustc / hir / mod.rs
index fe086347884b09c89f24d66e24fce10156bfc7b2..94cb33b138c58341dac9ec70c4850bc740d6829b 100644 (file)
@@ -77,6 +77,13 @@ macro_rules! hir_vec {
 pub struct Lifetime {
     pub id: NodeId,
     pub span: Span,
+
+    /// Either "'a", referring to a named lifetime definition,
+    /// or "" (aka keywords::Invalid), for elision placeholders.
+    ///
+    /// HIR lowering inserts these placeholders in type paths that
+    /// refer to type definitions needing lifetime parameters,
+    /// `&T` and `&mut T`, and trait objects without `... + 'a`.
     pub name: Name,
 }
 
@@ -89,6 +96,12 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
+impl Lifetime {
+    pub fn is_elided(&self) -> bool {
+        self.name == keywords::Invalid.name()
+    }
+}
+
 /// A lifetime definition, eg `'a: 'b+'c+'d`
 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
 pub struct LifetimeDef {
@@ -165,30 +178,6 @@ pub fn none() -> PathParameters {
         })
     }
 
-    pub fn is_empty(&self) -> bool {
-        match *self {
-            AngleBracketedParameters(ref data) => data.is_empty(),
-
-            // Even if the user supplied no types, something like
-            // `X()` is equivalent to `X<(),()>`.
-            ParenthesizedParameters(..) => false,
-        }
-    }
-
-    pub fn has_lifetimes(&self) -> bool {
-        match *self {
-            AngleBracketedParameters(ref data) => !data.lifetimes.is_empty(),
-            ParenthesizedParameters(_) => false,
-        }
-    }
-
-    pub fn has_types(&self) -> bool {
-        match *self {
-            AngleBracketedParameters(ref data) => !data.types.is_empty(),
-            ParenthesizedParameters(..) => true,
-        }
-    }
-
     /// Returns the types that the user wrote. Note that these do not necessarily map to the type
     /// parameters in the parenthesized case.
     pub fn types(&self) -> HirVec<&P<Ty>> {
@@ -245,12 +234,6 @@ pub struct AngleBracketedParameterData {
     pub bindings: HirVec<TypeBinding>,
 }
 
-impl AngleBracketedParameterData {
-    fn is_empty(&self) -> bool {
-        self.lifetimes.is_empty() && self.types.is_empty() && self.bindings.is_empty()
-    }
-}
-
 /// A path like `Foo(A,B) -> C`
 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
 pub struct ParenthesizedParameterData {
@@ -1208,7 +1191,7 @@ pub enum Ty_ {
     /// A raw pointer (`*const T` or `*mut T`)
     TyPtr(MutTy),
     /// A reference (`&'a T` or `&'a mut T`)
-    TyRptr(Option<Lifetime>, MutTy),
+    TyRptr(Lifetime, MutTy),
     /// A bare function (e.g. `fn(usize) -> bool`)
     TyBareFn(P<BareFnTy>),
     /// The never type (`!`)