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

[NEED HELP] Partial implementation of switch to linkme. #16

wants to merge 1 commit into
base: master


Copy link

commented Aug 28, 2019

Attempt at doing #15.


  • Switched inventory calls to distributed_slices.
  • Renamed traits in test to be different -- same-named macros cannot be exported from the same crate, this is a WIP hack.
  • Change the dummy const wrapper to a mod wrapper -- the linkme distributed slice macro cannot be referenced when inside the const.

This doesn't work yet -- unsure why the module static is not resolved when running cargo test --all:

error[E0433]: failed to resolve: could not find `TRAITONE_TYPETAG_REGISTRATIONS` in `_TraitOne_registry`
  --> tests/
22 |     #[typetag::serde]
   |     ^^^^^^^^^^^^^^^^^ could not find `TRAITONE_TYPETAG_REGISTRATIONS` in `_TraitOne_registry`

cargo expand shows that it exists:

mod externally_tagged {
    // ..

    mod _TraitOne_registry {
        // ..
        pub static TRAITONE_TYPETAG_REGISTRATIONS: linkme::DistributedSlice<
            [fn() -> TypetagRegistration],
        > = {
            // ..


    // ..

Anyone: feel free to work on this. I'm not continuing this attempt yet as I can't figure out what's wrong -- maybe it's to do with macro invocation and type resolution order, but that's beyond my current understanding.

Partial implementation of switch to linkme.
This doesn't work yet -- unsure why the module static is not resolved.

@azriel91 azriel91 changed the title Partial implementation of switch to linkme. [NEED HELP] Partial implementation of switch to linkme. Aug 28, 2019


This comment has been minimized.

Copy link

commented Aug 31, 2019

I think this is running into a general failure where linkme doesn't support distributed slices declared in modules.

The implementation for linkme::distributed_slice makes two things with the same ident - one of them is a static, and the other is a macro_rules! macro. The static can be referred to using xxx::THING syntax, but the macro can't, since #[macro_export] macro_rules! macros are always exported in the crate root, regardless of the module they're declared in.

I've opened dtolnay/linkme#18 to track this issue. In the meantime, maybe there'd be a way to do this avoiding using an inner module - so at least traits declared in the crate root could be supported?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.