Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature associated_type_defaults fails to resolve type equality #41868

Closed
chrivers opened this issue May 9, 2017 · 0 comments · Fixed by #61812
Closed

Feature associated_type_defaults fails to resolve type equality #41868

chrivers opened this issue May 9, 2017 · 0 comments · Fixed by #61812
Assignees
Labels
A-trait-system Area: Trait system A-type-system Area: Type system C-bug Category: This is a bug. F-associated_type_defaults `#![feature(associated_type_defaults)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@chrivers
Copy link

chrivers commented May 9, 2017

As far as I can tell, this is a legitimate bug, and I have not been able to find any similar reports on github.

I have a project where I have greatly simplified my codebase using associated_type_defaults. However, it seems like the type checker can't figure out that the literal type of the default case is the same as the default case. I have condensed my problem to the following test-case.

I feel both variants should definitely be valid, since the default is clearly Self. Have I misunderstood something, or is this a bug?

#![feature(associated_type_defaults)]
// rustc 1.19.0-nightly (f1140a331 2017-05-08)
pub struct Foo;

pub trait CanDecode {
    type Output = Self;
    fn read(rdr: &mut Foo) -> Option<Self::Output>;
}

impl CanDecode for u8 {
    fn read(rdr: &mut Foo) -> Option<Self::Output> { Some(42) }
}

impl CanDecode for u16 {
    fn read(rdr: &mut Foo) -> Option<u16> { Some(17) }
}

/*
error[E0053]: method `read` has an incompatible type for trait
  --> yo_dawg_i_heard_you_like_traits.rs:14:31
   |
6  |     fn read(rdr: &mut Foo) -> Option<Self::Output>;
   |                               -------------------- type in trait
...
14 |     fn read(rdr: &mut Foo) -> Option<u16> { Some(17) }
   |                               ^^^^^^^^^^^ expected associated type, found u16
   |
   = note: expected type `fn(&mut Foo) -> std::option::Option<<u16 as CanDecode>::Output>`
              found type `fn(&mut Foo) -> std::option::Option<u16>`

error: aborting due to previous error
*/
@Mark-Simulacrum Mark-Simulacrum added A-trait-system Area: Trait system A-type-system Area: Type system labels Jun 22, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 27, 2017
@jonas-schievink jonas-schievink added F-associated_type_defaults `#![feature(associated_type_defaults)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 29, 2019
@jonas-schievink jonas-schievink self-assigned this Aug 29, 2019
@bors bors closed this as completed in 3a0d106 Feb 26, 2020
@fmease fmease added A-trait-system Area: Trait system and removed A-trait-system Area: Trait system labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system A-type-system Area: Type system C-bug Category: This is a bug. F-associated_type_defaults `#![feature(associated_type_defaults)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants