Skip to content

Commit c3b477d

Browse files
committed
Support --cap-lints in rustdoc.
1 parent e366421 commit c3b477d

File tree

2 files changed

+90
-13
lines changed

2 files changed

+90
-13
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,7 @@ fn rustc<'a, 'cfg>(
164164
let name = unit.pkg.name().to_string();
165165
let buildkey = unit.buildkey();
166166

167-
// If this is an upstream dep we don't want warnings from, turn off all
168-
// lints.
169-
if !cx.bcx.show_warnings(unit.pkg.package_id()) {
170-
rustc.arg("--cap-lints").arg("allow");
171-
172-
// If this is an upstream dep but we *do* want warnings, make sure that they
173-
// don't fail compilation.
174-
} else if !unit.pkg.package_id().source_id().is_path() {
175-
rustc.arg("--cap-lints").arg("warn");
176-
}
167+
add_cap_lints(cx.bcx, unit, &mut rustc);
177168

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

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

650+
fn add_cap_lints(bcx: &BuildContext, unit: &Unit, cmd: &mut ProcessBuilder) {
651+
// If this is an upstream dep we don't want warnings from, turn off all
652+
// lints.
653+
if !bcx.show_warnings(unit.pkg.package_id()) {
654+
cmd.arg("--cap-lints").arg("allow");
655+
656+
// If this is an upstream dep but we *do* want warnings, make sure that they
657+
// don't fail compilation.
658+
} else if !unit.pkg.package_id().source_id().is_path() {
659+
cmd.arg("--cap-lints").arg("warn");
660+
}
661+
}
662+
658663
fn build_base_args<'a, 'cfg>(
659664
cx: &mut Context<'a, 'cfg>,
660665
cmd: &mut ProcessBuilder,

tests/testsuite/doc.rs

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use std::str;
33
use std::fs::{self, File};
44
use std::io::Read;
55

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

13931394
#[test]
13941395
fn doc_all_member_dependency_same_name() {
1396+
if !is_nightly() {
1397+
// This can be removed once 1.29 is stable (rustdoc --cap-lints).
1398+
return;
1399+
}
13951400
let p = project()
13961401
.file(
13971402
"Cargo.toml",
@@ -1625,6 +1630,10 @@ fn doc_edition() {
16251630
// caused `cargo doc` to fail.
16261631
#[test]
16271632
fn issue_5345() {
1633+
if !is_nightly() {
1634+
// This can be removed once 1.29 is stable (rustdoc --cap-lints).
1635+
return;
1636+
}
16281637
let foo = project()
16291638
.file(
16301639
"Cargo.toml",
@@ -1668,3 +1677,66 @@ fn doc_private_items() {
16681677
assert_that(&foo.root().join("target/doc"), existing_dir());
16691678
assert_that(&foo.root().join("target/doc/foo/private/index.html"), existing_file());
16701679
}
1680+
1681+
#[test]
1682+
fn doc_cap_lints() {
1683+
if !is_nightly() {
1684+
// This can be removed once 1.29 is stable (rustdoc --cap-lints).
1685+
return;
1686+
}
1687+
let a = git::new("a", |p| {
1688+
p.file("Cargo.toml", &basic_lib_manifest("a")).file(
1689+
"src/lib.rs",
1690+
"
1691+
#![deny(intra_doc_link_resolution_failure)]
1692+
1693+
/// [bad_link]
1694+
pub fn foo() {}
1695+
",
1696+
)
1697+
}).unwrap();
1698+
1699+
let p = project()
1700+
.file(
1701+
"Cargo.toml",
1702+
&format!(
1703+
r#"
1704+
[package]
1705+
name = "foo"
1706+
version = "0.0.1"
1707+
authors = []
1708+
1709+
[dependencies]
1710+
a = {{ git = '{}' }}
1711+
"#,
1712+
a.url()
1713+
),
1714+
)
1715+
.file("src/lib.rs", "")
1716+
.build();
1717+
1718+
assert_that(
1719+
p.cargo("doc"),
1720+
execs().with_status(0).with_stderr_unordered(
1721+
"\
1722+
[UPDATING] git repository `[..]`
1723+
[DOCUMENTING] a v0.5.0 ([..])
1724+
[CHECKING] a v0.5.0 ([..])
1725+
[DOCUMENTING] foo v0.0.1 ([..])
1726+
[FINISHED] dev [..]
1727+
",
1728+
),
1729+
);
1730+
1731+
p.root().join("target").rm_rf();
1732+
1733+
assert_that(
1734+
p.cargo("doc -vv"),
1735+
execs().with_status(0).with_stderr_contains(
1736+
"\
1737+
[WARNING] `[bad_link]` cannot be resolved, ignoring it...
1738+
",
1739+
),
1740+
);
1741+
1742+
}

0 commit comments

Comments
 (0)