Skip to content

Bare function do not implement trait unless explicitly casted #21086

Closed
@Marwes

Description

@Marwes

It might be that this is intended since it seems that each function is treated as its own type (and by casting you can get the common function type that the trait is implemented for). I'd still argue it is confusing behavior so maybe the error message should be improved in that case?

(In this case we could do a blanked implemantion over one of the function trait but that does not work for my case, atleast not without #[old_impl_check])

trait Test { }
impl Test for fn () { }

fn tester<T: Test>(_: T) { }

fn void() { }

fn main() {
    tester(void);//Test is not implemented for fn () {void}
    tester(void as fn ());//Works
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-type-systemArea: Type system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions