about summary refs log tree commit diff
path: root/compiler/rustc_ast/src/attr/mod.rs
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2025-06-22 08:49:05 +0200
committerGitHub <noreply@github.com>2025-06-22 08:49:05 +0200
commitbf63acfd3553fbd21e85e3eac3dd795d35fd0804 (patch)
treec752c7744aa84547803687c0deb9489bc641846e /compiler/rustc_ast/src/attr/mod.rs
parentb5b106ab91ef614c0e6629df8e5f42a283746346 (diff)
parent6729b667ce4b013a5ec6f50b096bde3edabc28e3 (diff)
downloadrust-bf63acfd3553fbd21e85e3eac3dd795d35fd0804.tar.gz
rust-bf63acfd3553fbd21e85e3eac3dd795d35fd0804.zip
Rollup merge of #142776 - dtolnay:hirattrstyle2, r=jdonszelmann
All HIR attributes are outer

Fixes https://github.com/rust-lang/rust/issues/142649. Closes https://github.com/rust-lang/rust/pull/142759.

All HIR attributes, including parsed and not yet parsed, will now be rendered as outer attributes by `rustc_hir_pretty`. The original style of the corresponding AST attribute(s) is not relevant for pretty printing, only for diagnostics.

r? ````@jdonszelmann````
Diffstat (limited to 'compiler/rustc_ast/src/attr/mod.rs')
-rw-r--r--compiler/rustc_ast/src/attr/mod.rs29
1 files changed, 22 insertions, 7 deletions
diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs
index 621e3042b62..44865c493b3 100644
--- a/compiler/rustc_ast/src/attr/mod.rs
+++ b/compiler/rustc_ast/src/attr/mod.rs
@@ -206,12 +206,24 @@ impl AttributeExt for Attribute {
         }
     }
 
-    fn style(&self) -> AttrStyle {
-        self.style
+    fn doc_resolution_scope(&self) -> Option<AttrStyle> {
+        match &self.kind {
+            AttrKind::DocComment(..) => Some(self.style),
+            AttrKind::Normal(normal)
+                if normal.item.path == sym::doc && normal.item.value_str().is_some() =>
+            {
+                Some(self.style)
+            }
+            _ => None,
+        }
     }
 }
 
 impl Attribute {
+    pub fn style(&self) -> AttrStyle {
+        self.style
+    }
+
     pub fn may_have_doc_links(&self) -> bool {
         self.doc_str().is_some_and(|s| comments::may_have_doc_links(s.as_str()))
     }
@@ -806,7 +818,14 @@ pub trait AttributeExt: Debug {
     /// * `#[doc(...)]` returns `None`.
     fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)>;
 
-    fn style(&self) -> AttrStyle;
+    /// Returns outer or inner if this is a doc attribute or a sugared doc
+    /// comment, otherwise None.
+    ///
+    /// This is used in the case of doc comments on modules, to decide whether
+    /// to resolve intra-doc links against the symbols in scope within the
+    /// commented module (for inner doc) vs within its parent module (for outer
+    /// doc).
+    fn doc_resolution_scope(&self) -> Option<AttrStyle>;
 }
 
 // FIXME(fn_delegation): use function delegation instead of manually forwarding
@@ -881,8 +900,4 @@ impl Attribute {
     pub fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)> {
         AttributeExt::doc_str_and_comment_kind(self)
     }
-
-    pub fn style(&self) -> AttrStyle {
-        AttributeExt::style(self)
-    }
 }