@@ -864,6 +864,8 @@ pub struct CrateTypes<'a> {
864
864
clonable_types : RefCell < HashSet < String > > ,
865
865
/// Key impls Value
866
866
pub trait_impls : HashMap < String , Vec < String > > ,
867
+ /// Value impls Key
868
+ pub traits_impld : HashMap < String , Vec < String > > ,
867
869
/// The full set of modules in the crate(s)
868
870
pub lib_ast : & ' a FullLibraryAST ,
869
871
}
@@ -874,7 +876,8 @@ impl<'a> CrateTypes<'a> {
874
876
opaques : HashMap :: new ( ) , mirrored_enums : HashMap :: new ( ) , traits : HashMap :: new ( ) ,
875
877
type_aliases : HashMap :: new ( ) , reverse_alias_map : HashMap :: new ( ) ,
876
878
templates_defined : RefCell :: new ( HashMap :: default ( ) ) , priv_structs : HashMap :: new ( ) ,
877
- clonable_types : RefCell :: new ( initial_clonable_types ( ) ) , trait_impls : HashMap :: new ( ) ,
879
+ clonable_types : RefCell :: new ( initial_clonable_types ( ) ) ,
880
+ trait_impls : HashMap :: new ( ) , traits_impld : HashMap :: new ( ) ,
878
881
template_file : RefCell :: new ( template_file) , lib_ast : & libast,
879
882
}
880
883
}
@@ -2131,7 +2134,19 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
2131
2134
if let Some ( decl_type) = self . types . maybe_resolve_declared ( ident) {
2132
2135
decl_lookup ( w, decl_type, & self . maybe_resolve_ident ( ident) . unwrap ( ) , is_ref, is_mut) ;
2133
2136
} else { unimplemented ! ( ) ; }
2134
- } else { unimplemented ! ( ) ; }
2137
+ } else {
2138
+ if let Some ( trait_impls) = self . crate_types . traits_impld . get ( & resolved_path) {
2139
+ if trait_impls. len ( ) == 1 {
2140
+ // If this is a no-export'd crate and there's only one implementation
2141
+ // in the whole crate, just treat it as a reference to whatever the
2142
+ // implementor is.
2143
+ let implementor = self . crate_types . opaques . get ( & trait_impls[ 0 ] ) . unwrap ( ) ;
2144
+ decl_lookup ( w, & DeclType :: StructImported { generics : & implementor. 1 } , & trait_impls[ 0 ] , true , is_mut) ;
2145
+ return ;
2146
+ }
2147
+ }
2148
+ unimplemented ! ( ) ;
2149
+ }
2135
2150
} ,
2136
2151
syn:: Type :: Array ( a) => {
2137
2152
if let syn:: Type :: Path ( p) = & * a. elem {
@@ -2969,6 +2984,18 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
2969
2984
}
2970
2985
true
2971
2986
} else {
2987
+ if let Some ( trait_impls) = self . crate_types . traits_impld . get ( & full_path) {
2988
+ if trait_impls. len ( ) == 1 {
2989
+ // If this is a no-export'd crate and there's only one implementation in the
2990
+ // whole crate, just treat it as a reference to whatever the implementor is.
2991
+ if with_ref_lifetime {
2992
+ write ! ( w, "&'static crate::{}" , trait_impls[ 0 ] ) . unwrap ( ) ;
2993
+ } else {
2994
+ write ! ( w, "&crate::{}" , trait_impls[ 0 ] ) . unwrap ( ) ;
2995
+ }
2996
+ return true ;
2997
+ }
2998
+ }
2972
2999
false
2973
3000
}
2974
3001
}
0 commit comments