Skip to content

Commit 3006ea3

Browse files
authored
Rollup merge of #71670 - GuillaumeGomez:enforce-codeblocks-attribute-check, r=Mark-Simulacrum
Enforce even more the code blocks attributes check through rustdoc `rustdoc` now has a lint which allows it to warn if a code block attribute is malformated (which can end up in bad situations, even more in case of testing examples!). Now it'll fail if such a situation is encountered when testing markdown code blocks examples. r? @Mark-Simulacrum
2 parents 39d5a61 + 5f6c079 commit 3006ea3

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/bootstrap/builder.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,11 @@ impl<'a> Builder<'a> {
725725
.env("CFG_RELEASE_CHANNEL", &self.config.channel)
726726
.env("RUSTDOC_REAL", self.rustdoc(compiler))
727727
.env("RUSTDOC_CRATE_VERSION", self.rust_version())
728-
.env("RUSTC_BOOTSTRAP", "1");
728+
.env("RUSTC_BOOTSTRAP", "1")
729+
.arg("-Winvalid_codeblock_attributes");
730+
if self.config.deny_warnings {
731+
cmd.arg("-Dwarnings");
732+
}
729733

730734
// Remove make-related flags that can cause jobserver problems.
731735
cmd.env_remove("MAKEFLAGS");
@@ -838,7 +842,7 @@ impl<'a> Builder<'a> {
838842
// FIXME: It might be better to use the same value for both `RUSTFLAGS` and `RUSTDOCFLAGS`,
839843
// but this breaks CI. At the very least, stage0 `rustdoc` needs `--cfg bootstrap`. See
840844
// #71458.
841-
let rustdocflags = rustflags.clone();
845+
let mut rustdocflags = rustflags.clone();
842846

843847
if let Ok(s) = env::var("CARGOFLAGS") {
844848
cargo.args(s.split_whitespace());
@@ -1140,6 +1144,7 @@ impl<'a> Builder<'a> {
11401144

11411145
if self.config.deny_warnings {
11421146
lint_flags.push("-Dwarnings");
1147+
rustdocflags.arg("-Dwarnings");
11431148
}
11441149

11451150
// FIXME(#58633) hide "unused attribute" errors in incremental
@@ -1157,6 +1162,8 @@ impl<'a> Builder<'a> {
11571162
// are always ignored in dependencies. Eventually this should be
11581163
// fixed via better support from Cargo.
11591164
cargo.env("RUSTC_LINT_FLAGS", lint_flags.join(" "));
1165+
1166+
rustdocflags.arg("-Winvalid_codeblock_attributes");
11601167
}
11611168

11621169
if let Mode::Rustc | Mode::Codegen = mode {

src/librustdoc/core.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
320320
let missing_doc_example = rustc_lint::builtin::MISSING_DOC_CODE_EXAMPLES.name;
321321
let private_doc_tests = rustc_lint::builtin::PRIVATE_DOC_TESTS.name;
322322
let no_crate_level_docs = rustc_lint::builtin::MISSING_CRATE_LEVEL_DOCS.name;
323-
let invalid_codeblock_attribute_name = rustc_lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES.name;
323+
let invalid_codeblock_attributes_name = rustc_lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES.name;
324324

325325
// In addition to those specific lints, we also need to allow those given through
326326
// command line, otherwise they'll get ignored and we don't want that.
@@ -330,12 +330,12 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
330330
missing_doc_example.to_owned(),
331331
private_doc_tests.to_owned(),
332332
no_crate_level_docs.to_owned(),
333-
invalid_codeblock_attribute_name.to_owned(),
333+
invalid_codeblock_attributes_name.to_owned(),
334334
];
335335

336336
let (lint_opts, lint_caps) = init_lints(allowed_lints, lint_opts, |lint| {
337337
if lint.name == intra_link_resolution_failure_name
338-
|| lint.name == invalid_codeblock_attribute_name
338+
|| lint.name == invalid_codeblock_attributes_name
339339
{
340340
None
341341
} else {

src/librustdoc/test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ pub struct TestOptions {
4545
pub fn run(options: Options) -> Result<(), String> {
4646
let input = config::Input::File(options.input.clone());
4747

48-
let invalid_codeblock_attribute_name = rustc_lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES.name;
48+
let invalid_codeblock_attributes_name = rustc_lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES.name;
4949

5050
// In addition to those specific lints, we also need to allow those given through
5151
// command line, otherwise they'll get ignored and we don't want that.
52-
let allowed_lints = vec![invalid_codeblock_attribute_name.to_owned()];
52+
let allowed_lints = vec![invalid_codeblock_attributes_name.to_owned()];
5353

5454
let (lint_opts, lint_caps) = init_lints(allowed_lints, options.lint_opts.clone(), |lint| {
55-
if lint.name == invalid_codeblock_attribute_name {
55+
if lint.name == invalid_codeblock_attributes_name {
5656
None
5757
} else {
5858
Some((lint.name_lower(), lint::Allow))

0 commit comments

Comments
 (0)