Skip to content

Commit fde91dd

Browse files
committed
fix(compile): Remove trailing newlines on errors
1 parent c276457 commit fde91dd

File tree

4 files changed

+7
-16
lines changed

4 files changed

+7
-16
lines changed

src/cargo/ops/cargo_compile/unit_generator.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl<'a> UnitGenerator<'a, '_> {
271271
let suggestion = closest_msg(target_name, targets.iter(), |t| t.name(), "target");
272272
let targets_elsewhere = self.get_targets_from_other_packages(filter)?;
273273
let need_append_targets_elsewhere = !targets_elsewhere.is_empty();
274-
let append_targets_elsewhere = |msg: &mut String, prefix: &str| {
274+
let append_targets_elsewhere = |msg: &mut String| {
275275
let mut available_msg = Vec::new();
276276
for (package, targets) in targets_elsewhere {
277277
if !targets.is_empty() {
@@ -284,7 +284,7 @@ impl<'a> UnitGenerator<'a, '_> {
284284
}
285285
}
286286
if !available_msg.is_empty() {
287-
write!(msg, "{prefix}{}", available_msg.join("\n"))?;
287+
write!(msg, "\n{}", available_msg.join("\n"))?;
288288
}
289289
CargoResult::Ok(())
290290
};
@@ -313,18 +313,18 @@ impl<'a> UnitGenerator<'a, '_> {
313313
msg,
314314
"no {target_desc} target {named} `{target_name}` in {unmatched_packages}{suggestion}",
315315
)?;
316-
append_targets_elsewhere(&mut msg, "\n")?;
316+
append_targets_elsewhere(&mut msg)?;
317317
} else {
318-
writeln!(
318+
write!(
319319
msg,
320320
"no {target_desc} target {named} `{target_name}` in {unmatched_packages}",
321321
)?;
322322

323-
append_targets_elsewhere(&mut msg, "")?;
323+
append_targets_elsewhere(&mut msg)?;
324324
if !targets.is_empty() && !need_append_targets_elsewhere {
325-
writeln!(msg, "Available {} targets:", target_desc)?;
325+
write!(msg, "\nAvailable {} targets:", target_desc)?;
326326
for target in targets {
327-
writeln!(msg, " {}", target.name())?;
327+
write!(msg, "\n {}", target.name())?;
328328
}
329329
}
330330
}

tests/testsuite/build.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,6 @@ fn cargo_compile_with_filename() {
13411341
Available bin targets:
13421342
a
13431343
1344-
13451344
"#]])
13461345
.run();
13471346

@@ -1362,7 +1361,6 @@ Available bin targets:
13621361
Available example targets:
13631362
a
13641363
1365-
13661364
"#]])
13671365
.run();
13681366

tests/testsuite/run.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,6 @@ https://github.com/rust-lang/cargo/issues/5330
627627
Available example targets:
628628
do_magic
629629
630-
631630
"#]])
632631
.run();
633632
}
@@ -659,7 +658,6 @@ fn run_example_autodiscover_2015_with_autoexamples_disabled() {
659658
Available example targets:
660659
do_magic
661660
662-
663661
"#]])
664662
.run();
665663
}
@@ -747,7 +745,6 @@ fn run_with_filename() {
747745
Available bin targets:
748746
a
749747
750-
751748
"#]])
752749
.run();
753750

@@ -768,7 +765,6 @@ Available bin targets:
768765
Available example targets:
769766
a
770767
771-
772768
"#]])
773769
.run();
774770

@@ -854,7 +850,6 @@ Available bin targets:
854850
ambiguous
855851
ambiguous
856852
857-
858853
"#]])
859854
.run();
860855
}

tests/testsuite/test.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,15 +2449,13 @@ fn bad_example() {
24492449
.with_stderr_data(str![[r#"
24502450
[ERROR] no example target named `foo` in default-run packages
24512451
2452-
24532452
"#]])
24542453
.run();
24552454
p.cargo("run --bin foo")
24562455
.with_status(101)
24572456
.with_stderr_data(str![[r#"
24582457
[ERROR] no bin target named `foo` in default-run packages
24592458
2460-
24612459
"#]])
24622460
.run();
24632461
}

0 commit comments

Comments
 (0)