Skip to content

Commit 348d9d9

Browse files
Correctly iterate doc comments in intra-doc resolution in rustc_resolve
1 parent 4936973 commit 348d9d9

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,19 @@ impl AttributeExt for Attribute {
233233
self.has_name(sym::doc)
234234
&& self.meta_item_list().is_some_and(|l| list_contains_name(&l, sym::hidden))
235235
}
236+
237+
fn is_doc_keyword_or_attribute(&self) -> bool {
238+
if self.has_name(sym::doc)
239+
&& let Some(items) = self.meta_item_list()
240+
{
241+
for item in items {
242+
if item.has_name(sym::keyword) || item.has_name(sym::attribute) {
243+
return true;
244+
}
245+
}
246+
}
247+
false
248+
}
236249
}
237250

238251
impl Attribute {
@@ -865,6 +878,9 @@ pub trait AttributeExt: Debug {
865878

866879
/// Returns `true` if this attribute contains `doc(hidden)`.
867880
fn is_doc_hidden(&self) -> bool;
881+
882+
/// Returns `true` is this attribute contains `doc(keyword)` or `doc(attribute)`.
883+
fn is_doc_keyword_or_attribute(&self) -> bool;
868884
}
869885

870886
// FIXME(fn_delegation): use function delegation instead of manually forwarding

compiler/rustc_hir/src/hir.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,10 @@ impl AttributeExt for Attribute {
14181418
fn is_doc_hidden(&self) -> bool {
14191419
matches!(self, Attribute::Parsed(AttributeKind::Doc(d)) if d.hidden.is_some())
14201420
}
1421+
1422+
fn is_doc_keyword_or_attribute(&self) -> bool {
1423+
matches!(self, Attribute::Parsed(AttributeKind::Doc(d)) if d.attribute.is_some() || d.keyword.is_some())
1424+
}
14211425
}
14221426

14231427
// FIXME(fn_delegation): use function delegation instead of manually forwarding

compiler/rustc_resolve/src/rustdoc.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -367,16 +367,8 @@ pub fn inner_docs(attrs: &[impl AttributeExt]) -> bool {
367367
/// Has `#[rustc_doc_primitive]` or `#[doc(keyword)]` or `#[doc(attribute)]`.
368368
pub fn has_primitive_or_keyword_or_attribute_docs(attrs: &[impl AttributeExt]) -> bool {
369369
for attr in attrs {
370-
if attr.has_name(sym::rustc_doc_primitive) {
370+
if attr.has_name(sym::rustc_doc_primitive) || attr.is_doc_keyword_or_attribute() {
371371
return true;
372-
} else if attr.has_name(sym::doc)
373-
&& let Some(items) = attr.meta_item_list()
374-
{
375-
for item in items {
376-
if item.has_name(sym::keyword) || item.has_name(sym::attribute) {
377-
return true;
378-
}
379-
}
380372
}
381373
}
382374
false

tests/rustdoc/doc-on-keyword.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// While working on <https://github.com/rust-lang/rust/pull/149645>, the
2+
// intra doc links on keyword/attribute items were not processed.
3+
4+
#![feature(rustdoc_internals)]
5+
#![crate_name = "foo"]
6+
7+
//@ has 'foo/keyword.trait.html'
8+
//@ has - '//a[@href="{{channel}}/core/marker/trait.Send.html"]' 'Send'
9+
//@ has - '//a[@href="{{channel}}/core/marker/trait.Sync.html"]' 'Sync'
10+
#[doc(keyword = "trait")]
11+
//
12+
/// [`Send`] and [Sync]
13+
mod bar {}

0 commit comments

Comments
 (0)