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

defaults on GATs emit an error but function correctlyish #99205

Closed
Tracked by #44265
BoxyUwU opened this issue Jul 13, 2022 · 2 comments · Fixed by #101807
Closed
Tracked by #44265

defaults on GATs emit an error but function correctlyish #99205

BoxyUwU opened this issue Jul 13, 2022 · 2 comments · Fixed by #101807
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs P-medium Medium priority

Comments

@BoxyUwU
Copy link
Member

BoxyUwU commented Jul 13, 2022

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?

@BoxyUwU BoxyUwU added C-bug Category: This is a bug. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs labels Jul 13, 2022
@lcnr
Copy link
Contributor

lcnr commented Jul 13, 2022

one issue is that we ignore defaults on the gat in impls

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

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

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

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

trait Trait2 {
    type Assoc<T>;
}

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

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


fn foo<T>() {}
    
fn main() {
    foo::<<() as Trait>::Assoc>(); // ok
    foo::<<u32 as Trait>::Assoc>(); // ok
    
    foo::<<() as Trait2>::Assoc>(); // err
    foo::<<u32 as Trait2>::Assoc>(); // err
}

@BoxyUwU BoxyUwU changed the title defaults on GATs emit an error but function correctly defaults on GATs emit an error but function correctlyish Jul 13, 2022
@lcnr lcnr added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Sep 14, 2022
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Sep 14, 2022
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 16, 2022
@bors bors closed this as completed in 7c55c99 Sep 17, 2022
@fmease fmease added the A-GATs Area: Generic associated types (GATs) label Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs P-medium Medium priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants