提交 9c09c943 编写于 作者: A Alex Crichton

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]
上级 01d58fe2
......@@ -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)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册