Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f89e2dd

Browse files
committed
Move anchor conflict check to call site
I think it makes the code easier to understand.
1 parent cfa4ac6 commit f89e2dd

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,14 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
514514
Res::Def(DefKind::AssocFn | DefKind::AssocConst, _) => assert_eq!(ns, ValueNS),
515515
Res::Def(DefKind::AssocTy, _) => assert_eq!(ns, TypeNS),
516516
Res::Def(DefKind::Variant, _) => {
517-
return handle_variant(self.cx, res, extra_fragment);
517+
if extra_fragment.is_some() {
518+
// NOTE: `res` can never be a primitive since this match arm means
519+
// `tcx.def_kind(res) == DefKind::Variant`.
520+
return Err(ErrorKind::AnchorFailure(
521+
AnchorFailure::RustdocAnchorConflict(res),
522+
));
523+
}
524+
return handle_variant(self.cx, res);
518525
}
519526
// Not a trait item; just return what we found.
520527
_ => return Ok((res, extra_fragment.clone())),
@@ -2272,14 +2279,9 @@ fn privacy_error(cx: &DocContext<'_>, diag_info: &DiagnosticInfo<'_>, path_str:
22722279
fn handle_variant(
22732280
cx: &DocContext<'_>,
22742281
res: Res,
2275-
extra_fragment: &Option<UrlFragment>,
22762282
) -> Result<(Res, Option<UrlFragment>), ErrorKind<'static>> {
22772283
use rustc_middle::ty::DefIdTree;
22782284

2279-
if extra_fragment.is_some() {
2280-
// NOTE: `res` can never be a primitive since this function is only called when `tcx.def_kind(res) == DefKind::Variant`.
2281-
return Err(ErrorKind::AnchorFailure(AnchorFailure::RustdocAnchorConflict(res)));
2282-
}
22832285
cx.tcx
22842286
.parent(res.def_id(cx.tcx))
22852287
.map(|parent| {

0 commit comments

Comments
 (0)