From 781b92c3f1bbf88252c6de7fbddc386c0c0c26b4 Mon Sep 17 00:00:00 2001 From: Thalia Archibald Date: Sat, 5 Apr 2025 18:18:31 -0700 Subject: [PATCH] Implement AsRef for Cow<'_, Path> In #31751, `impl AsRef for Cow<'_, OsStr>` was added, but the converse was omitted and it wasn't mentioned in discussion. This seems to have been a simple oversight, as it otherwise implemented traits mutually between `OsStr` and `Path`. --- library/std/src/path.rs | 8 ++++++++ src/tools/compiletest/src/runtest.rs | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 980213be7ea..6d3ec9d4c63 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -3173,6 +3173,14 @@ impl AsRef for Path { } } +#[stable(feature = "cow_path_as_ref_os_str", since = "CURRENT_RUSTC_VERSION")] +impl AsRef for Cow<'_, Path> { + #[inline] + fn as_ref(&self) -> &OsStr { + self.as_os_str() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for Path { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index c8a60b68da8..1c0339ab26a 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -941,7 +941,7 @@ impl<'test> TestCx<'test> { .arg("-L") .arg(aux_dir) .arg("-o") - .arg(out_dir.as_ref()) + .arg(out_dir) .arg("--deny") .arg("warnings") .arg(&self.testpaths.file)