dtolnay / typetag

Serde serializable and deserializable trait objects
Apache License 2.0
1.19k stars 38 forks source link

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

Closed azriel91 closed 4 years ago

azriel91 commented 5 years ago

Attempt at doing https://github.com/dtolnay/typetag/issues/15.

Changes:

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/test.rs:22:5
   |
22 |     #[typetag::serde]
   |     ^^^^^^^^^^^^^^^^^ could not find `TRAITONE_TYPETAG_REGISTRATIONS` in `_TraitOne_registry`

cargo expand shows that it exists:

mod externally_tagged {
    // ..

    #[allow(non_upper_case_globals)]
    #[macro_use]
    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.

daboross commented 5 years ago

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 https://github.com/dtolnay/linkme/issues/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?