Skip to content

Commit d5bd2d5

Browse files
committed
Handle Vecs 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.
1 parent 94b7d3f commit d5bd2d5

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

c-bindings-gen/src/types.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
656656
}
657657
}
658658

659-
if p.leading_colon.is_some() {
659+
let result = if p.leading_colon.is_some() {
660660
let mut res: String = p.segments.iter().enumerate().map(|(idx, seg)| {
661661
format!("{}{}", if idx == 0 { "" } else { "::" }, seg.ident)
662662
}).collect();
@@ -667,11 +667,10 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
667667
Some(res)
668668
} else if let Some(id) = p.get_ident() {
669669
self.maybe_resolve_ident(id)
670+
} else if p.segments.len() == 1 {
671+
let seg = p.segments.iter().next().unwrap();
672+
self.maybe_resolve_ident(&seg.ident)
670673
} else {
671-
if p.segments.len() == 1 {
672-
let seg = p.segments.iter().next().unwrap();
673-
return self.maybe_resolve_ident(&seg.ident);
674-
}
675674
let mut seg_iter = p.segments.iter();
676675
let first_seg = seg_iter.next().unwrap();
677676
let remaining: String = seg_iter.map(|seg| {
@@ -693,6 +692,13 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
693692
} else if self.library.modules.get(&format!("{}::{}", self.module_path, first_seg.ident)).is_some() {
694693
Some(format!("{}::{}{}", self.module_path, first_seg.ident, remaining))
695694
} else { None }
695+
};
696+
// We're only set up to handle `Vec` imported via the prelude, but its often imported
697+
// via the alloc stdlib crate, so map it here.
698+
if result.as_ref().map(|s| s.as_str()) == Some("alloc::vec::Vec") {
699+
Some("Vec".to_string())
700+
} else {
701+
result
696702
}
697703
}
698704

0 commit comments

Comments
 (0)