From 9bee3db85efc69c9848229e9b911b681d8b27c2b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 10 Feb 2023 21:05:07 -0800 Subject: [PATCH] Add ui test of current behavior of capture in nested macro --- tests/ui/capture-var-nested.rs | 6 ++++++ tests/ui/capture-var-nested.stderr | 8 ++++++++ 2 files changed, 14 insertions(+) create mode 100644 tests/ui/capture-var-nested.rs create mode 100644 tests/ui/capture-var-nested.stderr diff --git a/tests/ui/capture-var-nested.rs b/tests/ui/capture-var-nested.rs new file mode 100644 index 0000000..54dc432 --- /dev/null +++ b/tests/ui/capture-var-nested.rs @@ -0,0 +1,6 @@ +use indoc::indoc; + +fn main() { + let world = "world"; + println!(indoc!("Hello {world}")); +} diff --git a/tests/ui/capture-var-nested.stderr b/tests/ui/capture-var-nested.stderr new file mode 100644 index 0000000..c98b3c0 --- /dev/null +++ b/tests/ui/capture-var-nested.stderr @@ -0,0 +1,8 @@ +error: there is no argument named `world` + --> tests/ui/capture-var-nested.rs:5:21 + | +5 | println!(indoc!("Hello {world}")); + | ^^^^^^^^^^^^^^^ + | + = note: did you intend to capture a variable `world` from the surrounding scope? + = note: to avoid ambiguity, `format_args!` cannot capture variables when the format string is expanded from a macro