diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-10-06 19:15:08 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-10-09 09:44:51 -0700 |
| commit | 9c09c9434764127f857a9599b93dc090ac63cc2b (patch) | |
| tree | 4dc407a2998db57fbdc869d33ea75cf6c0e2b2d4 /src/libsyntax | |
| parent | 01d58fe2cbad0872f92571960ca3d8a5b01d0784 (diff) | |
| download | rust-9c09c9434764127f857a9599b93dc090ac63cc2b.tar.gz rust-9c09c9434764127f857a9599b93dc090ac63cc2b.zip | |
syntax: Tweak the return value of bytes!()
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]
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/bytes.rs | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/libsyntax/ext/bytes.rs b/src/libsyntax/ext/bytes.rs index 3c9e40d850b..a93295815e0 100644 --- a/src/libsyntax/ext/bytes.rs +++ b/src/libsyntax/ext/bytes.rs @@ -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) } |
