Skip to content

Commit 234927e

Browse files
Ignore "non-real" type Res in rustdoc intra doc link resolution
1 parent cda5bec commit 234927e

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

compiler/rustc_resolve/src/late.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_ast::*;
1717
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
1818
use rustc_errors::{Applicability, DiagnosticArgValue, DiagnosticId, IntoDiagnosticArg};
1919
use rustc_hir::def::Namespace::{self, *};
20-
use rustc_hir::def::{self, CtorKind, DefKind, LifetimeRes, PartialRes, PerNS};
20+
use rustc_hir::def::{self, CtorKind, DefKind, LifetimeRes, NonMacroAttrKind, PartialRes, PerNS};
2121
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
2222
use rustc_hir::{BindingAnnotation, PrimTy, TraitCandidate};
2323
use rustc_middle::middle::resolve_bound_vars::Set1;
@@ -4287,12 +4287,12 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
42874287
}
42884288
}
42894289

4290-
fn resolve_and_cache_rustdoc_path(&mut self, path_str: &str, ns: Namespace) -> bool {
4290+
fn resolve_and_cache_rustdoc_path(&mut self, path_str: &str, ns: Namespace) -> Option<Res> {
42914291
// FIXME: This caching may be incorrect in case of multiple `macro_rules`
42924292
// items with the same name in the same module.
42934293
// Also hygiene is not considered.
42944294
let mut doc_link_resolutions = std::mem::take(&mut self.r.doc_link_resolutions);
4295-
let res = doc_link_resolutions
4295+
let res = *doc_link_resolutions
42964296
.entry(self.parent_scope.module.nearest_parent_mod().expect_local())
42974297
.or_default()
42984298
.entry((Symbol::intern(path_str), ns))
@@ -4307,8 +4307,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
43074307
return None;
43084308
}
43094309
res
4310-
})
4311-
.is_some();
4310+
});
43124311
self.r.doc_link_resolutions = doc_link_resolutions;
43134312
res
43144313
}
@@ -4343,8 +4342,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
43434342
let mut any_resolved = false;
43444343
let mut need_assoc = false;
43454344
for ns in [TypeNS, ValueNS, MacroNS] {
4346-
if self.resolve_and_cache_rustdoc_path(&path_str, ns) {
4347-
any_resolved = true;
4345+
if let Some(res) = self.resolve_and_cache_rustdoc_path(&path_str, ns) {
4346+
// Rustdoc ignores tool attribute resolutions and attempts
4347+
// to resolve their prefixes for diagnostics.
4348+
any_resolved = !matches!(res, Res::NonMacroAttr(NonMacroAttrKind::Tool));
43484349
} else if ns != MacroNS {
43494350
need_assoc = true;
43504351
}

src/librustdoc/passes/collect_intra_doc_links.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl TryFrom<ResolveRes> for Res {
149149
Def(kind, id) => Ok(Res::Def(kind, id)),
150150
PrimTy(prim) => Ok(Res::Primitive(PrimitiveType::from_hir(prim))),
151151
// e.g. `#[derive]`
152-
NonMacroAttr(..) | Err => Result::Err(()),
152+
ToolMod | NonMacroAttr(..) | Err => Result::Err(()),
153153
other => bug!("unrecognized res {:?}", other),
154154
}
155155
}

0 commit comments

Comments
 (0)