From: Alex Crichton Date: Tue, 4 Oct 2016 16:58:28 +0000 (-0700) Subject: Blanket rename rustc-macro to proc-macro X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~13^2~44^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=55fc374c9d30e25a9fe1eb45f83ec0ee78307332;p=cargo.git Blanket rename rustc-macro to proc-macro --- diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index 827008b8b..e72674b96 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -61,7 +61,7 @@ pub enum LibKind { Lib, Rlib, Dylib, - RustcMacro, + ProcMacro, Other(String), } @@ -71,7 +71,7 @@ impl LibKind { "lib" => LibKind::Lib, "rlib" => LibKind::Rlib, "dylib" => LibKind::Dylib, - "rustc-macro" => LibKind::RustcMacro, + "procc-macro" => LibKind::ProcMacro, s => LibKind::Other(s.to_string()), } } @@ -82,7 +82,7 @@ impl LibKind { LibKind::Lib => "lib", LibKind::Rlib => "rlib", LibKind::Dylib => "dylib", - LibKind::RustcMacro => "rustc-macro", + LibKind::ProcMacro => "proc-macro", LibKind::Other(ref s) => s, } } @@ -92,7 +92,7 @@ impl LibKind { LibKind::Lib | LibKind::Rlib | LibKind::Dylib | - LibKind::RustcMacro => true, + LibKind::ProcMacro => true, LibKind::Other(..) => false, } } diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index a051a2836..0a9ecd613 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -905,7 +905,7 @@ struct TomlTarget { bench: Option, doc: Option, plugin: Option, - rustc_macro: Option, + proc_macro: Option, harness: Option, } @@ -934,7 +934,7 @@ impl TomlTarget { bench: None, doc: None, plugin: None, - rustc_macro: None, + proc_macro: None, harness: None, } } @@ -1017,15 +1017,15 @@ impl TomlTarget { fn validate_crate_type(&self) -> CargoResult<()> { // Per the Macros 1.1 RFC: // - // > Initially if a crate is compiled with the rustc-macro crate type + // > Initially if a crate is compiled with the proc-macro crate type // > (and possibly others) it will forbid exporting any items in the - // > crate other than those functions tagged #[rustc_macro_derive] and + // > crate other than those functions tagged #[proc_macro_derive] and // > those functions must also be placed at the crate root. // // A plugin requires exporting plugin_registrar so a crate cannot be // both at once. - if self.plugin == Some(true) && self.rustc_macro == Some(true) { - Err(human("lib.plugin and lib.rustc-macro cannot both be true".to_string())) + if self.plugin == Some(true) && self.proc_macro == Some(true) { + Err(human("lib.plugin and lib.proc-macro cannot both be true".to_string())) } else { Ok(()) } @@ -1064,7 +1064,7 @@ fn normalize(lib: &Option, .set_doctest(toml.doctest.unwrap_or(t2.doctested())) .set_benched(toml.bench.unwrap_or(t2.benched())) .set_harness(toml.harness.unwrap_or(t2.harness())) - .set_for_host(match (toml.plugin, toml.rustc_macro) { + .set_for_host(match (toml.plugin, toml.proc_macro) { (None, None) => t2.for_host(), (Some(true), _) | (_, Some(true)) => true, (Some(false), _) | (_, Some(false)) => false, @@ -1081,7 +1081,7 @@ fn normalize(lib: &Option, Some(kinds) => kinds.iter().map(|s| LibKind::from_str(s)).collect(), None => { vec![ if l.plugin == Some(true) {LibKind::Dylib} - else if l.rustc_macro == Some(true) {LibKind::RustcMacro} + else if l.proc_macro == Some(true) {LibKind::ProcMacro} else {LibKind::Lib} ] } }; diff --git a/src/doc/manifest.md b/src/doc/manifest.md index eb5331d54..9aaab6707 100644 --- a/src/doc/manifest.md +++ b/src/doc/manifest.md @@ -512,7 +512,7 @@ plugin = false # If the target is meant to be a "macros 1.1" procedural macro, this field must # be set to true. -rustc-macro = false +proc-macro = false # If set to false, `cargo test` will omit the `--test` flag to rustc, which # stops it from generating a test harness. This is useful when the binary being @@ -534,11 +534,11 @@ crate-type = ["dylib"] # could be `staticlib` as well ``` The available options are `dylib`, `rlib`, `staticlib`, `cdylib`, and -`rustc-macro`. You should only use this option in a project. Cargo will always +`proc-macro`. You should only use this option in a project. Cargo will always compile packages (dependencies) based on the requirements of the project that includes them. -You can read more about the different crate types in the +You can read more about the different crate types in the [Rust Reference Manual](https://doc.rust-lang.org/reference.html#linkage) # The `[replace]` Section diff --git a/tests/proc-macro.rs b/tests/proc-macro.rs new file mode 100644 index 000000000..daae388e0 --- /dev/null +++ b/tests/proc-macro.rs @@ -0,0 +1,190 @@ +extern crate cargotest; +extern crate hamcrest; + +use cargotest::is_nightly; +use cargotest::support::{project, execs}; +use hamcrest::assert_that; + +#[test] +#[ignore] +fn noop() { + if !is_nightly() { + return; + } + + let client = project("client") + .file("Cargo.toml", r#" + [package] + name = "client" + version = "0.0.1" + authors = [] + + [dependencies.noop] + path = "../noop" + "#) + .file("src/main.rs", r#" + #![feature(proc_macro)] + + #[macro_use] + extern crate noop; + + #[derive(Noop)] + struct X; + + fn main() {} + "#); + let noop = project("noop") + .file("Cargo.toml", r#" + [package] + name = "noop" + version = "0.0.1" + authors = [] + + [lib] + proc-macro = true + "#) + .file("src/lib.rs", r#" + #![feature(proc_macro, proc_macro_lib)] + + extern crate proc_macro; + use proc_macro::TokenStream; + + #[proc_macro_derive(Noop)] + pub fn noop(input: TokenStream) -> TokenStream { + input + } + "#); + noop.build(); + + assert_that(client.cargo_process("build"), + execs().with_status(0)); + assert_that(client.cargo("build"), + execs().with_status(0)); +} + +#[test] +#[ignore] +fn impl_and_derive() { + if !is_nightly() { + return; + } + + let client = project("client") + .file("Cargo.toml", r#" + [package] + name = "client" + version = "0.0.1" + authors = [] + + [dependencies.transmogrify] + path = "../transmogrify" + "#) + .file("src/main.rs", r#" + #![feature(proc_macro)] + + #[macro_use] + extern crate transmogrify; + + trait ImplByTransmogrify { + fn impl_by_transmogrify(&self) -> bool; + } + + #[derive(Transmogrify)] + struct X; + + fn main() { + let x = X::new(); + assert!(x.impl_by_transmogrify()); + println!("{:?}", x); + } + "#); + let transmogrify = project("transmogrify") + .file("Cargo.toml", r#" + [package] + name = "transmogrify" + version = "0.0.1" + authors = [] + + [lib] + proc-macro = true + "#) + .file("src/lib.rs", r#" + #![feature(proc_macro, proc_macro_lib)] + + extern crate proc_macro; + use proc_macro::TokenStream; + + #[proc_macro_derive(Transmogrify)] + #[doc(hidden)] + pub fn transmogrify(input: TokenStream) -> TokenStream { + assert_eq!(input.to_string(), "struct X;\n"); + + " + impl X { + fn new() -> Self { + X { success: true } + } + } + + impl ImplByTransmogrify for X { + fn impl_by_transmogrify(&self) -> bool { + true + } + } + + #[derive(Debug)] + struct X { + success: bool, + } + ".parse().unwrap() + } + "#); + transmogrify.build(); + + assert_that(client.cargo_process("build"), + execs().with_status(0)); + assert_that(client.cargo("run"), + execs().with_status(0).with_stdout("X { success: true }")); +} + +#[test] +#[ignore] +fn plugin_and_proc_macro() { + if !is_nightly() { + return; + } + + let questionable = project("questionable") + .file("Cargo.toml", r#" + [package] + name = "questionable" + version = "0.0.1" + authors = [] + + [lib] + plugin = true + proc-macro = true + "#) + .file("src/lib.rs", r#" + #![feature(plugin_registrar, rustc_private)] + #![feature(proc_macro, proc_macro_lib)] + + extern crate rustc_plugin; + use rustc_plugin::Registry; + + extern crate proc_macro; + use proc_macro::TokenStream; + + #[plugin_registrar] + pub fn plugin_registrar(reg: &mut Registry) {} + + #[proc_macro_derive(Questionable)] + pub fn questionable(input: TokenStream) -> TokenStream { + input + } + "#); + + let msg = " lib.plugin and lib.proc-macro cannot both be true"; + assert_that(questionable.cargo_process("build"), + execs().with_status(101).with_stderr_contains(msg)); +} diff --git a/tests/rustc-macro.rs b/tests/rustc-macro.rs deleted file mode 100644 index f9ea79d2a..000000000 --- a/tests/rustc-macro.rs +++ /dev/null @@ -1,190 +0,0 @@ -extern crate cargotest; -extern crate hamcrest; - -use cargotest::is_nightly; -use cargotest::support::{project, execs}; -use hamcrest::assert_that; - -#[test] -#[ignore] -fn noop() { - if !is_nightly() { - return; - } - - let client = project("client") - .file("Cargo.toml", r#" - [package] - name = "client" - version = "0.0.1" - authors = [] - - [dependencies.noop] - path = "../noop" - "#) - .file("src/main.rs", r#" - #![feature(rustc_macro)] - - #[macro_use] - extern crate noop; - - #[derive(Noop)] - struct X; - - fn main() {} - "#); - let noop = project("noop") - .file("Cargo.toml", r#" - [package] - name = "noop" - version = "0.0.1" - authors = [] - - [lib] - rustc-macro = true - "#) - .file("src/lib.rs", r#" - #![feature(rustc_macro, rustc_macro_lib)] - - extern crate rustc_macro; - use rustc_macro::TokenStream; - - #[rustc_macro_derive(Noop)] - pub fn noop(input: TokenStream) -> TokenStream { - input - } - "#); - noop.build(); - - assert_that(client.cargo_process("build"), - execs().with_status(0)); - assert_that(client.cargo("build"), - execs().with_status(0)); -} - -#[test] -#[ignore] -fn impl_and_derive() { - if !is_nightly() { - return; - } - - let client = project("client") - .file("Cargo.toml", r#" - [package] - name = "client" - version = "0.0.1" - authors = [] - - [dependencies.transmogrify] - path = "../transmogrify" - "#) - .file("src/main.rs", r#" - #![feature(rustc_macro)] - - #[macro_use] - extern crate transmogrify; - - trait ImplByTransmogrify { - fn impl_by_transmogrify(&self) -> bool; - } - - #[derive(Transmogrify)] - struct X; - - fn main() { - let x = X::new(); - assert!(x.impl_by_transmogrify()); - println!("{:?}", x); - } - "#); - let transmogrify = project("transmogrify") - .file("Cargo.toml", r#" - [package] - name = "transmogrify" - version = "0.0.1" - authors = [] - - [lib] - rustc-macro = true - "#) - .file("src/lib.rs", r#" - #![feature(rustc_macro, rustc_macro_lib)] - - extern crate rustc_macro; - use rustc_macro::TokenStream; - - #[rustc_macro_derive(Transmogrify)] - #[doc(hidden)] - pub fn transmogrify(input: TokenStream) -> TokenStream { - assert_eq!(input.to_string(), "struct X;\n"); - - " - impl X { - fn new() -> Self { - X { success: true } - } - } - - impl ImplByTransmogrify for X { - fn impl_by_transmogrify(&self) -> bool { - true - } - } - - #[derive(Debug)] - struct X { - success: bool, - } - ".parse().unwrap() - } - "#); - transmogrify.build(); - - assert_that(client.cargo_process("build"), - execs().with_status(0)); - assert_that(client.cargo("run"), - execs().with_status(0).with_stdout("X { success: true }")); -} - -#[test] -#[ignore] -fn plugin_and_rustc_macro() { - if !is_nightly() { - return; - } - - let questionable = project("questionable") - .file("Cargo.toml", r#" - [package] - name = "questionable" - version = "0.0.1" - authors = [] - - [lib] - plugin = true - rustc-macro = true - "#) - .file("src/lib.rs", r#" - #![feature(plugin_registrar, rustc_private)] - #![feature(rustc_macro, rustc_macro_lib)] - - extern crate rustc_plugin; - use rustc_plugin::Registry; - - extern crate rustc_macro; - use rustc_macro::TokenStream; - - #[plugin_registrar] - pub fn plugin_registrar(reg: &mut Registry) {} - - #[rustc_macro_derive(Questionable)] - pub fn questionable(input: TokenStream) -> TokenStream { - input - } - "#); - - let msg = " lib.plugin and lib.rustc-macro cannot both be true"; - assert_that(questionable.cargo_process("build"), - execs().with_status(101).with_stderr_contains(msg)); -}