writeln!(w, "impl Drop for {} {{", mangled_container).unwrap();
writeln!(w, "\tfn drop(&mut self) {{").unwrap();
writeln!(w, "\t\tif self.datalen == 0 {{ return; }}").unwrap();
- writeln!(w, "\t\tunsafe {{ Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }};").unwrap();
+ writeln!(w, "\t\tlet _ = unsafe {{ Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }};").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "}}").unwrap();
if clonable {
match token_iter.next().unwrap() {
TokenTree::Literal(lit) => {
// Drop the first and last chars from lit as they are always "
- let doc = format!("{}", lit);
+ let doc = format!("{}", lit).trim().replace("\n", &format!("\n{}//!", prefix));
writeln!(w, "{}//!{}", prefix, &doc[1..doc.len() - 1]).unwrap();
},
_ => unimplemented!(),
match token_iter.next().unwrap() {
TokenTree::Literal(lit) => {
// Drop the first and last chars from lit as they are always "
- let doc = format!("{}", lit);
+ let doc = format!("{}", lit).trim().replace("\n", &format!("\n{}///", prefix));
writeln!(w, "{}///{}", prefix, &doc[1..doc.len() - 1]).unwrap();
},
_ => unimplemented!(),
},
_ => unimplemented!(),
}
- w.write(&c_type).unwrap();
+ w.write_all(&c_type).unwrap();
}
}
}
/// Prints concrete generic parameters for a struct/trait/function, including the less-than and
/// greater-than symbols, if any generic parameters are defined.
-pub fn maybe_write_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generics, types: &TypeResolver, concrete_lifetimes: bool) {
+pub fn maybe_write_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generics, generics_impld: &syn::PathArguments, types: &TypeResolver, concrete_lifetimes: bool) {
let mut gen_types = GenericTypes::new(None);
assert!(gen_types.learn_generics(generics, types));
if generics.params.is_empty() { return; }
syn::GenericParam::Type(type_param) => {
write!(w, "{}", if idx != 0 { ", " } else { "" }).unwrap();
let type_ident = &type_param.ident;
- types.write_c_type_in_generic_param(w, &syn::parse_quote!(#type_ident), Some(&gen_types), false);
+ if types.understood_c_type(&syn::parse_quote!(#type_ident), Some(&gen_types)) {
+ types.write_c_type_in_generic_param(w, &syn::parse_quote!(#type_ident), Some(&gen_types), false);
+ } else {
+ if let syn::PathArguments::AngleBracketed(args) = generics_impld {
+ if let syn::GenericArgument::Type(ty) = &args.args[idx] {
+ types.write_c_type_in_generic_param(w, &ty, Some(&gen_types), false);
+ }
+ }
+ }
},
syn::GenericParam::Lifetime(lt) => {
if concrete_lifetimes {