Skip to content

Associated type bounded on another associated type with a default fails #76179

Closed
@zacps

Description

@zacps

I tried this code:

#![feature(associated_type_defaults)]

use std::io::Read;

trait View {
    type Deserializers: Deserializer<Item = Self::RequestParams>;
    type RequestParams = DefaultRequestParams;
}

struct DefaultRequestParams;

trait Deserializer {
    type Item;
    fn deserialize(r: impl Read) -> Self::Item;
}

I expected to see this happen: View::Deserializers has the as of yet unspecified type Deserializer<Item=Self::RequestParams>.

Instead, this happened:

error[E0271]: type mismatch resolving `<<Self as View>::Deserializers as Deserializer>::Item == DefaultRequestParams`
  --> src\lib.rs:17:38
   |
14 | trait View {
   | -------------- required by `View`
...
17 |     type Deserializers: Deserializer<Item = Self::RequestParams>;
   |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `DefaultRequestParams`, found associated type
   |
   = note:       expected struct `DefaultRequestParams`
           found associated type `<Self as View>::RequestParams`
   = help: consider constraining the associated type `<Self as View>::RequestParams` to `DefaultRequestParams`
   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html

This error does not occur when the default is removed.

Meta

rustc --version --verbose:

rustc 1.47.0-nightly (f44c6e4e2 2020-08-24)

See also: My initial question on the internals forum

RFC 2532 (assocaited type defaults

cc @jonas-schievink

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-associated_type_defaults`#![feature(associated_type_defaults)]`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