]> git.lizzy.rs Git - rust.git/commitdiff
syntax: Tweak the return value of bytes!()
authorAlex Crichton <alex@alexcrichton.com>
Tue, 7 Oct 2014 02:15:08 +0000 (19:15 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 9 Oct 2014 16:44:51 +0000 (09:44 -0700)
Instead of returning &'static [u8], an invocation of `bytes!()` now returns
`&'static [u8, ..N]` where `N` is the length of the byte vector. This should
functionally be the same, but there are some cases where an explicit cast may be
needed, so this is a:

[breaking-change]

src/libsyntax/ext/bytes.rs

index 3c9e40d850bac21adfec40ea9c7d2881764fc7d3..a93295815e0ed834c7bddff1b35aa9fcd3d549f1 100644 (file)
@@ -104,19 +104,14 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt,
         return DummyResult::expr(sp);
     }
 
-    let e = cx.expr_vec_slice(sp, 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")))));
+    let len = bytes.len();
+    let e = cx.expr_vec(sp, bytes);
+    let ty = cx.ty(sp, ast::TyFixedLengthVec(cx.ty_ident(sp, cx.ident_of("u8")),
+                                             cx.expr_uint(sp, len)));
+    let item = cx.item_static(sp, cx.ident_of("BYTES"), ty, ast::MutImmutable, e);
+    let ret = cx.expr_ident(sp, cx.ident_of("BYTES"));
+    let ret = cx.expr_addr_of(sp, ret);
+    let e = cx.expr_block(cx.block(sp, vec![cx.stmt_item(sp, item)],
+                                   Some(ret)));
     MacExpr::new(e)
 }