1
Fork 0

Stop resolving doc links on mod items twice

This commit is contained in:
Vadim Petrochenkov 2023-02-05 15:10:02 +04:00
parent b62b82aef4
commit 3b0866272a
3 changed files with 19 additions and 15 deletions

View file

@ -2199,7 +2199,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
}
fn resolve_item(&mut self, item: &'ast Item) {
self.resolve_doc_links(&item.attrs);
let mod_inner_docs =
matches!(item.kind, ItemKind::Mod(..)) && rustdoc::inner_docs(&item.attrs);
if !mod_inner_docs {
self.resolve_doc_links(&item.attrs);
}
let name = item.ident.name;
debug!("(resolving item) resolving {} ({:?})", name, item.kind);
@ -2292,7 +2296,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
ItemKind::Mod(..) => {
self.with_scope(item.id, |this| {
this.resolve_doc_links(&item.attrs);
if mod_inner_docs {
this.resolve_doc_links(&item.attrs);
}
let old_macro_rules = this.parent_scope.macro_rules;
visit::walk_item(this, item);
// Maintain macro_rules scopes in the same way as during early resolution

View file

@ -326,6 +326,14 @@ pub fn strip_generics_from_path(path_str: &str) -> Result<String, MalformedGener
if !stripped_path.is_empty() { Ok(stripped_path) } else { Err(MalformedGenerics::MissingType) }
}
/// Returns whether the first doc-comment is an inner attribute.
///
//// If there are no doc-comments, return true.
/// FIXME(#78591): Support both inner and outer attributes on the same item.
pub fn inner_docs(attrs: &[ast::Attribute]) -> bool {
attrs.iter().find(|a| a.doc_str().is_some()).map_or(true, |a| a.style == ast::AttrStyle::Inner)
}
/// Simplified version of the corresponding function in rustdoc.
/// If the rustdoc version returns a successful result, this function must return the same result.
/// Otherwise this function may return anything.