Skip to content

blank specializing impls don't "lock in" defaults #70442

Closed
@nikomatsakis

Description

@nikomatsakis

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

Labels

A-associated-itemsArea: Associated items (types, constants & functions)A-specializationArea: Trait impl specializationC-bugCategory: This is a bug.F-specialization`#![feature(specialization)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions