}
impl Region {
- fn early(hir_map: &Map, index: &mut u32, def: &hir::LifetimeDef) -> (ast::Name, Region) {
+ fn early(hir_map: &Map, index: &mut u32, def: &hir::LifetimeDef)
+ -> (hir::LifetimeName, Region)
+ {
let i = *index;
*index += 1;
let def_id = hir_map.local_def_id(def.lifetime.id);
(def.lifetime.name, Region::EarlyBound(i, def_id))
}
- fn late(hir_map: &Map, def: &hir::LifetimeDef) -> (ast::Name, Region) {
+ fn late(hir_map: &Map, def: &hir::LifetimeDef) -> (hir::LifetimeName, Region) {
let depth = ty::DebruijnIndex::new(1);
let def_id = hir_map.local_def_id(def.lifetime.id);
(def.lifetime.name, Region::LateBound(depth, def_id))
/// it should be shifted by the number of `Binder`s in between the
/// declaration `Binder` and the location it's referenced from.
Binder {
- lifetimes: FxHashMap<ast::Name, Region>,
+ lifetimes: FxHashMap<hir::LifetimeName, Region>,
s: ScopeRef<'a>
},
Scope::Binder { ref lifetimes, s } => {
// FIXME (#24278): non-hygienic comparison
- if let Some(def) = lifetimes.get(&label) {
+ if let Some(def) = lifetimes.get(&hir::LifetimeName::Name(label)) {
let node_id = hir_map.as_local_node_id(def.id().unwrap())
.unwrap();
Set1::Empty => "BaseDefault".to_string(),
Set1::One(Region::Static) => "'static".to_string(),
Set1::One(Region::EarlyBound(i, _)) => {
- generics.lifetimes[i as usize].lifetime.name.to_string()
+ generics.lifetimes[i as usize].lifetime.name.name().to_string()
}
Set1::One(_) => bug!(),
Set1::Many => "Ambiguous".to_string(),
/// for each type parameter.
fn object_lifetime_defaults_for_item(hir_map: &Map, generics: &hir::Generics)
-> Vec<ObjectLifetimeDefault> {
- fn add_bounds(set: &mut Set1<ast::Name>, bounds: &[hir::TyParamBound]) {
+ fn add_bounds(set: &mut Set1<hir::LifetimeName>, bounds: &[hir::TyParamBound]) {
for bound in bounds {
if let hir::RegionTyParamBound(ref lifetime) = *bound {
set.insert(lifetime.name);
match set {
Set1::Empty => Set1::Empty,
Set1::One(name) => {
- if name == "'static" {
+ if name == hir::LifetimeName::Static {
Set1::One(Region::Static)
} else {
generics.lifetimes.iter().enumerate().find(|&(_, def)| {
self.insert_lifetime(lifetime_ref, def);
} else {
struct_span_err!(self.sess, lifetime_ref.span, E0261,
- "use of undeclared lifetime name `{}`", lifetime_ref.name)
+ "use of undeclared lifetime name `{}`", lifetime_ref.name.name())
.span_label(lifetime_ref.span, "undeclared lifetime")
.emit();
}
let lifetime_i = &lifetimes[i];
for lifetime in lifetimes {
- if lifetime.lifetime.is_static() || lifetime.lifetime.name == "'_" {
- let lifetime = lifetime.lifetime;
- let mut err = struct_span_err!(self.sess, lifetime.span, E0262,
- "invalid lifetime parameter name: `{}`", lifetime.name);
- err.span_label(lifetime.span,
- format!("{} is a reserved lifetime name", lifetime.name));
- err.emit();
+ match lifetime.lifetime.name {
+ hir::LifetimeName::Static | hir::LifetimeName::Underscore => {
+ let lifetime = lifetime.lifetime;
+ let name = lifetime.name.name();
+ let mut err = struct_span_err!(self.sess, lifetime.span, E0262,
+ "invalid lifetime parameter name: `{}`", name);
+ err.span_label(lifetime.span,
+ format!("{} is a reserved lifetime name", name));
+ err.emit();
+ }
+ hir::LifetimeName::Implicit | hir::LifetimeName::Name(_) => {}
}
}
if lifetime_i.lifetime.name == lifetime_j.lifetime.name {
struct_span_err!(self.sess, lifetime_j.lifetime.span, E0263,
"lifetime name `{}` declared twice in the same scope",
- lifetime_j.lifetime.name)
+ lifetime_j.lifetime.name.name())
.span_label(lifetime_j.lifetime.span,
"declared twice")
.span_label(lifetime_i.lifetime.span,
self.check_lifetime_def_for_shadowing(old_scope, &lifetime_i.lifetime);
for bound in &lifetime_i.bounds {
- if bound.name == "'_" {
- let mut err = struct_span_err!(self.sess, bound.span, E0637,
- "invalid lifetime bound name: `{}`", bound.name);
- err.span_label(bound.span,
- format!("{} is a reserved lifetime name", bound.name));
- err.emit();
- } else if !bound.is_static() {
- self.resolve_lifetime_ref(bound);
- } else {
- self.insert_lifetime(bound, Region::Static);
- self.sess.struct_span_warn(lifetime_i.lifetime.span.to(bound.span),
- &format!("unnecessary lifetime parameter `{}`", lifetime_i.lifetime.name))
- .help(&format!("you can use the `'static` lifetime directly, in place \
- of `{}`", lifetime_i.lifetime.name))
- .emit();
+ match bound.name {
+ hir::LifetimeName::Underscore => {
+ let mut err = struct_span_err!(self.sess, bound.span, E0637,
+ "invalid lifetime bound name: `'_`");
+ err.span_label(bound.span, "`'_` is a reserved lifetime name");
+ err.emit();
+ }
+ hir::LifetimeName::Static => {
+ self.insert_lifetime(bound, Region::Static);
+ self.sess.struct_span_warn(lifetime_i.lifetime.span.to(bound.span),
+ &format!("unnecessary lifetime parameter `{}`",
+ lifetime_i.lifetime.name.name()))
+ .help(&format!(
+ "you can use the `'static` lifetime directly, in place \
+ of `{}`", lifetime_i.lifetime.name.name()))
+ .emit();
+ }
+ hir::LifetimeName::Implicit |
+ hir::LifetimeName::Name(_) => {
+ self.resolve_lifetime_ref(bound);
+ }
}
}
}
{
for &(label, label_span) in &self.labels_in_fn {
// FIXME (#24278): non-hygienic comparison
- if lifetime.name == label {
+ if lifetime.name.name() == label {
signal_shadowing_problem(self.sess,
- lifetime.name,
+ label,
original_label(label_span),
shadower_lifetime(&lifetime));
return;
signal_shadowing_problem(
self.sess,
- lifetime.name,
+ lifetime.name.name(),
original_lifetime(self.hir_map.span(node_id)),
shadower_lifetime(&lifetime));
return;
return;
struct ConstrainedCollector {
- regions: FxHashSet<ast::Name>,
+ regions: FxHashSet<hir::LifetimeName>,
}
impl<'v> Visitor<'v> for ConstrainedCollector {
}
struct AllCollector {
- regions: FxHashSet<ast::Name>,
+ regions: FxHashSet<hir::LifetimeName>,
impl_trait: bool
}