Auto merge of #36945 - alexcrichton:proc-macro-rename, r=nrc

rustc: Rename rustc_macro to proc_macro

This commit blanket renames the `rustc_macro` infrastructure to `proc_macro`,
which reflects the general consensus of #35900. A follow up PR to Cargo will be
required to purge the `rustc-macro` name as well.
This commit is contained in:
bors 2016-10-07 07:58:27 -07:00 committed by GitHub
commit ca76c7e014
86 changed files with 613 additions and 615 deletions

View File

@ -59,8 +59,8 @@ RUSTC_CRATES := rustc rustc_typeck rustc_mir rustc_borrowck rustc_resolve rustc_
rustc_trans rustc_back rustc_llvm rustc_privacy rustc_lint \
rustc_data_structures rustc_platform_intrinsics rustc_errors \
rustc_plugin rustc_metadata rustc_passes rustc_save_analysis \
rustc_const_eval rustc_const_math rustc_incremental rustc_macro
HOST_CRATES := syntax syntax_ext proc_macro syntax_pos $(RUSTC_CRATES) rustdoc fmt_macros \
rustc_const_eval rustc_const_math rustc_incremental proc_macro
HOST_CRATES := syntax syntax_ext proc_macro_plugin syntax_pos $(RUSTC_CRATES) rustdoc fmt_macros \
flate arena graphviz log serialize
TOOLS := compiletest rustdoc rustc rustbook error_index_generator
@ -101,8 +101,8 @@ DEPS_term := std
DEPS_test := std getopts term native:rust_test_helpers
DEPS_syntax := std term serialize log arena libc rustc_bitflags rustc_unicode rustc_errors syntax_pos
DEPS_syntax_ext := syntax syntax_pos rustc_errors fmt_macros rustc_macro
DEPS_proc_macro := syntax syntax_pos rustc_plugin log
DEPS_syntax_ext := syntax syntax_pos rustc_errors fmt_macros proc_macro
DEPS_proc_macro_plugin := syntax syntax_pos rustc_plugin log
DEPS_syntax_pos := serialize
DEPS_rustc_const_math := std syntax log serialize
@ -118,15 +118,15 @@ DEPS_rustc_data_structures := std log serialize libc
DEPS_rustc_driver := arena flate getopts graphviz libc rustc rustc_back rustc_borrowck \
rustc_typeck rustc_mir rustc_resolve log syntax serialize rustc_llvm \
rustc_trans rustc_privacy rustc_lint rustc_plugin \
rustc_metadata syntax_ext proc_macro \
rustc_metadata syntax_ext proc_macro_plugin \
rustc_passes rustc_save_analysis rustc_const_eval \
rustc_incremental syntax_pos rustc_errors rustc_macro
rustc_incremental syntax_pos rustc_errors proc_macro
DEPS_rustc_errors := log libc serialize syntax_pos
DEPS_rustc_lint := rustc log syntax syntax_pos rustc_const_eval
DEPS_rustc_llvm := native:rustllvm libc std rustc_bitflags
DEPS_rustc_macro := std syntax
DEPS_proc_macro := std syntax
DEPS_rustc_metadata := rustc syntax syntax_pos rustc_errors rustc_const_math \
rustc_macro syntax_ext
proc_macro syntax_ext
DEPS_rustc_passes := syntax syntax_pos rustc core rustc_const_eval rustc_errors
DEPS_rustc_mir := rustc syntax syntax_pos rustc_const_math rustc_const_eval rustc_bitflags
DEPS_rustc_resolve := arena rustc log syntax syntax_pos rustc_errors

View File

@ -4,12 +4,8 @@ name = "proc_macro"
version = "0.0.0"
[lib]
name = "proc_macro"
path = "lib.rs"
crate-type = ["dylib"]
[dependencies]
log = { path = "../liblog" }
rustc_plugin = { path = "../librustc_plugin" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }

View File

@ -8,130 +8,160 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! # Proc_Macro
//! A support library for macro authors when defining new macros.
//!
//! A library for procedural macro writers.
//! This library, provided by the standard distribution, provides the types
//! consumed in the interfaces of procedurally defined macro definitions.
//! Currently the primary use of this crate is to provide the ability to define
//! new custom derive modes through `#[proc_macro_derive]`.
//!
//! ## Usage
//! This package provides the `qquote!` macro for syntax creation, and the prelude
//! (at libproc_macro::prelude) provides a number of operations:
//! - `concat`, for concatenating two TokenStreams.
//! - `ident_eq`, for checking if two identifiers are equal regardless of syntax context.
//! - `str_to_token_ident`, for converting an `&str` into a Token.
//! - `keyword_to_token_delim`, for converting a `parse::token::keywords::Keyword` into a
//! Token.
//! - `build_delimited`, for creating a new TokenStream from an existing one and a delimiter
//! by wrapping the TokenStream in the delimiter.
//! - `build_bracket_delimited`, `build_brace_delimited`, and `build_paren_delimited`, for
//! easing the above.
//! - `build_empty_args`, which returns a TokenStream containing `()`.
//! - `lex`, which takes an `&str` and returns the TokenStream it represents.
//! Added recently as part of [RFC 1681] this crate is currently *unstable* and
//! requires the `#![feature(proc_macro_lib)]` directive to use.
//!
//! The `qquote!` macro also imports `syntax::ext::proc_macro_shim::prelude::*`, so you
//! will need to `extern crate syntax` for usage. (This is a temporary solution until more
//! of the external API in libproc_macro is stabilized to support the token construction
//! operations that the qausiquoter relies on.) The shim file also provides additional
//! operations, such as `build_block_emitter` (as used in the `cond` example below).
//!
//! ## TokenStreams
//!
//! TokenStreams serve as the basis of the macro system. They are, in essence, vectors of
//! TokenTrees, where indexing treats delimited values as a single term. That is, the term
//! `even(a+c) && even(b)` will be indexibly encoded as `even | (a+c) | even | (b)` where,
//! in reality, `(a+c)` is actually a decorated pointer to `a | + | c`.
//!
//! If a user has a TokenStream that is a single, delimited value, they can use
//! `maybe_delimited` to destruct it and receive the internal vector as a new TokenStream
//! as:
//! ```
//! `(a+c)`.maybe_delimited() ~> Some(a | + | c)`
//! ```
//!
//! Check the TokenStream documentation for more information; the structure also provides
//! cheap concatenation and slicing.
//!
//! ## Quasiquotation
//!
//! The quasiquoter creates output that, when run, constructs the tokenstream specified as
//! input. For example, `qquote!(5 + 5)` will produce a program, that, when run, will
//! construct the TokenStream `5 | + | 5`.
//!
//! ### Unquoting
//!
//! Unquoting is currently done as `unquote`, and works by taking the single next
//! TokenTree in the TokenStream as the unquoted term. Ergonomically, `unquote(foo)` works
//! fine, but `unquote foo` is also supported.
//!
//! A simple example might be:
//!
//!```
//!fn double(tmp: TokenStream) -> TokenStream {
//! qquote!(unquote(tmp) * 2)
//!}
//!```
//!
//! ### Large Example: Implementing Scheme's `cond`
//!
//! Below is the full implementation of Scheme's `cond` operator.
//!
//! ```
//! fn cond_rec(input: TokenStream) -> TokenStream {
//! if input.is_empty() { return quote!(); }
//!
//! let next = input.slice(0..1);
//! let rest = input.slice_from(1..);
//!
//! let clause : TokenStream = match next.maybe_delimited() {
//! Some(ts) => ts,
//! _ => panic!("Invalid input"),
//! };
//!
//! // clause is ([test]) [rhs]
//! if clause.len() < 2 { panic!("Invalid macro usage in cond: {:?}", clause) }
//!
//! let test: TokenStream = clause.slice(0..1);
//! let rhs: TokenStream = clause.slice_from(1..);
//!
//! if ident_eq(&test[0], str_to_ident("else")) || rest.is_empty() {
//! quote!({unquote(rhs)})
//! } else {
//! quote!({if unquote(test) { unquote(rhs) } else { cond!(unquote(rest)) } })
//! }
//! }
//! ```
//! [RFC 1681]: https://github.com/rust-lang/rfcs/blob/master/text/1681-macros-1.1.md
//!
//! Note that this crate is intentionally very bare-bones currently. The main
//! type, `TokenStream`, only supports `fmt::Display` and `FromStr`
//! implementations, indicating that it can only go to and come from a string.
//! This functionality is intended to be expanded over time as more surface
//! area for macro authors is stabilized.
#![crate_name = "proc_macro"]
#![unstable(feature = "rustc_private", issue = "27812")]
#![feature(plugin_registrar)]
#![crate_type = "dylib"]
#![unstable(feature = "proc_macro_lib", issue = "27812")]
#![crate_type = "rlib"]
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/")]
#![crate_type = "dylib"]
#![cfg_attr(not(stage0), deny(warnings))]
#![deny(missing_docs)]
#![feature(staged_api)]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
#![feature(staged_api)]
#![feature(lang_items)]
extern crate rustc_plugin;
extern crate syntax;
extern crate syntax_pos;
#[macro_use] extern crate log;
mod qquote;
pub mod build;
pub mod parse;
pub mod prelude;
use qquote::qquote;
use std::fmt;
use std::str::FromStr;
use rustc_plugin::Registry;
use syntax::ast;
use syntax::parse;
use syntax::ptr::P;
// ____________________________________________________________________________________________
// Main macro definition
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
reg.register_macro("qquote", qquote);
/// The main type provided by this crate, representing an abstract stream of
/// tokens.
///
/// This is both the input and output of `#[proc_macro_derive]` definitions.
/// Currently it's required to be a list of valid Rust items, but this
/// restriction may be lifted in the future.
///
/// The API of this type is intentionally bare-bones, but it'll be expanded over
/// time!
pub struct TokenStream {
inner: Vec<P<ast::Item>>,
}
/// Error returned from `TokenStream::from_str`.
#[derive(Debug)]
pub struct LexError {
_inner: (),
}
/// Permanently unstable internal implementation details of this crate. This
/// should not be used.
///
/// These methods are used by the rest of the compiler to generate instances of
/// `TokenStream` to hand to macro definitions, as well as consume the output.
///
/// Note that this module is also intentionally separate from the rest of the
/// crate. This allows the `#[unstable]` directive below to naturally apply to
/// all of the contents.
#[unstable(feature = "proc_macro_internals", issue = "27812")]
#[doc(hidden)]
pub mod __internal {
use std::cell::Cell;
use syntax::ast;
use syntax::ptr::P;
use syntax::parse::ParseSess;
use super::TokenStream;
pub fn new_token_stream(item: P<ast::Item>) -> TokenStream {
TokenStream { inner: vec![item] }
}
pub fn token_stream_items(stream: TokenStream) -> Vec<P<ast::Item>> {
stream.inner
}
pub trait Registry {
fn register_custom_derive(&mut self,
trait_name: &str,
expand: fn(TokenStream) -> TokenStream);
}
// Emulate scoped_thread_local!() here essentially
thread_local! {
static CURRENT_SESS: Cell<*const ParseSess> = Cell::new(0 as *const _);
}
pub fn set_parse_sess<F, R>(sess: &ParseSess, f: F) -> R
where F: FnOnce() -> R
{
struct Reset { prev: *const ParseSess }
impl Drop for Reset {
fn drop(&mut self) {
CURRENT_SESS.with(|p| p.set(self.prev));
}
}
CURRENT_SESS.with(|p| {
let _reset = Reset { prev: p.get() };
p.set(sess);
f()
})
}
pub fn with_parse_sess<F, R>(f: F) -> R
where F: FnOnce(&ParseSess) -> R
{
let p = CURRENT_SESS.with(|p| p.get());
assert!(!p.is_null());
f(unsafe { &*p })
}
}
impl FromStr for TokenStream {
type Err = LexError;
fn from_str(src: &str) -> Result<TokenStream, LexError> {
__internal::with_parse_sess(|sess| {
let src = src.to_string();
let cfg = Vec::new();
let name = "<proc-macro source code>".to_string();
let mut parser = parse::new_parser_from_source_str(sess, cfg, name,
src);
let mut ret = TokenStream { inner: Vec::new() };
loop {
match parser.parse_item() {
Ok(Some(item)) => ret.inner.push(item),
Ok(None) => return Ok(ret),
Err(mut err) => {
err.cancel();
return Err(LexError { _inner: () })
}
}
}
})
}
}
impl fmt::Display for TokenStream {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for item in self.inner.iter() {
let item = syntax::print::pprust::item_to_string(item);
try!(f.write_str(&item));
try!(f.write_str("\n"));
}
Ok(())
}
}

