Auto merge of #12501 - epage:rustdoc, r=weihanglo

fix(lints): Doctest extraction should respect `[lints]`

Note the first commit shows the bug and the second commit fixes it

Fixes #12497
This commit is contained in:
bors 2023-08-14 20:11:43 +00:00
commit 7c3904d6c3
2 changed files with 57 additions and 0 deletions

View File

@ -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 {

View File

@ -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 _ = "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();
}