about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2018-03-21 16:30:09 -0400
committerNiko Matsakis <niko@alum.mit.edu>2018-03-22 16:54:51 -0400
commit1488095b08b0b85bff4b3d6d432e3f7cc7cd6d09 (patch)
treedc2389ad9f03c2bc21ca335af3b2093c30da4dd0
parentd913af8691d4002166c9a6e1b60e51407cf82c9c (diff)
downloadrust-1488095b08b0b85bff4b3d6d432e3f7cc7cd6d09.tar.gz
rust-1488095b08b0b85bff4b3d6d432e3f7cc7cd6d09.zip
change in-band array to store hir::LifetimeName
-rw-r--r--src/librustc/hir/lowering.rs24
-rw-r--r--src/librustc/hir/mod.rs7
2 files changed, 25 insertions, 6 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index 8ac9c46d454..b8bacb24c71 100644
--- a/src/librustc/hir/lowering.rs
+++ b/src/librustc/hir/lowering.rs
@@ -121,7 +121,8 @@ pub struct LoweringContext<'a> {
     // (i.e. it doesn't appear in the in_scope_lifetimes list), it is added
     // to this list. The results of this list are then added to the list of
     // lifetime definitions in the corresponding impl or function generics.
-    lifetimes_to_define: Vec<(Span, Name)>,
+    lifetimes_to_define: Vec<(Span, hir::LifetimeName)>,
+
     // Whether or not in-band lifetimes are being collected. This is used to
     // indicate whether or not we're in a place where new lifetimes will result
     // in in-band lifetime definitions, such a function or an impl header.
@@ -566,14 +567,23 @@ impl<'a> LoweringContext<'a> {
 
         let params = lifetimes_to_define
             .into_iter()
-            .map(|(span, name)| {
+            .map(|(span, hir_name)| {
                 let def_node_id = self.next_id().node_id;
 
+                let str_name = match hir_name {
+                    hir::LifetimeName::Name(n) => n.as_str(),
+                    hir::LifetimeName::Implicit
+                    | hir::LifetimeName::Underscore
+                    | hir::LifetimeName::Static => {
+                        span_bug!(span, "unexpected in-band lifetime name: {:?}", hir_name)
+                    }
+                };
+
                 // Add a definition for the in-band lifetime def
                 self.resolver.definitions().create_def_with_parent(
                     parent_id.index,
                     def_node_id,
-                    DefPathData::LifetimeDef(name.as_str()),
+                    DefPathData::LifetimeDef(str_name),
                     DefIndexAddressSpace::High,
                     Mark::root(),
                     span,
@@ -583,7 +593,7 @@ impl<'a> LoweringContext<'a> {
                     lifetime: hir::Lifetime {
                         id: def_node_id,
                         span,
-                        name: hir::LifetimeName::Name(name),
+                        name: hir_name,
                     },
                     bounds: Vec::new().into(),
                     pure_wrt_drop: false,
@@ -613,14 +623,16 @@ impl<'a> LoweringContext<'a> {
             return;
         }
 
+        let hir_name = hir::LifetimeName::Name(name);
+
         if self.lifetimes_to_define
             .iter()
-            .any(|(_, lt_name)| *lt_name == name)
+            .any(|(_, lt_name)| *lt_name == hir_name)
         {
             return;
         }
 
-        self.lifetimes_to_define.push((span, name));
+        self.lifetimes_to_define.push((span, hir_name));
     }
 
     // Evaluates `f` with the lifetimes in `lt_defs` in-scope.
diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs
index d6810b2468b..d94fdb82d99 100644
--- a/src/librustc/hir/mod.rs
+++ b/src/librustc/hir/mod.rs
@@ -203,9 +203,16 @@ pub struct Lifetime {
 
 #[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
 pub enum LifetimeName {
+    /// User typed nothing. e.g. the lifetime in `&u32`.
     Implicit,
+
+    /// User typed `'_`.
     Underscore,
+
+    /// User wrote `'static`
     Static,
+
+    /// Some user-given name like `'x`
     Name(Name),
 }