librustc: Fix the issue with labels shadowing variable names by making

the leading quote part of the identifier for the purposes of hygiene.

This adopts @jbclements' solution to #14539.

I'm not sure if this is a breaking change or not.

Closes #12512.

[breaking-change]
This commit is contained in:
Patrick Walton 2014-06-10 13:54:13 -07:00 committed by Alex Crichton
parent e7f11f20e5
commit 2ed4734873
17 changed files with 159 additions and 89 deletions

View file

@ -165,7 +165,7 @@ impl<'a, 'b> Visitor<Scope<'a>> for LifetimeContext<'b> {
fn visit_lifetime_ref(&mut self,
lifetime_ref: &ast::Lifetime,
scope: Scope<'a>) {
if lifetime_ref.name == special_idents::statik.name {
if lifetime_ref.name == special_idents::static_lifetime.name {
self.insert_lifetime(lifetime_ref, DefStaticRegion);
return;
}
@ -330,7 +330,7 @@ impl<'a> LifetimeContext<'a> {
lifetime_ref: &ast::Lifetime) {
self.sess.span_err(
lifetime_ref.span,
format!("use of undeclared lifetime name `'{}`",
format!("use of undeclared lifetime name `{}`",
token::get_name(lifetime_ref.name)).as_slice());
}
@ -338,7 +338,7 @@ impl<'a> LifetimeContext<'a> {
for i in range(0, lifetimes.len()) {
let lifetime_i = lifetimes.get(i);
let special_idents = [special_idents::statik];
let special_idents = [special_idents::static_lifetime];
for lifetime in lifetimes.iter() {
if special_idents.iter().any(|&i| i.name == lifetime.name) {
self.sess.span_err(
@ -354,7 +354,7 @@ impl<'a> LifetimeContext<'a> {
if lifetime_i.name == lifetime_j.name {
self.sess.span_err(
lifetime_j.span,
format!("lifetime name `'{}` declared twice in \
format!("lifetime name `{}` declared twice in \
the same scope",
token::get_name(lifetime_j.name)).as_slice());
}

View file

@ -1505,7 +1505,8 @@ impl LifeGiver {
fn give_lifetime(&self) -> ast::Lifetime {
let mut lifetime;
loop {
let s = num_to_str(self.counter.get());
let mut s = String::from_str("'");
s.push_str(num_to_str(self.counter.get()).as_slice());
if !self.taken.contains(&s) {
lifetime = name_to_dummy_lifetime(
token::str_to_ident(s.as_slice()).name);

View file

@ -162,7 +162,7 @@ pub fn bound_region_to_str(cx: &ctxt,
match br {
BrNamed(_, name) => {
format!("{}'{}{}", prefix, token::get_name(name), space_str)
format!("{}{}{}", prefix, token::get_name(name), space_str)
}
BrAnon(_) => prefix.to_string(),
BrFresh(_) => prefix.to_string(),