Skip to content

Commit

Permalink
cap-lints when building rustdoc JSON (obi1kenobi#357)
Browse files Browse the repository at this point in the history
* cap-lints when building rustdoc JSON

* Add `broken_rustdoc` test crate.

* Conditionally disable lints when building rustdoc.

---------

Co-authored-by: Predrag Gruevski <obi1kenobi82@gmail.com>
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 11, 2023
1 parent 80d8e09 commit 618dc8f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
11 changes: 10 additions & 1 deletion scripts/regenerate_test_rustdocs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ for crate_pair in $(find "$TOPLEVEL/test_crates/" -maxdepth 1 -mindepth 1 -type
echo "Generating: $crate"

pushd "$TOPLEVEL/test_crates/$crate"
RUSTC_BOOTSTRAP=1 $RUSTDOC_CMD -- -Zunstable-options --document-private-items --document-hidden-items --output-format=json

# Determine whether to warn on lints or allow them.
CAP_LINTS="warn"
if [[ "$crate" == "broken_rustdoc" ]]; then
# This crate *intentionally* has broken rustdoc.
# Don't warn on it. The warnings and errors are thing being tested.
CAP_LINTS="allow"
fi

RUSTC_BOOTSTRAP=1 $RUSTDOC_CMD -- -Zunstable-options --document-private-items --document-hidden-items --cap-lints "$CAP_LINTS" --output-format=json
mkdir -p "$TARGET_DIR/$crate"
mv "$RUSTDOC_OUTPUT_DIR/$crate_pair.json" "$TARGET_DIR/$crate/rustdoc.json"
popd
Expand Down
2 changes: 1 addition & 1 deletion src/rustdoc_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl RustdocCommand {
cmd.env("RUSTC_BOOTSTRAP", "1")
.env(
"RUSTDOCFLAGS",
"-Z unstable-options --document-private-items --document-hidden-items --output-format=json",
"-Z unstable-options --document-private-items --document-hidden-items --output-format=json --cap-lints allow",
)
.stdout(std::process::Stdio::null()) // Don't pollute output
.stderr(stderr)
Expand Down
7 changes: 7 additions & 0 deletions test_crates/broken_rustdoc/new/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
publish = false
name = "broken_rustdoc"
version = "0.1.0"
edition = "2021"

[dependencies]
8 changes: 8 additions & 0 deletions test_crates/broken_rustdoc/new/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![deny(missing_docs, rustdoc::broken_intra_doc_links)]

/// Rust doc comment with an unescaped HTML <tag> that rustdoc will complain about.
///
/// Also, a link that points to nowhere: [`Foo::bar`].
pub struct Foo;

pub struct Undocumented; // fails the `missing_docs` lint
7 changes: 7 additions & 0 deletions test_crates/broken_rustdoc/old/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
publish = false
name = "broken_rustdoc"
version = "0.1.0"
edition = "2021"

[dependencies]
8 changes: 8 additions & 0 deletions test_crates/broken_rustdoc/old/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![deny(missing_docs, rustdoc::broken_intra_doc_links)]

/// Rust doc comment with an unescaped HTML <tag> that rustdoc will complain about.
///
/// Also, a link that points to nowhere: [`Foo::bar`].
pub struct Foo;

pub struct Undocumented; // fails the `missing_docs` lint

0 comments on commit 618dc8f

Please sign in to comment.