Skip to content

Commit ae9beb9

Browse files
committed
refactor(timings): make error into render context
1 parent 874b19b commit ae9beb9

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/cargo/core/compiler/timings/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,9 @@ impl<'gctx> Timings<'gctx> {
409409
host: &build_runner.bcx.rustc().host,
410410
requested_targets,
411411
jobs: build_runner.bcx.jobs(),
412+
error,
412413
};
413-
report::write_html(ctx, &mut f, error)?;
414+
report::write_html(ctx, &mut f)?;
414415

415416
let unstamped_filename = timings_path.join("cargo-timing.html");
416417
paths::link_or_copy(&filename, &unstamped_filename)?;

src/cargo/core/compiler/timings/report.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,20 @@ pub struct RenderContext<'a> {
7777
pub requested_targets: &'a [&'a str],
7878
/// The number of jobs specified for this build.
7979
pub jobs: u32,
80+
/// Fatal error during the build.
81+
pub error: &'a Option<anyhow::Error>,
8082
}
8183

8284
/// Writes an HTML report.
83-
pub(super) fn write_html(
84-
ctx: RenderContext<'_>,
85-
f: &mut impl Write,
86-
error: &Option<anyhow::Error>,
87-
) -> CargoResult<()> {
85+
pub(super) fn write_html(ctx: RenderContext<'_>, f: &mut impl Write) -> CargoResult<()> {
8886
let duration = ctx.start.elapsed().as_secs_f64();
8987
let roots: Vec<&str> = ctx
9088
.root_units
9189
.iter()
9290
.map(|(name, _targets)| name.as_str())
9391
.collect();
9492
f.write_all(HTML_TMPL.replace("{ROOTS}", &roots.join(", ")).as_bytes())?;
95-
write_summary_table(&ctx, f, duration, error)?;
93+
write_summary_table(&ctx, f, duration)?;
9694
f.write_all(HTML_CANVAS.as_bytes())?;
9795
write_unit_table(&ctx, f)?;
9896
// It helps with pixel alignment to use whole numbers.
@@ -121,7 +119,6 @@ fn write_summary_table(
121119
ctx: &RenderContext<'_>,
122120
f: &mut impl Write,
123121
duration: f64,
124-
error: &Option<anyhow::Error>,
125122
) -> CargoResult<()> {
126123
let targets = ctx
127124
.root_units
@@ -146,7 +143,7 @@ fn write_summary_table(
146143

147144
let requested_targets = ctx.requested_targets.join(", ");
148145

149-
let error_msg = match error {
146+
let error_msg = match ctx.error {
150147
Some(e) => format!(r#"<tr><td class="error-text">Error:</td><td>{e}</td></tr>"#),
151148
None => "".to_string(),
152149
};

0 commit comments

Comments
 (0)