Skip to content

Type based dispatch based on arguments to calls #1586

Open
@philberty

Description

@philberty

Rustc had this issue: rust-lang/rust#45510

The fix was: rust-lang/rust#55986

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

struct Ishmael;
struct Maybe;
struct CallMe;

impl FnOnce<(Ishmael,)> for CallMe {
    type Output = ();
    extern "rust-call" fn call_once(self, _args: (Ishmael,)) -> () {
        println!("Split your lungs with blood and thunder!");
    }
}

impl FnOnce<(Maybe,)> for CallMe {
    type Output = ();
    extern "rust-call" fn call_once(self, _args: (Maybe,)) -> () {
        println!("So we just met, and this is crazy");
    }
}

fn main() {
    CallMe(Ishmael);
    CallMe(Maybe);
}

To fix this in gccrs there are a few things we need to do:

  • refactor MethodResolver::Probe to return a set so that we can get multiple candidate errors properly
  • refactor autoderef to take an optional list of arguments which can be used to match function calls against if it is available
  • support looking for call_once implementations on call-expr's like this so that this becomes:
let a = CallMe;
a.fn_once(args)

Originally posted by @philberty in #195 (comment)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Todo

Relationships

None yet

Development

No branches or pull requests

Issue actions