Skip to content

Commit 1488095

Browse files
committed
change in-band array to store hir::LifetimeName
1 parent d913af8 commit 1488095

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/librustc/hir/lowering.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ pub struct LoweringContext<'a> {
121121
// (i.e. it doesn't appear in the in_scope_lifetimes list), it is added
122122
// to this list. The results of this list are then added to the list of
123123
// lifetime definitions in the corresponding impl or function generics.
124-
lifetimes_to_define: Vec<(Span, Name)>,
124+
lifetimes_to_define: Vec<(Span, hir::LifetimeName)>,
125+
125126
// Whether or not in-band lifetimes are being collected. This is used to
126127
// indicate whether or not we're in a place where new lifetimes will result
127128
// in in-band lifetime definitions, such a function or an impl header.
@@ -566,14 +567,23 @@ impl<'a> LoweringContext<'a> {
566567

567568
let params = lifetimes_to_define
568569
.into_iter()
569-
.map(|(span, name)| {
570+
.map(|(span, hir_name)| {
570571
let def_node_id = self.next_id().node_id;
571572

573+
let str_name = match hir_name {
574+
hir::LifetimeName::Name(n) => n.as_str(),
575+
hir::LifetimeName::Implicit
576+
| hir::LifetimeName::Underscore
577+
| hir::LifetimeName::Static => {
578+
span_bug!(span, "unexpected in-band lifetime name: {:?}", hir_name)
579+
}
580+
};
581+
572582
// Add a definition for the in-band lifetime def
573583
self.resolver.definitions().create_def_with_parent(
574584
parent_id.index,
575585
def_node_id,
576-
DefPathData::LifetimeDef(name.as_str()),
586+
DefPathData::LifetimeDef(str_name),
577587
DefIndexAddressSpace::High,
578588
Mark::root(),
579589
span,
@@ -583,7 +593,7 @@ impl<'a> LoweringContext<'a> {
583593
lifetime: hir::Lifetime {
584594
id: def_node_id,
585595
span,
586-
name: hir::LifetimeName::Name(name),
596+
name: hir_name,
587597
},
588598
bounds: Vec::new().into(),
589599
pure_wrt_drop: false,
@@ -613,14 +623,16 @@ impl<'a> LoweringContext<'a> {
613623
return;
614624
}
615625

626+
let hir_name = hir::LifetimeName::Name(name);
627+
616628
if self.lifetimes_to_define
617629
.iter()
618-
.any(|(_, lt_name)| *lt_name == name)
630+
.any(|(_, lt_name)| *lt_name == hir_name)
619631
{
620632
return;
621633
}
622634

623-
self.lifetimes_to_define.push((span, name));
635+
self.lifetimes_to_define.push((span, hir_name));
624636
}
625637

626638
// Evaluates `f` with the lifetimes in `lt_defs` in-scope.

src/librustc/hir/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,16 @@ pub struct Lifetime {
203203

204204
#[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
205205
pub enum LifetimeName {
206+
/// User typed nothing. e.g. the lifetime in `&u32`.
206207
Implicit,
208+
209+
/// User typed `'_`.
207210
Underscore,
211+
212+
/// User wrote `'static`
208213
Static,
214+
215+
/// Some user-given name like `'x`
209216
Name(Name),
210217
}
211218

0 commit comments

Comments
 (0)