Skip to content

Transitive conversion is a source of non-local build errors #251

@demurgos

Description

@demurgos

This library has the following trait implementation:

cookie-rs/src/expiration.rs

Lines 129 to 136 in 8e97000

impl<T: Into<Option<OffsetDateTime>>> From<T> for Expiration {
fn from(option: T) -> Self {
match option.into() {
Some(value) => Expiration::DateTime(value),
None => Expiration::Session
}
}
}

This is a transitive conversion going from T to Expiration through Option<OffsetDateTime>. Rust does not provide blanket transitive conversion impls because they are are footguns: they are ambiguous in the presence of multiple paths. This library provides this footgun impl though, and it just shot my foot.

error[E0119]: conflicting implementations of trait `From<format_description::parse::format_item::HourBase>` for type `<format_description::parse::format_item::HourBase as format_description::parse::format_item::ModifierValue>::Type`                                                                                                                                                                                                                                         
   --> /home/demurgos/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cookie-0.18.1/src/expiration.rs:129:1
    |
129 | impl<T: Into<Option<OffsetDateTime>>> From<T> for Expiration {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: conflicting implementation in crate `time`:
            - impl From<format_description::parse::format_item::HourBase> for <format_description::parse::format_item::HourBase as format_description::parse::format_item::ModifierValue>::Type;
    = note: upstream crates may add a new impl of trait `std::convert::Into<std::option::Option<time::OffsetDateTime>>` for type `time::format_description::parse::format_item::HourBase` in future versions


error: could not compile `cookie` (lib) due to 1 previous error

This is causing my builds to start failing due to some non-local combination of other crates after an update. I'll dig deeper to figure out a workaround for my project. I would however urge you to fix your library and remove all transitive conversions. The small convenience provided by them (less typing) is not worth the risks of non-local build errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions