Inference issues with trait constification
@oli-obk is already working on this.
Since Jun 2, 2026.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I'm just going to file an issue for this so it's tracked somewhere.
Tracking for const_convert feature: #143773
Essentially, Implementations for Cow were reverted (#148011 and #148016) due to inference failures on beta (see #147964):
impl<T: ?Sized + ToOwned> const AsRef<T> for Cow<'_, T> where T::Owned: [const] Borrow<T> { /* ... */ }
impl<T: ?Sized + ToOwned> const Borrow<T> for Cow<'_, T> where T::Owned: [const] Borrow<T> { /* ... */ }
impl<T: ?Sized + ToOwned> const Deref for Cow<'_, T> where T::Owned: [const] Borrow<T> { /* ... */ }
The main issue here is the extra where clauses adding bounds which are technically redundant, but required for constness. We could fix these by making these contingent on const ToOwned, but I intentionally didn't do that in the initial implementation because it wasn't necessary: only const borrowing is necessary here, not const allocation.
Perhaps the trait solver could correctly identify these where clauses as being "redundant" except for constness to avoid the issues, or maybe next-solver fixes this. Either way, constification of these is probably blocked in the meantime, and I doubt these are going to be the only decisions going forward.
The reality is that constifying traits generally involves a lot of where clauses that might mess with the trait solver, and something needs to be decided on that.
Extra note: Deref was specifically not de-constified properly in 1.57.0, so it has been changed a bit.
(note, I'm using modern syntax for this for ease of reading, but technically the const trait syntax changed between 1.57.0 and 1.90.0)
// 1.56.1
impl<T: ?Sized + ToOwned> Deref for Cow<'_, T> { /* ... */ }
// 1.57.0
impl<T: ?Sized + ToOwned> const Deref for Cow<'_, T> where T::Owned: [const] Borrow<T> { /* ... */ }
// 1.70.0 - 1.90.0
impl<T: ?Sized + ToOwned> Deref for Cow<'_, T> where T::Owned: Borrow<T> { /* ... */ }
// 1.91.0 beta
impl<T: ?Sized + ToOwned> Deref for Cow<'_, T> { /* ... */ }
The decision was made to keep the status quo this close to the 1.90.0 stable release, but the revert to the pre-1.57 version is still on the 1.91.0 beta for now.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.