From 9c09c9434764127f857a9599b93dc090ac63cc2b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 19:15:08 -0700 Subject: [PATCH] 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] --- src/libsyntax/ext/bytes.rs | 23 +++++++++-------------- 1 file 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) } -- GitLab