Skip to content

Commit f92e3b6

Browse files
committed
Replace rustc --print=cfg parsing with handrolled loop
1 parent bf56aa4 commit f92e3b6

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,21 @@ impl TargetInfo {
255255
res
256256
};
257257

258-
let cfg = lines
259-
.map(|line| Ok(Cfg::from_str(line)?))
260-
.filter(TargetInfo::not_user_specific_cfg)
261-
.collect::<CargoResult<Vec<_>>>()
262-
.with_context(|| {
263-
format!(
264-
"failed to parse the cfg from `rustc --print=cfg`, got:\n{}",
265-
output
266-
)
267-
})?;
258+
let cfg = {
259+
let mut res = Vec::new();
260+
for line in &mut lines {
261+
let cfg = Cfg::from_str(line).with_context(|| {
262+
format!(
263+
"failed to parse the cfg from `rustc --print=cfg`, got:\n{}",
264+
output
265+
)
266+
})?;
267+
if TargetInfo::not_user_specific_cfg(&cfg) {
268+
res.push(cfg);
269+
}
270+
}
271+
res
272+
};
268273

269274
// recalculate `rustflags` from above now that we have `cfg`
270275
// information
@@ -356,8 +361,8 @@ impl TargetInfo {
356361
}
357362
}
358363

359-
fn not_user_specific_cfg(cfg: &CargoResult<Cfg>) -> bool {
360-
if let Ok(Cfg::Name(cfg_name)) = cfg {
364+
fn not_user_specific_cfg(cfg: &Cfg) -> bool {
365+
if let Cfg::Name(cfg_name) = cfg {
361366
// This should also include "debug_assertions", but it causes
362367
// regressions. Maybe some day in the distant future it can be
363368
// added (and possibly change the warning to an error).

0 commit comments

Comments
 (0)