Skip to content

Commit e51c37c

Browse files
committed
Add AttributeExt::doc_resolution_scope
1 parent ea34650 commit e51c37c

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,18 @@ impl AttributeExt for Attribute {
206206
}
207207
}
208208

209+
fn doc_resolution_scope(&self) -> Option<AttrStyle> {
210+
match &self.kind {
211+
AttrKind::DocComment(..) => Some(self.style),
212+
AttrKind::Normal(normal)
213+
if normal.item.path == sym::doc && normal.item.value_str().is_some() =>
214+
{
215+
Some(self.style)
216+
}
217+
_ => None,
218+
}
219+
}
220+
209221
fn style(&self) -> AttrStyle {
210222
self.style
211223
}
@@ -806,6 +818,15 @@ pub trait AttributeExt: Debug {
806818
/// * `#[doc(...)]` returns `None`.
807819
fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)>;
808820

821+
/// Returns outer or inner if this is a doc attribute or a sugared doc
822+
/// comment, otherwise None.
823+
///
824+
/// This is used in the case of doc comments on modules, to decide whether
825+
/// to resolve intra-doc links against the symbols in scope within the
826+
/// commented module (for inner doc) vs within its parent module (for outer
827+
/// doc).
828+
fn doc_resolution_scope(&self) -> Option<AttrStyle>;
829+
809830
fn style(&self) -> AttrStyle;
810831
}
811832

compiler/rustc_hir/src/hir.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,16 @@ impl AttributeExt for Attribute {
13461346
}
13471347
}
13481348

1349+
fn doc_resolution_scope(&self) -> Option<AttrStyle> {
1350+
match self {
1351+
Attribute::Parsed(AttributeKind::DocComment { style, .. }) => Some(*style),
1352+
Attribute::Unparsed(attr) if self.has_name(sym::doc) && self.value_str().is_some() => {
1353+
Some(attr.style)
1354+
}
1355+
_ => None,
1356+
}
1357+
}
1358+
13491359
#[inline]
13501360
fn style(&self) -> AttrStyle {
13511361
match &self {

compiler/rustc_resolve/src/rustdoc.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,12 @@ pub fn strip_generics_from_path(path_str: &str) -> Result<Box<str>, MalformedGen
356356
/// If there are no doc-comments, return true.
357357
/// FIXME(#78591): Support both inner and outer attributes on the same item.
358358
pub fn inner_docs(attrs: &[impl AttributeExt]) -> bool {
359-
attrs.iter().find(|a| a.doc_str().is_some()).is_none_or(|a| a.style() == ast::AttrStyle::Inner)
359+
for attr in attrs {
360+
if let Some(attr_style) = attr.doc_resolution_scope() {
361+
return attr_style == ast::AttrStyle::Inner;
362+
}
363+
}
364+
true
360365
}
361366

362367
/// Has `#[rustc_doc_primitive]` or `#[doc(keyword)]`.

0 commit comments

Comments
 (0)