Skip to content

Commit 34ed047

Browse files
multivers: remove unneeded unsafe code
1 parent 6836ce9 commit 34ed047

File tree

1 file changed

+34
-46
lines changed

1 file changed

+34
-46
lines changed

src/multivers.rs

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -274,18 +274,16 @@ impl Multivers {
274274
);
275275

276276
let builds = self.build_package(selected_package)?;
277-
if builds.builds.len() == 1 {
278-
// SAFETY: The Vec is not empty, so the Option can only be Some.
279-
let build = unsafe { builds.builds.first().unwrap_unchecked() };
280277

281-
let original_filename = builds
282-
.builds
283-
.iter()
284-
.find_map(|build| build.original_filename.clone())
285-
.unwrap_or_else(|| {
286-
format!("multivers-runner{}", std::env::consts::EXE_SUFFIX).into()
287-
});
278+
let original_filename = builds
279+
.builds
280+
.iter()
281+
.find_map(|build| build.original_filename.clone())
282+
.unwrap_or_else(|| {
283+
format!("multivers-runner{}", std::env::consts::EXE_SUFFIX).into()
284+
});
288285

286+
if let [build] = builds.builds.as_slice() {
289287
let output_path = self
290288
.output_directory
291289
.join(&self.target)
@@ -305,46 +303,36 @@ impl Multivers {
305303
style("Finished").bold().green(),
306304
output_path.display()
307305
);
306+
} else {
307+
let encoded =
308+
rmp_serde::to_vec_named(&builds).context("Failed to encode the builds")?;
308309

309-
continue;
310-
}
311-
312-
let original_filename = builds
313-
.builds
314-
.iter()
315-
.find_map(|build| build.original_filename.clone())
316-
.unwrap_or_else(|| {
317-
format!("multivers-runner{}", std::env::consts::EXE_SUFFIX).into()
318-
});
319-
320-
let encoded =
321-
rmp_serde::to_vec_named(&builds).context("Failed to encode the builds")?;
322-
323-
let package_output_directory = self.output_directory.join(&selected_package.name);
324-
std::fs::create_dir_all(&package_output_directory)
325-
.context("Failed to create temporary output directory")?;
326-
let builds_path = package_output_directory.join("builds.msgpack");
327-
std::fs::write(&builds_path, encoded)
328-
.with_context(|| format!("Failed to write to `{}`", builds_path.display()))?;
310+
let package_output_directory = self.output_directory.join(&selected_package.name);
311+
std::fs::create_dir_all(&package_output_directory)
312+
.context("Failed to create temporary output directory")?;
313+
let builds_path = package_output_directory.join("builds.msgpack");
314+
std::fs::write(&builds_path, encoded)
315+
.with_context(|| format!("Failed to write to `{}`", builds_path.display()))?;
329316

330-
println!(
331-
"{:>12} {} versions compressed into a runner",
332-
style("Compiling").bold().green(),
333-
builds.builds.len(),
334-
);
317+
println!(
318+
"{:>12} {} versions compressed into a runner",
319+
style("Compiling").bold().green(),
320+
builds.builds.len(),
321+
);
335322

336-
let bin_path = self.runner.build(
337-
&self.cargo_args,
338-
&self.target,
339-
&builds_path,
340-
&original_filename,
341-
)?;
323+
let bin_path = self.runner.build(
324+
&self.cargo_args,
325+
&self.target,
326+
&builds_path,
327+
&original_filename,
328+
)?;
342329

343-
println!(
344-
"{:>12} ({})",
345-
style("Finished").bold().green(),
346-
bin_path.display()
347-
);
330+
println!(
331+
"{:>12} ({})",
332+
style("Finished").bold().green(),
333+
bin_path.display()
334+
);
335+
}
348336
}
349337

350338
Ok(())

0 commit comments

Comments
 (0)