Skip to content

Commit

Permalink
Auto merge of #38783 - alexcrichton:stabilize-proc-macro, r=nikomatsakis
Browse files Browse the repository at this point in the history
rustc: Stabilize the `proc_macro` feature

This commit stabilizes the `proc_macro` and `proc_macro_lib` features in the
compiler to stabilize the "Macros 1.1" feature of the language. Many more
details can be found on the tracking issue, #35900.

Closes #35900
  • Loading branch information
bors committed Jan 4, 2017
2 parents 05f4a75 + 045f8f6 commit 95b14a3
Show file tree
Hide file tree
Showing 65 changed files with 13 additions and 188 deletions.
9 changes: 6 additions & 3 deletions src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
//! Currently the primary use of this crate is to provide the ability to define
//! new custom derive modes through `#[proc_macro_derive]`.
//!
//! Added recently as part of [RFC 1681] this crate is currently *unstable* and
//! requires the `#![feature(proc_macro_lib)]` directive to use.
//! Added recently as part of [RFC 1681] this crate is stable as of Rust 1.15.0.
//!
//! [RFC 1681]: https://github.com/rust-lang/rfcs/blob/master/text/1681-macros-1.1.md
//!
Expand All @@ -27,7 +26,7 @@
//! area for macro authors is stabilized.

#![crate_name = "proc_macro"]
#![unstable(feature = "proc_macro_lib", issue = "27812")]
#![stable(feature = "proc_macro_lib", since = "1.15.0")]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
#![cfg_attr(not(stage0), deny(warnings))]
Expand Down Expand Up @@ -55,12 +54,14 @@ use syntax::ptr::P;
///
/// The API of this type is intentionally bare-bones, but it'll be expanded over
/// time!
#[stable(feature = "proc_macro_lib", since = "1.15.0")]
pub struct TokenStream {
inner: Vec<P<ast::Item>>,
}

/// Error returned from `TokenStream::from_str`.
#[derive(Debug)]
#[stable(feature = "proc_macro_lib", since = "1.15.0")]
pub struct LexError {
_inner: (),
}
Expand Down Expand Up @@ -131,6 +132,7 @@ pub mod __internal {
}
}

#[stable(feature = "proc_macro_lib", since = "1.15.0")]
impl FromStr for TokenStream {
type Err = LexError;

Expand All @@ -154,6 +156,7 @@ impl FromStr for TokenStream {
}
}

#[stable(feature = "proc_macro_lib", since = "1.15.0")]
impl fmt::Display for TokenStream {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for item in self.inner.iter() {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
is_proc_macro_crate,
is_test_crate,
num_crate_types,
sess.diagnostic(),
&sess.features.borrow())
sess.diagnostic())
});
}

Expand Down
1 change: 0 additions & 1 deletion src/librustc_metadata/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#![feature(conservative_impl_trait)]
#![feature(core_intrinsics)]
#![feature(proc_macro_internals)]
#![feature(proc_macro_lib)]
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,6 @@ 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_proc_macro = proc_macro,
}
}

Expand Down
12 changes: 3 additions & 9 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,6 @@ declare_features! (
// instead of just the platforms on which it is the C ABI
(active, abi_sysv64, "1.13.0", Some(36167)),

// Macros 1.1
(active, proc_macro, "1.13.0", Some(35900)),

// Allows untagged unions `union U { ... }`
(active, untagged_unions, "1.13.0", Some(32836)),

Expand Down Expand Up @@ -377,6 +374,8 @@ declare_features! (
// Allows `..` in tuple (struct) patterns
(accepted, dotdot_in_tuple_patterns, "1.14.0", Some(33627)),
(accepted, item_like_imports, "1.14.0", Some(35120)),
// Macros 1.1
(accepted, proc_macro, "1.15.0", Some(35900)),
);
// (changing above list without updating src/doc/reference.md makes @cmr sad)

Expand Down Expand Up @@ -650,11 +649,7 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
is an experimental feature",
cfg_fn!(fundamental))),

("proc_macro_derive", Normal, Gated(Stability::Unstable,
"proc_macro",
"the `#[proc_macro_derive]` attribute \
is an experimental feature",
cfg_fn!(proc_macro))),
("proc_macro_derive", Normal, Ungated),

("rustc_copy_clone_marker", Whitelisted, Gated(Stability::Unstable,
"rustc_attrs",
Expand Down Expand Up @@ -760,7 +755,6 @@ 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)),
("proc_macro", "proc_macro", cfg_fn!(proc_macro)),
];

