From faf3e0b589d2d1ec79b11948f7b90f860cce6575 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 28 Oct 2025 08:41:14 -0700 Subject: [PATCH] Further revert `Deref for Cow` to its 1.90.0 state ref: https://github.com/rust-lang/rust/issues/147964#issuecomment-3446420995 --- library/alloc/src/borrow.rs | 3 ++- tests/ui/traits/generic-cow-inference-regression.rs | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/borrow.rs b/library/alloc/src/borrow.rs index d2ab5412eeabc..d982e46e08afc 100644 --- a/library/alloc/src/borrow.rs +++ b/library/alloc/src/borrow.rs @@ -333,7 +333,8 @@ impl Cow<'_, B> { // #[rustc_const_unstable(feature = "const_convert", issue = "143773")] #[stable(feature = "rust1", since = "1.0.0")] impl Deref for Cow<'_, B> -// where +where + B::Owned: Borrow, // B::Owned: [const] Borrow, { type Target = B; diff --git a/tests/ui/traits/generic-cow-inference-regression.rs b/tests/ui/traits/generic-cow-inference-regression.rs index 6fd4715f85bbd..823570ab8d11a 100644 --- a/tests/ui/traits/generic-cow-inference-regression.rs +++ b/tests/ui/traits/generic-cow-inference-regression.rs @@ -5,9 +5,12 @@ use std::borrow::{Cow, Borrow}; -pub fn generic_deref<'a, T: ToOwned, U>(cow: Cow<'a, T>) { - let _: &T = &cow; -} +// This won't work even with the non-const bound on `Deref` like 1.90.0, although note +// as well that no such bound existed until 1.57 started `~const` experiments. +// +// pub fn generic_deref<'a, T: ToOwned, U>(cow: Cow<'a, T>) { +// let _: &T = &cow; +// } pub fn generic_borrow<'a, T: ToOwned, U>(cow: Cow<'a, T>) { let _: &T = cow.borrow();