From ebd5bea84fee777c5f79bb18e39f28b3f666206a Mon Sep 17 00:00:00 2001 From: ltdk Date: Thu, 23 Oct 2025 03:22:56 -0400 Subject: [PATCH 1/4] Revert inference failure from Deref/Borrow constification --- library/alloc/src/borrow.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/library/alloc/src/borrow.rs b/library/alloc/src/borrow.rs index 4659fb2a8426d..d2ab5412eeabc 100644 --- a/library/alloc/src/borrow.rs +++ b/library/alloc/src/borrow.rs @@ -16,12 +16,13 @@ use crate::fmt; #[cfg(not(no_global_oom_handling))] use crate::string::String; +// FIXME(inference): const bounds removed due to inference regressions found by crater; +// see https://github.com/rust-lang/rust/issues/147964 +// #[rustc_const_unstable(feature = "const_convert", issue = "143773")] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_convert", issue = "143773")] -impl<'a, B: ?Sized> const Borrow for Cow<'a, B> -where - B: ToOwned, - B::Owned: [const] Borrow, +impl<'a, B: ?Sized + ToOwned> Borrow for Cow<'a, B> +// where +// B::Owned: [const] Borrow, { fn borrow(&self) -> &B { &**self @@ -327,11 +328,13 @@ impl Cow<'_, B> { } } +// FIXME(inference): const bounds removed due to inference regressions found by crater; +// see https://github.com/rust-lang/rust/issues/147964 +// #[rustc_const_unstable(feature = "const_convert", issue = "143773")] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_convert", issue = "143773")] -impl const Deref for Cow<'_, B> -where - B::Owned: [const] Borrow, +impl Deref for Cow<'_, B> +// where +// B::Owned: [const] Borrow, { type Target = B; From 9ceb997e040250e0bdb425b324b7662abd1d42a2 Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Thu, 23 Oct 2025 17:52:54 +0200 Subject: [PATCH 2/4] Add myself to the review rotation --- triagebot.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/triagebot.toml b/triagebot.toml index fbe29dd182452..a0d0b1892e4fe 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -1370,6 +1370,7 @@ compiler = [ "@jackh726", "@jieyouxu", "@jdonszelmann", + "@JonathanBrouwer", "@lcnr", "@madsmtm", "@Nadrieril", From bca35effc216ce45bd07c25c706a261806f71b98 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 23 Oct 2025 11:47:53 -0500 Subject: [PATCH 3/4] test(frontmatter): Cover spaces between infostring parts As these characters are specifically called out in the RFC, I felt it would be important to have a test to cover them. --- tests/ui/frontmatter/space-in-infostring.rs | 9 +++++++++ tests/ui/frontmatter/space-in-infostring.stderr | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/ui/frontmatter/space-in-infostring.rs create mode 100644 tests/ui/frontmatter/space-in-infostring.stderr diff --git a/tests/ui/frontmatter/space-in-infostring.rs b/tests/ui/frontmatter/space-in-infostring.rs new file mode 100644 index 0000000000000..a8448af113443 --- /dev/null +++ b/tests/ui/frontmatter/space-in-infostring.rs @@ -0,0 +1,9 @@ +--- cargo clippy +//~^ ERROR: invalid infostring for frontmatter +--- + +// infostrings cannot have spaces + +#![feature(frontmatter)] + +fn main() {} diff --git a/tests/ui/frontmatter/space-in-infostring.stderr b/tests/ui/frontmatter/space-in-infostring.stderr new file mode 100644 index 0000000000000..b876ddae782e9 --- /dev/null +++ b/tests/ui/frontmatter/space-in-infostring.stderr @@ -0,0 +1,10 @@ +error: invalid infostring for frontmatter + --> $DIR/space-in-infostring.rs:1:4 + | +LL | --- cargo clippy + | ^^^^^^^^^^^^^ + | + = note: frontmatter infostrings must be a single identifier immediately following the opening + +error: aborting due to 1 previous error + From 4a4f3b0e8e9609136c10a190c3f5572d70bb33ee Mon Sep 17 00:00:00 2001 From: ltdk Date: Thu, 23 Oct 2025 18:24:39 -0400 Subject: [PATCH 4/4] Add regression test for inference failures --- .../generic-cow-inference-regression.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/ui/traits/generic-cow-inference-regression.rs diff --git a/tests/ui/traits/generic-cow-inference-regression.rs b/tests/ui/traits/generic-cow-inference-regression.rs new file mode 100644 index 0000000000000..6fd4715f85bbd --- /dev/null +++ b/tests/ui/traits/generic-cow-inference-regression.rs @@ -0,0 +1,20 @@ +//@ run-pass + +// regression test for #147964: +// constification of these traits resulted in inference errors due to additional where clauses + +use std::borrow::{Cow, Borrow}; + +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(); +} + +pub fn generic_as_ref<'a, T: ToOwned, U>(cow: Cow<'a, T>) { + let _: &T = cow.as_ref(); +} + +fn main() {}