Skip to content

Commit 40c773f

Browse files
authored
Merge pull request mozilla#355 from lu-zero/fix337
Fix the crate parsing order
2 parents b1de604 + abe104e commit 40c773f

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/bindgen/parser.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -156,44 +156,44 @@ impl<'a> Parser<'a> {
156156
assert!(self.lib.is_some());
157157
self.parsed_crates.insert(pkg.name.clone());
158158

159-
// Before we do anything with this crate, we must first parse all of its dependencies.
160-
// This is guaranteed to terminate because the crate-graph is acyclic (and even if it
161-
// wasn't, we've already marked the crate as parsed in the line above).
162-
for (dep_pkg, cfg) in self.lib.as_ref().unwrap().dependencies(&pkg) {
163-
if !self.should_parse_dependency(&dep_pkg.name) {
164-
continue;
165-
}
166-
167-
if let Some(ref cfg) = cfg {
168-
self.cfg_stack.push(cfg.clone());
169-
}
170-
171-
self.parse_crate(&dep_pkg)?;
172-
173-
if cfg.is_some() {
174-
self.cfg_stack.pop();
175-
}
176-
}
177-
178159
// Check if we should use cargo expand for this crate
179160
if self.expand.contains(&pkg.name) {
180161
return self.parse_expand_crate(pkg);
181162
}
182163

183-
// Otherwise do our normal parse
164+
// Parse the crate before the dependencies otherwise the same-named idents we
165+
// want to generate bindings for would be replaced by the ones provided
166+
// by the first dependency containing it.
184167
let crate_src = self.lib.as_ref().unwrap().find_crate_src(pkg);
185168

186169
match crate_src {
187-
Some(crate_src) => self.parse_mod(pkg, crate_src.as_path()),
170+
Some(crate_src) => self.parse_mod(pkg, crate_src.as_path())?,
188171
None => {
189172
// This should be an error, but is common enough to just elicit a warning
190173
warn!(
191174
"Parsing crate `{}`: can't find lib.rs with `cargo metadata`.",
192175
pkg.name
193176
);
194-
Ok(())
195177
}
196178
}
179+
180+
for (dep_pkg, cfg) in self.lib.as_ref().unwrap().dependencies(&pkg) {
181+
if !self.should_parse_dependency(&dep_pkg.name) {
182+
continue;
183+
}
184+
185+
if let Some(ref cfg) = cfg {
186+
self.cfg_stack.push(cfg.clone());
187+
}
188+
189+
self.parse_crate(&dep_pkg)?;
190+
191+
if cfg.is_some() {
192+
self.cfg_stack.pop();
193+
}
194+
}
195+
196+
Ok(())
197197
}
198198

199199
fn parse_expand_crate(&mut self, pkg: &PackageRef) -> Result<(), Error> {

0 commit comments

Comments
 (0)