diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-04-14 23:24:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-14 23:24:34 +0200 |
| commit | 4d32bc3801fb66d359ebcc8e0e90733094602858 (patch) | |
| tree | 3f0d67dd8c2a4012de4b4df8022592bc6a80c3a2 | |
| parent | 86b791a2723235c860c95a1fe1cf41ea853599e3 (diff) | |
| parent | 0fea38a01f4015d310230b76984068b6fe8414d4 (diff) | |
| download | rust-4d32bc3801fb66d359ebcc8e0e90733094602858.tar.gz rust-4d32bc3801fb66d359ebcc8e0e90733094602858.zip | |
Rollup merge of #123905 - notriddle:notriddle/redundant-explicit-link-hunks, r=GuillaumeGomez
rustdoc: check redundant explicit links with correct itemid Fixes #123677 (a regression caused by #120702)
| -rw-r--r-- | src/librustdoc/passes/lint/redundant_explicit_links.rs | 19 | ||||
| -rw-r--r-- | tests/rustdoc-ui/redundant-explicit-links-123677.rs | 14 |
2 files changed, 22 insertions, 11 deletions
diff --git a/src/librustdoc/passes/lint/redundant_explicit_links.rs b/src/librustdoc/passes/lint/redundant_explicit_links.rs index 569c17ee36e..09886024595 100644 --- a/src/librustdoc/passes/lint/redundant_explicit_links.rs +++ b/src/librustdoc/passes/lint/redundant_explicit_links.rs @@ -6,7 +6,7 @@ use rustc_errors::SuggestionStyle; use rustc_hir::def::{DefKind, DocLinkResMap, Namespace, Res}; use rustc_hir::HirId; use rustc_lint_defs::Applicability; -use rustc_resolve::rustdoc::source_span_for_markdown_range; +use rustc_resolve::rustdoc::{prepare_to_doc_link_resolution, source_span_for_markdown_range}; use rustc_span::def_id::DefId; use rustc_span::Symbol; @@ -29,16 +29,13 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) { return; }; - let doc = item.doc_value(); - if doc.is_empty() { - return; - } - - if let Some(item_id) = item.def_id() { - check_redundant_explicit_link_for_did(cx, item, item_id, hir_id, &doc); - } - if let Some(item_id) = item.inline_stmt_id { - check_redundant_explicit_link_for_did(cx, item, item_id, hir_id, &doc); + let hunks = prepare_to_doc_link_resolution(&item.attrs.doc_strings); + for (item_id, doc) in hunks { + if let Some(item_id) = item_id.or(item.def_id()) + && !doc.is_empty() + { + check_redundant_explicit_link_for_did(cx, item, item_id, hir_id, &doc); + } } } diff --git a/tests/rustdoc-ui/redundant-explicit-links-123677.rs b/tests/rustdoc-ui/redundant-explicit-links-123677.rs new file mode 100644 index 00000000000..f3a5e81f89d --- /dev/null +++ b/tests/rustdoc-ui/redundant-explicit-links-123677.rs @@ -0,0 +1,14 @@ +//@ check-pass +#![deny(rustdoc::redundant_explicit_links)] + +mod bar { + /// [`Rc`](std::rc::Rc) + pub enum Baz {} +} + +pub use bar::*; + +use std::rc::Rc; + +/// [`Rc::allocator`] [foo](std::rc::Rc) +pub fn winit_runner() {} |
