+ pub fn maybe_resolve_path(&self, p: &syn::Path, generics: Option<&GenericTypes>) -> Option<String> {
+ self.maybe_resolve_imported_path(p, generics).map(|mut path| {
+ if path == "core::ops::Deref" || path == "core::ops::DerefMut" {
+ let last_seg = p.segments.last().unwrap();
+ if let syn::PathArguments::AngleBracketed(args) = &last_seg.arguments {
+ assert_eq!(args.args.len(), 1);
+ if let syn::GenericArgument::Binding(binding) = &args.args[0] {
+ if let syn::Type::Path(p) = &binding.ty {
+ if let Some(inner_ty) = self.maybe_resolve_path(&p.path, generics) {
+ let mut module_riter = inner_ty.rsplitn(2, "::");
+ let ty_ident = module_riter.next().unwrap();
+ let module_name = module_riter.next().unwrap();
+ let module = self.library.modules.get(module_name).unwrap();
+ for item in module.items.iter() {
+ match item {
+ syn::Item::Trait(t) => {
+ if t.ident == ty_ident {
+ path = inner_ty;
+ break;
+ }
+ },
+ _ => {}
+ }
+ }
+ }
+ } else { unimplemented!(); }
+ } else { unimplemented!(); }
+ }
+ }
+ loop {
+ // Now that we've resolved the path to the path as-imported, check whether the path
+ // is actually a pub(.*) use statement and map it to the real path.
+ let path_tmp = path.clone();
+ let crate_name = path_tmp.splitn(2, "::").next().unwrap();
+ let mut module_riter = path_tmp.rsplitn(2, "::");
+ let obj = module_riter.next().unwrap();
+ if let Some(module_path) = module_riter.next() {
+ if let Some(m) = self.library.modules.get(module_path) {
+ for item in m.items.iter() {
+ if let syn::Item::Use(syn::ItemUse { vis, tree, .. }) = item {
+ match vis {
+ syn::Visibility::Public(_)|
+ syn::Visibility::Crate(_)|
+ syn::Visibility::Restricted(_) => {
+ Self::walk_use_intern(crate_name, module_path,
+ &self.library.dependencies, tree, "",
+ syn::punctuated::Punctuated::new(), &mut |ident, (use_path, _)| {
+ if format!("{}", ident) == obj {
+ path = use_path;
+ }
+ });
+ },
+ syn::Visibility::Inherited => {},
+ }
+ }
+ }
+ }
+ }
+ break;
+ }
+ path
+ })
+ }
+