Generic bound inference
dtolnay opened this issue · 1 comments
dtolnay commented
Suppose we have:
reflect::library! {
extern crate demo {
trait Demo {
fn f(&self);
}
trait SomeTrait {}
fn dynamic_dispatch(&dyn SomeTrait);
fn static_dispatch<T: SomeTrait>(&T);
}
}
and our user's derive(Demo)
macro is being invoked on:
#[derive(Demo)]
struct S<T> {
field: T,
}
Then if they do:
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.
impl<T> demo::Demo for S<T>
where
T: demo::SomeTrait, // inferred
{
fn f(&self) {
demo::dynamic_dispatch(&self.field);
}
}
dtolnay commented
More generally -- we need to keep track of how every reflect::Value is used and what trait bounds those uses require, and then tie that back to where the reflect::Value came from and generate bounds there appropriately.