Skip to content

Same trait with different input concrete parameters are considered duplicate bounds (: Bound<i8> + Bound<u8>) #22279

Closed
@japaric

Description

@japaric

STR

#![crate_type = "lib"]

pub trait Bound<T> {}
pub trait Trait: Bound<i8> + Bound<u8> {}
//~^ error: trait `Bound<u8>` already appears in the list of bounds
fn foo<T: Bound<i8> + Bound<u8>>() {}
//~^ error: trait `Bound<u8>` already appears in the list of bounds
fn foo<T>() where T: Bound<i8> + Bound<u8> {}  // OK

Due to multidispatch : Bound<i8> + Bound<u8> is a valid bound, but the compiler is rejecting it in some positions (supertraits and bounds in parameter list), but not in others (where clauses)

Workaround for the supertrait

You can use dummy intermediate traits to indirectly add the "duplicate" bounds, but this is very verbose.

pub trait Bound<T> {}
pub trait Dummy: Bound<i8> {}
pub trait Trait: Dummy + Bound<u8> {}  // `Trait` implies `Bound<i8> + Bound<u8>`

Version

rustc 1.0.0-nightly (3ef8ff1f8 2015-02-12 00:38:24 +0000)

cc @nikomatsakis

Originally reported in #18693 (Niko preferred opening a new issue, instead of re-opening the old one and modifying the original report)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions