Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic bound inference #18

Open
dtolnay opened this issue Sep 19, 2019 · 1 comment
Open

Generic bound inference #18

dtolnay opened this issue Sep 19, 2019 · 1 comment
Assignees

Comments

@dtolnay
Copy link
Owner

dtolnay commented Sep 19, 2019

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
Copy link
Owner Author

dtolnay commented Sep 19, 2019

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.

@8BitMate 8BitMate self-assigned this Nov 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants