Skip to content

Commit 1ff7f04

Browse files
Fix rustdoc run failures by shutting down definitely some lints
1 parent 94eb176 commit 1ff7f04

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

src/librustc/lint/levels.rs

+5
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ impl LintLevelSets {
118118
// Ensure that we never exceed the `--cap-lints` argument.
119119
level = cmp::min(level, self.lint_cap);
120120

121+
if let Some(driver_level) = sess.driver_lint_caps.get(&LintId::of(lint)) {
122+
// Ensure that we never exceed driver level.
123+
level = cmp::min(*driver_level, level);
124+
}
125+
121126
return (level, src)
122127
}
123128

src/librustc/session/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use middle::dependency_format;
2222
use session::search_paths::PathKind;
2323
use session::config::{OutputType};
2424
use ty::tls;
25-
use util::nodemap::{FxHashSet};
25+
use util::nodemap::{FxHashMap, FxHashSet};
2626
use util::common::{duration_to_secs_str, ErrorReported};
2727
use util::common::ProfileQueriesMsg;
2828

@@ -160,6 +160,9 @@ pub struct Session {
160160

161161
/// Metadata about the allocators for the current crate being compiled
162162
pub has_global_allocator: Once<bool>,
163+
164+
/// Cap lint level specified by a driver specifically.
165+
pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
163166
}
164167

165168
pub struct PerfStats {
@@ -1164,6 +1167,7 @@ pub fn build_session_(
11641167
(*GLOBAL_JOBSERVER).clone()
11651168
},
11661169
has_global_allocator: Once::new(),
1170+
driver_lint_caps: FxHashMap(),
11671171
};
11681172

11691173
sess

src/librustdoc/core.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,14 @@ pub fn run_core(search_paths: SearchPaths,
235235
let mut sess = session::build_session_(
236236
sessopts, cpath, diagnostic_handler, codemap,
237237
);
238+
239+
let shutdown_lints = [lint::builtin::UNUSED_IMPORTS,
240+
lint::builtin::UNUSED_EXTERN_CRATES];
241+
242+
for l in &shutdown_lints {
243+
sess.driver_lint_caps.insert(lint::LintId::of(l), lint::Allow);
244+
}
245+
238246
let codegen_backend = rustc_driver::get_codegen_backend(&sess);
239247
let cstore = Rc::new(CStore::new(codegen_backend.metadata_loader()));
240248
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
@@ -299,7 +307,6 @@ pub fn run_core(search_paths: SearchPaths,
299307
&sess);
300308

301309
let resolver = RefCell::new(resolver);
302-
303310
abort_on_err(driver::phase_3_run_analysis_passes(&*codegen_backend,
304311
control,
305312
&sess,

src/test/rustdoc-ui/unused.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2018 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.
10+
11+
// compile-pass
12+
13+
// This test purpose is to check that unused_imports lint isn't fired
14+
// by rustdoc. Why would it? Because when rustdoc is running, it uses
15+
// "everybody-loops" which replaces parts of code with "loop {}" to get
16+
// huge performance improvements.
17+
18+
#![deny(unused_imports)]
19+
20+
use std::fs::File;
21+
22+
pub fn f() {
23+
let _: File;
24+
}

0 commit comments

Comments
 (0)