From a80dfae761b8ee0fdb1a3143be3659baaaa2a681 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 14 Aug 2023 14:21:25 -0500 Subject: [PATCH 1/2] test(lints): Demo doctest bug --- tests/testsuite/lints.rs | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/tests/testsuite/lints.rs b/tests/testsuite/lints.rs index fb31da30a98..c3a0d81fb4f 100644 --- a/tests/testsuite/lints.rs +++ b/tests/testsuite/lints.rs @@ -637,3 +637,70 @@ 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 +warning: identifier pair considered confusable between `Ě` and `Ĕ` + --> src/lib.rs:12:11 + | +11 | pub const Ě: i32 = 1; + | - this is where the previous identifier occurred +12 | pub const Ĕ: i32 = 2; + | ^ + | + = note: `#[warn(confusable_idents)]` on by default + +[WARNING] 1 warning emitted + +", + ) + .run(); +} From 9984855904f900d9a7dbb120e11710635f01f57e Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 14 Aug 2023 14:23:59 -0500 Subject: [PATCH 2/2] fix(lints): Doctest extraction should respect `[lints]` Fixes #12497 --- src/cargo/ops/cargo_test.rs | 2 ++ tests/testsuite/lints.rs | 12 ------------ 2 files changed, 2 insertions(+), 12 deletions(-) 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 c3a0d81fb4f..854de69e9ec 100644 --- a/tests/testsuite/lints.rs +++ b/tests/testsuite/lints.rs @@ -688,18 +688,6 @@ pub const Ĕ: i32 = 2; [COMPILING] foo v0.0.1 ([CWD]) [FINISHED] test [unoptimized + debuginfo] target(s) in [..]s [DOCTEST] foo -warning: identifier pair considered confusable between `Ě` and `Ĕ` - --> src/lib.rs:12:11 - | -11 | pub const Ě: i32 = 1; - | - this is where the previous identifier occurred -12 | pub const Ĕ: i32 = 2; - | ^ - | - = note: `#[warn(confusable_idents)]` on by default - -[WARNING] 1 warning emitted - ", ) .run();