From: Matt Corallo Date: Tue, 4 Jun 2024 17:47:02 +0000 (+0000) Subject: Handle `Vec`s resolved as `alloc::vec::Vec` X-Git-Tag: v0.0.123.1^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=d5bd2d5366d797aa990799f78cc987b0be73de71;p=ldk-c-bindings Handle `Vec`s resolved as `alloc::vec::Vec` Up until now we'd always relied on `Vec`s being imported through a prelude, but LDK sometimes forgets to keep doing that. Thus, here we move to also accepting `alloc::vec::Vec` by mapping it to `Vec` during name resolution. --- diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index 0da41e6..877331e 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -656,7 +656,7 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr } } - if p.leading_colon.is_some() { + let result = if p.leading_colon.is_some() { let mut res: String = p.segments.iter().enumerate().map(|(idx, seg)| { format!("{}{}", if idx == 0 { "" } else { "::" }, seg.ident) }).collect(); @@ -667,11 +667,10 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr Some(res) } else if let Some(id) = p.get_ident() { self.maybe_resolve_ident(id) + } else if p.segments.len() == 1 { + let seg = p.segments.iter().next().unwrap(); + self.maybe_resolve_ident(&seg.ident) } else { - if p.segments.len() == 1 { - let seg = p.segments.iter().next().unwrap(); - return self.maybe_resolve_ident(&seg.ident); - } let mut seg_iter = p.segments.iter(); let first_seg = seg_iter.next().unwrap(); let remaining: String = seg_iter.map(|seg| { @@ -693,6 +692,13 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr } else if self.library.modules.get(&format!("{}::{}", self.module_path, first_seg.ident)).is_some() { Some(format!("{}::{}{}", self.module_path, first_seg.ident, remaining)) } else { None } + }; + // We're only set up to handle `Vec` imported via the prelude, but its often imported + // via the alloc stdlib crate, so map it here. + if result.as_ref().map(|s| s.as_str()) == Some("alloc::vec::Vec") { + Some("Vec".to_string()) + } else { + result } }