Skip to content

Generic bound inference #18

@dtolnay

Description

@dtolnay

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);
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions