Skip to content

Commit d84b267

Browse files
committed
Auto merge of #11771 - ehuss:fix-temp-unused, r=Eh2406
Fix warning with tempfile A recent release of the tempfile crate added a `#[must_use]` attribute to the `into_path` method. This triggers a warning when building. This also adds a test to verify that the intermediate artifacts persist in the temp directory.
2 parents 524231f + 736fb2f commit d84b267

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/cargo/ops/cargo_install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
308308
let compile = ops::compile_ws(&self.ws, &self.opts, &exec).with_context(|| {
309309
if let Some(td) = td_opt.take() {
310310
// preserve the temporary directory, so the user can inspect it
311-
td.into_path();
311+
drop(td.into_path());
312312
}
313313

314314
format!(

tests/testsuite/install.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
33
use std::fs::{self, OpenOptions};
44
use std::io::prelude::*;
5+
use std::path::Path;
56

7+
use cargo_test_support::compare;
68
use cargo_test_support::cross_compile;
79
use cargo_test_support::git;
810
use cargo_test_support::registry::{self, registry_path, Package};
911
use cargo_test_support::{
1012
basic_manifest, cargo_process, no_such_file_err_msg, project, project_in, symlink_supported, t,
1113
};
14+
use cargo_util::ProcessError;
1215

1316
use cargo_test_support::install::{
1417
assert_has_installed_exe, assert_has_not_installed_exe, cargo_home,
@@ -2103,3 +2106,39 @@ fn no_auto_fix_note() {
21032106
.run();
21042107
assert_has_not_installed_exe(cargo_home(), "auto_fix");
21052108
}
2109+
2110+
#[cargo_test]
2111+
fn failed_install_retains_temp_directory() {
2112+
// Verifies that the temporary directory persists after a build failure.
2113+
Package::new("foo", "0.0.1")
2114+
.file("src/main.rs", "x")
2115+
.publish();
2116+
let err = cargo_process("install foo").exec_with_output().unwrap_err();
2117+
let err = err.downcast::<ProcessError>().unwrap();
2118+
let stderr = String::from_utf8(err.stderr.unwrap()).unwrap();
2119+
compare::match_contains(
2120+
"\
2121+
[UPDATING] `dummy-registry` index
2122+
[DOWNLOADING] crates ...
2123+
[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`)
2124+
[INSTALLING] foo v0.0.1
2125+
[COMPILING] foo v0.0.1
2126+
",
2127+
&stderr,
2128+
None,
2129+
)
2130+
.unwrap();
2131+
compare::match_contains(
2132+
"error: failed to compile `foo v0.0.1`, intermediate artifacts can be found at `[..]`",
2133+
&stderr,
2134+
None,
2135+
)
2136+
.unwrap();
2137+
2138+
// Find the path in the output.
2139+
let start = stderr.find("found at `").unwrap() + 10;
2140+
let end = stderr[start..].find('\n').unwrap() - 1;
2141+
let path = Path::new(&stderr[start..(end + start)]);
2142+
assert!(path.exists());
2143+
assert!(path.join("release/deps").exists());
2144+
}

0 commit comments

Comments
 (0)