- /// Used for reporting better errors.
- ///
- /// Returns whether the link resolved 'fully' in another namespace.
- /// 'fully' here means that all parts of the link resolved, not just some path segments.
- /// This returns the `Res` even if it was erroneous for some reason
- /// (such as having invalid URL fragments or being in the wrong namespace).
- fn check_full_res(
- &mut self,
- ns: Namespace,
- path_str: &str,
- item_id: ItemId,
- module_id: DefId,
- extra_fragment: &Option<String>,
- ) -> Option<Res> {
- // resolve() can't be used for macro namespace
- let result = match ns {
- Namespace::MacroNS => self
- .resolve_macro(path_str, item_id, module_id)
- .map(|res| (res, None))
- .map_err(ErrorKind::from),
- Namespace::TypeNS | Namespace::ValueNS => {
- self.resolve(path_str, ns, item_id, module_id, extra_fragment)
- }
- };
-
- let res = match result {
- Ok((res, frag)) => {
- if let Some(UrlFragment::Item(ItemFragment(_, id))) = frag {
- Some(Res::Def(self.cx.tcx.def_kind(id), id))
- } else {
- Some(res)
- }
- }
- Err(ErrorKind::Resolve(box kind)) => kind.full_res(),
- Err(ErrorKind::AnchorFailure(AnchorFailure::RustdocAnchorConflict(res))) => Some(res),
- Err(ErrorKind::AnchorFailure(AnchorFailure::MultipleAnchors)) => None,
- };
- res
- }
+fn full_res(tcx: TyCtxt<'_>, (base, assoc_item): (Res, Option<DefId>)) -> Res {
+ assoc_item.map_or(base, |def_id| Res::from_def_id(tcx, def_id))