thomcc / arcstr

Better reference counted strings for Rust
Apache License 2.0
114 stars 18 forks source link

`arcstr::format` doesn't support captured identifiers and fails silently #37

Closed nalply closed 2 years ago

nalply commented 2 years ago

Since Rust v1.58 captured identifiers in format strings are stable.

https://blog.rust-lang.org/2022/01/13/Rust-1.58.0.html#captured-identifiers-in-format-strings

However they don't work with arcstr::format.

//# arcstr = "0.2"

fn main() {
  let s = "test";
  assert_eq!("1. test", format!("1. {s}"));
  assert_eq!("2. test", arcstr::format!("2. {}", s));
  assert_eq!("3. test", arcstr::format!("3. {s}"));
}

fails:

/home/nalp/.cargo/bin/cargo play scratch.rs
   Compiling pfateufxzav8cfrf9pg2wyq28puu v0.1.0 (/tmp/cargo-play.FaTEUfXZaV8cfrf9PG2wyQ28PUu)
    Finished dev [unoptimized + debuginfo] target(s) in 0.20s
     Running `/tmp/cargo-play.FaTEUfXZaV8cfrf9PG2wyQ28PUu/target/debug/pfateufxzav8cfrf9pg2wyq28puu`
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `"3. test"`,
 right: `"3. {s}"`', src/main.rs:7:3
stack backtrace:
   0: rust_begin_unwind
             at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/core/src/panicking.rs:142:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/core/src/panicking.rs:181:5
   4: pfateufxzav8cfrf9pg2wyq28puu::main
             at /tmp/cargo-play.FaTEUfXZaV8cfrf9PG2wyQ28PUu/src/main.rs:7:3
   5: core::ops::function::FnOnce::call_once
             at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Process finished with exit code 101

I am going to try to fix this myself and if I am successful I am willing to make a pull request. What do you think?

thomcc commented 2 years ago

Nice catch. I'll have it fixed in a few.

thomcc commented 2 years ago

Fixed in https://crates.io/crates/arcstr/1.1.4 (https://github.com/thomcc/arcstr/releases/tag/v1.1.4)

nalply commented 2 years ago

Thank you, that was fast.