if path_matches_nongeneric(&trait_bound.path, &["core", "clone", "Clone"]) { continue; }
assert_simple_bound(&trait_bound);
- if let Some(mut path) = types.maybe_resolve_path(&trait_bound.path, None) {
+ if let Some(path) = types.maybe_resolve_path(&trait_bound.path, None) {
if types.skip_path(&path) { continue; }
if path == "Sized" { continue; }
if non_lifetimes_processed { return false; }
non_lifetimes_processed = true;
let new_ident = if path != "std::ops::Deref" && path != "core::ops::Deref" {
- path = "crate::".to_string() + &path;
Some(&trait_bound.path)
} else if trait_bound.path.segments.len() == 1 {
// If we're templated on Deref<Target = ConcreteThing>, store
if non_lifetimes_processed { return false; }
non_lifetimes_processed = true;
assert_simple_bound(&trait_bound);
- *gen = ("crate::".to_string() + &types.resolve_path(&trait_bound.path, None),
+ *gen = (types.resolve_path(&trait_bound.path, None),
Some(&trait_bound.path));
}
}
match bounds_iter.next().unwrap() {
syn::TypeParamBound::Trait(tr) => {
assert_simple_bound(&tr);
- if let Some(mut path) = types.maybe_resolve_path(&tr.path, None) {
+ if let Some(path) = types.maybe_resolve_path(&tr.path, None) {
if types.skip_path(&path) { continue; }
// In general we handle Deref<Target=X> as if it were just X (and
// implement Deref<Target=Self> for relevant types). We don't
// bother to implement it for associated types, however, so we just
// ignore such bounds.
let new_ident = if path != "std::ops::Deref" && path != "core::ops::Deref" {
- path = "crate::".to_string() + &path;
Some(&tr.path)
} else { None };
self.typed_generics.insert(&t.ident, (path, new_ident));
} else { None }
}
- pub fn maybe_resolve_path(&self, p_arg: &syn::Path, generics: Option<&GenericTypes>) -> Option<String> {
- let p = if let Some(gen_types) = generics {
- if let Some((_, synpath)) = gen_types.maybe_resolve_path(p_arg) {
- synpath
- } else { p_arg }
- } else { p_arg };
+ pub fn maybe_resolve_path(&self, p: &syn::Path, generics: Option<&GenericTypes>) -> Option<String> {
+ if let Some(gen_types) = generics {
+ if let Some((resp, _)) = gen_types.maybe_resolve_path(p) {
+ return Some(resp.clone());
+ }
+ }
if p.leading_colon.is_some() {
let mut res: String = p.segments.iter().enumerate().map(|(idx, seg)| {
"std::time::SystemTime" => Some("u64"),
"std::io::Error" => Some("crate::c_types::IOError"),
+ "core::convert::Infallible" => Some("crate::c_types::NotConstructable"),
+
"bech32::u5" => Some("crate::c_types::u5"),
"core::num::NonZeroU8" => Some("u8"),
// Note that we'll panic for String if is_ref, as we only have non-owned memory, we
// cannot create a &String.
+ "core::convert::Infallible" => Some("panic!(\"You must never construct a NotConstructable! : "),
+
"std::time::Duration"|"core::time::Duration" => Some("std::time::Duration::from_secs("),
"std::time::SystemTime" => Some("(::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs("),
"alloc::string::String"|"String" => Some(".into_string()"),
"std::io::Error" if !is_ref => Some(".to_rust()"),
+ "core::convert::Infallible" => Some("\")"),
+
"std::time::Duration"|"core::time::Duration" => Some(")"),
"std::time::SystemTime" => Some("))"),
"std::time::SystemTime" => Some(""),
"std::io::Error" if !is_ref => Some("crate::c_types::IOError::from_rust("),
+ "core::convert::Infallible" => Some("panic!(\"Cannot construct an Infallible: "),
+
"bech32::u5" => Some(""),
"bitcoin::secp256k1::key::PublicKey"|"bitcoin::secp256k1::PublicKey"|"secp256k1::key::PublicKey"
"std::time::SystemTime" => Some(".duration_since(::std::time::SystemTime::UNIX_EPOCH).expect(\"Times must be post-1970\").as_secs()"),
"std::io::Error" if !is_ref => Some(")"),
+ "core::convert::Infallible" => Some("\")"),
+
"bech32::u5" => Some(".into()"),
"bitcoin::secp256k1::key::PublicKey"|"bitcoin::secp256k1::PublicKey"|"secp256k1::key::PublicKey"
}
}
+ /// When printing a reference to the source crate's rust type, if we need to map it to a
+ /// different "real" type, it can be done so here.
+ /// This is useful to work around limitations in the binding type resolver, where we reference
+ /// a non-public `use` alias.
+ /// TODO: We should never need to use this!
+ fn real_rust_type_mapping<'equiv>(&self, thing: &'equiv str) -> &'equiv str {
+ match thing {
+ "lightning::io::Read" => "std::io::Read",
+ _ => thing,
+ }
+ }
+
// ****************************
// *** Container Processing ***
// ****************************
// If we're printing a generic argument, it needs to reference the crate, otherwise
// the original crate:
} else if self.maybe_resolve_path(&path, None).as_ref() == Some(&resolved) {
- write!(w, "{}", resolved).unwrap();
+ write!(w, "{}", self.real_rust_type_mapping(&resolved)).unwrap();
} else {
write!(w, "crate::{}", resolved).unwrap();
}