-/// Insert ident -> absolute Path resolutions into imports from the given UseTree and path-prefix.
-fn process_use_intern<'a>(u: &'a syn::UseTree, mut path: syn::punctuated::Punctuated<syn::PathSegment, syn::token::Colon2>, imports: &mut HashMap<&'a syn::Ident, syn::Path>) {
- match u {
- syn::UseTree::Path(p) => {
- path.push(syn::PathSegment { ident: p.ident.clone(), arguments: syn::PathArguments::None });
- process_use_intern(&p.tree, path, imports);
- },
- syn::UseTree::Name(n) => {
- path.push(syn::PathSegment { ident: n.ident.clone(), arguments: syn::PathArguments::None });
- imports.insert(&n.ident, syn::Path { leading_colon: Some(syn::Token![::](Span::call_site())), segments: path });
- },
- syn::UseTree::Group(g) => {
- for i in g.items.iter() {
- process_use_intern(i, path.clone(), imports);
- }
- },
- _ => {}
- }
-}
-
-/// Map all the Paths in a Type into absolute paths given a set of imports (generated via process_use_intern)
-fn resolve_imported_refs(imports: &HashMap<&syn::Ident, syn::Path>, mut ty: syn::Type) -> syn::Type {
- match &mut ty {
- syn::Type::Path(p) => {
- if let Some(ident) = p.path.get_ident() {
- if let Some(newpath) = imports.get(ident) {
- p.path = newpath.clone();
+fn walk_private_mod<'a>(module: String, items: &'a syn::ItemMod, crate_types: &mut CrateTypes<'a>) {
+ let import_resolver = ImportResolver::new(&module, &items.content.as_ref().unwrap().1);
+ for item in items.content.as_ref().unwrap().1.iter() {
+ match item {
+ syn::Item::Mod(m) => walk_private_mod(format!("{}::{}", module, m.ident), m, crate_types),
+ syn::Item::Impl(i) => {
+ if let &syn::Type::Path(ref p) = &*i.self_ty {
+ if let Some(trait_path) = i.trait_.as_ref() {
+ if let Some(tp) = import_resolver.maybe_resolve_path(&trait_path.1, None) {
+ if let Some(sp) = import_resolver.maybe_resolve_path(&p.path, None) {
+ match crate_types.trait_impls.entry(sp) {
+ hash_map::Entry::Occupied(mut e) => { e.get_mut().push(tp); },
+ hash_map::Entry::Vacant(e) => { e.insert(vec![tp]); },
+ }
+ }
+ }
+ }