Skip to content

Commit 12d5e1d

Browse files
committed
Fix small bug with variant fields
Previously, they would be resolved as `DefKind::Variant`, and since they resolved successfully, passed through to `resolve_associated_item`. Then, if resolve_associated_item couldn't handle them, it would pass `path_str` to `variant_field`. But after my change, it no longer had access to `path_str` - all it had was `item_str`, which is only one path segment long. So it would never resolve through `variant_field`. This skips straight to `variant_field` if the path resolved to a variant.
1 parent 2039c41 commit 12d5e1d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
126126
// So there's no partial res and we should say the whole link failed to resolve.
127127
split.next().map(|f| (f, Symbol::intern(f))).ok_or_else(no_res)?;
128128
if split.next().is_some() {
129-
panic!("remaining_path must have at most 2 path segments");
129+
panic!("remaining_path must have at most 2 path segments (got {})", remaining_path);
130130
}
131131

132132
match ty_res {
@@ -311,21 +311,23 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
311311
})
312312
.map(|(_, res)| res);
313313
let ty_res = match ty_res {
314-
Err(()) | Ok(Res::Err) => {
314+
Err(()) | Ok(Res::Err) | Ok(Res::Def(DefKind::Variant, _)) => {
315315
if ns == Namespace::ValueNS {
316316
// Look for variant fields
317317
let mut iter = path_str.rmatch_indices("::");
318318
let segments = iter.by_ref().take(2);
319319
let (base, rest) = if let Some((idx, _)) = segments.last() {
320320
(&path_str[..idx], &path_str[idx + 2..])
321321
} else {
322+
debug!("didn't find three path segments; giving up");
322323
return Err(ResolutionFailure::NotResolved {
323324
module_id,
324325
partial_res: None,
325326
unresolved: path_root.into(),
326327
}
327328
.into());
328329
};
330+
debug!("looking for enum variant {} for enum {}", rest, base);
329331

330332
let ty_res = cx
331333
.enter_resolver(|resolver| {
@@ -538,12 +540,14 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
538540
};
539541
res.unwrap_or_else(|| {
540542
if ns == Namespace::ValueNS {
543+
debug!("considering variant fields for {}", item_str);
541544
let mut iter = item_str.rmatch_indices("::");
542545
let segments = iter.by_ref().take(2);
543546
if let Some((idx, _)) = segments.last() {
544547
// If we had `a::b::variant::field`, where `a` is `ty_res` and `b` is unresolved,
545548
// don't treat it as `a::variant::field`
546549
if !iter.next().is_some() {
550+
debug!("looking for variant field {:?}", &item_str[(idx + 2)..]);
547551
return self.variant_field(ty_res, &item_str[(idx + 2)..], module_id);
548552
}
549553
}

0 commit comments

Comments
 (0)