Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8309a4c

Browse files
committedAug 27, 2017
Address review comments, second turn
1 parent 611b111 commit 8309a4c

File tree

9 files changed

+29
-18
lines changed

9 files changed

+29
-18
lines changed
 

‎src/librustc/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ pub struct GlobalCtxt<'tcx> {
797797

798798
pub maybe_unused_trait_imports: NodeSet,
799799

800-
pub maybe_unused_extern_crates: Vec<(NodeId, Span, CrateNum)>,
800+
pub maybe_unused_extern_crates: Vec<(NodeId, Span)>,
801801

802802
// Internal cache for metadata decoding. No need to track deps on this.
803803
pub rcache: RefCell<FxHashMap<ty::CReaderCacheKey, Ty<'tcx>>>,

‎src/librustc/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub struct Resolutions {
131131
pub freevars: FreevarMap,
132132
pub trait_map: TraitMap,
133133
pub maybe_unused_trait_imports: NodeSet,
134-
pub maybe_unused_extern_crates: Vec<(NodeId, Span, CrateNum)>,
134+
pub maybe_unused_extern_crates: Vec<(NodeId, Span)>,
135135
pub export_map: ExportMap,
136136
}
137137

‎src/librustc_resolve/build_reduced_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<'a> Resolver<'a> {
264264
id: item.id,
265265
parent,
266266
imported_module: Cell::new(Some(module)),
267-
subclass: ImportDirectiveSubclass::ExternCrate { cnum: crate_id },
267+
subclass: ImportDirectiveSubclass::ExternCrate,
268268
span: item.span,
269269
module_path: Vec::new(),
270270
vis: Cell::new(vis),

‎src/librustc_resolve/check_unused.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ pub fn check_crate(resolver: &mut Resolver, krate: &ast::Crate) {
120120
_ if directive.used.get() ||
121121
directive.vis.get() == ty::Visibility::Public ||
122122
directive.span.source_equal(&DUMMY_SP) => {}
123-
ImportDirectiveSubclass::ExternCrate { cnum } => {
124-
resolver.maybe_unused_extern_crates.push((directive.id, directive.span, cnum));
123+
ImportDirectiveSubclass::ExternCrate => {
124+
resolver.maybe_unused_extern_crates.push((directive.id, directive.span));
125125
}
126126
ImportDirectiveSubclass::MacroUse => {
127127
let lint = lint::builtin::UNUSED_IMPORTS;

‎src/librustc_resolve/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc::middle::cstore::CrateLoader;
3535
use rustc::session::Session;
3636
use rustc::lint;
3737
use rustc::hir::def::*;
38-
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, CrateNum, DefId};
38+
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
3939
use rustc::ty;
4040
use rustc::hir::{Freevar, FreevarMap, TraitCandidate, TraitMap, GlobMap};
4141
use rustc::util::nodemap::{NodeMap, NodeSet, FxHashMap, FxHashSet, DefIdMap};
@@ -1102,7 +1102,7 @@ impl<'a> NameBinding<'a> {
11021102
match self.kind {
11031103
NameBindingKind::Import {
11041104
directive: &ImportDirective {
1105-
subclass: ImportDirectiveSubclass::ExternCrate { .. }, ..
1105+
subclass: ImportDirectiveSubclass::ExternCrate, ..
11061106
}, ..
11071107
} => true,
11081108
_ => false,
@@ -1250,7 +1250,7 @@ pub struct Resolver<'a> {
12501250

12511251
used_imports: FxHashSet<(NodeId, Namespace)>,
12521252
pub maybe_unused_trait_imports: NodeSet,
1253-
pub maybe_unused_extern_crates: Vec<(NodeId, Span, CrateNum)>,
1253+
pub maybe_unused_extern_crates: Vec<(NodeId, Span)>,
12541254

12551255
/// privacy errors are delayed until the end in order to deduplicate them
12561256
privacy_errors: Vec<PrivacyError<'a>>,

‎src/librustc_resolve/resolve_imports.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use {resolve_error, ResolutionError};
1919

2020
use rustc::ty;
2121
use rustc::lint::builtin::PUB_USE_OF_PRIVATE_EXTERN_CRATE;
22-
use rustc::hir::def_id::{CrateNum, DefId};
22+
use rustc::hir::def_id::DefId;
2323
use rustc::hir::def::*;
2424
use rustc::util::nodemap::{FxHashMap, FxHashSet};
2525

@@ -48,9 +48,7 @@ pub enum ImportDirectiveSubclass<'a> {
4848
max_vis: Cell<ty::Visibility>, // The visibility of the greatest reexport.
4949
// n.b. `max_vis` is only used in `finalize_import` to check for reexport errors.
5050
},
51-
ExternCrate {
52-
cnum: CrateNum,
53-
},
51+
ExternCrate,
5452
MacroUse,
5553
}
5654

@@ -926,7 +924,7 @@ fn import_directive_subclass_to_string(subclass: &ImportDirectiveSubclass) -> St
926924
match *subclass {
927925
SingleImport { source, .. } => source.to_string(),
928926
GlobImport { .. } => "*".to_string(),
929-
ExternCrate { .. } => "<extern crate>".to_string(),
927+
ExternCrate => "<extern crate>".to_string(),
930928
MacroUse => "#[macro_use]".to_string(),
931929
}
932930
}

‎src/librustc_typeck/check_unused.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
7373
let mut visitor = CheckVisitor { tcx, used_trait_imports };
7474
tcx.hir.krate().visit_all_item_likes(&mut visitor);
7575

76-
for &(id, span, cnum) in &tcx.maybe_unused_extern_crates {
77-
if !tcx.is_compiler_builtins(cnum.as_def_id())
78-
&& !tcx.is_panic_runtime(cnum.as_def_id())
79-
&& !tcx.has_global_allocator(cnum.as_def_id()) {
76+
for &(id, span) in &tcx.maybe_unused_extern_crates {
77+
let cnum = tcx.sess.cstore.extern_mod_stmt_cnum(id).unwrap().as_def_id();
78+
if !tcx.is_compiler_builtins(cnum)
79+
&& !tcx.is_panic_runtime(cnum)
80+
&& !tcx.has_global_allocator(cnum) {
8081
let lint = lint::builtin::UNUSED_EXTERN_CRATES;
8182
let msg = "unused extern crate";
8283
tcx.lint_node(lint, id, span, msg);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2017 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.

‎src/test/compile-fail/lint-unused-extern-crate.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
// aux-build:lint_unused_extern_crate2.rs
1313
// aux-build:lint_unused_extern_crate3.rs
1414
// aux-build:lint_unused_extern_crate4.rs
15+
// aux-build:lint_unused_extern_crate5.rs
1516

1617
#![deny(unused_extern_crates)]
1718
#![allow(unused_variables)]
1819
#![allow(deprecated)]
1920

20-
extern crate lint_unused_extern_crate4; //~ ERROR: unused extern crate
21+
extern crate lint_unused_extern_crate5; //~ ERROR: unused extern crate
22+
23+
pub extern crate lint_unused_extern_crate4; // no error, it is reexported
2124

2225
extern crate lint_unused_extern_crate3; // no error, it is used
2326

0 commit comments

Comments
 (0)
Please sign in to comment.