Skip to content

Commit

Permalink
Auto merge of #51956 - GuillaumeGomez:shutdown-doc-lints, r=oli-obk
Browse files Browse the repository at this point in the history
Fix rustdoc run failures by shutting down definitely some lints

Fixes #51661.

cc @oli-obk @arielb1 @eddyb
  • Loading branch information
bors committed Jul 9, 2018
2 parents c6807bb + 66beb4e commit bdd185c
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/librustc/lint/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,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)
}

Expand Down
6 changes: 5 additions & 1 deletion src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -160,6 +160,9 @@ pub struct Session {

/// Metadata about the allocators for the current crate being compiled
pub has_global_allocator: Once<bool>,

/// Cap lint level specified by a driver specifically.
pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
}

pub struct PerfStats {
Expand Down Expand Up @@ -1164,6 +1167,7 @@ pub fn build_session_(
(*GLOBAL_JOBSERVER).clone()
},
has_global_allocator: Once::new(),
driver_lint_caps: FxHashMap(),
};

sess
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnsafeCode {
}

declare_lint! {
MISSING_DOCS,
pub MISSING_DOCS,
Allow,
"detects missing documentation for public members"
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use lint::LintId;
use lint::FutureIncompatibleInfo;

mod bad_style;
mod builtin;
pub mod builtin;
mod types;
mod unused;

Expand Down
22 changes: 21 additions & 1 deletion src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ pub fn run_core(search_paths: SearchPaths,

let intra_link_resolution_failure_name = lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE.name;
let warnings_lint_name = lint::builtin::WARNINGS.name;
let missing_docs = rustc_lint::builtin::MISSING_DOCS.name;
let lints = lint::builtin::HardwiredLints.get_lints()
.into_iter()
.chain(rustc_lint::SoftLints.get_lints().into_iter())
Expand Down Expand Up @@ -240,6 +241,26 @@ pub fn run_core(search_paths: SearchPaths,
let mut sess = session::build_session_(
sessopts, cpath, diagnostic_handler, codemap,
);

lint::builtin::HardwiredLints.get_lints()
.into_iter()
.chain(rustc_lint::SoftLints.get_lints().into_iter())
.filter_map(|lint| {
// We don't want to whitelist *all* lints so let's
// ignore those ones.
if lint.name == warnings_lint_name ||
lint.name == intra_link_resolution_failure_name ||
lint.name == missing_docs {
None
} else {
Some(lint)
}
})
.for_each(|l| {
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));
Expand Down Expand Up @@ -304,7 +325,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,
Expand Down
24 changes: 24 additions & 0 deletions src/test/rustdoc-ui/unused.rs
Original file line number Diff line number Diff line change
@@ -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 <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.

// 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;
}

0 comments on commit bdd185c

Please sign in to comment.