Skip to content
Permalink
Browse files

Use new ErrorKind enum

  • Loading branch information
GuillaumeGomez committed Nov 27, 2019
1 parent b91a6fc commit 97c427cc5ee8d1748ff3a3547bd22cd64d23a6e2
Showing with 16 additions and 10 deletions.
  1. +16 −10 src/librustdoc/passes/collect_intra_doc_links.rs
@@ -61,25 +61,31 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
path_str: &str,
current_item: &Option<String>,
module_id: syntax::ast::NodeId,
) -> Result<(Res, Option<String>), ()> {
) -> Result<(Res, Option<String>), ErrorKind> {
let cx = self.cx;

let mut split = path_str.rsplitn(3, "::");
let variant_field_name = split.next().map(|f| Symbol::intern(f)).ok_or(())?;
let variant_name = split.next().map(|f| Symbol::intern(f)).ok_or(())?;
let variant_field_name = split
.next()
.map(|f| Symbol::intern(f))
.ok_or(ErrorKind::ResolutionFailure)?;
let variant_name = split
.next()
.map(|f| Symbol::intern(f))
.ok_or(ErrorKind::ResolutionFailure)?;
let path = split.next().map(|f| {
if f == "self" || f == "Self" {
if let Some(name) = current_item.as_ref() {
return name.clone();
}
}
f.to_owned()
}).ok_or(())?;
}).ok_or(ErrorKind::ResolutionFailure)?;
let (_, ty_res) = cx.enter_resolver(|resolver| {
resolver.resolve_str_path_error(DUMMY_SP, &path, TypeNS, module_id)
})?;
}).map_err(|_| ErrorKind::ResolutionFailure)?;
if let Res::Err = ty_res {
return Err(());
return Err(ErrorKind::ResolutionFailure);
}
let ty_res = ty_res.map_id(|_| panic!("unexpected node_id"));
match ty_res {
@@ -88,7 +94,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
.iter()
.flat_map(|imp| cx.tcx.associated_items(*imp))
.any(|item| item.ident.name == variant_name) {
return Err(());
return Err(ErrorKind::ResolutionFailure);
}
match cx.tcx.type_of(did).kind {
ty::Adt(def, _) if def.is_enum() => {
@@ -98,13 +104,13 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
Some(format!("variant.{}.field.{}",
variant_name, variant_field_name))))
} else {
Err(())
Err(ErrorKind::ResolutionFailure)
}
}
_ => Err(()),
_ => Err(ErrorKind::ResolutionFailure),
}
}
_ => Err(())
_ => Err(ErrorKind::ResolutionFailure)
}
}

0 comments on commit 97c427c

Please sign in to comment.
You can’t perform that action at this time.