about summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2014-06-10 13:54:13 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-06-13 13:53:34 -0700
commit2ed473487323bb4e5a600a3318e0981981214210 (patch)
treea48635d0cac054e7045be8d0fbbd506f4f50b74e /src/libsyntax/ext
parente7f11f20e5e72a3b22863a9913df94303321a5ce (diff)
downloadrust-2ed473487323bb4e5a600a3318e0981981214210.tar.gz
rust-2ed473487323bb4e5a600a3318e0981981214210.zip
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]
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/build.rs31
-rw-r--r--src/libsyntax/ext/bytes.rs14
-rw-r--r--src/libsyntax/ext/env.rs2
-rw-r--r--src/libsyntax/ext/format.rs2
4 files changed, 44 insertions, 5 deletions
diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs
index 148b653b61c..4ef7796c454 100644
--- a/src/libsyntax/ext/build.rs
+++ b/src/libsyntax/ext/build.rs
@@ -85,6 +85,7 @@ pub trait AstBuilder {
                       typ: P<ast::Ty>,
                       ex: Gc<ast::Expr>)
                       -> Gc<ast::Stmt>;
+    fn stmt_item(&self, sp: Span, item: Gc<ast::Item>) -> Gc<ast::Stmt>;
 
     // blocks
     fn block(&self, span: Span, stmts: Vec<Gc<ast::Stmt>>,
@@ -239,6 +240,14 @@ pub trait AstBuilder {
                 vi: Vec<ast::ViewItem>,
                 items: Vec<Gc<ast::Item>>) -> Gc<ast::Item>;
 
+    fn item_static(&self,
+                   span: Span,
+                   name: Ident,
+                   ty: P<ast::Ty>,
+                   mutbl: ast::Mutability,
+                   expr: Gc<ast::Expr>)
+                   -> Gc<ast::Item>;
+
     fn item_ty_poly(&self,
                     span: Span,
                     name: Ident,
@@ -484,11 +493,19 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
         box(GC) respan(sp, ast::StmtDecl(box(GC) decl, ast::DUMMY_NODE_ID))
     }
 
-    fn block(&self, span: Span, stmts: Vec<Gc<ast::Stmt>>,
-             expr: Option<Gc<Expr>>) -> P<ast::Block> {
+    fn block(&self,
+             span: Span,
+             stmts: Vec<Gc<ast::Stmt>>,
+             expr: Option<Gc<Expr>>)
+             -> P<ast::Block> {
         self.block_all(span, Vec::new(), stmts, expr)
     }
 
+    fn stmt_item(&self, sp: Span, item: Gc<ast::Item>) -> Gc<ast::Stmt> {
+        let decl = respan(sp, ast::DeclItem(item));
+        box(GC) respan(sp, ast::StmtDecl(box(GC) decl, ast::DUMMY_NODE_ID))
+    }
+
     fn block_expr(&self, expr: Gc<ast::Expr>) -> P<ast::Block> {
         self.block_all(expr.span, Vec::new(), Vec::new(), Some(expr))
     }
@@ -942,6 +959,16 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
         )
     }
 
+    fn item_static(&self,
+                   span: Span,
+                   name: Ident,
+                   ty: P<ast::Ty>,
+                   mutbl: ast::Mutability,
+                   expr: Gc<ast::Expr>)
+                   -> Gc<ast::Item> {
+        self.item(span, name, Vec::new(), ast::ItemStatic(ty, mutbl, expr))
+    }
+
     fn item_ty_poly(&self, span: Span, name: Ident, ty: P<ast::Ty>,
                     generics: Generics) -> Gc<ast::Item> {
         self.item(span, name, Vec::new(), ast::ItemTy(ty, generics))
diff --git a/src/libsyntax/ext/bytes.rs b/src/libsyntax/ext/bytes.rs
index b2088d2bc82..b87a25d4a44 100644
--- a/src/libsyntax/ext/bytes.rs
+++ b/src/libsyntax/ext/bytes.rs
@@ -94,6 +94,18 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
     }
 
     let e = cx.expr_vec_slice(sp, bytes);
-    let e = quote_expr!(cx, { static BYTES: &'static [u8] = $e; BYTES});
+    let ty = cx.ty(sp, ast::TyVec(cx.ty_ident(sp, cx.ident_of("u8"))));
+    let lifetime = cx.lifetime(sp, cx.ident_of("'static").name);
+    let item = cx.item_static(sp,
+                              cx.ident_of("BYTES"),
+                              cx.ty_rptr(sp,
+                                         ty,
+                                         Some(lifetime),
+                                         ast::MutImmutable),
+                              ast::MutImmutable,
+                              e);
+    let e = cx.expr_block(cx.block(sp,
+                                   vec!(cx.stmt_item(sp, item)),
+                                   Some(cx.expr_ident(sp, cx.ident_of("BYTES")))));
     MacExpr::new(e)
 }
diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs
index d1a4d2f3ee3..9ef7241ca24 100644
--- a/src/libsyntax/ext/env.rs
+++ b/src/libsyntax/ext/env.rs
@@ -43,7 +43,7 @@ pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
                                                         cx.ident_of("str")),
                                                    Some(cx.lifetime(sp,
                                                         cx.ident_of(
-                                                            "static").name)),
+                                                            "'static").name)),
                                                    ast::MutImmutable))))
       }
       Some(s) => {
diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs
index d3b73cbe33a..cfce4b1e0fc 100644
--- a/src/libsyntax/ext/format.rs
+++ b/src/libsyntax/ext/format.rs
@@ -465,7 +465,7 @@ impl<'a, 'b> Context<'a, 'b> {
                     self.ecx.ident_of("rt"),
                     self.ecx.ident_of("Piece")),
                 vec!(self.ecx.lifetime(self.fmtsp,
-                                       self.ecx.ident_of("static").name)),
+                                       self.ecx.ident_of("'static").name)),
                 Vec::new()
             ), None);
         let ty = ast::TyFixedLengthVec(