View File

@ -1,12 +1,14 @@
[package]
authors = ["The Rust Project Developers"]
name = "rustc_macro"
name = "proc_macro_plugin"
version = "0.0.0"
[lib]
name = "rustc_macro"
path = "lib.rs"
crate-type = ["dylib"]
[dependencies]
log = { path = "../liblog" }
rustc_plugin = { path = "../librustc_plugin" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }

View File

@ -0,0 +1,137 @@
// Copyright 2016 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.
//! # Proc_Macro
//!
//! A library for procedural macro writers.
//!
//! ## Usage
//! This package provides the `qquote!` macro for syntax creation, and the prelude
//! (at libproc_macro::prelude) provides a number of operations:
//! - `concat`, for concatenating two TokenStreams.
//! - `ident_eq`, for checking if two identifiers are equal regardless of syntax context.
//! - `str_to_token_ident`, for converting an `&str` into a Token.
//! - `keyword_to_token_delim`, for converting a `parse::token::keywords::Keyword` into a
//! Token.
//! - `build_delimited`, for creating a new TokenStream from an existing one and a delimiter
//! by wrapping the TokenStream in the delimiter.
//! - `build_bracket_delimited`, `build_brace_delimited`, and `build_paren_delimited`, for
//! easing the above.
//! - `build_empty_args`, which returns a TokenStream containing `()`.
//! - `lex`, which takes an `&str` and returns the TokenStream it represents.
//!
//! The `qquote!` macro also imports `syntax::ext::proc_macro_shim::prelude::*`, so you
//! will need to `extern crate syntax` for usage. (This is a temporary solution until more
//! of the external API in libproc_macro is stabilized to support the token construction
//! operations that the qausiquoter relies on.) The shim file also provides additional
//! operations, such as `build_block_emitter` (as used in the `cond` example below).
//!
//! ## TokenStreams
//!
//! TokenStreams serve as the basis of the macro system. They are, in essence, vectors of
//! TokenTrees, where indexing treats delimited values as a single term. That is, the term
//! `even(a+c) && even(b)` will be indexibly encoded as `even | (a+c) | even | (b)` where,
//! in reality, `(a+c)` is actually a decorated pointer to `a | + | c`.
//!
//! If a user has a TokenStream that is a single, delimited value, they can use
//! `maybe_delimited` to destruct it and receive the internal vector as a new TokenStream
//! as:
//! ```
//! `(a+c)`.maybe_delimited() ~> Some(a | + | c)`
//! ```
//!
//! Check the TokenStream documentation for more information; the structure also provides
//! cheap concatenation and slicing.
//!
//! ## Quasiquotation
//!
//! The quasiquoter creates output that, when run, constructs the tokenstream specified as
//! input. For example, `qquote!(5 + 5)` will produce a program, that, when run, will
//! construct the TokenStream `5 | + | 5`.
//!
//! ### Unquoting
//!
//! Unquoting is currently done as `unquote`, and works by taking the single next
//! TokenTree in the TokenStream as the unquoted term. Ergonomically, `unquote(foo)` works
//! fine, but `unquote foo` is also supported.
//!
//! A simple example might be:
//!
//!```
//!fn double(tmp: TokenStream) -> TokenStream {
//! qquote!(unquote(tmp) * 2)
//!}
//!```
//!
//! ### Large Example: Implementing Scheme's `cond`
//!
//! Below is the full implementation of Scheme's `cond` operator.
//!
//! ```
//! fn cond_rec(input: TokenStream) -> TokenStream {
//! if input.is_empty() { return quote!(); }
//!
//! let next = input.slice(0..1);
//! let rest = input.slice_from(1..);
//!
//! let clause : TokenStream = match next.maybe_delimited() {
//! Some(ts) => ts,
//! _ => panic!("Invalid input"),
//! };
//!
//! // clause is ([test]) [rhs]
//! if clause.len() < 2 { panic!("Invalid macro usage in cond: {:?}", clause) }
//!
//! let test: TokenStream = clause.slice(0..1);
//! let rhs: TokenStream = clause.slice_from(1..);
//!
//! if ident_eq(&test[0], str_to_ident("else")) || rest.is_empty() {
//! quote!({unquote(rhs)})
//! } else {
//! quote!({if unquote(test) { unquote(rhs) } else { cond!(unquote(rest)) } })
//! }
//! }
//! ```
//!
#![crate_name = "proc_macro_plugin"]
#![unstable(feature = "rustc_private", issue = "27812")]
#![feature(plugin_registrar)]
#![crate_type = "dylib"]
#![crate_type = "rlib"]
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/")]
#![cfg_attr(not(stage0), deny(warnings))]
#![feature(staged_api)]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
extern crate rustc_plugin;
extern crate syntax;
extern crate syntax_pos;
#[macro_use] extern crate log;
mod qquote;
pub mod build;
pub mod parse;
pub mod prelude;
use qquote::qquote;
use rustc_plugin::Registry;
// ____________________________________________________________________________________________
// Main macro definition
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
reg.register_macro("qquote", qquote);
}

View File

@ -51,7 +51,7 @@ pub fn qquote<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[TokenTree])
let output = qquoter(cx, TokenStream::from_tts(tts.clone().to_owned()));
debug!("\nQQ out: {}\n", pprust::tts_to_string(&output.to_tts()[..]));
let imports = concat(lex("use syntax::ext::proc_macro_shim::prelude::*;"),
lex("use proc_macro::prelude::*;"));
lex("use proc_macro_plugin::prelude::*;"));
build_block_emitter(cx, sp, build_brace_delimited(concat(imports, output)))
}
@ -219,7 +219,7 @@ fn convert_complex_tts<'cx>(cx: &'cx mut ExtCtxt, tts: Vec<QTT>) -> (Bindings, T
let sep = build_delim_tok(qdl.delim);
pushes.push(build_mod_call(vec![str_to_ident("proc_macro"),
pushes.push(build_mod_call(vec![str_to_ident("proc_macro_plugin"),
str_to_ident("build"),
str_to_ident("build_delimited")],
concat(from_tokens(vec![Token::Ident(new_id)]),

View File

@ -141,12 +141,12 @@ fn calculate_type(sess: &session::Session,
}
// Everything else falls through below. This will happen either with the
// `-C prefer-dynamic` or because we're a rustc-macro crate. Note that
// rustc-macro crates are required to be dylibs, and they're currently
// `-C prefer-dynamic` or because we're a proc-macro crate. Note that
// proc-macro crates are required to be dylibs, and they're currently
// required to link to libsyntax as well.
config::CrateTypeExecutable |
config::CrateTypeDylib |
config::CrateTypeRustcMacro => {},
config::CrateTypeProcMacro => {},
}
let mut formats = FnvHashMap();

View File

@ -139,7 +139,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ReachableContext<'a, 'tcx> {
let any_library = tcx.sess.crate_types.borrow().iter().any(|ty| {
*ty == config::CrateTypeRlib || *ty == config::CrateTypeDylib ||
*ty == config::CrateTypeRustcMacro
*ty == config::CrateTypeProcMacro
});
ReachableContext {
tcx: tcx,

View File

@ -71,7 +71,7 @@ fn verify(sess: &Session, items: &lang_items::LanguageItems) {
let needs_check = sess.crate_types.borrow().iter().any(|kind| {
match *kind {
config::CrateTypeDylib |
config::CrateTypeRustcMacro |
config::CrateTypeProcMacro |
config::CrateTypeCdylib |
config::CrateTypeExecutable |
config::CrateTypeStaticlib => true,

View File

@ -482,7 +482,7 @@ pub enum CrateType {
CrateTypeRlib,
CrateTypeStaticlib,
CrateTypeCdylib,
CrateTypeRustcMacro,
CrateTypeProcMacro,
}
#[derive(Clone, Hash)]
@ -972,8 +972,8 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
if sess.opts.debug_assertions {
ret.push(attr::mk_word_item(InternedString::new("debug_assertions")));
}
if sess.opts.crate_types.contains(&CrateTypeRustcMacro) {
ret.push(attr::mk_word_item(InternedString::new("rustc_macro")));
if sess.opts.crate_types.contains(&CrateTypeProcMacro) {
ret.push(attr::mk_word_item(InternedString::new("proc_macro")));
}
return ret;
}
@ -1546,7 +1546,7 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
"dylib" => CrateTypeDylib,
"cdylib" => CrateTypeCdylib,
"bin" => CrateTypeExecutable,
"rustc-macro" => CrateTypeRustcMacro,
"proc-macro" => CrateTypeProcMacro,
_ => {
return Err(format!("unknown crate type: `{}`",
part));
@ -1630,7 +1630,7 @@ impl fmt::Display for CrateType {
CrateTypeRlib => "rlib".fmt(f),
CrateTypeStaticlib => "staticlib".fmt(f),
CrateTypeCdylib => "cdylib".fmt(f),
CrateTypeRustcMacro => "rustc-macro".fmt(f),
CrateTypeProcMacro => "proc-macro".fmt(f),
}
}
}

View File

@ -493,7 +493,7 @@ pub struct GlobalCtxt<'tcx> {
pub layout_depth: Cell<usize>,
/// Map from function to the `#[derive]` mode that it's defining. Only used
/// by `rustc-macro` crates.
/// by `proc-macro` crates.
pub derive_macros: RefCell<NodeMap<token::InternedString>>,
}

View File

@ -13,25 +13,25 @@ arena = { path = "../libarena" }
flate = { path = "../libflate" }
graphviz = { path = "../libgraphviz" }
log = { path = "../liblog" }
proc_macro_plugin = { path = "../libproc_macro_plugin" }
rustc = { path = "../librustc" }
rustc_back = { path = "../librustc_back" }
rustc_borrowck = { path = "../librustc_borrowck" }
rustc_const_eval = { path = "../librustc_const_eval" }
rustc_errors = { path = "../librustc_errors" }
rustc_incremental = { path = "../librustc_incremental" }
rustc_lint = { path = "../librustc_lint" }
rustc_llvm = { path = "../librustc_llvm" }
rustc_metadata = { path = "../librustc_metadata" }
rustc_mir = { path = "../librustc_mir" }
rustc_plugin = { path = "../librustc_plugin" }
rustc_passes = { path = "../librustc_passes" }
rustc_plugin = { path = "../librustc_plugin" }
rustc_privacy = { path = "../librustc_privacy" }
rustc_incremental = { path = "../librustc_incremental" }
rustc_resolve = { path = "../librustc_resolve" }
rustc_save_analysis = { path = "../librustc_save_analysis" }
rustc_trans = { path = "../librustc_trans" }
rustc_typeck = { path = "../librustc_typeck" }
rustc_metadata = { path = "../librustc_metadata" }
serialize = { path = "../libserialize" }
syntax = { path = "../libsyntax" }
syntax_ext = { path = "../libsyntax_ext" }
syntax_pos = { path = "../libsyntax_pos" }
proc_macro = { path = "../libproc_macro" }

View File

@ -710,14 +710,14 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
krate = time(time_passes, "maybe creating a macro crate", || {
let crate_types = sess.crate_types.borrow();
let num_crate_types = crate_types.len();
let is_rustc_macro_crate = crate_types.contains(&config::CrateTypeRustcMacro);
syntax_ext::rustc_macro_registrar::modify(&sess.parse_sess,
&mut resolver,
krate,
is_rustc_macro_crate,
num_crate_types,
sess.diagnostic(),
&sess.features.borrow())
let is_proc_macro_crate = crate_types.contains(&config::CrateTypeProcMacro);
syntax_ext::proc_macro_registrar::modify(&sess.parse_sess,
&mut resolver,
krate,
is_proc_macro_crate,
num_crate_types,
sess.diagnostic(),
&sess.features.borrow())
});
}
@ -1181,8 +1181,8 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
Some(ref n) if *n == "staticlib" => {
Some(config::CrateTypeStaticlib)
}
Some(ref n) if *n == "rustc-macro" => {
Some(config::CrateTypeRustcMacro)
Some(ref n) if *n == "proc-macro" => {
Some(config::CrateTypeProcMacro)
}
Some(ref n) if *n == "bin" => Some(config::CrateTypeExecutable),
Some(_) => {

View File

@ -1,169 +0,0 @@
// Copyright 2016 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.
//! A support library for macro authors when defining new macros.
//!
//! This library, provided by the standard distribution, provides the types
//! consumed in the interfaces of procedurally defined macro definitions.
//! Currently the primary use of this crate is to provide the ability to define
//! new custom derive modes through `#[rustc_macro_derive]`.
//!
//! Added recently as part of [RFC 1681] this crate is currently *unstable* and
//! requires the `#![feature(rustc_macro_lib)]` directive to use. Eventually,
//! though, it is intended for this crate to become stable to use (perhaps under
//! a different name).
//!
//! [RFC 1681]: https://github.com/rust-lang/rfcs/blob/master/text/1681-macros-1.1.md
//!
//! Note that this crate is intentionally very bare-bones currently. The main
//! type, `TokenStream`, only supports `fmt::Display` and `FromStr`
//! implementations, indicating that it can only go to and come from a string.
//! This functionality is intended to be expanded over time as more surface
//! area for macro authors is stabilized.
#![crate_name = "rustc_macro"]
#![unstable(feature = "rustc_macro_lib", issue = "27812")]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
#![cfg_attr(not(stage0), deny(warnings))]
#![deny(missing_docs)]
#![feature(rustc_private)]
#![feature(staged_api)]
#![feature(lang_items)]
extern crate syntax;
use std::fmt;
use std::str::FromStr;
use syntax::ast;
use syntax::parse;
use syntax::ptr::P;
/// The main type provided by this crate, representing an abstract stream of
/// tokens.
///
/// This is both the input and output of `#[rustc_macro_derive]` definitions.
/// Currently it's required to be a list of valid Rust items, but this
/// restriction may be lifted in the future.
///
/// The API of this type is intentionally bare-bones, but it'll be expanded over
/// time!
pub struct TokenStream {
inner: Vec<P<ast::Item>>,
}
/// Error returned from `TokenStream::from_str`.
#[derive(Debug)]
pub struct LexError {
_inner: (),
}
/// Permanently unstable internal implementation details of this crate. This
/// should not be used.
///
/// These methods are used by the rest of the compiler to generate instances of
/// `TokenStream` to hand to macro definitions, as well as consume the output.
///
/// Note that this module is also intentionally separate from the rest of the
/// crate. This allows the `#[unstable]` directive below to naturally apply to
/// all of the contents.
#[unstable(feature = "rustc_macro_internals", issue = "27812")]
#[doc(hidden)]
pub mod __internal {
use std::cell::Cell;
use syntax::ast;
use syntax::ptr::P;
use syntax::parse::ParseSess;
use super::TokenStream;
pub fn new_token_stream(item: P<ast::Item>) -> TokenStream {
TokenStream { inner: vec![item] }
}
pub fn token_stream_items(stream: TokenStream) -> Vec<P<ast::Item>> {
stream.inner
}
pub trait Registry {
fn register_custom_derive(&mut self,
trait_name: &str,
expand: fn(TokenStream) -> TokenStream);
}
// Emulate scoped_thread_local!() here essentially
thread_local! {
static CURRENT_SESS: Cell<*const ParseSess> = Cell::new(0 as *const _);
}
pub fn set_parse_sess<F, R>(sess: &ParseSess, f: F) -> R
where F: FnOnce() -> R
{
struct Reset { prev: *const ParseSess }
impl Drop for Reset {
fn drop(&mut self) {
CURRENT_SESS.with(|p| p.set(self.prev));
}
}
CURRENT_SESS.with(|p| {
let _reset = Reset { prev: p.get() };
p.set(sess);
f()
})
}
pub fn with_parse_sess<F, R>(f: F) -> R
where F: FnOnce(&ParseSess) -> R
{
let p = CURRENT_SESS.with(|p| p.get());
assert!(!p.is_null());
f(unsafe { &*p })
}
}
impl FromStr for TokenStream {
type Err = LexError;
fn from_str(src: &str) -> Result<TokenStream, LexError> {
__internal::with_parse_sess(|sess| {
let src = src.to_string();
let cfg = Vec::new();
let name = "<rustc-macro source code>".to_string();
let mut parser = parse::new_parser_from_source_str(sess, cfg, name,
src);
let mut ret = TokenStream { inner: Vec::new() };
loop {
match parser.parse_item() {
Ok(Some(item)) => ret.inner.push(item),
Ok(None) => return Ok(ret),
Err(mut err) => {
err.cancel();
return Err(LexError { _inner: () })
}
}
}
})
}
}
impl fmt::Display for TokenStream {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for item in self.inner.iter() {
let item = syntax::print::pprust::item_to_string(item);
try!(f.write_str(&item));
try!(f.write_str("\n"));
}
Ok(())
}
}

View File

@ -11,13 +11,13 @@ crate-type = ["dylib"]
[dependencies]
flate = { path = "../libflate" }
log = { path = "../liblog" }
proc_macro = { path = "../libproc_macro" }
rustc = { path = "../librustc" }
rustc_back = { path = "../librustc_back" }
rustc_const_math = { path = "../librustc_const_math" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_errors = { path = "../librustc_errors" }
rustc_llvm = { path = "../librustc_llvm" }
rustc_macro = { path = "../librustc_macro" }
serialize = { path = "../libserialize" }
syntax = { path = "../libsyntax" }
syntax_ext = { path = "../libsyntax_ext" }

View File

@ -311,7 +311,7 @@ impl<'a> CrateReader<'a> {
let cnum_map = self.resolve_crate_deps(root, &crate_root, &metadata, cnum, span);
if crate_root.macro_derive_registrar.is_some() {
self.sess.span_err(span, "crates of the `rustc-macro` crate type \
self.sess.span_err(span, "crates of the `proc-macro` crate type \
cannot be linked at runtime");
}
@ -609,11 +609,11 @@ impl<'a> CrateReader<'a> {
match root.macro_derive_registrar {
Some(id) => ret.custom_derive_registrar = Some(id),
// If this crate is not a rustc-macro crate then we might be able to
// If this crate is not a proc-macro crate then we might be able to
// register it with the local crate store to prevent loading the
// metadata twice.
//
// If it's a rustc-macro crate, though, then we definitely don't
// If it's a proc-macro crate, though, then we definitely don't
// want to register it with the local crate store as we're just
// going to use it as we would a plugin.
None => {
@ -625,11 +625,11 @@ impl<'a> CrateReader<'a> {
self.cstore.add_used_for_derive_macros(item);
ret.dylib = ekrate.dylib.clone();
if ret.dylib.is_none() {
span_bug!(item.span, "rustc-macro crate not dylib");
span_bug!(item.span, "proc-macro crate not dylib");
}
if ekrate.target_only {
let message = format!("rustc-macro crate is not available for \
let message = format!("proc-macro crate is not available for \
triple `{}` (only found {})",
config::host_triple(),
self.sess.opts.target_triple);
@ -804,7 +804,7 @@ impl<'a> CrateReader<'a> {
match *ct {
config::CrateTypeExecutable => need_exe_alloc = true,
config::CrateTypeDylib |
config::CrateTypeRustcMacro |
config::CrateTypeProcMacro |
config::CrateTypeCdylib |
config::CrateTypeStaticlib => need_lib_alloc = true,
config::CrateTypeRlib => {}

View File

@ -23,7 +23,7 @@ use rustc::traits::specialization_graph;
use rustc::ty::{self, Ty, TyCtxt};
use rustc::mir::mir_map::MirMap;
use rustc::session::config::{self, CrateTypeRustcMacro};
use rustc::session::config::{self, CrateTypeProcMacro};
use rustc::util::nodemap::{FnvHashMap, NodeSet};
use rustc_serialize::{Encodable, Encoder, SpecializedEncoder, opaque};
@ -1283,7 +1283,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let tcx = self.tcx;
let link_meta = self.link_meta;
let is_rustc_macro = tcx.sess.crate_types.borrow().contains(&CrateTypeRustcMacro);
let is_proc_macro = tcx.sess.crate_types.borrow().contains(&CrateTypeProcMacro);
let root = self.lazy(&CrateRoot {
rustc_version: rustc_version(),
name: link_meta.crate_name.clone(),
@ -1294,7 +1294,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
plugin_registrar_fn: tcx.sess.plugin_registrar_fn.get().map(|id| {
tcx.map.local_def_id(id).index
}),
macro_derive_registrar: if is_rustc_macro {
macro_derive_registrar: if is_proc_macro {
let id = tcx.sess.derive_registrar_fn.get().unwrap();
Some(tcx.map.local_def_id(id).index)
} else {

View File

@ -17,15 +17,15 @@
html_root_url = "https://doc.rust-lang.org/nightly/")]
#![cfg_attr(not(stage0), deny(warnings))]
#![feature(box_patterns)]
#![feature(conservative_impl_trait)]
#![feature(core_intrinsics)]
#![feature(box_patterns)]
#![feature(dotdot_in_tuple_patterns)]
#![feature(proc_macro_internals)]
#![feature(proc_macro_lib)]
#![feature(question_mark)]
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_macro_lib)]
#![feature(rustc_macro_internals)]
#![feature(rustc_private)]
#![feature(specialization)]
#![feature(staged_api)]
@ -37,14 +37,14 @@ extern crate flate;
extern crate serialize as rustc_serialize; // used by deriving
extern crate rustc_errors as errors;
extern crate syntax_ext;
extern crate proc_macro;
#[macro_use]
extern crate rustc;
extern crate rustc_data_structures;
extern crate rustc_back;
extern crate rustc_llvm;
extern crate rustc_macro;
extern crate rustc_const_math;
extern crate rustc_data_structures;
extern crate rustc_llvm;
mod diagnostics;

View File

@ -17,13 +17,13 @@ use std::mem;
use creader::{CrateLoader, Macros};
use proc_macro::TokenStream;
use proc_macro::__internal::Registry;
use rustc::hir::def_id::DefIndex;
use rustc::middle::cstore::{LoadedMacro, LoadedMacroKind};
use rustc::session::Session;
use rustc::util::nodemap::FnvHashMap;
use rustc_back::dynamic_lib::DynamicLibrary;
use rustc_macro::TokenStream;
use rustc_macro::__internal::Registry;
use syntax::ast;
use syntax::attr;
use syntax::parse::token;
@ -145,13 +145,13 @@ impl<'a> CrateLoader<'a> {
assert_eq!(ret.len(), 0);
if let ImportSelection::Some(..) = import {
self.sess.span_err(vi.span, "`rustc-macro` crates cannot be \
self.sess.span_err(vi.span, "`proc-macro` crates cannot be \
selectively imported from, must \
use `#[macro_use]`");
}
if reexport.len() > 0 {
self.sess.span_err(vi.span, "`rustc-macro` crates cannot be \
self.sess.span_err(vi.span, "`proc-macro` crates cannot be \
reexported from");
}

View File

@ -507,10 +507,10 @@ impl<'b> Resolver<'b> {
}
fn insert_custom_derive(&mut self, name: &str, ext: Rc<MultiItemModifier>, sp: Span) {
if !self.session.features.borrow().rustc_macro {
if !self.session.features.borrow().proc_macro {
let sess = &self.session.parse_sess;
let msg = "loading custom derive macro crates is experimentally supported";
emit_feature_err(sess, "rustc_macro", sp, feature_gate::GateIssue::Language, msg);
emit_feature_err(sess, "proc_macro", sp, feature_gate::GateIssue::Language, msg);
}
if self.derive_modes.insert(token::intern(name), ext).is_some() {
self.session.span_err(sp, &format!("cannot shadow existing derive mode `{}`", name));

View File

@ -239,7 +239,7 @@ pub fn invalid_output_for_target(sess: &Session,
match (sess.target.target.options.dynamic_linking,
sess.target.target.options.executables, crate_type) {
(false, _, config::CrateTypeCdylib) |
(false, _, config::CrateTypeRustcMacro) |
(false, _, config::CrateTypeProcMacro) |
(false, _, config::CrateTypeDylib) => true,
(_, false, config::CrateTypeExecutable) => true,
_ => false
@ -263,7 +263,7 @@ pub fn filename_for_input(sess: &Session,
outputs.out_directory.join(&format!("lib{}.rlib", libname))
}
config::CrateTypeCdylib |
config::CrateTypeRustcMacro |
config::CrateTypeProcMacro |
config::CrateTypeDylib => {
let (prefix, suffix) = (&sess.target.target.options.dll_prefix,
&sess.target.target.options.dll_suffix);
@ -295,7 +295,7 @@ pub fn each_linked_rlib(sess: &Session,
let fmts = fmts.get(&config::CrateTypeExecutable)
.or_else(|| fmts.get(&config::CrateTypeStaticlib))
.or_else(|| fmts.get(&config::CrateTypeCdylib))
.or_else(|| fmts.get(&config::CrateTypeRustcMacro));
.or_else(|| fmts.get(&config::CrateTypeProcMacro));
let fmts = fmts.unwrap_or_else(|| {
bug!("could not find formats for rlibs")
});
@ -736,7 +736,7 @@ fn link_args(cmd: &mut Linker,
// executable. This metadata is in a separate object file from the main
// object file, so we link that in here.
if crate_type == config::CrateTypeDylib ||
crate_type == config::CrateTypeRustcMacro {
crate_type == config::CrateTypeProcMacro {
cmd.add_object(&outputs.with_extension("metadata.o"));
}

View File

@ -245,7 +245,7 @@ impl<'a> Linker for GnuLinker<'a> {
// have far more public symbols than we actually want to export, so we
// hide them all here.
if crate_type == CrateType::CrateTypeDylib ||
crate_type == CrateType::CrateTypeRustcMacro {
crate_type == CrateType::CrateTypeProcMacro {
return
}
@ -450,7 +450,7 @@ fn exported_symbols(scx: &SharedCrateContext,
// See explanation in GnuLinker::export_symbols, for
// why we don't ever need dylib symbols on non-MSVC.
if crate_type == CrateType::CrateTypeDylib ||
crate_type == CrateType::CrateTypeRustcMacro {
crate_type == CrateType::CrateTypeProcMacro {
if !scx.sess().target.target.options.is_like_msvc {
return vec![];
}

View File

@ -862,7 +862,7 @@ impl<'feat> ExpansionConfig<'feat> {
fn enable_allow_internal_unstable = allow_internal_unstable,
fn enable_custom_derive = custom_derive,
fn enable_pushpop_unsafe = pushpop_unsafe,
fn enable_rustc_macro = rustc_macro,
fn enable_proc_macro = proc_macro,
}
}

View File

@ -292,7 +292,7 @@ declare_features! (
(active, item_like_imports, "1.13.0", Some(35120)),
// Macros 1.1
(active, rustc_macro, "1.13.0", Some(35900)),
(active, proc_macro, "1.13.0", Some(35900)),
// Allows untagged unions `union U { ... }`
(active, untagged_unions, "1.13.0", Some(32836)),
@ -576,10 +576,10 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeGat
is an experimental feature",
cfg_fn!(linked_from))),
("rustc_macro_derive", Normal, Gated("rustc_macro",
"the `#[rustc_macro_derive]` attribute \
is an experimental feature",
cfg_fn!(rustc_macro))),
("proc_macro_derive", Normal, Gated("proc_macro",
"the `#[proc_macro_derive]` attribute \
is an experimental feature",
cfg_fn!(proc_macro))),
("rustc_copy_clone_marker", Whitelisted, Gated("rustc_attrs",
"internal implementation detail",
@ -658,7 +658,7 @@ const GATED_CFGS: &'static [(&'static str, &'static str, fn(&Features) -> bool)]
("target_vendor", "cfg_target_vendor", cfg_fn!(cfg_target_vendor)),
("target_thread_local", "cfg_target_thread_local", cfg_fn!(cfg_target_thread_local)),
("target_has_atomic", "cfg_target_has_atomic", cfg_fn!(cfg_target_has_atomic)),
("rustc_macro", "rustc_macro", cfg_fn!(rustc_macro)),
("proc_macro", "proc_macro", cfg_fn!(proc_macro)),
];
#[derive(Debug, Eq, PartialEq)]

View File

@ -11,7 +11,7 @@ crate-type = ["dylib"]
[dependencies]
fmt_macros = { path = "../libfmt_macros" }
log = { path = "../liblog" }
proc_macro = { path = "../libproc_macro" }
rustc_errors = { path = "../librustc_errors" }
rustc_macro = { path = "../librustc_macro" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }

View File

@ -11,7 +11,7 @@
use std::panic;
use errors::FatalError;
use rustc_macro::{TokenStream, __internal};
use proc_macro::{TokenStream, __internal};
use syntax::ast::{self, ItemKind};
use syntax::codemap::{ExpnInfo, MacroAttribute, NameAndSpan, Span};
use syntax::ext::base::*;

View File

@ -20,8 +20,8 @@
#![cfg_attr(not(stage0), deny(warnings))]
#![feature(dotdot_in_tuple_patterns)]
#![feature(rustc_macro_lib)]
#![feature(rustc_macro_internals)]
#![feature(proc_macro_lib)]
#![feature(proc_macro_internals)]
#![feature(rustc_private)]
#![feature(staged_api)]
@ -31,7 +31,7 @@ extern crate log;
#[macro_use]
extern crate syntax;
extern crate syntax_pos;
extern crate rustc_macro;
extern crate proc_macro;
extern crate rustc_errors as errors;
mod asm;
@ -43,7 +43,7 @@ mod format;
mod log_syntax;
mod trace_macros;
pub mod rustc_macro_registrar;
pub mod proc_macro_registrar;
// for custom_derive
pub mod deriving;

View File

@ -36,45 +36,45 @@ struct CollectCustomDerives<'a> {
derives: Vec<CustomDerive>,
in_root: bool,
handler: &'a errors::Handler,
is_rustc_macro_crate: bool,
is_proc_macro_crate: bool,
}
pub fn modify(sess: &ParseSess,
resolver: &mut ::syntax::ext::base::Resolver,
mut krate: ast::Crate,
is_rustc_macro_crate: bool,
is_proc_macro_crate: bool,
num_crate_types: usize,
handler: &errors::Handler,
features: &Features) -> ast::Crate {
let ecfg = ExpansionConfig::default("rustc_macro".to_string());
let ecfg = ExpansionConfig::default("proc_macro".to_string());
let mut cx = ExtCtxt::new(sess, Vec::new(), ecfg, resolver);
let mut collect = CollectCustomDerives {
derives: Vec::new(),
in_root: true,
handler: handler,
is_rustc_macro_crate: is_rustc_macro_crate,
is_proc_macro_crate: is_proc_macro_crate,
};
visit::walk_crate(&mut collect, &krate);
if !is_rustc_macro_crate {
if !is_proc_macro_crate {
return krate
} else if !features.rustc_macro {
let mut err = handler.struct_err("the `rustc-macro` crate type is \
} else if !features.proc_macro {
let mut err = handler.struct_err("the `proc-macro` crate type is \
experimental");
err.help("add #![feature(rustc_macro)] to the crate attributes to \
err.help("add #![feature(proc_macro)] to the crate attributes to \
enable");
err.emit();
}
if num_crate_types > 1 {
handler.err("cannot mix `rustc-macro` crate type with others");
handler.err("cannot mix `proc-macro` crate type with others");
}
krate.module.items.push(mk_registrar(&mut cx, &collect.derives));
if krate.exported_macros.len() > 0 {
handler.err("cannot export macro_rules! macros from a `rustc-macro` \
handler.err("cannot export macro_rules! macros from a `proc-macro` \
crate type currently");
}
@ -83,13 +83,13 @@ pub fn modify(sess: &ParseSess,
impl<'a> CollectCustomDerives<'a> {
fn check_not_pub_in_root(&self, vis: &ast::Visibility, sp: Span) {
if self.is_rustc_macro_crate &&
if self.is_proc_macro_crate &&
self.in_root &&
*vis == ast::Visibility::Public {
self.handler.span_err(sp,
"`rustc-macro` crate types cannot \
"`proc-macro` crate types cannot \
export any items other than functions \
tagged with `#[rustc_macro_derive]` \
tagged with `#[proc_macro_derive]` \
currently");
}
}
@ -100,7 +100,7 @@ impl<'a> Visitor for CollectCustomDerives<'a> {
// First up, make sure we're checking a bare function. If we're not then
// we're just not interested in this item.
//
// If we find one, try to locate a `#[rustc_macro_derive]` attribute on
// If we find one, try to locate a `#[proc_macro_derive]` attribute on
// it.
match item.node {
ast::ItemKind::Fn(..) => {}
@ -111,7 +111,7 @@ impl<'a> Visitor for CollectCustomDerives<'a> {
}
let mut attrs = item.attrs.iter()
.filter(|a| a.check_name("rustc_macro_derive"));
.filter(|a| a.check_name("proc_macro_derive"));
let attr = match attrs.next() {
Some(attr) => attr,
None => {
@ -121,25 +121,25 @@ impl<'a> Visitor for CollectCustomDerives<'a> {
};
if let Some(a) = attrs.next() {
self.handler.span_err(a.span(), "multiple `#[rustc_macro_derive]` \
self.handler.span_err(a.span(), "multiple `#[proc_macro_derive]` \
attributes found");
}
if !self.is_rustc_macro_crate {
if !self.is_proc_macro_crate {
self.handler.span_err(attr.span(),
"the `#[rustc_macro_derive]` attribute is \
only usable with crates of the `rustc-macro` \
"the `#[proc_macro_derive]` attribute is \
only usable with crates of the `proc-macro` \
crate type");
}
// Once we've located the `#[rustc_macro_derive]` attribute, verify
// that it's of the form `#[rustc_macro_derive(Foo)]`
// Once we've located the `#[proc_macro_derive]` attribute, verify
// that it's of the form `#[proc_macro_derive(Foo)]`
let list = match attr.meta_item_list() {
Some(list) => list,
None => {
self.handler.span_err(attr.span(),
"attribute must be of form: \
#[rustc_macro_derive(TraitName)]");
#[proc_macro_derive(TraitName)]");
return
}
};
@ -177,7 +177,7 @@ impl<'a> Visitor for CollectCustomDerives<'a> {
function_name: item.ident,
});
} else {
let msg = "functions tagged with `#[rustc_macro_derive]` must \
let msg = "functions tagged with `#[proc_macro_derive]` must \
currently reside in the root of the crate";
self.handler.span_err(item.span, msg);
}
@ -202,9 +202,9 @@ impl<'a> Visitor for CollectCustomDerives<'a> {
// Creates a new module which looks like:
//
// mod $gensym {
// extern crate rustc_macro;
// extern crate proc_macro;
//
// use rustc_macro::__internal::Registry;
// use proc_macro::__internal::Registry;
//
// #[plugin_registrar]
// fn registrar(registrar: &mut Registry) {
@ -218,16 +218,16 @@ fn mk_registrar(cx: &mut ExtCtxt,
let eid = cx.codemap().record_expansion(ExpnInfo {
call_site: DUMMY_SP,
callee: NameAndSpan {
format: MacroAttribute(token::intern("rustc_macro")),
format: MacroAttribute(token::intern("proc_macro")),
span: None,
allow_internal_unstable: true,
}
});
let span = Span { expn_id: eid, ..DUMMY_SP };
let rustc_macro = token::str_to_ident("rustc_macro");
let proc_macro = token::str_to_ident("proc_macro");
let krate = cx.item(span,
rustc_macro,
proc_macro,
Vec::new(),
ast::ItemKind::ExternCrate(None));
@ -241,7 +241,7 @@ fn mk_registrar(cx: &mut ExtCtxt,
(path, trait_name)
}).map(|(path, trait_name)| {
let registrar = cx.expr_ident(span, registrar);
let ufcs_path = cx.path(span, vec![rustc_macro, __internal, registry,
let ufcs_path = cx.path(span, vec![proc_macro, __internal, registry,
register_custom_derive]);
cx.expr_call(span,
cx.expr_path(ufcs_path),
@ -250,7 +250,7 @@ fn mk_registrar(cx: &mut ExtCtxt,
cx.stmt_expr(expr)
}).collect::<Vec<_>>();
let path = cx.path(span, vec![rustc_macro, __internal, registry]);
let path = cx.path(span, vec![proc_macro, __internal, registry]);
let registrar_path = cx.ty_path(path);
let arg_ty = cx.ty_rptr(span, registrar_path, None, ast::Mutability::Mutable);
let func = cx.item_fn(span,

20
src/rustc/Cargo.lock generated
View File

@ -43,6 +43,13 @@ version = "0.0.0"
[[package]]
name = "proc_macro"
version = "0.0.0"
dependencies = [
"syntax 0.0.0",
]
[[package]]
name = "proc_macro_plugin"
version = "0.0.0"
dependencies = [
"log 0.0.0",
"rustc_plugin 0.0.0",
@ -137,7 +144,7 @@ dependencies = [
"flate 0.0.0",
"graphviz 0.0.0",
"log 0.0.0",
"proc_macro 0.0.0",
"proc_macro_plugin 0.0.0",
"rustc 0.0.0",
"rustc_back 0.0.0",
"rustc_borrowck 0.0.0",
@ -204,26 +211,19 @@ dependencies = [
"rustc_bitflags 0.0.0",
]
[[package]]
name = "rustc_macro"
version = "0.0.0"
dependencies = [
"syntax 0.0.0",
]
[[package]]
name = "rustc_metadata"
version = "0.0.0"
dependencies = [
"flate 0.0.0",
"log 0.0.0",
"proc_macro 0.0.0",
"rustc 0.0.0",
"rustc_back 0.0.0",
"rustc_const_math 0.0.0",
"rustc_data_structures 0.0.0",
"rustc_errors 0.0.0",
"rustc_llvm 0.0.0",
"rustc_macro 0.0.0",
"serialize 0.0.0",
"syntax 0.0.0",
"syntax_ext 0.0.0",
@ -396,8 +396,8 @@ version = "0.0.0"
dependencies = [
"fmt_macros 0.0.0",
"log 0.0.0",
"proc_macro 0.0.0",
"rustc_errors 0.0.0",
"rustc_macro 0.0.0",
"syntax 0.0.0",
"syntax_pos 0.0.0",
]

View File

@ -8,15 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type = "rustc-macro"]
#![feature(rustc_macro)]
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
extern crate rustc_macro;
extern crate proc_macro;
pub mod a { //~ `rustc-macro` crate types cannot export any items
use rustc_macro::TokenStream;
pub mod a { //~ `proc-macro` crate types cannot export any items
use proc_macro::TokenStream;
#[rustc_macro_derive(B)]
#[proc_macro_derive(B)]
pub fn bar(a: TokenStream) -> TokenStream {
//~^ ERROR: must currently reside in the root of the crate
a

View File

@ -0,0 +1,46 @@
// Copyright 2016 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.
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
extern crate proc_macro;
#[proc_macro_derive]
//~^ ERROR: attribute must be of form: #[proc_macro_derive(TraitName)]
pub fn foo1(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
input
}
#[proc_macro_derive = "foo"]
//~^ ERROR: attribute must be of form: #[proc_macro_derive(TraitName)]
pub fn foo2(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
input
}
#[proc_macro_derive(
a = "b"
)]
//~^^ ERROR: must only be one word
pub fn foo3(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
input
}
#[proc_macro_derive(b, c)]
//~^ ERROR: attribute must only have one argument
pub fn foo4(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
input
}
#[proc_macro_derive(d(e))]
//~^ ERROR: must only be one word
pub fn foo5(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
input
}

View File

@ -11,15 +11,15 @@
// force-host
// no-prefer-dynamic
#![feature(rustc_macro)]
#![feature(rustc_macro_lib)]
#![crate_type = "rustc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]
extern crate rustc_macro;
extern crate proc_macro;
use rustc_macro::TokenStream;
use proc_macro::TokenStream;
#[rustc_macro_derive(A)]
#[proc_macro_derive(A)]
pub fn derive_a(input: TokenStream) -> TokenStream {
input
}

View File

@ -11,15 +11,15 @@
// force-host
// no-prefer-dynamic
#![feature(rustc_macro)]
#![feature(rustc_macro_lib)]
#![crate_type = "rustc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]
extern crate rustc_macro;
extern crate proc_macro;
use rustc_macro::TokenStream;
use proc_macro::TokenStream;
#[rustc_macro_derive(A)]
#[proc_macro_derive(A)]
pub fn derive_a(input: TokenStream) -> TokenStream {
input
}

View File

@ -11,15 +11,15 @@
// no-prefer-dynamic
// force-host
#![feature(rustc_macro)]
#![feature(rustc_macro_lib)]
#![crate_type = "rustc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]
extern crate rustc_macro;
extern crate proc_macro;
use rustc_macro::TokenStream;
use proc_macro::TokenStream;
#[rustc_macro_derive(A)]
#[proc_macro_derive(A)]
pub fn derive_a(_input: TokenStream) -> TokenStream {
"struct A { inner }".parse().unwrap()
}

View File

@ -11,15 +11,15 @@
// no-prefer-dynamic
// force-host
#![feature(rustc_macro)]
#![feature(rustc_macro_lib)]
#![crate_type = "rustc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]
extern crate rustc_macro;
extern crate proc_macro;
use rustc_macro::TokenStream;
use proc_macro::TokenStream;
#[rustc_macro_derive(A)]
#[proc_macro_derive(A)]
pub fn derive_a(_input: TokenStream) -> TokenStream {
panic!("nope!");
}

View File

@ -11,15 +11,15 @@
// force-host
// no-prefer-dynamic
#![feature(rustc_macro)]
#![feature(rustc_macro_lib)]
#![crate_type = "rustc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]
extern crate rustc_macro;
extern crate proc_macro;
use rustc_macro::TokenStream;
use proc_macro::TokenStream;
#[rustc_macro_derive(Unstable)]
#[proc_macro_derive(Unstable)]
pub fn derive(_input: TokenStream) -> TokenStream {
"

View File

@ -11,15 +11,15 @@
// force-host
// no-prefer-dynamic
#![feature(rustc_macro)]
#![feature(rustc_macro_lib)]
#![crate_type = "rustc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]
extern crate rustc_macro;
extern crate proc_macro;
use rustc_macro::TokenStream;
use proc_macro::TokenStream;
#[rustc_macro_derive(Unstable)]
#[proc_macro_derive(Unstable)]
pub fn derive(_input: TokenStream) -> TokenStream {
"unsafe fn foo() -> u32 { ::std::intrinsics::init() }".parse().unwrap()

View File

@ -11,6 +11,6 @@
// aux-build:derive-a.rs
extern crate derive_a;
//~^ ERROR: crates of the `rustc-macro` crate type cannot be linked at runtime
//~^ ERROR: crates of the `proc-macro` crate type cannot be linked at runtime
fn main() {}

View File

@ -10,19 +10,19 @@
// no-prefer-dynamic
#![crate_type = "rustc-macro"]
#![feature(rustc_macro)]
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
extern crate rustc_macro;
extern crate proc_macro;
use rustc_macro::TokenStream;
use proc_macro::TokenStream;
#[rustc_macro_derive(A)]
#[proc_macro_derive(A)]
pub fn foo(input: TokenStream) -> TokenStream {
input
}
#[rustc_macro_derive(A)] //~ ERROR: derive mode defined twice in this crate
#[proc_macro_derive(A)] //~ ERROR: derive mode defined twice in this crate
pub fn bar(input: TokenStream) -> TokenStream {
input
}

View File

@ -10,7 +10,7 @@
// aux-build:derive-bad.rs
#![feature(rustc_macro)]
#![feature(proc_macro)]
#[macro_use]
extern crate derive_bad;

View File

@ -10,7 +10,7 @@
// aux-build:derive-a.rs
#![feature(rustc_macro)]
#![feature(proc_macro)]
#![allow(warnings)]
#[macro_use]

View File

@ -10,7 +10,7 @@
// aux-build:derive-unstable-2.rs
#![feature(rustc_macro)]
#![feature(proc_macro)]
#![allow(warnings)]
#[macro_use]

View File

@ -10,7 +10,7 @@
// aux-build:derive-unstable.rs
#![feature(rustc_macro)]
#![feature(proc_macro)]
#![allow(warnings)]
#[macro_use]

View File

@ -8,10 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: cannot export macro_rules! macros from a `rustc-macro` crate
// error-pattern: cannot export macro_rules! macros from a `proc-macro` crate
#![crate_type = "rustc-macro"]
#![feature(rustc_macro)]
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#[macro_export]
macro_rules! foo {

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type = "rustc-macro"]
#![crate_type = "proc-macro"]
#![allow(warnings)]
pub fn a() {} //~ ERROR: cannot export any items

View File

@ -8,6 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: the `rustc-macro` crate type is experimental
// error-pattern: the `proc-macro` crate type is experimental
#![crate_type = "rustc-macro"]
#![crate_type = "proc-macro"]

View File

@ -8,6 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate rustc_macro; //~ ERROR: use of unstable library feature
extern crate proc_macro; //~ ERROR: use of unstable library feature
fn main() {}

View File

@ -8,8 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type = "rustc-macro"]
#![crate_type = "proc-macro"]
#[rustc_macro_derive(Foo)] //~ ERROR: is an experimental feature
#[proc_macro_derive(Foo)] //~ ERROR: is an experimental feature
pub fn foo() {
}

View File

@ -8,5 +8,5 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[cfg(rustc_macro)] //~ ERROR: experimental and subject to change
#[cfg(proc_macro)] //~ ERROR: experimental and subject to change
fn foo() {}

View File

@ -10,7 +10,7 @@
// aux-build:derive-a.rs
#![feature(rustc_macro)]
#![feature(proc_macro)]
#![allow(warnings)]
#[macro_use]

View File

@ -10,7 +10,7 @@
// aux-build:derive-panic.rs
#![feature(rustc_macro)]
#![feature(proc_macro)]
#[macro_use]
extern crate derive_panic;

View File

@ -8,13 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(rustc_macro)]
#![feature(proc_macro)]
extern crate rustc_macro;
extern crate proc_macro;
#[rustc_macro_derive(Foo)]
//~^ ERROR: only usable with crates of the `rustc-macro` crate type
pub fn foo(a: rustc_macro::TokenStream) -> rustc_macro::TokenStream {
#[proc_macro_derive(Foo)]
//~^ ERROR: only usable with crates of the `proc-macro` crate type
pub fn foo(a: proc_macro::TokenStream) -> proc_macro::TokenStream {
a
}

View File

@ -8,14 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type = "rustc-macro"]
#![feature(rustc_macro)]
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
extern crate rustc_macro;
extern crate proc_macro;
use rustc_macro::TokenStream;
use proc_macro::TokenStream;
#[rustc_macro_derive(PartialEq)]
#[proc_macro_derive(PartialEq)]
//~^ ERROR: cannot override a built-in #[derive] mode
pub fn foo(input: TokenStream) -> TokenStream {
input

View File

@ -11,7 +11,7 @@
// aux-build:derive-a.rs
// aux-build:derive-a-2.rs
#![feature(rustc_macro)]
#![feature(proc_macro)]
#[macro_use]
extern crate derive_a;

View File

@ -8,17 +8,17 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type = "rustc-macro"]
#![feature(rustc_macro)]
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#![allow(warnings)]
extern crate rustc_macro;
extern crate proc_macro;
#[rustc_macro_derive(A)]
#[proc_macro_derive(A)]
unsafe extern fn foo(a: i32, b: u32) -> u32 {
//~^ ERROR: mismatched types
//~| NOTE: expected normal fn, found unsafe fn
//~| NOTE: expected type `fn(rustc_macro::TokenStream) -> rustc_macro::TokenStream`
//~| NOTE: expected type `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
//~| NOTE: found type `unsafe extern "C" fn(i32, u32) -> u32 {foo}`
loop {}
}

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: cannot mix `rustc-macro` crate type with others
// error-pattern: cannot mix `proc-macro` crate type with others
#![crate_type = "rustc-macro"]
#![crate_type = "proc-macro"]
#![crate_type = "rlib"]

View File

@ -8,5 +8,5 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: cannot mix `rustc-macro` crate type with others
// compile-flags: --crate-type rlib --crate-type rustc-macro
// error-pattern: cannot mix `proc-macro` crate type with others
// compile-flags: --crate-type rlib --crate-type proc-macro

View File

@ -1,46 +0,0 @@
// Copyright 2016 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.
#![crate_type = "rustc-macro"]
#![feature(rustc_macro)]
extern crate rustc_macro;
#[rustc_macro_derive]
//~^ ERROR: attribute must be of form: #[rustc_macro_derive(TraitName)]
pub fn foo1(input: rustc_macro::TokenStream) -> rustc_macro::TokenStream {
input
}
#[rustc_macro_derive = "foo"]
//~^ ERROR: attribute must be of form: #[rustc_macro_derive(TraitName)]
pub fn foo2(input: rustc_macro::TokenStream) -> rustc_macro::TokenStream {
input
}
#[rustc_macro_derive(
a = "b"
)]
//~^^ ERROR: must only be one word
pub fn foo3(input: rustc_macro::TokenStream) -> rustc_macro::TokenStream {
input
}
#[rustc_macro_derive(b, c)]
//~^ ERROR: attribute must only have one argument
pub fn foo4(input: rustc_macro::TokenStream) -> rustc_macro::TokenStream {
input
}
#[rustc_macro_derive(d(e))]
//~^ ERROR: must only be one word
pub fn foo5(input: rustc_macro::TokenStream) -> rustc_macro::TokenStream {
input
}

View File

@ -3,4 +3,4 @@
all:
$(RUSTC) foo.rs
$(RUSTC) bar.rs --emit dep-info
grep "rustc-macro source" $(TMPDIR)/bar.d && exit 1 || exit 0
grep "proc-macro source" $(TMPDIR)/bar.d && exit 1 || exit 0

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(rustc_macro)]
#![feature(proc_macro)]
#[macro_use]
extern crate foo;

View File

@ -8,15 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type = "rustc-macro"]
#![feature(rustc_macro)]
#![feature(rustc_macro_lib)]
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
extern crate rustc_macro;
extern crate proc_macro;
use rustc_macro::TokenStream;
use proc_macro::TokenStream;
#[rustc_macro_derive(A)]
#[proc_macro_derive(A)]
pub fn derive(input: TokenStream) -> TokenStream {
let input = input.to_string();
assert!(input.contains("struct A;"));

View File

@ -12,13 +12,13 @@
#![feature(plugin)]
#![feature(plugin_registrar)]
#![feature(rustc_private)]
#![plugin(proc_macro)]
#![plugin(proc_macro_plugin)]
extern crate rustc_plugin;
extern crate proc_macro;
extern crate proc_macro_plugin;
extern crate syntax;
use proc_macro::build::ident_eq;
use proc_macro_plugin::build::ident_eq;
use syntax::ext::base::{ExtCtxt, MacResult};
use syntax::ext::proc_macro_shim::build_block_emitter;

View File

@ -12,13 +12,13 @@
#![feature(plugin)]
#![feature(plugin_registrar)]
#![feature(rustc_private)]
#![plugin(proc_macro)]
#![plugin(proc_macro_plugin)]
extern crate rustc_plugin;
extern crate proc_macro;
extern crate proc_macro_plugin;
extern crate syntax;
use proc_macro::prelude::*;
use proc_macro_plugin::prelude::*;
use rustc_plugin::Registry;

View File

@ -12,14 +12,14 @@
#![feature(plugin)]
#![feature(plugin_registrar)]
#![feature(rustc_private)]
#![plugin(proc_macro)]
#![plugin(proc_macro_plugin)]
extern crate rustc_plugin;
extern crate proc_macro;
extern crate proc_macro_plugin;
extern crate syntax;
use syntax::ext::proc_macro_shim::prelude::*;
use proc_macro::prelude::*;
use proc_macro_plugin::prelude::*;
use rustc_plugin::Registry;

View File

@ -10,11 +10,11 @@
#![feature(plugin, plugin_registrar, rustc_private)]
extern crate proc_macro;
extern crate proc_macro_plugin;
extern crate rustc_plugin;
extern crate syntax;
use proc_macro::prelude::*;
use proc_macro_plugin::prelude::*;
use rustc_plugin::Registry;
use syntax::ext::base::SyntaxExtension;
use syntax::ext::proc_macro_shim::prelude::*;

View File

@ -12,10 +12,10 @@
#![feature(plugin)]
#![feature(rustc_private)]
#![plugin(proc_macro)]
#![plugin(proc_macro_plugin)]
extern crate proc_macro;
use proc_macro::prelude::*;
extern crate proc_macro_plugin;
use proc_macro_plugin::prelude::*;
extern crate syntax;
use syntax::ast::Ident;

View File

@ -10,7 +10,7 @@
// aux-build:add-impl.rs
#![feature(rustc_macro)]
#![feature(proc_macro)]
#[macro_use]
extern crate add_impl;

View File

@ -10,7 +10,7 @@
// aux-build:append-impl.rs
#![feature(rustc_macro)]
#![feature(proc_macro)]
#![allow(warnings)]
#[macro_use]

View File

@ -10,16 +10,16 @@
// no-prefer-dynamic
#![crate_type = "rustc-macro"]
#![feature(rustc_macro)]
#![feature(rustc_macro_lib)]
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
extern crate rustc_macro;
extern crate proc_macro;
use rustc_macro::TokenStream;
use proc_macro::TokenStream;
#[rustc_macro_derive(AddImpl)]
// #[cfg(rustc_macro)]
#[proc_macro_derive(AddImpl)]
// #[cfg(proc_macro)]
pub fn derive(input: TokenStream) -> TokenStream {
(input.to_string() + "
impl B {

View File

@ -11,15 +11,15 @@
// force-host
// no-prefer-dynamic
#![feature(rustc_macro)]
#![feature(rustc_macro_lib)]
#![crate_type = "rustc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]
extern crate rustc_macro;
extern crate proc_macro;
use rustc_macro::TokenStream;
use proc_macro::TokenStream;
#[rustc_macro_derive(Append)]
#[proc_macro_derive(Append)]
pub fn derive_a(input: TokenStream) -> TokenStream {
let mut input = input.to_string();
input.push_str("

View File

@ -10,15 +10,15 @@
// no-prefer-dynamic
#![crate_type = "rustc-macro"]
#![feature(rustc_macro)]
#![feature(rustc_macro_lib)]
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
extern crate rustc_macro;
extern crate proc_macro;
use rustc_macro::TokenStream;
use proc_macro::TokenStream;
#[rustc_macro_derive(A)]
#[proc_macro_derive(A)]
pub fn derive(input: TokenStream) -> TokenStream {
let input = input.to_string();
assert!(input.contains("struct A;"));

View File

@ -10,15 +10,15 @@
// no-prefer-dynamic
#![crate_type = "rustc-macro"]
#![feature(rustc_macro)]
#![feature(rustc_macro_lib)]
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
extern crate rustc_macro;
extern crate proc_macro;
use rustc_macro::TokenStream;
use proc_macro::TokenStream;
#[rustc_macro_derive(AToB)]
#[proc_macro_derive(AToB)]
pub fn derive(input: TokenStream) -> TokenStream {
let input = input.to_string();
assert_eq!(input, "struct A;\n");

View File

@ -10,15 +10,15 @@
// no-prefer-dynamic
#![crate_type = "rustc-macro"]
#![feature(rustc_macro)]
#![feature(rustc_macro_lib)]
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
extern crate rustc_macro;
extern crate proc_macro;
use rustc_macro::TokenStream;
use proc_macro::TokenStream;
#[rustc_macro_derive(CToD)]
#[proc_macro_derive(CToD)]
pub fn derive(input: TokenStream) -> TokenStream {
let input = input.to_string();
assert_eq!(input, "struct C;\n");

View File

@ -9,23 +9,23 @@
// except according to those terms.
// no-prefer-dynamic
// compile-flags:--crate-type rustc-macro
// compile-flags:--crate-type proc-macro
#![feature(rustc_macro)]
#![feature(rustc_macro_lib)]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
extern crate rustc_macro;
extern crate proc_macro;
use rustc_macro::TokenStream;
use proc_macro::TokenStream;
#[rustc_macro_derive(AToB)]
#[proc_macro_derive(AToB)]
pub fn derive1(input: TokenStream) -> TokenStream {
println!("input1: {:?}", input.to_string());
assert_eq!(input.to_string(), "#[derive(BToC)]\nstruct A;\n");
"#[derive(BToC)] struct B;".parse().unwrap()
}
#[rustc_macro_derive(BToC)]
#[proc_macro_derive(BToC)]
pub fn derive2(input: TokenStream) -> TokenStream {
assert_eq!(input.to_string(), "struct B;\n");
"struct C;".parse().unwrap()

View File

@ -10,16 +10,16 @@
// no-prefer-dynamic
#![crate_type = "rustc-macro"]
#![feature(rustc_macro)]
#![feature(rustc_macro_lib)]
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![deny(warnings)]
extern crate rustc_macro;
extern crate proc_macro;
use rustc_macro::TokenStream;
use proc_macro::TokenStream;
#[rustc_macro_derive(A)]
#[proc_macro_derive(A)]
pub fn derive(input: TokenStream) -> TokenStream {
let input = input.to_string();
assert!(input.contains("struct A;"));

View File

@ -10,7 +10,7 @@
// aux-build:derive-same-struct.rs
#![feature(rustc_macro)]
#![feature(proc_macro)]
#[macro_use]
extern crate derive_same_struct;

View File

@ -11,7 +11,7 @@
// aux-build:expand-with-a-macro.rs
// ignore-stage1
#![feature(rustc_macro)]
#![feature(proc_macro)]
#![deny(warnings)]
#[macro_use]

View File

@ -11,7 +11,7 @@
// aux-build:derive-atob.rs
// aux-build:derive-ctod.rs
#![feature(rustc_macro)]
#![feature(proc_macro)]
#[macro_use]
extern crate derive_atob;

View File

@ -11,7 +11,7 @@
// aux-build:derive-a.rs
// ignore-stage1
#![feature(rustc_macro)]
#![feature(proc_macro)]
#[macro_use]
extern crate derive_a;

View File

@ -10,15 +10,15 @@
// no-prefer-dynamic
#![feature(rustc_macro)]
#![feature(rustc_macro_lib)]
#![crate_type = "rustc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]
extern crate rustc_macro;
extern crate proc_macro;
use rustc_macro::TokenStream;
use proc_macro::TokenStream;
#[rustc_macro_derive(Foo)]
#[proc_macro_derive(Foo)]
pub fn foo(input: TokenStream) -> TokenStream {
input
}

View File

@ -24,7 +24,7 @@ struct Test {
const TEST_REPOS: &'static [Test] = &[Test {
name: "cargo",
repo: "https://github.com/rust-lang/cargo",
sha: "d8936af1390ab0844e5e68b459214f2529c9f647",
sha: "d3bad1ab29efae414e9b4c24534b2d02b3a59782",
lock: None,
},
Test {

View File

@ -88,9 +88,11 @@ fn verify(tomlfile: &Path, libfile: &Path, bad: &mut bool) {
continue
}
// We want the compiler to depend on the proc_macro crate so that it is built and
// included in the end, but we don't want to actually use it in the compiler.
if toml.contains("name = \"rustc_driver\"") && krate == "proc_macro" {
// We want the compiler to depend on the proc_macro_plugin crate so
// that it is built and included in the end, but we don't want to
// actually use it in the compiler.
if toml.contains("name = \"rustc_driver\"") &&
krate == "proc_macro_plugin" {
continue
}