orlp / slotmap

Slotmap data structure for Rust
zlib License
1.13k stars 70 forks source link

`Result` type in `__serialize_key` macro does not use absolute path #78

Closed Stupremee closed 3 years ago

Stupremee commented 3 years ago

The __serialize_key macro currently emits Result<S::Ok, S::Error> as the return type of the functions, which can break the macro code if Result is redefined (e.g. type Result<T> = ... which is pretty common)

This occurred to me while I was building zbus (2.0.0-beta.7) and already had slotmap with the serde feature enabled inside my crate, which lead to this error:

error[E0107]: this type alias takes 1 generic argument but 2 generic arguments were supplied
   --> /home/stu/.cargo/registry/src/github.com-1ecc6299db9ec823/zbus-2.0.0-beta.7/src/proxy.rs:51:1
    |
51  | / new_key_type! {
52  | |     /// The ID for a registered proprety changed handler.
53  | |     pub struct PropertyChangedHandlerId;
54  | | }
    | | ^
    | | |
    | |_expected 1 generic argument
    |   help: remove this generic argument
    |
note: type alias defined here, with 1 generic parameter: `T`
   --> /home/stu/.cargo/registry/src/github.com-1ecc6299db9ec823/zbus-2.0.0-beta.7/src/error.rs:227:10
    |
227 | pub type Result<T> = std::result::Result<T, Error>;
    |          ^^^^^^ -
    = note: this error originates in the macro `$crate::__serialize_key` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0107`.
error: could not compile `zbus` due to 4 previous errors
orlp commented 3 years ago

Thanks for reporting, the fix is easy enough - I'll get on that later today or tomorrow.

Stupremee commented 3 years ago

Thank you! This is also the case for the From, which is much harder to hit, but still possible.

orlp commented 3 years ago

Fixed in https://github.com/orlp/slotmap/commit/941c39301211a03385e8d7915d0d31b6f6f5ecd5.