diff --git a/src/librustc_builtin_macros/format.rs b/src/librustc_builtin_macros/format.rs index 538d513c5d6..16e11fecf29 100644 --- a/src/librustc_builtin_macros/format.rs +++ b/src/librustc_builtin_macros/format.rs @@ -507,8 +507,8 @@ impl<'a, 'b> Context<'a, 'b> { .features .map_or(false, |features| features.format_args_capture); - // For the moment capturing variables from format strings expanded from - // literals is disabled (see RFC #2795) + // For the moment capturing variables from format strings expanded from macros is + // disabled (see RFC #2795) let can_capture = capture_feature_enabled && self.is_literal; if can_capture { @@ -541,15 +541,11 @@ impl<'a, 'b> Context<'a, 'b> { when the format string is expanded from a macro", ); } else if self.ecx.parse_sess().unstable_features.is_nightly_build() { - err.note(&format!( - "did you intend to capture a variable `{}` from \ - the surrounding scope?", + err.help(&format!( + "if you intended to capture `{}` from the surrounding scope, add \ + `#![feature(format_args_capture)]` to the crate attributes", name )); - err.help( - "add `#![feature(format_args_capture)]` to the crate \ - attributes to enable", - ); } err.emit(); diff --git a/src/test/ui/fmt/feature-gate-format-args-capture.stderr b/src/test/ui/fmt/feature-gate-format-args-capture.stderr index bbd4d759fb5..f08f1651cb6 100644 --- a/src/test/ui/fmt/feature-gate-format-args-capture.stderr +++ b/src/test/ui/fmt/feature-gate-format-args-capture.stderr @@ -4,8 +4,7 @@ error: there is no argument named `foo` LL | format!("{foo}"); | ^^^^^ | - = note: did you intend to capture a variable `foo` from the surrounding scope? - = help: add `#![feature(format_args_capture)]` to the crate attributes to enable + = help: if you intended to capture `foo` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes error: there is no argument named `foo` --> $DIR/feature-gate-format-args-capture.rs:5:13 @@ -13,8 +12,7 @@ error: there is no argument named `foo` LL | panic!("{foo} {bar}", bar=1); | ^^^^^ | - = note: did you intend to capture a variable `foo` from the surrounding scope? - = help: add `#![feature(format_args_capture)]` to the crate attributes to enable + = help: if you intended to capture `foo` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes error: aborting due to 2 previous errors diff --git a/src/test/ui/if/ifmt-bad-arg.stderr b/src/test/ui/if/ifmt-bad-arg.stderr index cbcb1df4985..0ff478826f7 100644 --- a/src/test/ui/if/ifmt-bad-arg.stderr +++ b/src/test/ui/if/ifmt-bad-arg.stderr @@ -64,8 +64,7 @@ error: there is no argument named `foo` LL | format!("{} {foo} {} {bar} {}", 1, 2, 3); | ^^^^^ | - = note: did you intend to capture a variable `foo` from the surrounding scope? - = help: add `#![feature(format_args_capture)]` to the crate attributes to enable + = help: if you intended to capture `foo` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes error: there is no argument named `bar` --> $DIR/ifmt-bad-arg.rs:27:26 @@ -73,8 +72,7 @@ error: there is no argument named `bar` LL | format!("{} {foo} {} {bar} {}", 1, 2, 3); | ^^^^^ | - = note: did you intend to capture a variable `bar` from the surrounding scope? - = help: add `#![feature(format_args_capture)]` to the crate attributes to enable + = help: if you intended to capture `bar` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes error: there is no argument named `foo` --> $DIR/ifmt-bad-arg.rs:31:14 @@ -82,8 +80,7 @@ error: there is no argument named `foo` LL | format!("{foo}"); | ^^^^^ | - = note: did you intend to capture a variable `foo` from the surrounding scope? - = help: add `#![feature(format_args_capture)]` to the crate attributes to enable + = help: if you intended to capture `foo` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes error: multiple unused formatting arguments --> $DIR/ifmt-bad-arg.rs:32:17 @@ -165,8 +162,7 @@ error: there is no argument named `valueb` LL | format!("{valuea} {valueb}", valuea=5, valuec=7); | ^^^^^^^^ | - = note: did you intend to capture a variable `valueb` from the surrounding scope? - = help: add `#![feature(format_args_capture)]` to the crate attributes to enable + = help: if you intended to capture `valueb` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes error: named argument never used --> $DIR/ifmt-bad-arg.rs:45:51 @@ -218,8 +214,7 @@ error: there is no argument named `foo` LL | {foo} | ^^^^^ | - = note: did you intend to capture a variable `foo` from the surrounding scope? - = help: add `#![feature(format_args_capture)]` to the crate attributes to enable + = help: if you intended to capture `foo` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes error: invalid format string: expected `'}'`, found `'t'` --> $DIR/ifmt-bad-arg.rs:75:1