Skip to content

defaults on GATs emit an error but function correctlyish #99205

Closed
Listed in
@BoxyUwU

Description

@BoxyUwU
Member

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?

Activity

lcnr

lcnr commented on Jul 13, 2022

@lcnr
Contributor

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
}
changed the title [-]defaults on `GATs` emit an error but function correctly[/-] [+]defaults on `GATs` emit an error but function correctlyish[/+] on Jul 13, 2022
added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Sep 14, 2022
apiraino

apiraino commented on Sep 14, 2022

@apiraino
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

added and removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Sep 14, 2022
added a commit that references this issue on Sep 16, 2022

Rollup merge of rust-lang#101807 - jackh726:no-gat-defaults, r=lcnr

a75fdd9
added a commit that references this issue on Sep 17, 2022

Rollup merge of rust-lang#101807 - jackh726:no-gat-defaults, r=lcnr

7c55c99
added
A-GATsArea: Generic associated types (GATs)
on Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)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

      Participants

      @apiraino@fmease@BoxyUwU@lcnr@rustbot

      Issue actions

        defaults on `GATs` emit an error but function correctlyish · Issue #99205 · rust-lang/rust