Skip to content

Unique function types are not unique enough #23733

@petrochenkov

Description

@petrochenkov

In this example

trait Check: std::marker::MarkerTrait {
    fn check();
}
impl Check for u8 {
    fn check() { println!("u8"); }
}
impl Check for u16 {
    fn check() { println!("u16"); }
}

fn f<T: Check>() {
    T::check();
}



fn main() {
    fn same_type<T>(_: T, _: T) {}
    same_type(f::<u8>, f::<u16>);
    println!("{} {}", f::<u8> as usize, f::<u16> as usize);
}

functions f::<u8> and f::<u16> have the same type fn() {f} tied to the id of the generic function item, but different function pointers. So, in general case a function pointer can't be unambiguosly obtained from function item's type.

cc @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemA-type-systemArea: Type systemT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions