Skip to content

Commit 9c09c94

Browse files
committed
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]
1 parent 01d58fe commit 9c09c94

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/libsyntax/ext/bytes.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,14 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt,
104104
return DummyResult::expr(sp);
105105
}
106106

107-
let e = cx.expr_vec_slice(sp, bytes);
108-
let ty = cx.ty(sp, ast::TyVec(cx.ty_ident(sp, cx.ident_of("u8"))));
109-
let lifetime = cx.lifetime(sp, cx.ident_of("'static").name);
110-
let item = cx.item_static(sp,
111-
cx.ident_of("BYTES"),
112-
cx.ty_rptr(sp,
113-
ty,
114-
Some(lifetime),
115-
ast::MutImmutable),
116-
ast::MutImmutable,
117-
e);
118-
let e = cx.expr_block(cx.block(sp,
119-
vec!(cx.stmt_item(sp, item)),
120-
Some(cx.expr_ident(sp, cx.ident_of("BYTES")))));
107+
let len = bytes.len();
108+
let e = cx.expr_vec(sp, bytes);
109+
let ty = cx.ty(sp, ast::TyFixedLengthVec(cx.ty_ident(sp, cx.ident_of("u8")),
110+
cx.expr_uint(sp, len)));
111+
let item = cx.item_static(sp, cx.ident_of("BYTES"), ty, ast::MutImmutable, e);
112+
let ret = cx.expr_ident(sp, cx.ident_of("BYTES"));
113+
let ret = cx.expr_addr_of(sp, ret);
114+
let e = cx.expr_block(cx.block(sp, vec![cx.stmt_item(sp, item)],
115+
Some(ret)));
121116
MacExpr::new(e)
122117
}

0 commit comments

Comments
 (0)