diff options
| -rw-r--r-- | src/libproc_macro_tokens/lib.rs | 2 | ||||
| -rw-r--r-- | src/librustc/lib.rs | 2 | ||||
| -rw-r--r-- | src/librustc_const_math/lib.rs | 4 | ||||
| -rw-r--r-- | src/librustc_driver/lib.rs | 1 | ||||
| -rw-r--r-- | src/librustc_errors/lib.rs | 2 | ||||
| -rw-r--r-- | src/librustc_incremental/lib.rs | 2 | ||||
| -rw-r--r-- | src/librustc_lint/lib.rs | 1 | ||||
| -rw-r--r-- | src/librustc_plugin/Cargo.toml | 1 | ||||
| -rw-r--r-- | src/librustc_plugin/lib.rs | 3 | ||||
| -rw-r--r-- | src/librustc_resolve/build_reduced_graph.rs | 23 | ||||
| -rw-r--r-- | src/librustc_resolve/check_unused.rs | 5 | ||||
| -rw-r--r-- | src/librustc_resolve/macros.rs | 16 | ||||
| -rw-r--r-- | src/librustc_resolve/resolve_imports.rs | 2 | ||||
| -rw-r--r-- | src/libserialize/lib.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/imports/unused-macro-use.rs | 21 | ||||
| -rw-r--r-- | src/test/compile-fail/lint-unused-extern-crate.rs | 2 | ||||
| -rw-r--r-- | src/tools/cargotest/main.rs | 2 |
17 files changed, 67 insertions, 24 deletions
diff --git a/src/libproc_macro_tokens/lib.rs b/src/libproc_macro_tokens/lib.rs index 0dd9aaab1c6..b99b8f29299 100644 --- a/src/libproc_macro_tokens/lib.rs +++ b/src/libproc_macro_tokens/lib.rs @@ -59,7 +59,7 @@ extern crate syntax; extern crate syntax_pos; -#[macro_use] extern crate log; +extern crate log; pub mod build; pub mod parse; diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 151d7cd17ab..bf0829cbdd0 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -57,7 +57,7 @@ extern crate rustc_const_math; extern crate rustc_errors as errors; #[macro_use] extern crate log; #[macro_use] extern crate syntax; -#[macro_use] extern crate syntax_pos; +extern crate syntax_pos; #[macro_use] #[no_link] extern crate rustc_bitflags; extern crate serialize as rustc_serialize; // used by deriving diff --git a/src/librustc_const_math/lib.rs b/src/librustc_const_math/lib.rs index cd933c00599..beecf4cd8eb 100644 --- a/src/librustc_const_math/lib.rs +++ b/src/librustc_const_math/lib.rs @@ -28,8 +28,8 @@ #![feature(const_fn)] #![cfg_attr(not(stage0), feature(i128))] -#[macro_use] extern crate log; -#[macro_use] extern crate syntax; +extern crate log; +extern crate syntax; // SNAP: remove use of this crate extern crate rustc_i128; diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 48eb6f68564..e82ba32c34a 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -57,7 +57,6 @@ extern crate serialize; extern crate rustc_llvm as llvm; #[macro_use] extern crate log; -#[macro_use] extern crate syntax; extern crate syntax_ext; extern crate syntax_pos; diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index bcae7b262c6..7946f6a0a46 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -27,9 +27,7 @@ extern crate serialize; extern crate term; -#[macro_use] extern crate log; -#[macro_use] extern crate libc; extern crate std_unicode; extern crate serialize as rustc_serialize; // used by deriving diff --git a/src/librustc_incremental/lib.rs b/src/librustc_incremental/lib.rs index e96d5977419..2d25baf6960 100644 --- a/src/librustc_incremental/lib.rs +++ b/src/librustc_incremental/lib.rs @@ -30,7 +30,7 @@ extern crate rustc_data_structures; extern crate serialize as rustc_serialize; #[macro_use] extern crate log; -#[macro_use] extern crate syntax; +extern crate syntax; extern crate syntax_pos; extern crate rustc_i128; diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 60497fe171c..34bc57884ec 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -37,7 +37,6 @@ #![feature(slice_patterns)] #![feature(staged_api)] -#[macro_use] extern crate syntax; #[macro_use] extern crate rustc; diff --git a/src/librustc_plugin/Cargo.toml b/src/librustc_plugin/Cargo.toml index 48d4437358c..42d1d3c2ba5 100644 --- a/src/librustc_plugin/Cargo.toml +++ b/src/librustc_plugin/Cargo.toml @@ -13,7 +13,6 @@ crate-type = ["dylib"] log = { path = "../liblog" } rustc = { path = "../librustc" } rustc_back = { path = "../librustc_back" } -rustc_bitflags = { path = "../librustc_bitflags" } rustc_metadata = { path = "../librustc_metadata" } syntax = { path = "../libsyntax" } syntax_pos = { path = "../libsyntax_pos" } diff --git a/src/librustc_plugin/lib.rs b/src/librustc_plugin/lib.rs index 8d4e61ad8e5..8f389499dd6 100644 --- a/src/librustc_plugin/lib.rs +++ b/src/librustc_plugin/lib.rs @@ -63,9 +63,8 @@ #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] -#[macro_use] extern crate log; +extern crate log; #[macro_use] extern crate syntax; -#[macro_use] #[no_link] extern crate rustc_bitflags; extern crate rustc; extern crate rustc_back; diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 0217aefc227..f74af416cde 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -552,16 +552,35 @@ impl<'a> Resolver<'a> { used = true; // Avoid the normal unused extern crate warning } + let (graph_root, arenas) = (self.graph_root, self.arenas); + let macro_use_directive = |span| arenas.alloc_import_directive(ImportDirective { + id: item.id, + parent: graph_root, + imported_module: Cell::new(Some(module)), + subclass: ImportDirectiveSubclass::MacroUse, + span: span, + module_path: Vec::new(), + vis: Cell::new(ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX))), + expansion: expansion, + used: Cell::new(false), + }); + if let Some(span) = legacy_imports.import_all { + let directive = macro_use_directive(span); + self.potentially_unused_imports.push(directive); module.for_each_child(|ident, ns, binding| if ns == MacroNS { - self.legacy_import_macro(ident.name, binding, span, allow_shadowing); + let imported_binding = self.import(binding, directive); + self.legacy_import_macro(ident.name, imported_binding, span, allow_shadowing); }); } else { for (name, span) in legacy_imports.imports { let ident = Ident::with_empty_ctxt(name); let result = self.resolve_ident_in_module(module, ident, MacroNS, false, None); if let Ok(binding) = result { - self.legacy_import_macro(name, binding, span, allow_shadowing); + let directive = macro_use_directive(span); + self.potentially_unused_imports.push(directive); + let imported_binding = self.import(binding, directive); + self.legacy_import_macro(name, imported_binding, span, allow_shadowing); } else { span_err!(self.session, span, E0469, "imported macro not found"); } diff --git a/src/librustc_resolve/check_unused.rs b/src/librustc_resolve/check_unused.rs index 0e44f4556dd..d150ff1ff81 100644 --- a/src/librustc_resolve/check_unused.rs +++ b/src/librustc_resolve/check_unused.rs @@ -125,6 +125,11 @@ pub fn check_crate(resolver: &mut Resolver, krate: &ast::Crate) { let msg = "unused extern crate".to_string(); resolver.session.add_lint(lint, directive.id, directive.span, msg); } + ImportDirectiveSubclass::MacroUse => { + let lint = lint::builtin::UNUSED_IMPORTS; + let msg = "unused `#[macro_use]` import".to_string(); + resolver.session.add_lint(lint, directive.id, directive.span, msg); + } _ => {} } } diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 9b7d6f33a7f..682b3ff834f 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -341,12 +341,15 @@ impl<'a> Resolver<'a> { }; } - let binding = match binding { - Some(binding) => MacroBinding::Legacy(binding), - None => match self.builtin_macros.get(&name).cloned() { - Some(binding) => MacroBinding::Modern(binding), - None => return None, - }, + let binding = if let Some(binding) = binding { + MacroBinding::Legacy(binding) + } else if let Some(binding) = self.builtin_macros.get(&name).cloned() { + if !self.use_extern_macros { + self.record_use(Ident::with_empty_ctxt(name), MacroNS, binding, DUMMY_SP); + } + MacroBinding::Modern(binding) + } else { + return None; }; if !self.use_extern_macros { @@ -378,6 +381,7 @@ impl<'a> Resolver<'a> { let (legacy_resolution, resolution) = match (legacy_resolution, resolution) { (Some(legacy_resolution), Ok(resolution)) => (legacy_resolution, resolution), (Some(MacroBinding::Modern(binding)), Err(_)) => { + self.record_use(ident, MacroNS, binding, span); self.err_if_macro_use_proc_macro(ident.name, span, binding); continue }, diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 8d94fd86b17..65cdeb9253d 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -49,6 +49,7 @@ pub enum ImportDirectiveSubclass<'a> { // n.b. `max_vis` is only used in `finalize_import` to check for reexport errors. }, ExternCrate, + MacroUse, } /// One import directive. @@ -835,5 +836,6 @@ fn import_directive_subclass_to_string(subclass: &ImportDirectiveSubclass) -> St SingleImport { source, .. } => source.to_string(), GlobImport { .. } => "*".to_string(), ExternCrate => "<extern crate>".to_string(), + MacroUse => "#[macro_use]".to_string(), } } diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index cfa09361cce..3d9ce864ec1 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -39,7 +39,7 @@ Core encoding and decoding interfaces. // test harness access #[cfg(test)] extern crate test; -#[macro_use] extern crate log; +extern crate log; extern crate std_unicode; extern crate collections; diff --git a/src/test/compile-fail/imports/unused-macro-use.rs b/src/test/compile-fail/imports/unused-macro-use.rs new file mode 100644 index 00000000000..365521970cd --- /dev/null +++ b/src/test/compile-fail/imports/unused-macro-use.rs @@ -0,0 +1,21 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![deny(unused)] + +#[macro_use] //~ ERROR unused `#[macro_use]` import +extern crate core; + +#[macro_use( + panic //~ ERROR unused `#[macro_use]` import +)] +extern crate core as core_2; + +fn main() {} diff --git a/src/test/compile-fail/lint-unused-extern-crate.rs b/src/test/compile-fail/lint-unused-extern-crate.rs index 515e3b833d9..40671353f8a 100644 --- a/src/test/compile-fail/lint-unused-extern-crate.rs +++ b/src/test/compile-fail/lint-unused-extern-crate.rs @@ -26,8 +26,6 @@ extern crate rand; // no error, the use marks it as used extern crate lint_unused_extern_crate as other; // no error, the use * marks it as used -#[macro_use] extern crate core; // no error, the `#[macro_use]` marks it as used - #[allow(unused_imports)] use rand::isaac::IsaacRng; diff --git a/src/tools/cargotest/main.rs b/src/tools/cargotest/main.rs index 8a891d624f4..83fd766c547 100644 --- a/src/tools/cargotest/main.rs +++ b/src/tools/cargotest/main.rs @@ -25,7 +25,7 @@ const TEST_REPOS: &'static [Test] = &[ Test { name: "cargo", repo: "https://github.com/rust-lang/cargo", - sha: "b7be4f2ef2cf743492edc6dfb55d087ed88f2d76", + sha: "2324c2bbaf7fc6ea9cbdd77c034ef1af769cb617", lock: None, }, Test { |
