Skip to content

associated_type_bounds: errors with ambiguous associated type #61752

Closed
@RustyYato

Description

@RustyYato

I think I found a bug with associated type bounds! #52662

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=28d566e7244a0b3ad21b73e31418894d

#![feature(associated_type_bounds)]

trait Foo {
    type Bar;
}

fn works<F: Foo>() where F::Bar: Copy {}

// This should be fine, but I get `error[E0221]` instead
fn breaks<F: Foo<Bar: Foo>>() where F::Bar: Copy {}

This is the exact same error you get when you do this

trait Foo<T> {
    type Bar;
}

fn breaks<F: Foo<String> + Foo<u32>>() where F::Bar: Copy {}

Because Rust can't tell which Foo::<_>::Bar you mean, but in the case of associated_type_bounds, there is no ambiguity, which makes this error confusing.

Metadata

Metadata

Assignees

Labels

A-trait-systemArea: Trait systemA-type-systemArea: Type systemC-bugCategory: This is a bug.F-associated_type_bounds`#![feature(associated_type_bounds)]`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