Skip to content

Commit 356fa2c

Browse files
committed
Warn on unused #[macro_use] imports.
1 parent 2efec3c commit 356fa2c

File tree

17 files changed

+67
-24
lines changed

17 files changed

+67
-24
lines changed

src/libproc_macro_tokens/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
extern crate syntax;
6161
extern crate syntax_pos;
62-
#[macro_use] extern crate log;
62+
extern crate log;
6363

6464
pub mod build;
6565
pub mod parse;

src/librustc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ extern crate rustc_const_math;
5757
extern crate rustc_errors as errors;
5858
#[macro_use] extern crate log;
5959
#[macro_use] extern crate syntax;
60-
#[macro_use] extern crate syntax_pos;
60+
extern crate syntax_pos;
6161
#[macro_use] #[no_link] extern crate rustc_bitflags;
6262

6363
extern crate serialize as rustc_serialize; // used by deriving

src/librustc_const_math/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
#![feature(const_fn)]
2929
#![cfg_attr(not(stage0), feature(i128))]
3030

31-
#[macro_use] extern crate log;
32-
#[macro_use] extern crate syntax;
31+
extern crate log;
32+
extern crate syntax;
3333

3434
// SNAP: remove use of this crate
3535
extern crate rustc_i128;

src/librustc_driver/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ extern crate serialize;
5757
extern crate rustc_llvm as llvm;
5858
#[macro_use]
5959
extern crate log;
60-
#[macro_use]
6160
extern crate syntax;
6261
extern crate syntax_ext;
6362
extern crate syntax_pos;

src/librustc_errors/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727

2828
extern crate serialize;
2929
extern crate term;
30-
#[macro_use]
3130
extern crate log;
32-
#[macro_use]
3331
extern crate libc;
3432
extern crate std_unicode;
3533
extern crate serialize as rustc_serialize; // used by deriving

src/librustc_incremental/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extern crate rustc_data_structures;
3030
extern crate serialize as rustc_serialize;
3131

3232
#[macro_use] extern crate log;
33-
#[macro_use] extern crate syntax;
33+
extern crate syntax;
3434
extern crate syntax_pos;
3535

3636
extern crate rustc_i128;

src/librustc_lint/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#![feature(slice_patterns)]
3838
#![feature(staged_api)]
3939

40-
#[macro_use]
4140
extern crate syntax;
4241
#[macro_use]
4342
extern crate rustc;

src/librustc_plugin/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ crate-type = ["dylib"]
1313
log = { path = "../liblog" }
1414
rustc = { path = "../librustc" }
1515
rustc_back = { path = "../librustc_back" }
16-
rustc_bitflags = { path = "../librustc_bitflags" }
1716
rustc_metadata = { path = "../librustc_metadata" }
1817
syntax = { path = "../libsyntax" }
1918
syntax_pos = { path = "../libsyntax_pos" }

src/librustc_plugin/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@
6363
#![feature(rustc_diagnostic_macros)]
6464
#![feature(rustc_private)]
6565

66-
#[macro_use] extern crate log;
66+
extern crate log;
6767
#[macro_use] extern crate syntax;
68-
#[macro_use] #[no_link] extern crate rustc_bitflags;
6968

7069
extern crate rustc;
7170
extern crate rustc_back;

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,16 +552,35 @@ impl<'a> Resolver<'a> {
552552
used = true; // Avoid the normal unused extern crate warning
553553
}
554554

555+
let (graph_root, arenas) = (self.graph_root, self.arenas);
556+
let macro_use_directive = |span| arenas.alloc_import_directive(ImportDirective {
557+
id: item.id,
558+
parent: graph_root,
559+
imported_module: Cell::new(Some(module)),
560+
subclass: ImportDirectiveSubclass::MacroUse,
561+
span: span,
562+
module_path: Vec::new(),
563+
vis: Cell::new(ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX))),
564+
expansion: expansion,
565+
used: Cell::new(false),
566+
});
567+
555568
if let Some(span) = legacy_imports.import_all {
569+
let directive = macro_use_directive(span);
570+
self.potentially_unused_imports.push(directive);
556571
module.for_each_child(|ident, ns, binding| if ns == MacroNS {
557-
self.legacy_import_macro(ident.name, binding, span, allow_shadowing);
572+
let imported_binding = self.import(binding, directive);
573+
self.legacy_import_macro(ident.name, imported_binding, span, allow_shadowing);
558574
});
559575
} else {
560576
for (name, span) in legacy_imports.imports {
561577
let ident = Ident::with_empty_ctxt(name);
562578
let result = self.resolve_ident_in_module(module, ident, MacroNS, false, None);
563579
if let Ok(binding) = result {
564-
self.legacy_import_macro(name, binding, span, allow_shadowing);
580+
let directive = macro_use_directive(span);
581+
self.potentially_unused_imports.push(directive);
582+
let imported_binding = self.import(binding, directive);
583+
self.legacy_import_macro(name, imported_binding, span, allow_shadowing);
565584
} else {
566585
span_err!(self.session, span, E0469, "imported macro not found");
567586
}

0 commit comments

Comments
 (0)