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
This commit is contained in:
Alex Crichton 2017-01-01 16:14:35 -08:00
parent 917e5baae7
commit 045f8f6929
65 changed files with 13 additions and 188 deletions

View File

@ -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
//!
@ -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))]
@ -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: (),
}
@ -131,6 +132,7 @@ pub mod __internal {
}
}
#[stable(feature = "proc_macro_lib", since = "1.15.0")]
impl FromStr for TokenStream {
type Err = LexError;
@ -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() {

View File

@ -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())
});
}

View File

@ -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)]

View File

@ -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,
}
}

View File

@ -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)),
@ -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)
@ -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",
@ -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)]

View File

@ -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;
@ -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();

View File

@ -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)]

View File

@ -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;
@ -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);
@ -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 {

View File

@ -9,7 +9,6 @@
// except according to those terms.
#![crate_type = "proc-macro"]
#![feature(proc_macro, proc_macro_lib)]
extern crate proc_macro;

View File

@ -11,7 +11,6 @@
// force-host
// no-prefer-dynamic
#![feature(proc_macro, proc_macro_lib)]
#![crate_type = "proc-macro"]
extern crate proc_macro;

View File

@ -11,8 +11,6 @@
// force-host
// no-prefer-dynamic
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]
extern crate proc_macro;

View File

@ -11,8 +11,6 @@
// force-host
// no-prefer-dynamic
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]
extern crate proc_macro;

View File

@ -11,8 +11,6 @@
// no-prefer-dynamic
// force-host
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]
extern crate proc_macro;

View File

@ -11,8 +11,6 @@
// no-prefer-dynamic
// force-host
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]
extern crate proc_macro;

View File

@ -11,8 +11,6 @@
// force-host
// no-prefer-dynamic
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]
extern crate proc_macro;

View File

@ -11,8 +11,6 @@
// force-host
// no-prefer-dynamic
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]
extern crate proc_macro;

View File

@ -11,7 +11,6 @@
// no-prefer-dynamic
#![crate_type = "proc-macro"]
#![feature(proc_macro, proc_macro_lib)]
extern crate proc_macro;

View File

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

View File

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

View File

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

View File

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

View File

@ -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 {

View File

@ -1,13 +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.
// error-pattern: the `proc-macro` crate type is experimental
#![crate_type = "proc-macro"]

View File

@ -1,13 +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.
extern crate proc_macro; //~ ERROR: use of unstable library feature
fn main() {}

View File

@ -1,15 +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 = "proc-macro"]
#[proc_macro_derive(Foo)] //~ ERROR: is an experimental feature
pub fn foo() {
}

View File

@ -1,17 +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.
// aux-build:derive-a.rs
#[macro_use]
extern crate derive_a;
#[derive(A)] //~ ERROR custom derive macros are experimentally supported
struct S;

View File

@ -1,12 +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.
#[cfg(proc_macro)] //~ ERROR: experimental and subject to change
fn foo() {}

View File

@ -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)]

View File

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

View File

@ -10,8 +10,6 @@
// aux-build:derive-a-b.rs
#![feature(proc_macro)]
#[macro_use]
extern crate derive_a_b;

View File

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

View File

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

View File

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

View File

@ -9,7 +9,6 @@
// except according to those terms.
#![crate_type = "proc-macro"]
#![feature(proc_macro, proc_macro_lib)]
extern crate proc_macro;

View File

@ -9,7 +9,6 @@
// except according to those terms.
#![crate_type = "proc-macro"]
#![feature(proc_macro, proc_macro_lib)]
extern crate proc_macro;

View File

@ -10,8 +10,6 @@
// aux-build:derive-a.rs
#![feature(proc_macro)]
#[macro_use]
extern crate derive_a;
#[macro_use]

View File

@ -9,7 +9,6 @@
// except according to those terms.
#![crate_type = "proc-macro"]
#![feature(proc_macro, proc_macro_lib)]
#![allow(warnings)]
extern crate proc_macro;

View File

@ -8,6 +8,5 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(proc_macro)]
#![allow(unused)]
#![crate_type = "proc-macro"]

View File

@ -8,6 +8,5 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(proc_macro)]
#![allow(unused)]
#![crate_type = "proc-macro"]

View File

@ -9,7 +9,6 @@
// except according to those terms.
#![crate_type = "proc-macro"]
#![feature(proc_macro, proc_macro_lib)]
extern crate proc_macro;

View File

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

View File

@ -9,8 +9,6 @@
// except according to those terms.
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
extern crate proc_macro;

View File

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

View File

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

View File

@ -11,8 +11,6 @@
// no-prefer-dynamic
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
extern crate proc_macro;

View File

@ -11,8 +11,6 @@
// force-host
// no-prefer-dynamic
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]
extern crate proc_macro;

View File

@ -11,8 +11,6 @@
// no-prefer-dynamic
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
extern crate proc_macro;

View File

@ -11,8 +11,6 @@
// no-prefer-dynamic
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
extern crate proc_macro;

View File

@ -11,8 +11,6 @@
// no-prefer-dynamic
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
extern crate proc_macro;

View File

@ -11,8 +11,6 @@
// no-prefer-dynamic
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
extern crate proc_macro;

View File

@ -11,8 +11,6 @@
// no-prefer-dynamic
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
extern crate proc_macro;

View File

@ -10,7 +10,7 @@
// ignore-test
#![feature(macro_reexport, proc_macro)]
#![feature(macro_reexport)]
#[macro_reexport(A)]
extern crate derive_a;

View File

@ -11,9 +11,6 @@
// no-prefer-dynamic
// compile-flags:--crate-type proc-macro
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
extern crate proc_macro;
use proc_macro::TokenStream;

View File

@ -11,8 +11,6 @@
// no-prefer-dynamic
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
extern crate proc_macro;

View File

@ -11,8 +11,6 @@
// no-prefer-dynamic
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![deny(warnings)]
extern crate proc_macro;

View File

@ -10,7 +10,6 @@
// aux-build:double.rs
#![feature(proc_macro)]
#![allow(unused)]
#[macro_use]

View File

@ -11,8 +11,6 @@
// aux-build:derive-b.rs
// ignore-stage1
#![feature(proc_macro)]
#[macro_use]
extern crate derive_b;

View File

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

View File

@ -12,8 +12,6 @@
// compile-flags: --test
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
#![feature(proc_macro, proc_macro_lib)]
extern crate proc_macro;

View File

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

View File

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

View File

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

View File

@ -11,8 +11,6 @@
// aux-build:derive-nothing.rs
// ignore-stage1
#![feature(proc_macro)]
#[macro_use]
extern crate derive_nothing;

View File

@ -11,8 +11,6 @@
// aux-build:derive-a.rs
// aux-build:derive-reexport.rs
#![feature(proc_macro)]
#[macro_use]
extern crate derive_reexport;

View File

@ -10,8 +10,6 @@
// no-prefer-dynamic
#![feature(proc_macro)]
#![feature(proc_macro_lib)]
#![crate_type = "proc-macro"]
extern crate proc_macro;