Skip to content

defaults on GATs emit an error but function correctlyish #99205

Closed

Description

I tried this code: playground

#![feature(generic_associated_types)]
#![allow(invalid_type_param_default)]

trait Trait {
    type Assoc<T = u32>;
}

impl Trait for () {
    type Assoc<T = u32> = u64; 
}

impl Trait for u32 {
    type Assoc<T = u32> = T;
}

trait Other {}
impl Other for u32 {}

fn foo<T>()
where
    T: Trait<Assoc = u32>, 
    T::Assoc: Other {
        
    }
    
fn main() {
    // errors
    foo::<()>();
    // works
    foo::<u32>();
}

I expected to see this happen: It not work correctly as if you remove #![allow(invalid_type_param_default)] it shouts at you saying its unsupported and will be a hard error one day.

Instead, this happened: defaults on GATs seem to function perfectly fine

Meta

version from playground:

 1.64.0-nightly
(2022-07-12 1c7b36d4db582cb47513)

cc @jackh726 this is probably should either be allowed or a hard error before stabilisation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-generic_associated_types`#![feature(generic_associated_types)]` a.k.a. GATsP-mediumMedium priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions