Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nyurik opened this issue Sep 23, 2022 · 0 comments
Open

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

nyurik opened this issue Sep 23, 2022 · 0 comments

Comments

@nyurik
Copy link

nyurik commented Sep 23, 2022

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?

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

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant