-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-specializationArea: Trait impl specializationArea: Trait impl specializationC-bugCategory: This is a bug.Category: This is a bug.F-specialization`#![feature(specialization)]``#![feature(specialization)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
I believe RFC 2532 changed the behavior so that a "blank impl" effectively "locks in" inherited defaults. This means that, in this code, the ()
impl "locks in" the associated type value of bool
:
#![feature(specialization)]
trait Trait {
type Assoc;
}
impl<T> Trait for T {
default type Assoc = bool;
}
impl Trait for () {}
fn foo<X: Trait<Assoc=bool>>() {}
fn main() {
foo::<u8>(); //~ ERROR
foo::<()>();
}
However, we currently get two errors (playground):
error[E0271]: type mismatch resolving `<u8 as Trait>::Assoc == bool`
--> src/main.rs:16:5
|
13 | fn foo<X: Trait<Assoc=bool>>() {}
| --- ---------- required by this bound in `foo`
...
16 | foo::<u8>();
| ^^^^^^^^^ expected `bool`, found associated type
|
= note: expected type `bool`
found associated type `<u8 as Trait>::Assoc`
= note: consider constraining the associated type `<u8 as Trait>::Assoc` to `bool`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
error[E0271]: type mismatch resolving `<() as Trait>::Assoc == bool`
--> src/main.rs:17:5
|
13 | fn foo<X: Trait<Assoc=bool>>() {}
| --- ---------- required by this bound in `foo`
...
17 | foo::<()>();
| ^^^^^^^^^ expected `bool`, found associated type
|
= note: expected type `bool`
found associated type `<() as Trait>::Assoc`
= note: consider constraining the associated type `<() as Trait>::Assoc` to `bool`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-specializationArea: Trait impl specializationArea: Trait impl specializationC-bugCategory: This is a bug.Category: This is a bug.F-specialization`#![feature(specialization)]``#![feature(specialization)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.