Skip to content

Constraints on associated types declared in subtraits do not propagate. #32722

Closed
@brendanzab

Description

@brendanzab

Pretty bad title - sorry. Somebody who knows the type checker might be able to do better.

Here is a minimal example:

pub trait Real {}

pub trait VectorSpace {
    type Scalar;
}

pub trait InnerSpace: VectorSpace where
    <Self as VectorSpace>::Scalar: Real,
{
    fn dot(self, other: Self) -> Self::Scalar;
}

pub fn dot<V: InnerSpace>(a: V, b: V) -> V::Scalar {
    V::dot(a, b)
}
<anon>:13:1: 15:2 error: the trait `Real` is not implemented for the type `<V as VectorSpace>::Scalar` [E0277]
<anon>:13 pub fn dot<V: InnerSpace>(a: V, b: V) -> V::Scalar {
<anon>:14     V::dot(a, b)
<anon>:15 }
<anon>:13:1: 15:2 help: see the detailed explanation for E0277
<anon>:13:1: 15:2 note: required by `InnerSpace`

http://is.gd/vjIVwO

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-trait-systemArea: Trait systemA-type-systemArea: Type systemC-bugCategory: This is a bug.F-associated_type_bounds`#![feature(associated_type_bounds)]`T-langRelevant to the language 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