dtolnay / dtolnay/reflect

Generic bound inference

Open
#18 1 comment 0 reactions 1 assignee Claimed by @8BitMate View on GitHub
Dominant language
Rust
Stars
780
Forks
23
PR merge metrics
No merged PRs in 30d

Description

Suppose we have:

```rust
reflect::library! {
extern crate demo {
trait Demo {
fn f(&self);
}
trait SomeTrait {}
fn dynamic_dispatch(&dyn SomeTrait);
fn static_dispatch(&T);
}
}
```

and our user's `derive(Demo)` macro is being invoked on:

```rust
#[derive(Demo)]
struct S {
field: T,
}
```

Then if they do:

```rust
let field = receiver.get_field("field");
RUNTIME::demo::dynamic_dispatch.INVOKE(field);

// OR

RUNTIME::demo::static_dispatch.INVOKE(field);
```

then `reflect` needs to identify that these INVOKEs require a trait bound and emit the right bound on the impl we generate.

```rust
impl demo::Demo for S
where
T: demo::SomeTrait, // inferred
{
fn f(&self) {
demo::dynamic_dispatch(&self.field);
}
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.