-
Notifications
You must be signed in to change notification settings - Fork 264
Description
The following code panics while handling a panic in beta and nightly versions of Rust:
main.rs:
use std::str::FromStr;
use icu_calendar::Date;
use icu_datetime::{options::length, DateFormatter};
use icu_locid::Locale;
fn main() {
let locale = Locale::from_str("en-u-ca-japanese").unwrap();
let formatter = DateFormatter::try_new_with_length(&locale.into(), length::Date::Full).unwrap();
let date = Date::try_new_iso_date(2020, 5, 30).unwrap().to_any();
dbg!(formatter.format_to_string(&date).unwrap());
}cargo.toml
[package]
name = "bar"
version = "0.1.0"
edition = "2021"
[dependencies]
icu_datetime = { version = "1.5.1", features = ["std"] }
icu_calendar = { version = "1.5.1", features = ["std"] }
icu_locid = { version = "1.5.0", features = ["std"] }output:
panicked at library\core\src\fmt\mod.rs:2431:38:
thread panicked while processing panic. aborting.
error: process didn't exit successfully: `target\debug\bar.exe` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)
(library\core\src\fmt\mod.rs:2431:38)
It's not really easy to debug, but it seems like the original panic is because of this debug_assert failing and the next panic seems to happen while trying to format icu_calendar::Era - so the original error was probably DateTimeWriteError::MissingEraSymbol. In release mode, this causes invalid UTF-8 to be written, because the era is wrong (from debugging I noticed it seems to be garbage - at least until the next nul).
test_japanese panics on nightly as well (when changing the toolchain in rust-toolchain.toml to nightly).
Update: It seems like rustc decided to swap the order of the tuple elements inside dates_to_eras, so it thinks the string comes first, but that one doesn't contain valid UTF-8.