Skip to content

Commit 0352866

Browse files
committed
Auto merge of #33378 - oli-obk:fix/registry_args, r=Manishearth
fix Registry::args for plugins loaded with --extra-plugins r? @Manishearth
2 parents 55cabda + 46de0fa commit 0352866

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/librustc_plugin/registry.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@ impl<'a> Registry<'a> {
9292
/// ```no_run
9393
/// #![plugin(my_plugin_name(... args ...))]
9494
/// ```
95-
pub fn args<'b>(&'b self) -> &'b Vec<P<ast::MetaItem>> {
96-
self.args_hidden.as_ref().expect("args not set")
95+
///
96+
/// Returns empty slice in case the plugin was loaded
97+
/// with `--extra-plugins`
98+
pub fn args<'b>(&'b self) -> &'b [P<ast::MetaItem>] {
99+
self.args_hidden.as_ref().map(|v| &v[..]).unwrap_or(&[])
97100
}
98101

99102
/// Register a syntax extension of any kind.

src/test/run-pass-fulldeps/auxiliary/plugin_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl TTMacroExpander for Expander {
4545

4646
#[plugin_registrar]
4747
pub fn plugin_registrar(reg: &mut Registry) {
48-
let args = reg.args().clone();
48+
let args = reg.args().to_owned();
4949
reg.register_syntax_extension(token::intern("plugin_args"),
5050
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
5151
NormalTT(Box::new(Expander { args: args, }), None, false));

0 commit comments

Comments
 (0)