@@ -205,10 +205,10 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
205
205
}
206
206
207
207
/// Learn the generics in generics in the current context, given a TypeResolver.
208
- pub fn learn_generics < ' b , ' c > ( & mut self , generics : & ' a syn:: Generics , types : & ' b TypeResolver < ' a , ' c > ) -> bool {
208
+ pub fn learn_generics_with_impls < ' b , ' c > ( & mut self , generics : & ' a syn:: Generics , impld_generics : & ' a syn :: PathArguments , types : & ' b TypeResolver < ' a , ' c > ) -> bool {
209
209
let mut new_typed_generics = HashMap :: new ( ) ;
210
210
// First learn simple generics...
211
- for generic in generics. params . iter ( ) {
211
+ for ( idx , generic) in generics. params . iter ( ) . enumerate ( ) {
212
212
match generic {
213
213
syn:: GenericParam :: Type ( type_param) => {
214
214
let mut non_lifetimes_processed = false ;
@@ -260,6 +260,15 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
260
260
if let Some ( default) = type_param. default . as_ref ( ) {
261
261
assert ! ( type_param. bounds. is_empty( ) ) ;
262
262
self . default_generics . insert ( & type_param. ident , ( default. clone ( ) , parse_quote ! ( & #default ) , parse_quote ! ( & mut #default ) ) ) ;
263
+ } else if type_param. bounds . is_empty ( ) {
264
+ if let syn:: PathArguments :: AngleBracketed ( args) = impld_generics {
265
+ match & args. args [ idx] {
266
+ syn:: GenericArgument :: Type ( ty) => {
267
+ self . default_generics . insert ( & type_param. ident , ( ty. clone ( ) , parse_quote ! ( & #ty) , parse_quote ! ( & mut #ty) ) ) ;
268
+ }
269
+ _ => unimplemented ! ( ) ,
270
+ }
271
+ }
263
272
}
264
273
} ,
265
274
_ => { } ,
@@ -270,6 +279,7 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
270
279
for pred in wh. predicates . iter ( ) {
271
280
if let syn:: WherePredicate :: Type ( t) = pred {
272
281
if let syn:: Type :: Path ( p) = & t. bounded_ty {
282
+ if first_seg_self ( & t. bounded_ty ) . is_some ( ) && p. path . segments . len ( ) == 1 { continue ; }
273
283
if p. qself . is_some ( ) { return false ; }
274
284
if p. path . leading_colon . is_some ( ) { return false ; }
275
285
let mut p_iter = p. path . segments . iter ( ) ;
@@ -315,6 +325,11 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
315
325
true
316
326
}
317
327
328
+ /// Learn the generics in generics in the current context, given a TypeResolver.
329
+ pub fn learn_generics < ' b , ' c > ( & mut self , generics : & ' a syn:: Generics , types : & ' b TypeResolver < ' a , ' c > ) -> bool {
330
+ self . learn_generics_with_impls ( generics, & syn:: PathArguments :: None , types)
331
+ }
332
+
318
333
/// Learn the associated types from the trait in the current context.
319
334
pub fn learn_associated_types < ' b , ' c > ( & mut self , t : & ' a syn:: ItemTrait , types : & ' b TypeResolver < ' a , ' c > ) {
320
335
for item in t. items . iter ( ) {
@@ -635,6 +650,8 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
635
650
Some ( format ! ( "{}::{}{}" , self . module_path, first_seg. ident, remaining) )
636
651
} else if first_seg_is_stdlib ( & first_seg_str) || self . dependencies . contains ( & first_seg. ident ) {
637
652
Some ( first_seg_str + & remaining)
653
+ } else if first_seg_str == "crate" {
654
+ Some ( self . crate_name . to_owned ( ) + & remaining)
638
655
} else { None }
639
656
}
640
657
}
@@ -915,7 +932,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
915
932
916
933
"std::time::Duration" |"core::time::Duration" => Some ( "u64" ) ,
917
934
"std::time::SystemTime" => Some ( "u64" ) ,
918
- "std::io::Error" |"lightning::io::Error" => Some ( "crate::c_types::IOError" ) ,
935
+ "std::io::Error" |"lightning::io::Error" | "lightning::io::ErrorKind" => Some ( "crate::c_types::IOError" ) ,
919
936
"core::fmt::Arguments" if is_ref => Some ( "crate::c_types::Str" ) ,
920
937
921
938
"core::convert::Infallible" => Some ( "crate::c_types::NotConstructable" ) ,
@@ -1000,7 +1017,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1000
1017
1001
1018
"str" if is_ref => Some ( "" ) ,
1002
1019
"alloc::string::String" |"String" => Some ( "" ) ,
1003
- "std::io::Error" |"lightning::io::Error" => Some ( "" ) ,
1020
+ "std::io::Error" |"lightning::io::Error" | "lightning::io::ErrorKind" => Some ( "" ) ,
1004
1021
// Note that we'll panic for String if is_ref, as we only have non-owned memory, we
1005
1022
// cannot create a &String.
1006
1023
@@ -1091,6 +1108,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1091
1108
"str" if is_ref => Some ( ".into_str()" ) ,
1092
1109
"alloc::string::String" |"String" => Some ( ".into_string()" ) ,
1093
1110
"std::io::Error" |"lightning::io::Error" => Some ( ".to_rust()" ) ,
1111
+ "lightning::io::ErrorKind" => Some ( ".to_rust_kind()" ) ,
1094
1112
1095
1113
"core::convert::Infallible" => Some ( "\" )" ) ,
1096
1114
@@ -1187,6 +1205,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1187
1205
"std::time::Duration" |"core::time::Duration" => Some ( "" ) ,
1188
1206
"std::time::SystemTime" => Some ( "" ) ,
1189
1207
"std::io::Error" |"lightning::io::Error" => Some ( "crate::c_types::IOError::from_rust(" ) ,
1208
+ "lightning::io::ErrorKind" => Some ( "crate::c_types::IOError::from_rust_kind(" ) ,
1190
1209
"core::fmt::Arguments" => Some ( "alloc::format!(\" {}\" , " ) ,
1191
1210
1192
1211
"core::convert::Infallible" => Some ( "panic!(\" Cannot construct an Infallible: " ) ,
@@ -1266,7 +1285,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1266
1285
1267
1286
"std::time::Duration" |"core::time::Duration" => Some ( ".as_secs()" ) ,
1268
1287
"std::time::SystemTime" => Some ( ".duration_since(::std::time::SystemTime::UNIX_EPOCH).expect(\" Times must be post-1970\" ).as_secs()" ) ,
1269
- "std::io::Error" |"lightning::io::Error" => Some ( ")" ) ,
1288
+ "std::io::Error" |"lightning::io::Error" | "lightning::io::ErrorKind" => Some ( ")" ) ,
1270
1289
"core::fmt::Arguments" => Some ( ").into()" ) ,
1271
1290
1272
1291
"core::convert::Infallible" => Some ( "\" )" ) ,
0 commit comments