mirror of https://github.com/rust-lang/rust.git
Stop resolving doc links on `mod` items twice
This commit is contained in:
parent
b62b82aef4
commit
3b0866272a
|
@ -2199,7 +2199,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_item(&mut self, item: &'ast Item) {
|
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;
|
let name = item.ident.name;
|
||||||
debug!("(resolving item) resolving {} ({:?})", name, item.kind);
|
debug!("(resolving item) resolving {} ({:?})", name, item.kind);
|
||||||
|
@ -2292,7 +2296,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
|
|
||||||
ItemKind::Mod(..) => {
|
ItemKind::Mod(..) => {
|
||||||
self.with_scope(item.id, |this| {
|
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;
|
let old_macro_rules = this.parent_scope.macro_rules;
|
||||||
visit::walk_item(this, item);
|
visit::walk_item(this, item);
|
||||||
// Maintain macro_rules scopes in the same way as during early resolution
|
// Maintain macro_rules scopes in the same way as during early resolution
|
||||||
|
|
|
@ -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) }
|
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.
|
/// Simplified version of the corresponding function in rustdoc.
|
||||||
/// If the rustdoc version returns a successful result, this function must return the same result.
|
/// If the rustdoc version returns a successful result, this function must return the same result.
|
||||||
/// Otherwise this function may return anything.
|
/// Otherwise this function may return anything.
|
||||||
|
|
|
@ -10,7 +10,7 @@ use std::{fmt, iter};
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use thin_vec::ThinVec;
|
use thin_vec::ThinVec;
|
||||||
|
|
||||||
use rustc_ast::{self as ast, AttrStyle};
|
use rustc_ast as ast;
|
||||||
use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel};
|
use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel};
|
||||||
use rustc_const_eval::const_eval::is_unstable_const_fn;
|
use rustc_const_eval::const_eval::is_unstable_const_fn;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
|
@ -23,7 +23,7 @@ use rustc_hir_analysis::check::intrinsic::intrinsic_operation_unsafety;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_middle::ty::fast_reject::SimplifiedType;
|
use rustc_middle::ty::fast_reject::SimplifiedType;
|
||||||
use rustc_middle::ty::{self, DefIdTree, TyCtxt, Visibility};
|
use rustc_middle::ty::{self, DefIdTree, TyCtxt, Visibility};
|
||||||
use rustc_resolve::rustdoc::{add_doc_fragment, attrs_to_doc_fragments, DocFragment};
|
use rustc_resolve::rustdoc::{add_doc_fragment, attrs_to_doc_fragments, inner_docs, DocFragment};
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::hygiene::MacroKind;
|
use rustc_span::hygiene::MacroKind;
|
||||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
|
@ -405,7 +405,7 @@ impl Item {
|
||||||
pub(crate) fn inner_docs(&self, tcx: TyCtxt<'_>) -> bool {
|
pub(crate) fn inner_docs(&self, tcx: TyCtxt<'_>) -> bool {
|
||||||
self.item_id
|
self.item_id
|
||||||
.as_def_id()
|
.as_def_id()
|
||||||
.map(|did| tcx.get_attrs_unchecked(did).inner_docs())
|
.map(|did| inner_docs(tcx.get_attrs_unchecked(did)))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -874,8 +874,6 @@ pub(crate) trait AttributesExt {
|
||||||
|
|
||||||
fn span(&self) -> Option<rustc_span::Span>;
|
fn span(&self) -> Option<rustc_span::Span>;
|
||||||
|
|
||||||
fn inner_docs(&self) -> bool;
|
|
||||||
|
|
||||||
fn cfg(&self, tcx: TyCtxt<'_>, hidden_cfg: &FxHashSet<Cfg>) -> Option<Arc<Cfg>>;
|
fn cfg(&self, tcx: TyCtxt<'_>, hidden_cfg: &FxHashSet<Cfg>) -> Option<Arc<Cfg>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -894,14 +892,6 @@ impl AttributesExt for [ast::Attribute] {
|
||||||
self.iter().find(|attr| attr.doc_str().is_some()).map(|attr| attr.span)
|
self.iter().find(|attr| attr.doc_str().is_some()).map(|attr| attr.span)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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.
|
|
||||||
fn inner_docs(&self) -> bool {
|
|
||||||
self.iter().find(|a| a.doc_str().is_some()).map_or(true, |a| a.style == AttrStyle::Inner)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn cfg(&self, tcx: TyCtxt<'_>, hidden_cfg: &FxHashSet<Cfg>) -> Option<Arc<Cfg>> {
|
fn cfg(&self, tcx: TyCtxt<'_>, hidden_cfg: &FxHashSet<Cfg>) -> Option<Arc<Cfg>> {
|
||||||
let sess = tcx.sess;
|
let sess = tcx.sess;
|
||||||
let doc_cfg_active = tcx.features().doc_cfg;
|
let doc_cfg_active = tcx.features().doc_cfg;
|
||||||
|
|
Loading…
Reference in New Issue