#[derive(Debug, Eq, PartialEq)]
Expand Down
8 changes: 1 addition & 7 deletions src/libsyntax_ext/deriving/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use syntax::attr::HasAttrs;
use syntax::codemap;
use syntax::ext::base::{Annotatable, ExtCtxt, SyntaxExtension};
use syntax::ext::build::AstBuilder;
use syntax::feature_gate::{self, emit_feature_err};
use syntax::feature_gate;
use syntax::ptr::P;
use syntax::symbol::Symbol;
use syntax_pos::Span;
Expand Down Expand Up @@ -220,12 +220,6 @@ pub fn expand_derive(cx: &mut ExtCtxt,
.filter(|&(_, ref name)| !is_builtin_trait(name.name().unwrap()))
.next();
if let Some((i, titem)) = macros_11_derive {
if !cx.ecfg.features.unwrap().proc_macro {
let issue = feature_gate::GateIssue::Language;
let msg = "custom derive macros are experimentally supported";
emit_feature_err(cx.parse_sess, "proc_macro", titem.span, issue, msg);
}

let tname = ast::Ident::with_empty_ctxt(titem.name().unwrap());
let path = ast::Path::from_ident(titem.span, tname);
let ext = cx.resolver.resolve_macro(cx.current_expansion.mark, &path, false).unwrap();
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax_ext/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
html_root_url = "https://doc.rust-lang.org/nightly/")]
#![cfg_attr(not(stage0), deny(warnings))]

#![feature(proc_macro_lib)]
#![feature(proc_macro_internals)]
#![feature(rustc_private)]
#![feature(staged_api)]
Expand Down
10 changes: 1 addition & 9 deletions src/libsyntax_ext/proc_macro_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use syntax::ext::base::ExtCtxt;
use syntax::ext::build::AstBuilder;
use syntax::ext::expand::ExpansionConfig;
use syntax::parse::ParseSess;
use syntax::feature_gate::Features;
use syntax::fold::Folder;
use syntax::ptr::P;
use syntax::symbol::Symbol;
Expand Down Expand Up @@ -47,8 +46,7 @@ pub fn modify(sess: &ParseSess,
is_proc_macro_crate: bool,
is_test_crate: bool,
num_crate_types: usize,
handler: &errors::Handler,
features: &Features) -> ast::Crate {
handler: &errors::Handler) -> ast::Crate {
let ecfg = ExpansionConfig::default("proc_macro".to_string());
let mut cx = ExtCtxt::new(sess, ecfg, resolver);

Expand All @@ -66,12 +64,6 @@ pub fn modify(sess: &ParseSess,

if !is_proc_macro_crate {
return krate
} else if !features.proc_macro {
let mut err = handler.struct_err("the `proc-macro` crate type is \
experimental");
err.help("add #![feature(proc_macro)] to the crate attributes to \
enable");
err.emit();
}

if num_crate_types > 1 {
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail-fulldeps/proc-macro/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

#![crate_type = "proc-macro"]
#![feature(proc_macro, proc_macro_lib)]

extern crate proc_macro;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// force-host
// no-prefer-dynamic

#![feature(proc_macro, proc_macro_lib)]
#![crate_type = "proc-macro"]

extern crate proc_macro;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// force-host
// no-prefer-dynamic

#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]

extern crate proc_macro;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// force-host
// no-prefer-dynamic

#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]

extern crate proc_macro;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// no-prefer-dynamic
// force-host

#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]

extern crate proc_macro;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// no-prefer-dynamic
// force-host

#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]

extern crate proc_macro;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// force-host
// no-prefer-dynamic

#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]

extern crate proc_macro;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// force-host
// no-prefer-dynamic

#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]

extern crate proc_macro;
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail-fulldeps/proc-macro/define-two.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// no-prefer-dynamic

#![crate_type = "proc-macro"]
#![feature(proc_macro, proc_macro_lib)]

extern crate proc_macro;

Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail-fulldeps/proc-macro/derive-bad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

// aux-build:derive-bad.rs

#![feature(proc_macro)]

#[macro_use]
extern crate derive_bad;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

// aux-build:derive-a.rs

#![feature(proc_macro)]
#![allow(warnings)]

#[macro_use]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

// aux-build:derive-unstable-2.rs

#![feature(proc_macro)]
#![allow(warnings)]

#[macro_use]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

// aux-build:derive-unstable.rs

#![feature(proc_macro)]
#![allow(warnings)]

#[macro_use]
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail-fulldeps/proc-macro/export-macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// error-pattern: cannot export macro_rules! macros from a `proc-macro` crate

#![crate_type = "proc-macro"]
#![feature(proc_macro)]

#[macro_export]
macro_rules! foo {
Expand Down
13 changes: 0 additions & 13 deletions src/test/compile-fail-fulldeps/proc-macro/feature-gate-1.rs

This file was deleted.

13 changes: 0 additions & 13 deletions src/test/compile-fail-fulldeps/proc-macro/feature-gate-2.rs

This file was deleted.

15 changes: 0 additions & 15 deletions src/test/compile-fail-fulldeps/proc-macro/feature-gate-3.rs

This file was deleted.

17 changes: 0 additions & 17 deletions src/test/compile-fail-fulldeps/proc-macro/feature-gate-4.rs

This file was deleted.

12 changes: 0 additions & 12 deletions src/test/compile-fail-fulldeps/proc-macro/feature-gate-5.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(proc_macro, proc_macro_lib)]

extern crate proc_macro;

#[proc_macro_derive(Foo)]
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail-fulldeps/proc-macro/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

// aux-build:derive-a.rs

#![feature(proc_macro)]
#![allow(warnings)]

#[macro_use]
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail-fulldeps/proc-macro/issue-37788.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

// aux-build:derive-a-b.rs

#![feature(proc_macro)]

#[macro_use]
extern crate derive_a_b;

Expand Down
Loading

0 comments on commit 95b14a3

Please sign in to comment.