Skip to content

Unexpected trait behavior with default_type_params #18754

Open
@carllerche

Description

@carllerche

This seems more like an error message issue than anything, but I was very confused for a while. Here is a repro:

#![feature(unboxed_closures)]
#![feature(default_type_params)]

pub trait Invoke<A, R = ()> {
    fn invoke(&mut self, args: A) -> R;
}

impl<A, R, F: Send + FnMut(A) -> R> Invoke<A, R> for F {
    fn invoke(&mut self, args: A) -> R {
        self.call_mut((args,))
    }
}

pub struct Foo;


impl Invoke<uint, uint> for Foo {
    fn invoke(&mut self, args: uint) -> uint {
        args
    }
}

fn repro<A, I: Invoke<A>>(_: I) {
    unimplemented!();
}

pub fn main() {
    repro(Foo);
}

output:

repro.rs:28:5: 28:10 error: the trait `core::ops::Fn<(_,), ()>` is not implemented for the type `Foo`
repro.rs:28     repro(Foo);
                ^~~~~
repro.rs:28:5: 28:10 note: the trait `core::ops::Fn` must be implemented because it is required by `repro`
repro.rs:28     repro(Foo);
                ^~~~~
error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.F-unboxed_closures`#![feature(unboxed_closures)]`T-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