chronotope / chrono

Date and time library for Rust
Other
3.3k stars 523 forks source link

Compile error using most recent version of chrono 0.4.36 #1545

Closed yinho999 closed 6 months ago

yinho999 commented 6 months ago

Description

Compiling with most recent version of chrono 0.4.36 causes compilation error.

Steps to Reproduce

  1. Create a new rust project and add this to Cargo.toml
    
    [package]
    name = "testing"
    version = "0.1.0"
    edition = "2021"

[dependencies] chrono-tz = "0.8.6"

2. Add the following code to `src/main.rs` file
```rust
use chrono_tz::US::Pacific;
fn main() {
    let pacific_time = Pacific.ymd(1990, 5, 6).and_hms(12, 30, 45);
}
  1. run cargo check to see the compilation error.

    Expected behavior

    The program should compile normally.

Error

error[E0432]: unresolved import `chrono::LocalResult`
   --> chrono-tz/src/timezone_impl.rs:318:21
    |
318 |         use chrono::LocalResult::*;
    |                     ^^^^^^^^^^^ `LocalResult` is a type alias, not a module

error[E0531]: cannot find tuple struct or tuple variant `Single` in this scope
   --> chrono-tz/src/timezone_impl.rs:320:23
    |
320 |             (result @ Single(_), _) => result,
    |                       ^^^^^^ not found in this scope
    |
help: consider importing this tuple variant
    |
1   + use chrono::MappedLocalTime::Single;
    |

error[E0531]: cannot find tuple struct or tuple variant `Single` in this scope
   --> chrono-tz/src/timezone_impl.rs:321:26
    |
321 |             (_, result @ Single(_)) => result,
    |                          ^^^^^^ not found in this scope
    |
help: consider importing this tuple variant
    |
1   + use chrono::MappedLocalTime::Single;
    |

error[E0531]: cannot find tuple struct or tuple variant `Ambiguous` in this scope
   --> chrono-tz/src/timezone_impl.rs:322:14
    |
322 |             (Ambiguous(offset, _), _) => Single(offset),
    |              ^^^^^^^^^ not found in this scope
    |
help: consider importing this tuple variant
    |
1   + use chrono::MappedLocalTime::Ambiguous;
    |

error[E0425]: cannot find function, tuple struct or tuple variant `Single` in this scope
   --> chrono-tz/src/timezone_impl.rs:322:42
    |
322 |             (Ambiguous(offset, _), _) => Single(offset),
    |                                          ^^^^^^ not found in this scope
    |
help: consider importing this tuple variant
    |
1   + use chrono::MappedLocalTime::Single;
    |

error[E0531]: cannot find tuple struct or tuple variant `Ambiguous` in this scope
   --> chrono-tz/src/timezone_impl.rs:323:17
    |
323 |             (_, Ambiguous(offset, _)) => Single(offset),
    |                 ^^^^^^^^^ not found in this scope
    |
help: consider importing this tuple variant
    |
1   + use chrono::MappedLocalTime::Ambiguous;
    |

error[E0425]: cannot find function, tuple struct or tuple variant `Single` in this scope
   --> chrono-tz/src/timezone_impl.rs:323:42
    |
323 |             (_, Ambiguous(offset, _)) => Single(offset),
    |                                          ^^^^^^ not found in this scope
    |
help: consider importing this tuple variant
    |
1   + use chrono::MappedLocalTime::Single;
    |

error[E0308]: mismatched types
   --> chrono-tz/src/timezone_impl.rs:324:14
    |
319 |         match (earliest, latest) {
    |               ------------------ this expression has type `(MappedLocalTime<TzOffset>, MappedLocalTime<TzOffset>)`
...
324 |             (None, None) => None,
    |              ^^^^ expected `MappedLocalTime<TzOffset>`, found `Option<_>`
    |
    = note: expected enum `MappedLocalTime<TzOffset>`
               found enum `Option<_>`

error[E0308]: mismatched types
   --> chrono-tz/src/timezone_impl.rs:324:20
    |
319 |         match (earliest, latest) {
    |               ------------------ this expression has type `(MappedLocalTime<TzOffset>, MappedLocalTime<TzOffset>)`
...
324 |             (None, None) => None,
    |                    ^^^^ expected `MappedLocalTime<TzOffset>`, found `Option<_>`
    |
    = note: expected enum `MappedLocalTime<TzOffset>`
               found enum `Option<_>`

Fix

// chrono-tz/src/timezone_impl.rs
use chrono::MappedLocalTime::{Ambiguous, Single};
// line 289
    #[allow(deprecated)]
    fn offset_from_local_date(&self, local: &NaiveDate) -> LocalResult<Self::Offset> {
        let earliest = self.offset_from_local_datetime(&local.and_time(NaiveTime::MIN));
        let latest = self.offset_from_local_datetime(&local.and_hms_opt(23, 59, 59).unwrap());
        // comments...
        match (earliest, latest) {
            (result @ Single(_), _) => result,
            (_, result @ Single(_)) => result,
            (Ambiguous(offset, _), _) => Single(offset),
            (_, Ambiguous(offset, _)) => Single(offset),
            (LocalResult::None, LocalResult::None) => LocalResult::None,
        }
    }
pitdicker commented 6 months ago

This is an accidental breaking change in chrono. I've yanked the version for now. See https://github.com/chronotope/chrono/issues/1544.

ddimaria commented 6 months ago

Thanks for the quick resolution @pitdicker, our CI is now unclogged ❤️