diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 1166ea6832c..7b1dbbc1148 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -260,6 +260,8 @@ fn run_doc_tests( p.arg("--test-args").arg("--quiet"); } + p.args(unit.pkg.manifest().lint_rustflags()); + p.args(args); if *unstable_opts { diff --git a/tests/testsuite/lints.rs b/tests/testsuite/lints.rs index fb31da30a98..854de69e9ec 100644 --- a/tests/testsuite/lints.rs +++ b/tests/testsuite/lints.rs @@ -637,3 +637,58 @@ error: unresolved link to `bar` ) .run(); } + +#[cargo_test] +fn doctest_respects_lints() { + let foo = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [lints.rust] + confusable-idents = 'allow' + "#, + ) + .file( + "src/lib.rs", + r#" +/// Test +/// +/// [`Foo`] +/// +/// ``` +/// let s = "rust"; +/// let s_s = "rust2"; +/// ``` +pub fn f() {} +pub const Ě: i32 = 1; +pub const Ĕ: i32 = 2; +"#, + ) + .build(); + + foo.cargo("check -Zlints") + .masquerade_as_nightly_cargo(&["lints"]) + .with_stderr( + "\ +[CHECKING] foo v0.0.1 ([CWD]) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s +", + ) + .run(); + + foo.cargo("test --doc -Zlints") + .masquerade_as_nightly_cargo(&["lints"]) + .with_stderr( + "\ +[COMPILING] foo v0.0.1 ([CWD]) +[FINISHED] test [unoptimized + debuginfo] target(s) in [..]s +[DOCTEST] foo +", + ) + .run(); +}