diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs index 3393a2bf89d..f8676a3e7a1 100644 --- a/src/librustc/lint/levels.rs +++ b/src/librustc/lint/levels.rs @@ -118,6 +118,11 @@ impl LintLevelSets { // Ensure that we never exceed the `--cap-lints` argument. level = cmp::min(level, self.lint_cap); + if let Some(driver_level) = sess.driver_lint_caps.get(&LintId::of(lint)) { + // Ensure that we never exceed driver level. + level = cmp::min(*driver_level, level); + } + return (level, src) } diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 076d56fb808..180c5867e93 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -22,7 +22,7 @@ use middle::dependency_format; use session::search_paths::PathKind; use session::config::{OutputType}; use ty::tls; -use util::nodemap::{FxHashSet}; +use util::nodemap::{FxHashMap, FxHashSet}; use util::common::{duration_to_secs_str, ErrorReported}; use util::common::ProfileQueriesMsg; @@ -160,6 +160,9 @@ pub struct Session { /// Metadata about the allocators for the current crate being compiled pub has_global_allocator: Once, + + /// Cap lint level specified by a driver specifically. + pub driver_lint_caps: FxHashMap, } pub struct PerfStats { @@ -1164,6 +1167,7 @@ pub fn build_session_( (*GLOBAL_JOBSERVER).clone() }, has_global_allocator: Once::new(), + driver_lint_caps: FxHashMap(), }; sess diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index ddc9bdb384c..5cfdd07ab92 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -235,6 +235,14 @@ pub fn run_core(search_paths: SearchPaths, let mut sess = session::build_session_( sessopts, cpath, diagnostic_handler, codemap, ); + + let shutdown_lints = [lint::builtin::UNUSED_IMPORTS, + lint::builtin::UNUSED_EXTERN_CRATES]; + + for l in &shutdown_lints { + sess.driver_lint_caps.insert(lint::LintId::of(l), lint::Allow); + } + let codegen_backend = rustc_driver::get_codegen_backend(&sess); let cstore = Rc::new(CStore::new(codegen_backend.metadata_loader())); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); @@ -299,7 +307,6 @@ pub fn run_core(search_paths: SearchPaths, &sess); let resolver = RefCell::new(resolver); - abort_on_err(driver::phase_3_run_analysis_passes(&*codegen_backend, control, &sess, diff --git a/src/test/rustdoc-ui/unused.rs b/src/test/rustdoc-ui/unused.rs new file mode 100644 index 00000000000..8b530986392 --- /dev/null +++ b/src/test/rustdoc-ui/unused.rs @@ -0,0 +1,24 @@ +// Copyright 2018 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-pass + +// This test purpose is to check that unused_imports lint isn't fired +// by rustdoc. Why would it? Because when rustdoc is running, it uses +// "everybody-loops" which replaces parts of code with "loop {}" to get +// huge performance improvements. + +#![deny(unused_imports)] + +use std::fs::File; + +pub fn f() { + let _: File; +}