Skip to content

Associated type equality in trait bounds not properly matched #37883

Closed
@sebcrozet

Description

@sebcrozet

I might be missing something but I believe the following (playpen) should compile but does not:

use std::ops::Mul;


fn main() {
}


trait Ring { }
trait Real: Ring { }

trait Module: Sized + Mul<<Self as Module>::Ring, Output = Self> {
    type Ring: Ring;
}

trait EuclideanSpace {
    type Coordinates: Module<Ring = Self::Real>;
    type Real:        Real;
}


pub trait Translation<E: EuclideanSpace> {
    fn to_vector(&self) -> E::Coordinates;

    fn powf(&self, n: <E::Coordinates as Module>::Ring) -> E::Coordinates {
        self.to_vector() * n
    }
}

In self.to_vector() * n, the compiler seems to understand that <E::Coordinates as Module>::Ring> is the same thing as E::Real but fails to applies the Mul<<Self as Module>::Ring, Output = Self> trait from Module.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)A-trait-systemArea: Trait systemC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions