From f9ba1078245bc2c023f51d2a63e0ca84863600e7 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Thu, 10 Dec 2015 23:23:14 +0900 Subject: [PATCH 1/4] Move built-in syntax extensions to a separate crate --- mk/crates.mk | 9 +- src/librustc_driver/driver.rs | 16 ++- src/librustc_driver/lib.rs | 1 + src/libsyntax/ext/base.rs | 29 ----- src/libsyntax/ext/expand.rs | 18 ++- src/libsyntax/lib.rs | 10 -- src/{libsyntax/ext => libsyntax_ext}/asm.rs | 18 +-- src/{libsyntax/ext => libsyntax_ext}/cfg.rs | 18 +-- .../ext => libsyntax_ext}/concat.rs | 10 +- .../ext => libsyntax_ext}/concat_idents.rs | 16 +-- .../ext => libsyntax_ext}/deriving/bounds.rs | 11 +- .../ext => libsyntax_ext}/deriving/clone.rs | 17 +-- .../ext => libsyntax_ext}/deriving/cmp/eq.rs | 17 +-- .../ext => libsyntax_ext}/deriving/cmp/ord.rs | 19 ++-- .../deriving/cmp/partial_eq.rs | 17 +-- .../deriving/cmp/partial_ord.rs | 19 ++-- .../ext => libsyntax_ext}/deriving/debug.rs | 19 ++-- .../deriving/decodable.rs | 21 ++-- .../ext => libsyntax_ext}/deriving/default.rs | 17 +-- .../deriving/encodable.rs | 17 +-- .../deriving/generic/mod.rs | 106 +++--------------- .../deriving/generic/ty.rs | 17 +-- .../ext => libsyntax_ext}/deriving/hash.rs | 15 +-- .../ext => libsyntax_ext}/deriving/mod.rs | 19 ++-- .../deriving/primitive.rs | 19 ++-- src/{libsyntax/ext => libsyntax_ext}/env.rs | 12 +- .../ext => libsyntax_ext}/format.rs | 19 ++-- src/libsyntax_ext/lib.rs | 82 ++++++++++++++ .../ext => libsyntax_ext}/log_syntax.rs | 10 +- .../ext => libsyntax_ext}/trace_macros.rs | 12 +- 30 files changed, 310 insertions(+), 320 deletions(-) rename src/{libsyntax/ext => libsyntax_ext}/asm.rs (97%) rename src/{libsyntax/ext => libsyntax_ext}/cfg.rs (85%) rename src/{libsyntax/ext => libsyntax_ext}/concat.rs (95%) rename src/{libsyntax/ext => libsyntax_ext}/concat_idents.rs (91%) rename src/{libsyntax/ext => libsyntax_ext}/deriving/bounds.rs (90%) rename src/{libsyntax/ext => libsyntax_ext}/deriving/clone.rs (93%) rename src/{libsyntax/ext => libsyntax_ext}/deriving/cmp/eq.rs (90%) rename src/{libsyntax/ext => libsyntax_ext}/deriving/cmp/ord.rs (94%) rename src/{libsyntax/ext => libsyntax_ext}/deriving/cmp/partial_eq.rs (92%) rename src/{libsyntax/ext => libsyntax_ext}/deriving/cmp/partial_ord.rs (96%) rename src/{libsyntax/ext => libsyntax_ext}/deriving/debug.rs (95%) rename src/{libsyntax/ext => libsyntax_ext}/deriving/decodable.rs (96%) rename src/{libsyntax/ext => libsyntax_ext}/deriving/default.rs (92%) rename src/{libsyntax/ext => libsyntax_ext}/deriving/encodable.rs (97%) rename src/{libsyntax/ext => libsyntax_ext}/deriving/generic/mod.rs (95%) rename src/{libsyntax/ext => libsyntax_ext}/deriving/generic/ty.rs (96%) rename src/{libsyntax/ext => libsyntax_ext}/deriving/hash.rs (93%) rename src/{libsyntax/ext => libsyntax_ext}/deriving/mod.rs (92%) rename src/{libsyntax/ext => libsyntax_ext}/deriving/primitive.rs (94%) rename src/{libsyntax/ext => libsyntax_ext}/env.rs (95%) rename src/{libsyntax/ext => libsyntax_ext}/format.rs (99%) create mode 100644 src/libsyntax_ext/lib.rs rename src/{libsyntax/ext => libsyntax_ext}/log_syntax.rs (92%) rename src/{libsyntax/ext => libsyntax_ext}/trace_macros.rs (89%) diff --git a/mk/crates.mk b/mk/crates.mk index 7ad0a99aadae9..2b66baed45b94 100644 --- a/mk/crates.mk +++ b/mk/crates.mk @@ -58,7 +58,7 @@ 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_front rustc_platform_intrinsics \ rustc_plugin rustc_metadata -HOST_CRATES := syntax $(RUSTC_CRATES) rustdoc fmt_macros +HOST_CRATES := syntax syntax_ext $(RUSTC_CRATES) rustdoc fmt_macros TOOLS := compiletest rustdoc rustc rustbook error-index-generator DEPS_core := @@ -86,9 +86,10 @@ DEPS_serialize := std log DEPS_term := std log DEPS_test := std getopts serialize rbml term native:rust_test_helpers -DEPS_syntax := std term serialize log fmt_macros arena libc rustc_bitflags +DEPS_syntax := std term serialize log arena libc rustc_bitflags +DEPS_syntax_ext := syntax fmt_macros -DEPS_rustc := syntax flate arena serialize getopts rbml rustc_front\ +DEPS_rustc := syntax fmt_macros flate arena serialize getopts rbml rustc_front\ log graphviz rustc_llvm rustc_back rustc_data_structures DEPS_rustc_back := std syntax rustc_llvm rustc_front flate log libc DEPS_rustc_borrowck := rustc rustc_front log graphviz syntax @@ -96,7 +97,7 @@ DEPS_rustc_data_structures := std log serialize 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_front rustc_plugin \ - rustc_metadata + rustc_metadata syntax_ext DEPS_rustc_front := std syntax log serialize DEPS_rustc_lint := rustc log syntax DEPS_rustc_llvm := native:rustllvm libc std rustc_bitflags diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 69e065b3e8f97..5f2548a550467 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -54,6 +54,7 @@ use syntax::parse::token; use syntax::util::node_count::NodeCounter; use syntax::visit; use syntax; +use syntax_ext; pub fn compile_input(sess: Session, cstore: &CStore, @@ -563,12 +564,15 @@ pub fn phase_2_configure_and_expand(sess: &Session, recursion_limit: sess.recursion_limit.get(), trace_mac: sess.opts.debugging_opts.trace_macros, }; - let (ret, macro_names) = syntax::ext::expand::expand_crate(&sess.parse_sess, - cfg, - macros, - syntax_exts, - &mut feature_gated_cfgs, - krate); + let mut ecx = syntax::ext::base::ExtCtxt::new(&sess.parse_sess, + krate.config.clone(), + cfg, + &mut feature_gated_cfgs); + syntax_ext::register_builtins(&mut ecx.syntax_env); + let (ret, macro_names) = syntax::ext::expand::expand_crate(ecx, + macros, + syntax_exts, + krate); if cfg!(windows) { env::set_var("PATH", &_old_path); } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index e293a9506873a..fcbcdbacd33cb 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -57,6 +57,7 @@ extern crate rustc_llvm as llvm; extern crate log; #[macro_use] extern crate syntax; +extern crate syntax_ext; pub use syntax::diagnostic; diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 22315454f8907..9d62e407cb913 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -464,26 +464,6 @@ fn initial_syntax_expander_table<'feat>(ecfg: &expand::ExpansionConfig<'feat>) let mut syntax_expanders = SyntaxEnv::new(); syntax_expanders.insert(intern("macro_rules"), MacroRulesTT); - syntax_expanders.insert(intern("format_args"), - // format_args uses `unstable` things internally. - NormalTT(Box::new(ext::format::expand_format_args), None, true)); - syntax_expanders.insert(intern("env"), - builtin_normal_expander( - ext::env::expand_env)); - syntax_expanders.insert(intern("option_env"), - builtin_normal_expander( - ext::env::expand_option_env)); - syntax_expanders.insert(intern("concat_idents"), - builtin_normal_expander( - ext::concat_idents::expand_syntax_ext)); - syntax_expanders.insert(intern("concat"), - builtin_normal_expander( - ext::concat::expand_syntax_ext)); - syntax_expanders.insert(intern("log_syntax"), - builtin_normal_expander( - ext::log_syntax::expand_syntax_ext)); - - ext::deriving::register_all(&mut syntax_expanders); if ecfg.enable_quotes() { // Quasi-quoting expanders @@ -552,15 +532,6 @@ fn initial_syntax_expander_table<'feat>(ecfg: &expand::ExpansionConfig<'feat>) syntax_expanders.insert(intern("module_path"), builtin_normal_expander( ext::source_util::expand_mod)); - syntax_expanders.insert(intern("asm"), - builtin_normal_expander( - ext::asm::expand_asm)); - syntax_expanders.insert(intern("cfg"), - builtin_normal_expander( - ext::cfg::expand_cfg)); - syntax_expanders.insert(intern("trace_macros"), - builtin_normal_expander( - ext::trace_macros::expand_trace_macros)); syntax_expanders } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 573f4cfe8fa5d..a67115e82bb29 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -21,7 +21,7 @@ use attr::{AttrMetaMethods, WithAttrs}; use codemap; use codemap::{Span, Spanned, ExpnInfo, NameAndSpan, MacroBang, MacroAttribute}; use ext::base::*; -use feature_gate::{self, Features, GatedCfgAttr}; +use feature_gate::{self, Features}; use fold; use fold::*; use util::move_map::MoveMap; @@ -1276,15 +1276,11 @@ impl<'feat> ExpansionConfig<'feat> { } } -pub fn expand_crate<'feat>(parse_sess: &parse::ParseSess, - cfg: ExpansionConfig<'feat>, - // these are the macros being imported to this crate: - imported_macros: Vec, - user_exts: Vec, - feature_gated_cfgs: &mut Vec, - c: Crate) -> (Crate, HashSet) { - let mut cx = ExtCtxt::new(parse_sess, c.config.clone(), cfg, - feature_gated_cfgs); +pub fn expand_crate(mut cx: ExtCtxt, + // these are the macros being imported to this crate: + imported_macros: Vec, + user_exts: Vec, + c: Crate) -> (Crate, HashSet) { if std_inject::no_core(&c) { cx.crate_root = None; } else if std_inject::no_std(&c) { @@ -1305,7 +1301,7 @@ pub fn expand_crate<'feat>(parse_sess: &parse::ParseSess, let mut ret = expander.fold_crate(c); ret.exported_macros = expander.cx.exported_macros.clone(); - parse_sess.span_diagnostic.handler().abort_if_errors(); + cx.parse_sess.span_diagnostic.handler().abort_if_errors(); ret }; return (ret, cx.syntax_env.names); diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 4498120a78f79..73d7025b4f155 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -37,7 +37,6 @@ #![feature(str_escape)] #![feature(unicode)] -extern crate fmt_macros; extern crate serialize; extern crate term; extern crate libc; @@ -110,21 +109,12 @@ pub mod print { } pub mod ext { - pub mod asm; pub mod base; pub mod build; - pub mod cfg; - pub mod concat; - pub mod concat_idents; - pub mod deriving; - pub mod env; pub mod expand; - pub mod format; - pub mod log_syntax; pub mod mtwt; pub mod quote; pub mod source_util; - pub mod trace_macros; pub mod tt { pub mod transcribe; diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax_ext/asm.rs similarity index 97% rename from src/libsyntax/ext/asm.rs rename to src/libsyntax_ext/asm.rs index b4f29f837263f..072be5712219a 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax_ext/asm.rs @@ -13,15 +13,15 @@ */ use self::State::*; -use ast; -use codemap; -use codemap::Span; -use ext::base; -use ext::base::*; -use feature_gate; -use parse::token::{intern, InternedString}; -use parse::token; -use ptr::P; +use syntax::ast; +use syntax::codemap; +use syntax::codemap::Span; +use syntax::ext::base; +use syntax::ext::base::*; +use syntax::feature_gate; +use syntax::parse::token::{intern, InternedString}; +use syntax::parse::token; +use syntax::ptr::P; use syntax::ast::AsmDialect; enum State { diff --git a/src/libsyntax/ext/cfg.rs b/src/libsyntax_ext/cfg.rs similarity index 85% rename from src/libsyntax/ext/cfg.rs rename to src/libsyntax_ext/cfg.rs index e100355e4f868..1e1bf5388765f 100644 --- a/src/libsyntax/ext/cfg.rs +++ b/src/libsyntax_ext/cfg.rs @@ -12,15 +12,15 @@ /// a literal `true` or `false` based on whether the given cfg matches the /// current compilation environment. -use ast; -use codemap::Span; -use ext::base::*; -use ext::base; -use ext::build::AstBuilder; -use attr; -use attr::*; -use parse::token; -use config::CfgDiagReal; +use syntax::ast; +use syntax::codemap::Span; +use syntax::ext::base::*; +use syntax::ext::base; +use syntax::ext::build::AstBuilder; +use syntax::attr; +use syntax::attr::*; +use syntax::parse::token; +use syntax::config::CfgDiagReal; pub fn expand_cfg<'cx>(cx: &mut ExtCtxt, sp: Span, diff --git a/src/libsyntax/ext/concat.rs b/src/libsyntax_ext/concat.rs similarity index 95% rename from src/libsyntax/ext/concat.rs rename to src/libsyntax_ext/concat.rs index 71430b7aad596..de913fe043139 100644 --- a/src/libsyntax/ext/concat.rs +++ b/src/libsyntax_ext/concat.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast; -use codemap; -use ext::base; -use ext::build::AstBuilder; -use parse::token; +use syntax::ast; +use syntax::codemap; +use syntax::ext::base; +use syntax::ext::build::AstBuilder; +use syntax::parse::token; use std::string::String; diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax_ext/concat_idents.rs similarity index 91% rename from src/libsyntax/ext/concat_idents.rs rename to src/libsyntax_ext/concat_idents.rs index c2233202b2f81..9702b24ffd417 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax_ext/concat_idents.rs @@ -8,14 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{self, TokenTree}; -use codemap::Span; -use ext::base::*; -use ext::base; -use feature_gate; -use parse::token; -use parse::token::str_to_ident; -use ptr::P; +use syntax::ast::{self, TokenTree}; +use syntax::codemap::Span; +use syntax::ext::base::*; +use syntax::ext::base; +use syntax::feature_gate; +use syntax::parse::token; +use syntax::parse::token::str_to_ident; +use syntax::ptr::P; pub fn expand_syntax_ext<'cx>(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box { diff --git a/src/libsyntax/ext/deriving/bounds.rs b/src/libsyntax_ext/deriving/bounds.rs similarity index 90% rename from src/libsyntax/ext/deriving/bounds.rs rename to src/libsyntax_ext/deriving/bounds.rs index 87a6d0805b561..9bc0e08811071 100644 --- a/src/libsyntax/ext/deriving/bounds.rs +++ b/src/libsyntax_ext/deriving/bounds.rs @@ -8,11 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::MetaItem; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast::MetaItem; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; pub fn expand_deriving_unsafe_bound(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs similarity index 93% rename from src/libsyntax/ext/deriving/clone.rs rename to src/libsyntax_ext/deriving/clone.rs index f1a2983479c49..1825c3d347eeb 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax_ext/deriving/clone.rs @@ -8,14 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, Expr}; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token::InternedString; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast::{MetaItem, Expr}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token::InternedString; +use syntax::ptr::P; pub fn expand_deriving_clone(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax_ext/deriving/cmp/eq.rs similarity index 90% rename from src/libsyntax/ext/deriving/cmp/eq.rs rename to src/libsyntax_ext/deriving/cmp/eq.rs index bd6b27fb44e4c..1b855c56a48bf 100644 --- a/src/libsyntax/ext/deriving/cmp/eq.rs +++ b/src/libsyntax_ext/deriving/cmp/eq.rs @@ -8,14 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, Expr}; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token::InternedString; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast::{MetaItem, Expr}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token::InternedString; +use syntax::ptr::P; pub fn expand_deriving_eq(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax_ext/deriving/cmp/ord.rs similarity index 94% rename from src/libsyntax/ext/deriving/cmp/ord.rs rename to src/libsyntax_ext/deriving/cmp/ord.rs index ff36e01d6cc8e..95a5d184d0e6c 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax_ext/deriving/cmp/ord.rs @@ -8,15 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast; -use ast::{MetaItem, Expr}; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token::InternedString; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast; +use syntax::ast::{MetaItem, Expr}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token::InternedString; +use syntax::ptr::P; pub fn expand_deriving_ord(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/cmp/partial_eq.rs b/src/libsyntax_ext/deriving/cmp/partial_eq.rs similarity index 92% rename from src/libsyntax/ext/deriving/cmp/partial_eq.rs rename to src/libsyntax_ext/deriving/cmp/partial_eq.rs index 495761c499b9e..29be5a7ddc3a1 100644 --- a/src/libsyntax/ext/deriving/cmp/partial_eq.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_eq.rs @@ -8,14 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, Expr, self}; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token::InternedString; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast::{MetaItem, Expr, self}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token::InternedString; +use syntax::ptr::P; pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/cmp/partial_ord.rs b/src/libsyntax_ext/deriving/cmp/partial_ord.rs similarity index 96% rename from src/libsyntax/ext/deriving/cmp/partial_ord.rs rename to src/libsyntax_ext/deriving/cmp/partial_ord.rs index 084e3ef3f910c..bd825e5c8df0e 100644 --- a/src/libsyntax/ext/deriving/cmp/partial_ord.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_ord.rs @@ -10,15 +10,16 @@ pub use self::OrderingOp::*; -use ast; -use ast::{MetaItem, Expr}; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token::InternedString; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast; +use syntax::ast::{MetaItem, Expr}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token::InternedString; +use syntax::ptr::P; pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/debug.rs b/src/libsyntax_ext/deriving/debug.rs similarity index 95% rename from src/libsyntax/ext/deriving/debug.rs rename to src/libsyntax_ext/deriving/debug.rs index 9488cfb86fc9f..ed3f764c1d2aa 100644 --- a/src/libsyntax/ext/deriving/debug.rs +++ b/src/libsyntax_ext/deriving/debug.rs @@ -8,15 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast; -use ast::{MetaItem, Expr}; -use codemap::{Span, respan}; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast; +use syntax::ast::{MetaItem, Expr}; +use syntax::codemap::{Span, respan}; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token; +use syntax::ptr::P; pub fn expand_deriving_debug(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax_ext/deriving/decodable.rs similarity index 96% rename from src/libsyntax/ext/deriving/decodable.rs rename to src/libsyntax_ext/deriving/decodable.rs index 0fdcbec844779..4ea4f04623a01 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax_ext/deriving/decodable.rs @@ -10,16 +10,17 @@ //! The compiler code necessary for `#[derive(Decodable)]`. See encodable.rs for more. -use ast; -use ast::{MetaItem, Expr, MutMutable}; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token::InternedString; -use parse::token; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast; +use syntax::ast::{MetaItem, Expr, MutMutable}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token::InternedString; +use syntax::parse::token; +use syntax::ptr::P; pub fn expand_deriving_rustc_decodable(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/default.rs b/src/libsyntax_ext/deriving/default.rs similarity index 92% rename from src/libsyntax/ext/deriving/default.rs rename to src/libsyntax_ext/deriving/default.rs index 6a25088782a04..bee63a98c252f 100644 --- a/src/libsyntax/ext/deriving/default.rs +++ b/src/libsyntax_ext/deriving/default.rs @@ -8,14 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, Expr}; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token::InternedString; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast::{MetaItem, Expr}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token::InternedString; +use syntax::ptr::P; pub fn expand_deriving_default(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax_ext/deriving/encodable.rs similarity index 97% rename from src/libsyntax/ext/deriving/encodable.rs rename to src/libsyntax_ext/deriving/encodable.rs index 786739938e58c..02747d38c0043 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax_ext/deriving/encodable.rs @@ -88,14 +88,15 @@ //! } //! ``` -use ast::{MetaItem, Expr, ExprRet, MutMutable}; -use codemap::Span; -use ext::base::{ExtCtxt,Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast::{MetaItem, Expr, ExprRet, MutMutable}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt,Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token; +use syntax::ptr::P; pub fn expand_deriving_rustc_encodable(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs similarity index 95% rename from src/libsyntax/ext/deriving/generic/mod.rs rename to src/libsyntax_ext/deriving/generic/mod.rs index bd89430d81de0..5977144dae708 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -192,23 +192,23 @@ use std::cell::RefCell; use std::collections::HashSet; use std::vec; -use abi::Abi; -use abi; -use ast; -use ast::{EnumDef, Expr, Ident, Generics, VariantData}; -use ast_util; -use attr; -use attr::AttrMetaMethods; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use codemap::{self, DUMMY_SP}; -use codemap::Span; -use diagnostic::SpanHandler; -use util::move_map::MoveMap; -use owned_slice::OwnedSlice; -use parse::token::{intern, InternedString}; -use parse::token::special_idents; -use ptr::P; +use syntax::abi::Abi; +use syntax::abi; +use syntax::ast; +use syntax::ast::{EnumDef, Expr, Ident, Generics, VariantData}; +use syntax::ast_util; +use syntax::attr; +use syntax::attr::AttrMetaMethods; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::codemap::{self, DUMMY_SP}; +use syntax::codemap::Span; +use syntax::diagnostic::SpanHandler; +use syntax::util::move_map::MoveMap; +use syntax::owned_slice::OwnedSlice; +use syntax::parse::token::{intern, InternedString}; +use syntax::parse::token::special_idents; +use syntax::ptr::P; use self::ty::{LifetimeBounds, Path, Ptr, PtrTy, Self_, Ty}; @@ -347,7 +347,7 @@ pub fn combine_substructure<'a>(f: CombineSubstructureFunc<'a>) /// type. For a type parameter ``, it looks for either a `TyPath` that /// is not global and starts with `T`, or a `TyQPath`. fn find_type_parameters(ty: &ast::Ty, ty_param_names: &[ast::Name]) -> Vec> { - use visit; + use syntax::visit; struct Visitor<'a> { ty_param_names: &'a [ast::Name], @@ -1632,73 +1632,3 @@ pub fn cs_same_method(f: F, } } } - -/// Fold together the results of calling the derived method on all the -/// fields. `use_foldl` controls whether this is done left-to-right -/// (`true`) or right-to-left (`false`). -#[inline] -pub fn cs_same_method_fold(use_foldl: bool, - mut f: F, - base: P, - enum_nonmatch_f: EnumNonMatchCollapsedFunc, - cx: &mut ExtCtxt, - trait_span: Span, - substructure: &Substructure) - -> P where - F: FnMut(&mut ExtCtxt, Span, P, P) -> P, -{ - cs_same_method( - |cx, span, vals| { - if use_foldl { - vals.into_iter().fold(base.clone(), |old, new| { - f(cx, span, old, new) - }) - } else { - vals.into_iter().rev().fold(base.clone(), |old, new| { - f(cx, span, old, new) - }) - } - }, - enum_nonmatch_f, - cx, trait_span, substructure) -} - -/// Use a given binop to combine the result of calling the derived method -/// on all the fields. -#[inline] -pub fn cs_binop(binop: ast::BinOp_, base: P, - enum_nonmatch_f: EnumNonMatchCollapsedFunc, - cx: &mut ExtCtxt, trait_span: Span, - substructure: &Substructure) -> P { - cs_same_method_fold( - true, // foldl is good enough - |cx, span, old, new| { - cx.expr_binary(span, - binop, - old, new) - - }, - base, - enum_nonmatch_f, - cx, trait_span, substructure) -} - -/// cs_binop with binop == or -#[inline] -pub fn cs_or(enum_nonmatch_f: EnumNonMatchCollapsedFunc, - cx: &mut ExtCtxt, span: Span, - substructure: &Substructure) -> P { - cs_binop(ast::BiOr, cx.expr_bool(span, false), - enum_nonmatch_f, - cx, span, substructure) -} - -/// cs_binop with binop == and -#[inline] -pub fn cs_and(enum_nonmatch_f: EnumNonMatchCollapsedFunc, - cx: &mut ExtCtxt, span: Span, - substructure: &Substructure) -> P { - cs_binop(ast::BiAnd, cx.expr_bool(span, true), - enum_nonmatch_f, - cx, span, substructure) -} diff --git a/src/libsyntax/ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs similarity index 96% rename from src/libsyntax/ext/deriving/generic/ty.rs rename to src/libsyntax_ext/deriving/generic/ty.rs index 67826c9c6cdff..0c4a81361aef2 100644 --- a/src/libsyntax/ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -14,17 +14,18 @@ pub use self::PtrTy::*; pub use self::Ty::*; -use ast; -use ast::{Expr,Generics,Ident}; -use ext::base::ExtCtxt; -use ext::build::AstBuilder; -use codemap::{Span,respan}; -use owned_slice::OwnedSlice; -use parse::token::special_idents; -use ptr::P; +use syntax::ast; +use syntax::ast::{Expr,Generics,Ident}; +use syntax::ext::base::ExtCtxt; +use syntax::ext::build::AstBuilder; +use syntax::codemap::{Span,respan}; +use syntax::owned_slice::OwnedSlice; +use syntax::parse::token::special_idents; +use syntax::ptr::P; /// The types of pointers #[derive(Clone, Eq, PartialEq)] +#[allow(dead_code)] pub enum PtrTy<'a> { /// &'lifetime mut Borrowed(Option<&'a str>, ast::Mutability), diff --git a/src/libsyntax/ext/deriving/hash.rs b/src/libsyntax_ext/deriving/hash.rs similarity index 93% rename from src/libsyntax/ext/deriving/hash.rs rename to src/libsyntax_ext/deriving/hash.rs index 96be774ebdcf7..6bd21f7c0e0ca 100644 --- a/src/libsyntax/ext/deriving/hash.rs +++ b/src/libsyntax_ext/deriving/hash.rs @@ -8,13 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, Expr, MutMutable}; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast::{MetaItem, Expr, MutMutable}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::ptr::P; pub fn expand_deriving_hash(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs similarity index 92% rename from src/libsyntax/ext/deriving/mod.rs rename to src/libsyntax_ext/deriving/mod.rs index d26bb794c88b9..919540724ca6d 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -13,13 +13,14 @@ //! FIXME (#2810): hygiene. Search for "__" strings (in other files too). We also assume "extra" is //! the standard library, and "std" is the core library. -use ast::{MetaItem, MetaWord}; -use attr::AttrMetaMethods; -use ext::base::{ExtCtxt, SyntaxEnv, MultiDecorator, MultiItemDecorator, MultiModifier, Annotatable}; -use ext::build::AstBuilder; -use feature_gate; -use codemap::Span; -use parse::token::{intern, intern_and_get_ident}; +use syntax::ast::{MetaItem, MetaWord}; +use syntax::attr::AttrMetaMethods; +use syntax::ext::base::{ExtCtxt, SyntaxEnv, Annotatable}; +use syntax::ext::base::{MultiDecorator, MultiItemDecorator, MultiModifier}; +use syntax::ext::build::AstBuilder; +use syntax::feature_gate; +use syntax::codemap::Span; +use syntax::parse::token::{intern, intern_and_get_ident}; macro_rules! pathvec { ($($x:ident)::+) => ( @@ -35,7 +36,7 @@ macro_rules! path { macro_rules! path_local { ($x:ident) => ( - ::ext::deriving::generic::ty::Path::new_local(stringify!($x)) + ::deriving::generic::ty::Path::new_local(stringify!($x)) ) } @@ -51,7 +52,7 @@ macro_rules! pathvec_std { macro_rules! path_std { ($($x:tt)*) => ( - ::ext::deriving::generic::ty::Path::new( pathvec_std!( $($x)* ) ) + ::deriving::generic::ty::Path::new( pathvec_std!( $($x)* ) ) ) } diff --git a/src/libsyntax/ext/deriving/primitive.rs b/src/libsyntax_ext/deriving/primitive.rs similarity index 94% rename from src/libsyntax/ext/deriving/primitive.rs rename to src/libsyntax_ext/deriving/primitive.rs index 07b587783583e..121fe01976ef7 100644 --- a/src/libsyntax/ext/deriving/primitive.rs +++ b/src/libsyntax_ext/deriving/primitive.rs @@ -8,15 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, Expr}; -use ast; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token::InternedString; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast::{MetaItem, Expr}; +use syntax::ast; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token::InternedString; +use syntax::ptr::P; pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax_ext/env.rs similarity index 95% rename from src/libsyntax/ext/env.rs rename to src/libsyntax_ext/env.rs index d85071e78af6e..f1dd6854a3a40 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax_ext/env.rs @@ -14,12 +14,12 @@ * interface. */ -use ast; -use codemap::Span; -use ext::base::*; -use ext::base; -use ext::build::AstBuilder; -use parse::token; +use syntax::ast; +use syntax::codemap::Span; +use syntax::ext::base::*; +use syntax::ext::base; +use syntax::ext::build::AstBuilder; +use syntax::parse::token; use std::env; diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax_ext/format.rs similarity index 99% rename from src/libsyntax/ext/format.rs rename to src/libsyntax_ext/format.rs index 904cf0c47768e..24094f797e6c2 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -11,16 +11,17 @@ use self::ArgumentType::*; use self::Position::*; -use ast; -use codemap::{Span, respan}; -use ext::base::*; -use ext::base; -use ext::build::AstBuilder; use fmt_macros as parse; -use fold::Folder; -use parse::token::special_idents; -use parse::token; -use ptr::P; + +use syntax::ast; +use syntax::codemap::{Span, respan}; +use syntax::ext::base::*; +use syntax::ext::base; +use syntax::ext::build::AstBuilder; +use syntax::fold::Folder; +use syntax::parse::token::special_idents; +use syntax::parse::token; +use syntax::ptr::P; use std::collections::HashMap; diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs new file mode 100644 index 0000000000000..49c2618d51b9c --- /dev/null +++ b/src/libsyntax_ext/lib.rs @@ -0,0 +1,82 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Syntax extensions in the Rust compiler. + +#![crate_name = "syntax_ext"] +#![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/")] + +#![feature(rustc_private)] +#![feature(str_char)] + +extern crate fmt_macros; +extern crate syntax; + +use syntax::ext::base::{MacroExpanderFn, NormalTT}; +use syntax::ext::base::{SyntaxEnv, SyntaxExtension}; +use syntax::parse::token::intern; + +// A variant of 'try!' that panics on Err(FatalError). This is used as a +// crutch on the way towards a non-panic!-prone parser. It should be used +// for fatal parsing errors; eventually we plan to convert all code using +// panictry to just use normal try +macro_rules! panictry { + ($e:expr) => ({ + use std::result::Result::{Ok, Err}; + use syntax::diagnostic::FatalError; + match $e { + Ok(e) => e, + Err(FatalError) => panic!(FatalError) + } + }) +} + +mod asm; +mod cfg; +mod concat; +mod concat_idents; +mod deriving; +mod env; +mod format; +mod log_syntax; +mod trace_macros; + +pub fn register_builtins(env: &mut SyntaxEnv) { + // utility function to simplify creating NormalTT syntax extensions + fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension { + NormalTT(Box::new(f), None, false) + } + + env.insert(intern("asm"), + builtin_normal_expander(asm::expand_asm)); + env.insert(intern("cfg"), + builtin_normal_expander(cfg::expand_cfg)); + env.insert(intern("concat"), + builtin_normal_expander(concat::expand_syntax_ext)); + env.insert(intern("concat_idents"), + builtin_normal_expander(concat_idents::expand_syntax_ext)); + env.insert(intern("env"), + builtin_normal_expander(env::expand_env)); + env.insert(intern("option_env"), + builtin_normal_expander(env::expand_option_env)); + env.insert(intern("format_args"), + // format_args uses `unstable` things internally. + NormalTT(Box::new(format::expand_format_args), None, true)); + env.insert(intern("log_syntax"), + builtin_normal_expander(log_syntax::expand_syntax_ext)); + env.insert(intern("trace_macros"), + builtin_normal_expander(trace_macros::expand_trace_macros)); + + deriving::register_all(env); +} diff --git a/src/libsyntax/ext/log_syntax.rs b/src/libsyntax_ext/log_syntax.rs similarity index 92% rename from src/libsyntax/ext/log_syntax.rs rename to src/libsyntax_ext/log_syntax.rs index 5f7ce8d994172..ee944abb645dc 100644 --- a/src/libsyntax/ext/log_syntax.rs +++ b/src/libsyntax_ext/log_syntax.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast; -use codemap; -use ext::base; -use feature_gate; -use print; +use syntax::ast; +use syntax::codemap; +use syntax::ext::base; +use syntax::feature_gate; +use syntax::print; pub fn expand_syntax_ext<'cx>(cx: &'cx mut base::ExtCtxt, sp: codemap::Span, diff --git a/src/libsyntax/ext/trace_macros.rs b/src/libsyntax_ext/trace_macros.rs similarity index 89% rename from src/libsyntax/ext/trace_macros.rs rename to src/libsyntax_ext/trace_macros.rs index 628b88d13537a..7b1e985442adb 100644 --- a/src/libsyntax/ext/trace_macros.rs +++ b/src/libsyntax_ext/trace_macros.rs @@ -8,12 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::TokenTree; -use codemap::Span; -use ext::base::ExtCtxt; -use ext::base; -use feature_gate; -use parse::token::keywords; +use syntax::ast::TokenTree; +use syntax::codemap::Span; +use syntax::ext::base::ExtCtxt; +use syntax::ext::base; +use syntax::feature_gate; +use syntax::parse::token::keywords; pub fn expand_trace_macros(cx: &mut ExtCtxt, From bb21b6738a90b232b0e9864c7b2e753d0507f6c0 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Fri, 11 Dec 2015 03:42:47 +0900 Subject: [PATCH 2/4] Fix expansion tests --- src/libsyntax/ext/expand.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index a67115e82bb29..b1afe2bb69c02 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1397,6 +1397,7 @@ mod tests { use ast; use ast::Name; use codemap; + use ext::base::ExtCtxt; use ext::mtwt; use fold::Folder; use parse; @@ -1467,7 +1468,9 @@ mod tests { src, Vec::new(), &sess); // should fail: - expand_crate(&sess,test_ecfg(),vec!(),vec!(), &mut vec![], crate_ast); + let mut gated_cfgs = vec![]; + let ecx = ExtCtxt::new(&sess, vec![], test_ecfg(), &mut gated_cfgs); + expand_crate(ecx, vec![], vec![], crate_ast); } // make sure that macros can't escape modules @@ -1480,7 +1483,9 @@ mod tests { "".to_string(), src, Vec::new(), &sess); - expand_crate(&sess,test_ecfg(),vec!(),vec!(), &mut vec![], crate_ast); + let mut gated_cfgs = vec![]; + let ecx = ExtCtxt::new(&sess, vec![], test_ecfg(), &mut gated_cfgs); + expand_crate(ecx, vec![], vec![], crate_ast); } // macro_use modules should allow macros to escape @@ -1492,14 +1497,18 @@ mod tests { "".to_string(), src, Vec::new(), &sess); - expand_crate(&sess, test_ecfg(), vec!(), vec!(), &mut vec![], crate_ast); + let mut gated_cfgs = vec![]; + let ecx = ExtCtxt::new(&sess, vec![], test_ecfg(), &mut gated_cfgs); + expand_crate(ecx, vec![], vec![], crate_ast); } fn expand_crate_str(crate_str: String) -> ast::Crate { let ps = parse::ParseSess::new(); let crate_ast = panictry!(string_to_parser(&ps, crate_str).parse_crate_mod()); // the cfg argument actually does matter, here... - expand_crate(&ps,test_ecfg(),vec!(),vec!(), &mut vec![], crate_ast).0 + let mut gated_cfgs = vec![]; + let ecx = ExtCtxt::new(&ps, vec![], test_ecfg(), &mut gated_cfgs); + expand_crate(ecx, vec![], vec![], crate_ast).0 } // find the pat_ident paths in a crate From 9410bfa0cd68947a1f4b21c3b624855cf5732a7a Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Fri, 11 Dec 2015 16:40:25 +0900 Subject: [PATCH 3/4] Fix custom deriving tests --- src/libsyntax_ext/lib.rs | 4 +++- src/test/auxiliary/custom_derive_plugin.rs | 5 +++-- src/test/auxiliary/custom_derive_plugin_attr.rs | 7 ++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index 49c2618d51b9c..b59b7db28cbdc 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -46,12 +46,14 @@ mod asm; mod cfg; mod concat; mod concat_idents; -mod deriving; mod env; mod format; mod log_syntax; mod trace_macros; +// for custom_derive +pub mod deriving; + pub fn register_builtins(env: &mut SyntaxEnv) { // utility function to simplify creating NormalTT syntax extensions fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension { diff --git a/src/test/auxiliary/custom_derive_plugin.rs b/src/test/auxiliary/custom_derive_plugin.rs index 542b10fd1c68c..a3f42edbed2a8 100644 --- a/src/test/auxiliary/custom_derive_plugin.rs +++ b/src/test/auxiliary/custom_derive_plugin.rs @@ -15,6 +15,7 @@ #![feature(rustc_private)] extern crate syntax; +extern crate syntax_ext; extern crate rustc; extern crate rustc_plugin; @@ -22,10 +23,10 @@ use syntax::ast; use syntax::codemap::Span; use syntax::ext::base::{MultiDecorator, ExtCtxt, Annotatable}; use syntax::ext::build::AstBuilder; -use syntax::ext::deriving::generic::{cs_fold, TraitDef, MethodDef, combine_substructure}; -use syntax::ext::deriving::generic::ty::{Literal, LifetimeBounds, Path, borrowed_explicit_self}; use syntax::parse::token; use syntax::ptr::P; +use syntax_ext::deriving::generic::{cs_fold, TraitDef, MethodDef, combine_substructure}; +use syntax_ext::deriving::generic::ty::{Literal, LifetimeBounds, Path, borrowed_explicit_self}; use rustc_plugin::Registry; #[plugin_registrar] diff --git a/src/test/auxiliary/custom_derive_plugin_attr.rs b/src/test/auxiliary/custom_derive_plugin_attr.rs index f44e77d563a9e..fe12d3b1f080f 100644 --- a/src/test/auxiliary/custom_derive_plugin_attr.rs +++ b/src/test/auxiliary/custom_derive_plugin_attr.rs @@ -15,6 +15,7 @@ #![feature(rustc_private)] extern crate syntax; +extern crate syntax_ext; extern crate rustc; extern crate rustc_plugin; @@ -23,11 +24,11 @@ use syntax::attr::AttrMetaMethods; use syntax::codemap::Span; use syntax::ext::base::{MultiDecorator, ExtCtxt, Annotatable}; use syntax::ext::build::AstBuilder; -use syntax::ext::deriving::generic::{cs_fold, TraitDef, MethodDef, combine_substructure}; -use syntax::ext::deriving::generic::{Substructure, Struct, EnumMatching}; -use syntax::ext::deriving::generic::ty::{Literal, LifetimeBounds, Path, borrowed_explicit_self}; use syntax::parse::token; use syntax::ptr::P; +use syntax_ext::deriving::generic::{cs_fold, TraitDef, MethodDef, combine_substructure}; +use syntax_ext::deriving::generic::{Substructure, Struct, EnumMatching}; +use syntax_ext::deriving::generic::ty::{Literal, LifetimeBounds, Path, borrowed_explicit_self}; use rustc_plugin::Registry; #[plugin_registrar] From 0883f10550299af021bbdec95b98693b395153b6 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Tue, 15 Dec 2015 16:23:18 +0900 Subject: [PATCH 4/4] Mark libsyntax_ext unstable --- src/libsyntax_ext/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index b59b7db28cbdc..f4dd621c97ecd 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -17,7 +17,12 @@ html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] +#![cfg_attr(stage0, feature(custom_attribute))] +#![cfg_attr(stage0, staged_api)] +#![unstable(feature = "rustc_private", issue = "27812")] + #![feature(rustc_private)] +#![feature(staged_api)] #![feature(str_char)] extern crate fmt_macros;