Skip to content

Multiple associated type-parametrized bounds fail to resolve #70756

Open
@syntacticsugarglider

Description

@syntacticsugarglider

With this source

use core::marker::PhantomData;

pub trait Wrap<T> {
    type Wrapper;
}

fn fail<
    T,
    C: Trait<<WrapMarker as Wrap<T>>::Wrapper>
        + Wrap<<C as Trait<<WrapMarker as Wrap<T>>::Wrapper>>::Assoc>,
>() {
}

fn succeed<
    T,
    C: Trait<PhantomData<T>> + Wrap<<C as Trait<<WrapMarker as Wrap<T>>::Wrapper>>::Assoc>,
>() {
}

pub trait Trait<P> {
    type Assoc;
}

pub struct WrapMarker;

impl<T> Wrap<T> for WrapMarker {
    type Wrapper = PhantomData<T>;
}

I expect both fail and succeed to compile. Instead, fail fails to compile with "E0277: the trait bound C: Trait<std::marker::PhantomData<T>> is not satisfied". rustc is clearly able to unambiguously resolve the type here, not only just in theory as associated types are singly defined for a given parametrization, but in practice as it is able to clearly specify the constraint to be added, indicating that <C as Trait<<WrapMarker as Wrap<T>>::Wrapper is already uniquely resolved.

playground reproduction

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.T-compilerRelevant to the compiler 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