rollup merge of #20657: alexcrichton/stabilize-macros

This commit is contained in:
Alex Crichton 2015-01-07 17:36:16 -08:00
commit 6621325601
9 changed files with 33 additions and 224 deletions

View file

@ -341,9 +341,6 @@ fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv {
let mut syntax_expanders = SyntaxEnv::new();
syntax_expanders.insert(intern("macro_rules"), MacroRulesTT);
syntax_expanders.insert(intern("fmt"),
builtin_normal_expander(
ext::fmt::expand_syntax_ext));
syntax_expanders.insert(intern("format_args"),
builtin_normal_expander(
ext::format::expand_format_args));
@ -353,9 +350,6 @@ fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv {
syntax_expanders.insert(intern("option_env"),
builtin_normal_expander(
ext::env::expand_option_env));
syntax_expanders.insert(intern("bytes"),
builtin_normal_expander(
ext::bytes::expand_syntax_ext));
syntax_expanders.insert(intern("concat_idents"),
builtin_normal_expander(
ext::concat_idents::expand_syntax_ext));
@ -367,8 +361,6 @@ fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv {
ext::log_syntax::expand_syntax_ext));
syntax_expanders.insert(intern("derive"),
Decorator(box ext::deriving::expand_meta_derive));
syntax_expanders.insert(intern("deriving"),
Decorator(box ext::deriving::expand_meta_deriving));
if ecfg.enable_quotes {
// Quasi-quoting expanders
@ -416,9 +408,6 @@ fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv {
syntax_expanders.insert(intern("include_str"),
builtin_normal_expander(
ext::source_util::expand_include_str));
syntax_expanders.insert(intern("include_bin"),
builtin_normal_expander(
ext::source_util::expand_include_bin));
syntax_expanders.insert(intern("include_bytes"),
builtin_normal_expander(
ext::source_util::expand_include_bytes));

View file

@ -1,117 +0,0 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
/* The compiler code necessary to support the bytes! extension. */
use ast;
use codemap::Span;
use ext::base::*;
use ext::base;
use ext::build::AstBuilder;
use std::ascii::AsciiExt;
pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt,
sp: Span,
tts: &[ast::TokenTree])
-> Box<base::MacResult+'cx> {
cx.span_warn(sp, "`bytes!` is deprecated, use `b\"foo\"` literals instead");
cx.parse_sess.span_diagnostic.span_help(sp,
"see http://doc.rust-lang.org/reference.html#byte-and-byte-string-literals \
for documentation");
cx.parse_sess.span_diagnostic.span_help(sp,
"see https://github.com/rust-lang/rust/blob/master/src/etc/2014-06-rewrite-bytes-macros.py \
for an automated migration");
// Gather all argument expressions
let exprs = match get_exprs_from_tts(cx, sp, tts) {
None => return DummyResult::expr(sp),
Some(e) => e,
};
let mut bytes = Vec::new();
let mut err = false;
for expr in exprs.iter() {
match expr.node {
// expression is a literal
ast::ExprLit(ref lit) => match lit.node {
// string literal, push each byte to vector expression
ast::LitStr(ref s, _) => {
for byte in s.get().bytes() {
bytes.push(cx.expr_u8(expr.span, byte));
}
}
// u8 literal, push to vector expression
ast::LitInt(v, ast::UnsignedIntLit(ast::TyU8)) => {
if v > 0xFF {
cx.span_err(expr.span, "too large u8 literal in bytes!");
err = true;
} else {
bytes.push(cx.expr_u8(expr.span, v as u8));
}
}
// integer literal, push to vector expression
ast::LitInt(_, ast::UnsuffixedIntLit(ast::Minus)) => {
cx.span_err(expr.span, "negative integer literal in bytes!");
err = true;
}
ast::LitInt(v, ast::UnsuffixedIntLit(ast::Plus)) => {
if v > 0xFF {
cx.span_err(expr.span, "too large integer literal in bytes!");
err = true;
} else {
bytes.push(cx.expr_u8(expr.span, v as u8));
}
}
// char literal, push to vector expression
ast::LitChar(v) => {
if v.is_ascii() {
bytes.push(cx.expr_u8(expr.span, v as u8));
} else {
cx.span_err(expr.span, "non-ascii char literal in bytes!");
err = true;
}
}
_ => {
cx.span_err(expr.span, "unsupported literal in bytes!");
err = true;
}
},
_ => {
cx.span_err(expr.span, "non-literal in bytes!");
err = true;
}
}
}
// For some reason using quote_expr!() here aborts if we threw an error.
// I'm assuming that the end of the recursive parse tricks the compiler
// into thinking this is a good time to stop. But we'd rather keep going.
if err {
// Since the compiler will stop after the macro expansion phase anyway, we
// don't need type info, so we can just return a DummyResult
return DummyResult::expr(sp);
}
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)
}

View file

@ -40,16 +40,6 @@ pub mod totalord;
pub mod generic;
pub fn expand_meta_deriving(cx: &mut ExtCtxt,
_span: Span,
mitem: &MetaItem,
item: &Item,
push: Box<FnMut(P<Item>)>) {
cx.span_warn(mitem.span, "`deriving` is deprecated; use `derive`");
expand_meta_derive(cx, _span, mitem, item, push)
}
pub fn expand_meta_derive(cx: &mut ExtCtxt,
_span: Span,
mitem: &MetaItem,

View file

@ -1,29 +0,0 @@
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
/// Deprecated fmt! syntax extension
use ast;
use codemap::Span;
use ext::base;
use ext::build::AstBuilder;
pub fn expand_syntax_ext(ecx: &mut base::ExtCtxt,
sp: Span,
_tts: &[ast::TokenTree])
-> Box<base::MacResult+'static> {
ecx.span_err(sp, "`fmt!` is deprecated, use `format!` instead");
ecx.parse_sess.span_diagnostic.span_note(sp,
"see http://doc.rust-lang.org/std/fmt/ \
for documentation");
base::MacExpr::new(ecx.expr_uint(sp, 2))
}

View file

@ -161,12 +161,6 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
}
}
pub fn expand_include_bin(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> Box<base::MacResult+'static> {
cx.span_warn(sp, "include_bin! is deprecated; use include_bytes! instead");
expand_include_bytes(cx, sp, tts)
}
pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> Box<base::MacResult+'static> {
let file = match get_single_str_from_tts(cx, sp, tts, "include_bytes!") {