@@ -156,44 +156,44 @@ impl<'a> Parser<'a> {
156
156
assert ! ( self . lib. is_some( ) ) ;
157
157
self . parsed_crates . insert ( pkg. name . clone ( ) ) ;
158
158
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
-
178
159
// Check if we should use cargo expand for this crate
179
160
if self . expand . contains ( & pkg. name ) {
180
161
return self . parse_expand_crate ( pkg) ;
181
162
}
182
163
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.
184
167
let crate_src = self . lib . as_ref ( ) . unwrap ( ) . find_crate_src ( pkg) ;
185
168
186
169
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 ( ) ) ? ,
188
171
None => {
189
172
// This should be an error, but is common enough to just elicit a warning
190
173
warn ! (
191
174
"Parsing crate `{}`: can't find lib.rs with `cargo metadata`." ,
192
175
pkg. name
193
176
) ;
194
- Ok ( ( ) )
195
177
}
196
178
}
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 ( ( ) )
197
197
}
198
198
199
199
fn parse_expand_crate ( & mut self , pkg : & PackageRef ) -> Result < ( ) , Error > {
0 commit comments