dtolnay / dtolnay/indoc

Captured vars don't work with indoc!, but work with printdoc!

Open
#50 1 comment 3 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
789
Forks
24
PR merge metrics
No merged PRs in 30d

Description

According to the readme, `printdoc!($fmt, ...) — equivalent to print!(indoc!($fmt), ...)`, but this case is clearly different. Is there a way to have `indoc!` properly handle such cases for backward compatibility?

```rust
use indoc::{indoc, printdoc};

fn main() {
let s = "world";
println!(indoc!("Hello {}"), s);
printdoc!("Hello {s}");

println!(indoc!("Hello {s}"));
// error: there is no argument named `s`
// --> src/main.rs:8:21
// |
// 8 | println!(indoc!("Hello {s}"));
// | ^^^^^^^^^^^
// |
// = note: did you intend to capture a variable `s` from the surrounding scope?
// = note: to avoid ambiguity, `format_args!` cannot capture variables when the format string is expanded from a macro

}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the captured-variable examples in src/main.rs and compare the README's claimed equivalence between indoc! and printdoc!. Then trace how each macro handles the format string and determine whether backward-compatible support is possible; done means the reported case works or the limitation and rationale are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.