Skip to content

Commit bdd185c

Browse files
committed
Auto merge of #51956 - GuillaumeGomez:shutdown-doc-lints, r=oli-obk
Fix rustdoc run failures by shutting down definitely some lints Fixes #51661. cc @oli-obk @arielb1 @eddyb
2 parents c6807bb + 66beb4e commit bdd185c

File tree

6 files changed

+57
-4
lines changed

6 files changed

+57
-4
lines changed

src/librustc/lint/levels.rs

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

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

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/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnsafeCode {
280280
}
281281

282282
declare_lint! {
283-
MISSING_DOCS,
283+
pub MISSING_DOCS,
284284
Allow,
285285
"detects missing documentation for public members"
286286
}

src/librustc_lint/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use lint::LintId;
5656
use lint::FutureIncompatibleInfo;
5757

5858
mod bad_style;
59-
mod builtin;
59+
pub mod builtin;
6060
mod types;
6161
mod unused;
6262

src/librustdoc/core.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ pub fn run_core(search_paths: SearchPaths,
192192

193193
let intra_link_resolution_failure_name = lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE.name;
194194
let warnings_lint_name = lint::builtin::WARNINGS.name;
195+
let missing_docs = rustc_lint::builtin::MISSING_DOCS.name;
195196
let lints = lint::builtin::HardwiredLints.get_lints()
196197
.into_iter()
197198
.chain(rustc_lint::SoftLints.get_lints().into_iter())
@@ -240,6 +241,26 @@ pub fn run_core(search_paths: SearchPaths,
240241
let mut sess = session::build_session_(
241242
sessopts, cpath, diagnostic_handler, codemap,
242243
);
244+
245+
lint::builtin::HardwiredLints.get_lints()
246+
.into_iter()
247+
.chain(rustc_lint::SoftLints.get_lints().into_iter())
248+
.filter_map(|lint| {
249+
// We don't want to whitelist *all* lints so let's
250+
// ignore those ones.
251+
if lint.name == warnings_lint_name ||
252+
lint.name == intra_link_resolution_failure_name ||
253+
lint.name == missing_docs {
254+
None
255+
} else {
256+
Some(lint)
257+
}
258+
})
259+
.for_each(|l| {
260+
sess.driver_lint_caps.insert(lint::LintId::of(l),
261+
lint::Allow);
262+
});
263+
243264
let codegen_backend = rustc_driver::get_codegen_backend(&sess);
244265
let cstore = Rc::new(CStore::new(codegen_backend.metadata_loader()));
245266
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
@@ -304,7 +325,6 @@ pub fn run_core(search_paths: SearchPaths,
304325
&sess);
305326

306327
let resolver = RefCell::new(resolver);
307-
308328
abort_on_err(driver::phase_3_run_analysis_passes(&*codegen_backend,
309329
control,
310330
&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)