]> git.lizzy.rs Git - rust.git/commitdiff
fix Registry::args for plugins loaded with --extra-plugins
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Tue, 3 May 2016 15:20:48 +0000 (17:20 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Tue, 10 May 2016 11:36:39 +0000 (13:36 +0200)
src/librustc_plugin/registry.rs
src/test/run-pass-fulldeps/auxiliary/plugin_args.rs

index 3cfd6a76dda63005649773a72f86d92d936d66ca..dc5a38bb7647ee6d2974c4e9f7a611a2b093be0b 100644 (file)
@@ -92,8 +92,11 @@ pub fn new(sess: &'a Session, krate: &ast::Crate) -> Registry<'a> {
     /// ```no_run
     /// #![plugin(my_plugin_name(... args ...))]
     /// ```
-    pub fn args<'b>(&'b self) -> &'b Vec<P<ast::MetaItem>> {
-        self.args_hidden.as_ref().expect("args not set")
+    ///
+    /// Returns empty slice in case the plugin was loaded
+    /// with `--extra-plugins`
+    pub fn args<'b>(&'b self) -> &'b [P<ast::MetaItem>] {
+        self.args_hidden.as_ref().map(|v| &v[..]).unwrap_or(&[])
     }
 
     /// Register a syntax extension of any kind.
index f6e80266a15f51f679b09f1f2e227f8072a79062..99321ad42418dd8f0b2dddb61b84e1289e25e514 100644 (file)
@@ -45,7 +45,7 @@ fn expand<'cx>(&self,
 
 #[plugin_registrar]
 pub fn plugin_registrar(reg: &mut Registry) {
-    let args = reg.args().clone();
+    let args = reg.args().to_owned();
     reg.register_syntax_extension(token::intern("plugin_args"),
         // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
         NormalTT(Box::new(Expander { args: args, }), None, false));