Skip to content

Commit 594cc22

Browse files
committed
Restrict DerefPure for Cow<T> impl to T = impl Clone, [impl Clone], str.
1 parent 9cd60bd commit 594cc22

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Diff for: library/alloc/src/borrow.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,16 @@ where
340340
}
341341
}
342342

343+
// `Cow<'_, T>` can only implement `DerefPure` if `<T::Owned as Borrow<T>>` (and `BorrowMut<T>`) is trusted.
344+
// For now, we restrict `DerefPure for Cow<T>` to `T: Sized` (`T as Borrow<T>` is trusted),
345+
// `str` (`String as Borrow<str>` is trusted) and `[T]` (`Vec<T> as Borrow<[T]>` is trusted).
346+
// In the future, a `BorrowPure<T>` trait analogous to `DerefPure` might generalize this.
343347
#[unstable(feature = "deref_pure_trait", issue = "87121")]
344-
unsafe impl<B: ?Sized + ToOwned> DerefPure for Cow<'_, B> where B::Owned: Borrow<B> {}
348+
unsafe impl<T: Clone> DerefPure for Cow<'_, T> {}
349+
#[unstable(feature = "deref_pure_trait", issue = "87121")]
350+
unsafe impl DerefPure for Cow<'_, str> {}
351+
#[unstable(feature = "deref_pure_trait", issue = "87121")]
352+
unsafe impl<T: Clone> DerefPure for Cow<'_, [T]> {}
345353

346354
#[stable(feature = "rust1", since = "1.0.0")]
347355
impl<B: ?Sized> Eq for Cow<'_, B> where B: Eq + ToOwned {}

0 commit comments

Comments
 (0)