Correctly iterate doc comments in intra-doc resolution in rustc_resolve

This commit is contained in:
Guillaume Gomez 2025-12-05 22:54:56 +01:00
parent 4936973d49
commit 348d9d98e0
4 changed files with 34 additions and 9 deletions

View file

@ -233,6 +233,19 @@ impl AttributeExt for Attribute {
self.has_name(sym::doc)
&& self.meta_item_list().is_some_and(|l| list_contains_name(&l, sym::hidden))
}
fn is_doc_keyword_or_attribute(&self) -> bool {
if self.has_name(sym::doc)
&& let Some(items) = self.meta_item_list()
{
for item in items {
if item.has_name(sym::keyword) || item.has_name(sym::attribute) {
return true;
}
}
}
false
}
}
impl Attribute {
@ -865,6 +878,9 @@ pub trait AttributeExt: Debug {
/// Returns `true` if this attribute contains `doc(hidden)`.
fn is_doc_hidden(&self) -> bool;
/// Returns `true` is this attribute contains `doc(keyword)` or `doc(attribute)`.
fn is_doc_keyword_or_attribute(&self) -> bool;
}
// FIXME(fn_delegation): use function delegation instead of manually forwarding

View file

@ -1418,6 +1418,10 @@ impl AttributeExt for Attribute {
fn is_doc_hidden(&self) -> bool {
matches!(self, Attribute::Parsed(AttributeKind::Doc(d)) if d.hidden.is_some())
}
fn is_doc_keyword_or_attribute(&self) -> bool {
matches!(self, Attribute::Parsed(AttributeKind::Doc(d)) if d.attribute.is_some() || d.keyword.is_some())
}
}
// FIXME(fn_delegation): use function delegation instead of manually forwarding

View file

@ -367,16 +367,8 @@ pub fn inner_docs(attrs: &[impl AttributeExt]) -> bool {
/// Has `#[rustc_doc_primitive]` or `#[doc(keyword)]` or `#[doc(attribute)]`.
pub fn has_primitive_or_keyword_or_attribute_docs(attrs: &[impl AttributeExt]) -> bool {
for attr in attrs {
if attr.has_name(sym::rustc_doc_primitive) {
if attr.has_name(sym::rustc_doc_primitive) || attr.is_doc_keyword_or_attribute() {
return true;
} else if attr.has_name(sym::doc)
&& let Some(items) = attr.meta_item_list()
{
for item in items {
if item.has_name(sym::keyword) || item.has_name(sym::attribute) {
return true;
}
}
}
}
false

View file

@ -0,0 +1,13 @@
// While working on <https://github.com/rust-lang/rust/pull/149645>, the
// intra doc links on keyword/attribute items were not processed.
#![feature(rustdoc_internals)]
#![crate_name = "foo"]
//@ has 'foo/keyword.trait.html'
//@ has - '//a[@href="{{channel}}/core/marker/trait.Send.html"]' 'Send'
//@ has - '//a[@href="{{channel}}/core/marker/trait.Sync.html"]' 'Sync'
#[doc(keyword = "trait")]
//
/// [`Send`] and [Sync]
mod bar {}