-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Rustdoc should warn about unused reference links #62345
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
Comments
There seem to be a few exceptions to the rule. The link tags |
There were three problems: * I hadn't thoroughly updated Mockall's docs since the omnimacro project. There were still some links to structures that are now autogenerated. * Fix a few grammar issues. * Workaround a rustdoc bug. Rustdoc can't handle footnote links to external sites. I had to convert them to internal links. * Deny intra_doc_link_resolution_failure, so I'll catch issues like the Rustdoc bug faster. rust-lang/rust#62345
I think you just have incorrect markdown syntax? Anything inside the parentheses will be interpreted as a link. If you use square brackets or remove the parentheses entirely it should work as expected. |
Yes, I had a syntax error in the snippet that I posted. Thanks for pointing it out; it helped me narrow the problem. It looks like the real problem is that if you leave out the link name, rustdoc will try to interpret the presentation name as an intra-crate symbol, without checking whether or not a footnote exists. Oddly, if the presentation name isn't a valid identifier, then rustdoc will ignore it without printing a warning. Here's a corrected example: /! This is an inline link to [`CStr`](https://doc.rust-lang.org/stable/std/ffi/struct.CStr.html).
//! It works!
//!
//! This is an intra-crate footnote link to [`MyType`][MyType]. It also works.
//!
//! This is a footnote link, aka "reference link", to [`OsStr`][OsStr]. It work
s.
//!
//! This is an implied footnote link to [`CString`]. It fails :( .
//!
//! This is an implied link that can't be an identifier [`some-thing`]. It fails, but doesn't
//! print a warning.
//!
//! [MyType]: t/struct.MyType.html
//! [OsStr]: https://doc.rust-lang.org/stable/std/ffi/struct.OsStr.html
//! [CString]: https://doc.rust-lang.org/stable/std/ffi/struct.CString.html
//! [some-thing]: http://some-thing.com
pub mod t {
pub struct MyType {}
}
I feel a little dumb for not figuring this out more quickly. Would it be a reasonable feature request to ask rustc do check if a presentation name could point to a footnote instead of only being an identifier, or should I just forget about it? |
Your markdown is still incorrect. The link is pointing to There's certainly room for improvement on the diagnostic, though. Maybe we could do a Levenshtein check on footnotes to see if there's a typo and suggest it? |
You're right; that fixed it. Your fix would be helpful, but a simpler solution might be to warn for any unreferenced footnotes. Would that be easier? |
Both solutions may need additional pulldown-cmark support. I'm not sure that it's possible to extract unused footnotes with the current API. |
This comment has been minimized.
This comment has been minimized.
This might be fixable with the current pulldown API using the strategy in pulldown-cmark/pulldown-cmark#466 (comment). |
rustdoc can easily generate external links by using a full URL as the target. However, this only works with inline links. It doesn't work when using footnote links, sometimes called "reference links". If you try to use a full URL as the target of a footnote link, rustdoc will throw up a
intra_doc_link_resolution_failure
warning. Here's an example.src/libs.rs
:The workaround is to only use inline links for external targets. But that uglies up the code, and it requires duplication if the same comment block needs to instantiate the link multiple times.
The text was updated successfully, but these errors were encountered: