Skip to content

Regression in clone impl of enum with variant that has a field with a bivariant substitution #129286

Closed
@compiler-errors

Description

@compiler-errors

I tried this code:

trait Array {
    type Item;
}

trait Platform {
    type Assoc: Array<Item = Self::Assoc2>;
    type Assoc2;
}

struct Message<A, B>
where
    A: Array<Item = B>,
{
    pub field: A,
}

impl<A, B> Clone for Message<A, B>
where
    A: Array<Item = B>,
{
    fn clone(&self) -> Self {
        todo!()
    }
}

fn clone<P: Platform>(x: &Message<P::Assoc, P::Assoc2>) {
    let x: Message<_, _> = Clone::clone(x);
}

I expected it to work.

Instead, this happened:

error[E0282]: type annotations needed
  --> src/lib.rs:31:32
   |
31 |     Enum::Variant(Clone::clone(x))
   |                                ^ cannot infer type for reference `&Message<<P as Platform>::Assoc, _>`

I regressed this in #129059. I have no idea yet why it's happening! This also could be minimized further, I think.

Metadata

Metadata

Labels

A-coercionsArea: implicit and explicit `expr as Type` coercionsA-varianceArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)C-bugCategory: This is a bug.P-mediumMedium priorityT-typesRelevant to the types team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions