Skip to content

Commit 117eb68

Browse files
committedJan 23, 2018
Rollup merge of rust-lang#47655 - etaoins:fix-spurious-warning-on-empty-proc-macro-crate, r=alexcrichton
Fix spurious warning on empty proc macro crates While attempting to reproduce rust-lang#47086 I noticed the following warning: ```shell > rustc /dev/null --crate-type proc-macro warning: unused variable: `registrar` --> /dev/null:0:1 ``` As there are no macros to register the automatically generated registrar function for the crate has no body. As a result its `registrar` argument is unused triggering the above warning. The warning is confusing and not easily actionable by the developer. It could also be triggered legitimately by e.g. having all of the macros in a crate #[cfg]'ed out. Fix by naming the generated argument `_registrar` inside `mk_registrar()`. This suppresses the unused variable warning.
2 parents 9d26a25 + e1bffbd commit 117eb68

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed
 

‎src/libsyntax_ext/proc_macro_registrar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ fn mk_registrar(cx: &mut ExtCtxt,
381381

382382
let __internal = Ident::from_str("__internal");
383383
let registry = Ident::from_str("Registry");
384-
let registrar = Ident::from_str("registrar");
384+
let registrar = Ident::from_str("_registrar");
385385
let register_custom_derive = Ident::from_str("register_custom_derive");
386386
let register_attr_proc_macro = Ident::from_str("register_attr_proc_macro");
387387
let register_bang_proc_macro = Ident::from_str("register_bang_proc_macro");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// no-prefer-dynamic
12+
13+
#![crate_type = "proc-macro"]
14+
#![deny(unused_variables)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:empty-crate.rs
12+
// ignore-stage1
13+
14+
#[macro_use]
15+
extern crate empty_crate;
16+
17+
fn main() {}

0 commit comments

Comments
 (0)