Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc::broken_intra_doc_links won't catch obvious invalid links #130126

Open
SteveLauC opened this issue Sep 9, 2024 · 3 comments
Open

rustdoc::broken_intra_doc_links won't catch obvious invalid links #130126

SteveLauC opened this issue Sep 9, 2024 · 3 comments
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@SteveLauC
Copy link
Contributor

I tried this code:

Lint rustdoc::broken_intra_doc_links warns by default, but it cannot catch obvious invalid links in the fanotify module of the Nix crate.

See the section Steps to reproduce for how to reproduce this behavior.

I expected to see this happen: explanation

Invalid links will be caught

Instead, this happened: explanation

They are not caught

Meta

rustc --version --verbose:

$ rustc --version --verbose
rustc 1.80.1 (3f5fd8dd4 2024-08-06)
binary: rustc
commit-hash: 3f5fd8dd41153bc5fdca9427e9e05be2c767ba23
commit-date: 2024-08-06
host: aarch64-apple-darwin
release: 1.80.1
LLVM version: 18.1.7
Backtrace

no backtrace

Context:

Today I found some invalid links in the Nix crate, and fixed them in this PR nix-rust/nix#2493, then I am surprised that they weren't caught by this lint

Steps to reproduce

$ git clone https://github.com/nix-rust/nix.git
$ cd nix
$ git reset --hard 82301035e4af3ca7903ba1abaf1955b2de61c8d5 # This is a commit where the invalid links exist
$ cargo doc --target x86_64-unknown-linux-gnu --all-features

    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s
   Generated /Users/steve/Documents/workspace/test/target/x86_64-unknown-linux-gnu/doc/nix/index.html
$ echo $?
0
@SteveLauC SteveLauC added the C-bug Category: This is a bug. label Sep 9, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 9, 2024
@fmease
Copy link
Member

fmease commented Sep 9, 2024

None of the links / inline code blocks touched in PR nix-rust/nix#2493 were intra-doc links to begin with (which is a requirement for this lint).

The links whose target/ref ended in .html were regular hyperlinks pointing at a URL, not intra-doc links. So this wouldn't apply. Although I could've sworn we once had a migration lint from manual URL-based intra-doc links to proper ones. That would've detected them.

Scanning all inline code blocks for intra-doc link candidates is practically infeasible I think. The implementation wouldn't be that difficult but it would require rustc storing all candidates in the crate metadata for rustdoc to winnow later on. This will likely have a noticable impact on performance and memory usage due to the extra encoding, decoding and filtering. Of course, if there is sufficient interest in creating such a lint, we should just test if what I said actually holds.

@fmease fmease added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 9, 2024
@fmease
Copy link
Member

fmease commented Sep 9, 2024

So in my view, this boils down to two feature requests, namely two lints:

  1. One for detecting manual URL-based intra-doc links. I bet there have already been discussions about this like years ago before my time; one would need to check their resolution, maybe there's an issue for this already.
  2. One for detecting inline code blocks that resemble intra-doc links.

@SteveLauC
Copy link
Contributor Author

Hi, thanks for the quick response! Appreciate it

None of the links / inline code blocks touched in PR nix-rust/nix#2493 were intra-doc links to begin with (which is a requirement for this lint).

Sorry for confusing them:<

Scanning all inline code blocks for intra-doc link candidates is practically infeasible I think. The implementation wouldn't be that difficult but it would require rustc storing all candidates in the crate metadata for rustdoc to winnow later on. This will likely have a noticable impact on performance and memory usage due to the extra encoding, decoding and filtering. Of course, if there is sufficient interest in creating such a lint, we should just test if what I said actually holds.

Thanks for the explanation of the impl details.


Then to solve my issue, I guess I need to use something similar to cargo-deadlinks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants