Address review comments, second turn
This commit is contained in:
parent
611b111139
commit
8309a4c43b
9 changed files with 29 additions and 18 deletions
|
@ -797,7 +797,7 @@ pub struct GlobalCtxt<'tcx> {
|
||||||
|
|
||||||
pub maybe_unused_trait_imports: NodeSet,
|
pub maybe_unused_trait_imports: NodeSet,
|
||||||
|
|
||||||
pub maybe_unused_extern_crates: Vec<(NodeId, Span, CrateNum)>,
|
pub maybe_unused_extern_crates: Vec<(NodeId, Span)>,
|
||||||
|
|
||||||
// Internal cache for metadata decoding. No need to track deps on this.
|
// Internal cache for metadata decoding. No need to track deps on this.
|
||||||
pub rcache: RefCell<FxHashMap<ty::CReaderCacheKey, Ty<'tcx>>>,
|
pub rcache: RefCell<FxHashMap<ty::CReaderCacheKey, Ty<'tcx>>>,
|
||||||
|
|
|
@ -131,7 +131,7 @@ pub struct Resolutions {
|
||||||
pub freevars: FreevarMap,
|
pub freevars: FreevarMap,
|
||||||
pub trait_map: TraitMap,
|
pub trait_map: TraitMap,
|
||||||
pub maybe_unused_trait_imports: NodeSet,
|
pub maybe_unused_trait_imports: NodeSet,
|
||||||
pub maybe_unused_extern_crates: Vec<(NodeId, Span, CrateNum)>,
|
pub maybe_unused_extern_crates: Vec<(NodeId, Span)>,
|
||||||
pub export_map: ExportMap,
|
pub export_map: ExportMap,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -264,7 +264,7 @@ impl<'a> Resolver<'a> {
|
||||||
id: item.id,
|
id: item.id,
|
||||||
parent,
|
parent,
|
||||||
imported_module: Cell::new(Some(module)),
|
imported_module: Cell::new(Some(module)),
|
||||||
subclass: ImportDirectiveSubclass::ExternCrate { cnum: crate_id },
|
subclass: ImportDirectiveSubclass::ExternCrate,
|
||||||
span: item.span,
|
span: item.span,
|
||||||
module_path: Vec::new(),
|
module_path: Vec::new(),
|
||||||
vis: Cell::new(vis),
|
vis: Cell::new(vis),
|
||||||
|
|
|
@ -120,8 +120,8 @@ pub fn check_crate(resolver: &mut Resolver, krate: &ast::Crate) {
|
||||||
_ if directive.used.get() ||
|
_ if directive.used.get() ||
|
||||||
directive.vis.get() == ty::Visibility::Public ||
|
directive.vis.get() == ty::Visibility::Public ||
|
||||||
directive.span.source_equal(&DUMMY_SP) => {}
|
directive.span.source_equal(&DUMMY_SP) => {}
|
||||||
ImportDirectiveSubclass::ExternCrate { cnum } => {
|
ImportDirectiveSubclass::ExternCrate => {
|
||||||
resolver.maybe_unused_extern_crates.push((directive.id, directive.span, cnum));
|
resolver.maybe_unused_extern_crates.push((directive.id, directive.span));
|
||||||
}
|
}
|
||||||
ImportDirectiveSubclass::MacroUse => {
|
ImportDirectiveSubclass::MacroUse => {
|
||||||
let lint = lint::builtin::UNUSED_IMPORTS;
|
let lint = lint::builtin::UNUSED_IMPORTS;
|
||||||
|
|
|
@ -35,7 +35,7 @@ use rustc::middle::cstore::CrateLoader;
|
||||||
use rustc::session::Session;
|
use rustc::session::Session;
|
||||||
use rustc::lint;
|
use rustc::lint;
|
||||||
use rustc::hir::def::*;
|
use rustc::hir::def::*;
|
||||||
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, CrateNum, DefId};
|
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
|
||||||
use rustc::ty;
|
use rustc::ty;
|
||||||
use rustc::hir::{Freevar, FreevarMap, TraitCandidate, TraitMap, GlobMap};
|
use rustc::hir::{Freevar, FreevarMap, TraitCandidate, TraitMap, GlobMap};
|
||||||
use rustc::util::nodemap::{NodeMap, NodeSet, FxHashMap, FxHashSet, DefIdMap};
|
use rustc::util::nodemap::{NodeMap, NodeSet, FxHashMap, FxHashSet, DefIdMap};
|
||||||
|
@ -1102,7 +1102,7 @@ impl<'a> NameBinding<'a> {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
NameBindingKind::Import {
|
NameBindingKind::Import {
|
||||||
directive: &ImportDirective {
|
directive: &ImportDirective {
|
||||||
subclass: ImportDirectiveSubclass::ExternCrate { .. }, ..
|
subclass: ImportDirectiveSubclass::ExternCrate, ..
|
||||||
}, ..
|
}, ..
|
||||||
} => true,
|
} => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
|
@ -1250,7 +1250,7 @@ pub struct Resolver<'a> {
|
||||||
|
|
||||||
used_imports: FxHashSet<(NodeId, Namespace)>,
|
used_imports: FxHashSet<(NodeId, Namespace)>,
|
||||||
pub maybe_unused_trait_imports: NodeSet,
|
pub maybe_unused_trait_imports: NodeSet,
|
||||||
pub maybe_unused_extern_crates: Vec<(NodeId, Span, CrateNum)>,
|
pub maybe_unused_extern_crates: Vec<(NodeId, Span)>,
|
||||||
|
|
||||||
/// privacy errors are delayed until the end in order to deduplicate them
|
/// privacy errors are delayed until the end in order to deduplicate them
|
||||||
privacy_errors: Vec<PrivacyError<'a>>,
|
privacy_errors: Vec<PrivacyError<'a>>,
|
||||||
|
|
|
@ -19,7 +19,7 @@ use {resolve_error, ResolutionError};
|
||||||
|
|
||||||
use rustc::ty;
|
use rustc::ty;
|
||||||
use rustc::lint::builtin::PUB_USE_OF_PRIVATE_EXTERN_CRATE;
|
use rustc::lint::builtin::PUB_USE_OF_PRIVATE_EXTERN_CRATE;
|
||||||
use rustc::hir::def_id::{CrateNum, DefId};
|
use rustc::hir::def_id::DefId;
|
||||||
use rustc::hir::def::*;
|
use rustc::hir::def::*;
|
||||||
use rustc::util::nodemap::{FxHashMap, FxHashSet};
|
use rustc::util::nodemap::{FxHashMap, FxHashSet};
|
||||||
|
|
||||||
|
@ -48,9 +48,7 @@ pub enum ImportDirectiveSubclass<'a> {
|
||||||
max_vis: Cell<ty::Visibility>, // The visibility of the greatest reexport.
|
max_vis: Cell<ty::Visibility>, // The visibility of the greatest reexport.
|
||||||
// n.b. `max_vis` is only used in `finalize_import` to check for reexport errors.
|
// n.b. `max_vis` is only used in `finalize_import` to check for reexport errors.
|
||||||
},
|
},
|
||||||
ExternCrate {
|
ExternCrate,
|
||||||
cnum: CrateNum,
|
|
||||||
},
|
|
||||||
MacroUse,
|
MacroUse,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -926,7 +924,7 @@ fn import_directive_subclass_to_string(subclass: &ImportDirectiveSubclass) -> St
|
||||||
match *subclass {
|
match *subclass {
|
||||||
SingleImport { source, .. } => source.to_string(),
|
SingleImport { source, .. } => source.to_string(),
|
||||||
GlobImport { .. } => "*".to_string(),
|
GlobImport { .. } => "*".to_string(),
|
||||||
ExternCrate { .. } => "<extern crate>".to_string(),
|
ExternCrate => "<extern crate>".to_string(),
|
||||||
MacroUse => "#[macro_use]".to_string(),
|
MacroUse => "#[macro_use]".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,10 +73,11 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||||
let mut visitor = CheckVisitor { tcx, used_trait_imports };
|
let mut visitor = CheckVisitor { tcx, used_trait_imports };
|
||||||
tcx.hir.krate().visit_all_item_likes(&mut visitor);
|
tcx.hir.krate().visit_all_item_likes(&mut visitor);
|
||||||
|
|
||||||
for &(id, span, cnum) in &tcx.maybe_unused_extern_crates {
|
for &(id, span) in &tcx.maybe_unused_extern_crates {
|
||||||
if !tcx.is_compiler_builtins(cnum.as_def_id())
|
let cnum = tcx.sess.cstore.extern_mod_stmt_cnum(id).unwrap().as_def_id();
|
||||||
&& !tcx.is_panic_runtime(cnum.as_def_id())
|
if !tcx.is_compiler_builtins(cnum)
|
||||||
&& !tcx.has_global_allocator(cnum.as_def_id()) {
|
&& !tcx.is_panic_runtime(cnum)
|
||||||
|
&& !tcx.has_global_allocator(cnum) {
|
||||||
let lint = lint::builtin::UNUSED_EXTERN_CRATES;
|
let lint = lint::builtin::UNUSED_EXTERN_CRATES;
|
||||||
let msg = "unused extern crate";
|
let msg = "unused extern crate";
|
||||||
tcx.lint_node(lint, id, span, msg);
|
tcx.lint_node(lint, id, span, msg);
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
// Copyright 2017 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.
|
|
@ -12,12 +12,15 @@
|
||||||
// aux-build:lint_unused_extern_crate2.rs
|
// aux-build:lint_unused_extern_crate2.rs
|
||||||
// aux-build:lint_unused_extern_crate3.rs
|
// aux-build:lint_unused_extern_crate3.rs
|
||||||
// aux-build:lint_unused_extern_crate4.rs
|
// aux-build:lint_unused_extern_crate4.rs
|
||||||
|
// aux-build:lint_unused_extern_crate5.rs
|
||||||
|
|
||||||
#![deny(unused_extern_crates)]
|
#![deny(unused_extern_crates)]
|
||||||
#![allow(unused_variables)]
|
#![allow(unused_variables)]
|
||||||
#![allow(deprecated)]
|
#![allow(deprecated)]
|
||||||
|
|
||||||
extern crate lint_unused_extern_crate4; //~ ERROR: unused extern crate
|
extern crate lint_unused_extern_crate5; //~ ERROR: unused extern crate
|
||||||
|
|
||||||
|
pub extern crate lint_unused_extern_crate4; // no error, it is reexported
|
||||||
|
|
||||||
extern crate lint_unused_extern_crate3; // no error, it is used
|
extern crate lint_unused_extern_crate3; // no error, it is used
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue