Skip to content

Commit b2e231a

Browse files
authored
Unrolled build for #148016
Rollup merge of #148016 - clarfonthey:const-convert-revert-2, r=cuviper Revert constification of `Borrow` and `Deref for Cow` due to inference failure Reported issue: #147964 Original PR: #145279 Previous revert: #148011 `const Borrow`/`Deref` tracking issue: #143773 Should have additional crater run to verify this fixes the issue. Since other PR is in the queue, this will need to be rebased after that merges. Also will want a beta nomination.
2 parents 38bc246 + 4a4f3b0 commit b2e231a

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

library/alloc/src/borrow.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ use crate::fmt;
1616
#[cfg(not(no_global_oom_handling))]
1717
use crate::string::String;
1818

19+
// FIXME(inference): const bounds removed due to inference regressions found by crater;
20+
// see https://github.com/rust-lang/rust/issues/147964
21+
// #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
1922
#[stable(feature = "rust1", since = "1.0.0")]
20-
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
21-
impl<'a, B: ?Sized> const Borrow<B> for Cow<'a, B>
22-
where
23-
B: ToOwned,
24-
B::Owned: [const] Borrow<B>,
23+
impl<'a, B: ?Sized + ToOwned> Borrow<B> for Cow<'a, B>
24+
// where
25+
// B::Owned: [const] Borrow<B>,
2526
{
2627
fn borrow(&self) -> &B {
2728
&**self
@@ -327,11 +328,13 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
327328
}
328329
}
329330

331+
// FIXME(inference): const bounds removed due to inference regressions found by crater;
332+
// see https://github.com/rust-lang/rust/issues/147964
333+
// #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
330334
#[stable(feature = "rust1", since = "1.0.0")]
331-
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
332-
impl<B: ?Sized + ToOwned> const Deref for Cow<'_, B>
333-
where
334-
B::Owned: [const] Borrow<B>,
335+
impl<B: ?Sized + ToOwned> Deref for Cow<'_, B>
336+
// where
337+
// B::Owned: [const] Borrow<B>,
335338
{
336339
type Target = B;
337340

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ run-pass
2+
3+
// regression test for #147964:
4+
// constification of these traits resulted in inference errors due to additional where clauses
5+
6+
use std::borrow::{Cow, Borrow};
7+
8+
pub fn generic_deref<'a, T: ToOwned<Owned = U>, U>(cow: Cow<'a, T>) {
9+
let _: &T = &cow;
10+
}
11+
12+
pub fn generic_borrow<'a, T: ToOwned<Owned = U>, U>(cow: Cow<'a, T>) {
13+
let _: &T = cow.borrow();
14+
}
15+
16+
pub fn generic_as_ref<'a, T: ToOwned<Owned = U>, U>(cow: Cow<'a, T>) {
17+
let _: &T = cow.as_ref();
18+
}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)