Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support --cap-lints in rustdoc. #5765

Merged
merged 1 commit into from
Jul 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,7 @@ fn rustc<'a, 'cfg>(
let name = unit.pkg.name().to_string();
let buildkey = unit.buildkey();

// If this is an upstream dep we don't want warnings from, turn off all
// lints.
if !cx.bcx.show_warnings(unit.pkg.package_id()) {
rustc.arg("--cap-lints").arg("allow");

// If this is an upstream dep but we *do* want warnings, make sure that they
// don't fail compilation.
} else if !unit.pkg.package_id().source_id().is_path() {
rustc.arg("--cap-lints").arg("warn");
}
add_cap_lints(cx.bcx, unit, &mut rustc);

let outputs = cx.outputs(unit)?;
let root = cx.files().out_dir(unit);
Expand Down Expand Up @@ -575,7 +566,8 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
let mut rustdoc = cx.compilation.rustdoc_process(unit.pkg)?;
rustdoc.inherit_jobserver(&cx.jobserver);
rustdoc.arg("--crate-name").arg(&unit.target.crate_name());
add_path_args(&cx.bcx, unit, &mut rustdoc);
add_path_args(bcx, unit, &mut rustdoc);
add_cap_lints(bcx, unit, &mut rustdoc);

if unit.kind != Kind::Host {
if let Some(ref target) = bcx.build_config.requested_target {
Expand Down Expand Up @@ -655,6 +647,19 @@ fn add_path_args(bcx: &BuildContext, unit: &Unit, cmd: &mut ProcessBuilder) {
cmd.cwd(cwd);
}

fn add_cap_lints(bcx: &BuildContext, unit: &Unit, cmd: &mut ProcessBuilder) {
// If this is an upstream dep we don't want warnings from, turn off all
// lints.
if !bcx.show_warnings(unit.pkg.package_id()) {
cmd.arg("--cap-lints").arg("allow");

// If this is an upstream dep but we *do* want warnings, make sure that they
// don't fail compilation.
} else if !unit.pkg.package_id().source_id().is_path() {
cmd.arg("--cap-lints").arg("warn");
}
}

fn build_base_args<'a, 'cfg>(
cx: &mut Context<'a, 'cfg>,
cmd: &mut ProcessBuilder,
Expand Down
76 changes: 74 additions & 2 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use std::str;
use std::fs::{self, File};
use std::io::Read;

use cargotest::{rustc_host, ChannelChanger};
use cargotest::support::{execs, project, path2url};
use cargotest::{is_nightly, rustc_host, ChannelChanger};
use cargotest::support::{basic_lib_manifest, execs, git, project, path2url};
use cargotest::support::paths::CargoPathExt;
use cargotest::support::registry::Package;
use hamcrest::{assert_that, existing_dir, existing_file, is_not};
use cargo::util::ProcessError;
Expand Down Expand Up @@ -1392,6 +1393,10 @@ fn doc_virtual_manifest_all_implied() {

#[test]
fn doc_all_member_dependency_same_name() {
if !is_nightly() {
// This can be removed once 1.29 is stable (rustdoc --cap-lints).
return;
}
let p = project()
.file(
"Cargo.toml",
Expand Down Expand Up @@ -1625,6 +1630,10 @@ fn doc_edition() {
// caused `cargo doc` to fail.
#[test]
fn issue_5345() {
if !is_nightly() {
// This can be removed once 1.29 is stable (rustdoc --cap-lints).
return;
}
let foo = project()
.file(
"Cargo.toml",
Expand Down Expand Up @@ -1668,3 +1677,66 @@ fn doc_private_items() {
assert_that(&foo.root().join("target/doc"), existing_dir());
assert_that(&foo.root().join("target/doc/foo/private/index.html"), existing_file());
}

#[test]
fn doc_cap_lints() {
if !is_nightly() {
// This can be removed once 1.29 is stable (rustdoc --cap-lints).
return;
}
let a = git::new("a", |p| {
p.file("Cargo.toml", &basic_lib_manifest("a")).file(
"src/lib.rs",
"
#![deny(intra_doc_link_resolution_failure)]

/// [bad_link]
pub fn foo() {}
",
)
}).unwrap();

let p = project()
.file(
"Cargo.toml",
&format!(
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []

[dependencies]
a = {{ git = '{}' }}
"#,
a.url()
),
)
.file("src/lib.rs", "")
.build();

assert_that(
p.cargo("doc"),
execs().with_status(0).with_stderr_unordered(
"\
[UPDATING] git repository `[..]`
[DOCUMENTING] a v0.5.0 ([..])
[CHECKING] a v0.5.0 ([..])
[DOCUMENTING] foo v0.0.1 ([..])
[FINISHED] dev [..]
",
),
);

p.root().join("target").rm_rf();

assert_that(
p.cargo("doc -vv"),
execs().with_status(0).with_stderr_contains(
"\
[WARNING] `[bad_link]` cannot be resolved, ignoring it...
",
),
);

}