From 60be2f52d2434dfbf2df7728454d572d76f58bf8 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Wed, 31 Dec 2014 20:43:46 -0800 Subject: Replace #[phase] with #[plugin] / #[macro_use] / #[no_link] --- src/librustc/plugin/load.rs | 34 ++++++++++++++++++++++------------ src/librustc/plugin/mod.rs | 8 ++++---- 2 files changed, 26 insertions(+), 16 deletions(-) (limited to 'src/librustc/plugin') diff --git a/src/librustc/plugin/load.rs b/src/librustc/plugin/load.rs index 78730defc7f..d17ef199aa1 100644 --- a/src/librustc/plugin/load.rs +++ b/src/librustc/plugin/load.rs @@ -84,26 +84,36 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> { _ => return, } - let mut plugin_phase = false; - for attr in vi.attrs.iter().filter(|a| a.check_name("phase")) { - let phases = attr.meta_item_list().unwrap_or(&[]); - if attr::contains_name(phases, "plugin") { - plugin_phase = true; + // Parse the attributes relating to macro / plugin loading. + let mut load_macros = false; + let mut load_registrar = false; + for attr in vi.attrs.iter() { + let mut used = true; + match attr.name().get() { + "phase" => { + self.sess.span_err(attr.span, "#[phase] is deprecated; use \ + #[macro_use], #[plugin], and/or #[no_link]"); + } + "plugin" => load_registrar = true, + "macro_use" => load_macros = true, + _ => used = false, } - if attr::contains_name(phases, "syntax") { - plugin_phase = true; - self.sess.span_warn(attr.span, - "phase(syntax) is a deprecated synonym for phase(plugin)"); + if used { + attr::mark_used(attr); } } let mut macros = vec![]; let mut registrar = None; - if plugin_phase { + if load_macros || load_registrar { let pmd = self.reader.read_plugin_metadata(vi); - macros = pmd.exported_macros(); - registrar = pmd.plugin_registrar(); + if load_macros { + macros = pmd.exported_macros(); + } + if load_registrar { + registrar = pmd.plugin_registrar(); + } } self.plugins.macros.extend(macros.into_iter()); diff --git a/src/librustc/plugin/mod.rs b/src/librustc/plugin/mod.rs index 8dd60880cdd..fd8873454b4 100644 --- a/src/librustc/plugin/mod.rs +++ b/src/librustc/plugin/mod.rs @@ -43,14 +43,14 @@ //! To use a plugin while compiling another crate: //! //! ```rust -//! #![feature(phase)] +//! #![feature(plugin)] //! -//! #[phase(plugin)] +//! #[plugin] //! extern crate myplugin; //! ``` //! -//! If you also need the plugin crate available at runtime, use -//! `phase(plugin, link)`. +//! If you don't need the plugin crate available at runtime, use +//! `#[no_link]` as well. //! //! See [the compiler plugin guide](../../guide-plugin.html) //! for more examples. -- cgit 1.4.1-3-g733a5