Skip to content

Overloaded calls must now be written as (*self)() instead of self() #18742

Closed
@japaric

Description

@japaric

STR

#![feature(overloaded_calls)]

struct Foo;

impl Fn<(), ()> for Foo {
    extern "rust-call" fn call(&self, args: ()) {
        unimplemented!();
    }
}

impl Foo {
    fn foo(self) {
        self();
        self.call(());
    }

    fn bar(&self) {
        (*self)();  // OK
        self();  //~ error: expected function, found `&Foo`
        self.call(());  // OK
    }

    fn baz(&mut self) {
        (*self)();  // OK
        self();  //~ error: expected function, found `&mut Foo`
        self.call(());  // OK
    }
}

fn main() {}

Version

rustc 0.13.0-dev (97a57ec90 2014-11-07 11:31:25 +0000)

I think all these cases should work since self() should be sugar for self.call(()) and that method call works on the three cases.

Also, it seems the situation has regressed recently, because on the playpen bar is also working. The playpen is using this older version of the compiler:

rustc 0.13.0-dev (5c1fd5f8b 2014-11-05 18:01:53 +0000)

This is probably related to #18349

cc @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions