Skip to content

Commit 95fb05d

Browse files
committed
rustdoc: Remove ResolutionFailure::Dummy
The variant resolution check didn't make sense, and derive trait collision could be processed in a different way
1 parent c979ef5 commit 95fb05d

File tree

1 file changed

+20
-37
lines changed

1 file changed

+20
-37
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,6 @@ enum ResolutionFailure<'a> {
181181
/// In `[std::io::Error::x]`, `x` would be unresolved.
182182
unresolved: Cow<'a, str>,
183183
},
184-
/// Used to communicate that this should be ignored, but shouldn't be reported to the user.
185-
///
186-
/// This happens when there is no disambiguator and one of the namespaces
187-
/// failed to resolve.
188-
Dummy,
189184
}
190185

191186
#[derive(Clone, Copy, Debug)]
@@ -405,35 +400,22 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
405400
let ty_res = self.resolve_path(&path, TypeNS, item_id, module_id).ok_or_else(no_res)?;
406401

407402
match ty_res {
408-
Res::Def(DefKind::Enum, did) => {
409-
if tcx
410-
.inherent_impls(did)
411-
.iter()
412-
.flat_map(|imp| tcx.associated_items(*imp).in_definition_order())
413-
.any(|item| item.name == variant_name)
414-
{
415-
// This is just to let `fold_item` know that this shouldn't be considered;
416-
// it's a bug for the error to make it to the user
417-
return Err(ResolutionFailure::Dummy.into());
418-
}
419-
match tcx.type_of(did).kind() {
420-
ty::Adt(def, _) if def.is_enum() => {
421-
if let Some(field) = def.all_fields().find(|f| f.name == variant_field_name)
422-
{
423-
Ok((ty_res, Some(ItemFragment(FragmentKind::VariantField, field.did))))
424-
} else {
425-
Err(ResolutionFailure::NotResolved {
426-
item_id,
427-
module_id,
428-
partial_res: Some(Res::Def(DefKind::Enum, def.did())),
429-
unresolved: variant_field_name.to_string().into(),
430-
}
431-
.into())
403+
Res::Def(DefKind::Enum, did) => match tcx.type_of(did).kind() {
404+
ty::Adt(def, _) if def.is_enum() => {
405+
if let Some(field) = def.all_fields().find(|f| f.name == variant_field_name) {
406+
Ok((ty_res, Some(ItemFragment(FragmentKind::VariantField, field.did))))
407+
} else {
408+
Err(ResolutionFailure::NotResolved {
409+
item_id,
410+
module_id,
411+
partial_res: Some(Res::Def(DefKind::Enum, def.did())),
412+
unresolved: variant_field_name.to_string().into(),
432413
}
414+
.into())
433415
}
434-
_ => unreachable!(),
435416
}
436-
}
417+
_ => unreachable!(),
418+
},
437419
_ => Err(ResolutionFailure::NotResolved {
438420
item_id,
439421
module_id,
@@ -1535,7 +1517,7 @@ impl LinkCollector<'_, '_> {
15351517
}
15361518
None => {
15371519
// Try everything!
1538-
let mut candidates = PerNS {
1520+
let candidates = PerNS {
15391521
macro_ns: self
15401522
.resolve_macro(path_str, item_id, base_node)
15411523
.map(|res| (res, extra_fragment.clone().map(UrlFragment::UserWritten))),
@@ -1611,11 +1593,13 @@ impl LinkCollector<'_, '_> {
16111593
} else if len == 2 && is_derive_trait_collision(&candidates) {
16121594
Some(candidates.type_ns.unwrap())
16131595
} else {
1614-
if is_derive_trait_collision(&candidates) {
1615-
candidates.macro_ns = Err(ResolutionFailure::Dummy);
1616-
}
1596+
let ignore_macro = is_derive_trait_collision(&candidates);
16171597
// If we're reporting an ambiguity, don't mention the namespaces that failed
1618-
let candidates = candidates.map(|candidate| candidate.ok().map(|(res, _)| res));
1598+
let mut candidates =
1599+
candidates.map(|candidate| candidate.ok().map(|(res, _)| res));
1600+
if ignore_macro {
1601+
candidates.macro_ns = None;
1602+
}
16191603
ambiguity_error(self.cx, diag, path_str, candidates.present_items().collect());
16201604
None
16211605
}
@@ -2092,7 +2076,6 @@ fn resolution_failure(
20922076
}
20932077
let note = match failure {
20942078
ResolutionFailure::NotResolved { .. } => unreachable!("handled above"),
2095-
ResolutionFailure::Dummy => continue,
20962079
ResolutionFailure::WrongNamespace { res, expected_ns } => {
20972080
suggest_disambiguator(res, diag, path_str, diag_info.ori_link, sp);
20982081

0 commit comments

Comments
 (0)