Skip to content

Commit 51eda74

Browse files
committed
rustdoc: Remove ResolutionFailure::NoParentItem
It's a bug and not an error
1 parent a7d6408 commit 51eda74

File tree

1 file changed

+8
-49
lines changed

1 file changed

+8
-49
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_resolve::ParentScope;
1616
use rustc_session::lint::Lint;
1717
use rustc_span::hygiene::MacroKind;
1818
use rustc_span::symbol::{sym, Ident, Symbol};
19-
use rustc_span::{BytePos, DUMMY_SP};
19+
use rustc_span::BytePos;
2020
use smallvec::{smallvec, SmallVec};
2121

2222
use std::borrow::Cow;
@@ -97,14 +97,6 @@ impl Res {
9797
}
9898
}
9999

100-
fn as_hir_res(self) -> Option<rustc_hir::def::Res> {
101-
match self {
102-
Res::Def(kind, id) => Some(rustc_hir::def::Res::Def(kind, id)),
103-
// FIXME: maybe this should handle the subset of PrimitiveType that fits into hir::PrimTy?
104-
Res::Primitive(_) => None,
105-
}
106-
}
107-
108100
/// Used for error reporting.
109101
fn disambiguator_suggestion(self) -> Suggestion {
110102
let kind = match self {
@@ -189,9 +181,6 @@ enum ResolutionFailure<'a> {
189181
/// In `[std::io::Error::x]`, `x` would be unresolved.
190182
unresolved: Cow<'a, str>,
191183
},
192-
/// This happens when rustdoc can't determine the parent scope for an item.
193-
/// It is always a bug in rustdoc.
194-
NoParentItem,
195184
/// This link has malformed generic parameters; e.g., the angle brackets are unbalanced.
196185
MalformedGenerics(MalformedGenerics),
197186
/// Used to communicate that this should be ignored, but shouldn't be reported to the user.
@@ -616,8 +605,12 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
616605
// item a separate function.
617606
Res::Def(DefKind::AssocFn | DefKind::AssocConst, _) => assert_eq!(ns, ValueNS),
618607
Res::Def(DefKind::AssocTy, _) => assert_eq!(ns, TypeNS),
619-
Res::Def(DefKind::Variant, _) => {
620-
return handle_variant(self.cx, res);
608+
Res::Def(DefKind::Variant, def_id) => {
609+
let enum_def_id = self.cx.tcx.parent(def_id).expect("variant has no parent");
610+
return Ok((
611+
Res::Def(DefKind::Enum, enum_def_id),
612+
Some(ItemFragment(FragmentKind::Variant, def_id)),
613+
));
621614
}
622615
// Not a trait item; just return what we found.
623616
_ => return Ok((res, None)),
@@ -1268,19 +1261,7 @@ impl LinkCollector<'_, '_> {
12681261
// parent_node first.
12691262
let base_node =
12701263
if item.is_mod() && inner_docs { self.mod_ids.last().copied() } else { parent_node };
1271-
1272-
let Some(module_id) = base_node else {
1273-
// This is a bug.
1274-
debug!("attempting to resolve item without parent module: {}", path_str);
1275-
resolution_failure(
1276-
self,
1277-
diag_info,
1278-
path_str,
1279-
disambiguator,
1280-
smallvec![ResolutionFailure::NoParentItem],
1281-
);
1282-
return None;
1283-
};
1264+
let module_id = base_node.expect("doc link without parent module");
12841265

12851266
let (mut res, fragment) = self.resolve_with_disambiguator_cached(
12861267
ResolutionInfo {
@@ -2140,17 +2121,6 @@ fn resolution_failure(
21402121
expected_ns.descr()
21412122
)
21422123
}
2143-
ResolutionFailure::NoParentItem => {
2144-
// FIXME(eddyb) this doesn't belong here, whatever made
2145-
// the `ResolutionFailure::NoParentItem` should emit an
2146-
// immediate or delayed `span_bug` about the issue.
2147-
tcx.sess.delay_span_bug(
2148-
sp.unwrap_or(DUMMY_SP),
2149-
"intra-doc link missing parent item",
2150-
);
2151-
2152-
"BUG: all intra-doc links should have a parent item".to_owned()
2153-
}
21542124
ResolutionFailure::MalformedGenerics(variant) => match variant {
21552125
MalformedGenerics::UnbalancedAngleBrackets => {
21562126
String::from("unbalanced angle brackets")
@@ -2331,17 +2301,6 @@ fn privacy_error(cx: &DocContext<'_>, diag_info: &DiagnosticInfo<'_>, path_str:
23312301
});
23322302
}
23332303

2334-
/// Given an enum variant's res, return the res of its enum and the associated fragment.
2335-
fn handle_variant(
2336-
cx: &DocContext<'_>,
2337-
res: Res,
2338-
) -> Result<(Res, Option<ItemFragment>), ErrorKind<'static>> {
2339-
let parent = cx.tcx.parent(res.def_id(cx.tcx));
2340-
let parent_def = Res::Def(DefKind::Enum, parent);
2341-
let variant = cx.tcx.expect_variant_res(res.as_hir_res().unwrap());
2342-
Ok((parent_def, Some(ItemFragment(FragmentKind::Variant, variant.def_id))))
2343-
}
2344-
23452304
/// Resolve a primitive type or value.
23462305
fn resolve_primitive(path_str: &str, ns: Namespace) -> Option<Res> {
23472306
if ns != TypeNS {

0 commit comments

Comments
 (0)