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]); },
+ match crate_types.trait_impls.entry(sp.clone()) {
+ hash_map::Entry::Occupied(mut e) => { e.get_mut().push(tp.clone()); },
+ hash_map::Entry::Vacant(e) => { e.insert(vec![tp.clone()]); },
+ }
+ match crate_types.traits_impld.entry(tp) {
+ hash_map::Entry::Occupied(mut e) => { e.get_mut().push(sp); },
+ hash_map::Entry::Vacant(e) => { e.insert(vec![sp]); },
}
}
}
}
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]); },
+ match crate_types.trait_impls.entry(sp.clone()) {
+ hash_map::Entry::Occupied(mut e) => { e.get_mut().push(tp.clone()); },
+ hash_map::Entry::Vacant(e) => { e.insert(vec![tp.clone()]); },
+ }
+ match crate_types.traits_impld.entry(tp) {
+ hash_map::Entry::Occupied(mut e) => { e.get_mut().push(sp); },
+ hash_map::Entry::Vacant(e) => { e.insert(vec![sp]); },
}
}
}
clonable_types: RefCell<HashSet<String>>,
/// Key impls Value
pub trait_impls: HashMap<String, Vec<String>>,
+ /// Value impls Key
+ pub traits_impld: HashMap<String, Vec<String>>,
/// The full set of modules in the crate(s)
pub lib_ast: &'a FullLibraryAST,
}
opaques: HashMap::new(), mirrored_enums: HashMap::new(), traits: HashMap::new(),
type_aliases: HashMap::new(), reverse_alias_map: HashMap::new(),
templates_defined: RefCell::new(HashMap::default()), priv_structs: HashMap::new(),
- clonable_types: RefCell::new(initial_clonable_types()), trait_impls: HashMap::new(),
+ clonable_types: RefCell::new(initial_clonable_types()),
+ trait_impls: HashMap::new(), traits_impld: HashMap::new(),
template_file: RefCell::new(template_file), lib_ast: &libast,
}
}
if let Some(decl_type) = self.types.maybe_resolve_declared(ident) {
decl_lookup(w, decl_type, &self.maybe_resolve_ident(ident).unwrap(), is_ref, is_mut);
} else { unimplemented!(); }
- } else { unimplemented!(); }
+ } else {
+ if let Some(trait_impls) = self.crate_types.traits_impld.get(&resolved_path) {
+ if trait_impls.len() == 1 {
+ // If this is a no-export'd crate and there's only one implementation
+ // in the whole crate, just treat it as a reference to whatever the
+ // implementor is.
+ let implementor = self.crate_types.opaques.get(&trait_impls[0]).unwrap();
+ decl_lookup(w, &DeclType::StructImported { generics: &implementor.1 }, &trait_impls[0], true, is_mut);
+ return;
+ }
+ }
+ unimplemented!();
+ }
},
syn::Type::Array(a) => {
if let syn::Type::Path(p) = &*a.elem {
}
true
} else {
+ if let Some(trait_impls) = self.crate_types.traits_impld.get(&full_path) {
+ if trait_impls.len() == 1 {
+ // If this is a no-export'd crate and there's only one implementation in the
+ // whole crate, just treat it as a reference to whatever the implementor is.
+ if with_ref_lifetime {
+ write!(w, "&'static crate::{}", trait_impls[0]).unwrap();
+ } else {
+ write!(w, "&crate::{}", trait_impls[0]).unwrap();
+ }
+ return true;
+ }
+ }
false
}
}