Skip to content

Inference issues with trait constification #148028

@clarfonthey

Description

@clarfonthey

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.I-types-nominatedNominated for discussion during a types team meeting.PG-const-traitsProject group: Const traitsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions