Skip to content

Commit 8caf604

Browse files
committed
Improve messaging from PR feedback
1 parent 6b95f31 commit 8caf604

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

src/librustc_builtin_macros/format.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,8 @@ impl<'a, 'b> Context<'a, 'b> {
507507
.features
508508
.map_or(false, |features| features.format_args_capture);
509509

510-
// For the moment capturing variables from format strings expanded from
511-
// literals is disabled (see RFC #2795)
510+
// For the moment capturing variables from format strings expanded from macros is
511+
// disabled (see RFC #2795)
512512
let can_capture = capture_feature_enabled && self.is_literal;
513513

514514
if can_capture {
@@ -541,15 +541,11 @@ impl<'a, 'b> Context<'a, 'b> {
541541
when the format string is expanded from a macro",
542542
);
543543
} else if self.ecx.parse_sess().unstable_features.is_nightly_build() {
544-
err.note(&format!(
545-
"did you intend to capture a variable `{}` from \
546-
the surrounding scope?",
544+
err.help(&format!(
545+
"if you intended to capture `{}` from the surrounding scope, add \
546+
`#![feature(format_args_capture)]` to the crate attributes",
547547
name
548548
));
549-
err.help(
550-
"add `#![feature(format_args_capture)]` to the crate \
551-
attributes to enable",
552-
);
553549
}
554550

555551
err.emit();

src/test/ui/fmt/feature-gate-format-args-capture.stderr

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@ error: there is no argument named `foo`
44
LL | format!("{foo}");
55
| ^^^^^
66
|
7-
= note: did you intend to capture a variable `foo` from the surrounding scope?
8-
= help: add `#![feature(format_args_capture)]` to the crate attributes to enable
7+
= help: if you intended to capture `foo` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes
98

109
error: there is no argument named `foo`
1110
--> $DIR/feature-gate-format-args-capture.rs:5:13
1211
|
1312
LL | panic!("{foo} {bar}", bar=1);
1413
| ^^^^^
1514
|
16-
= note: did you intend to capture a variable `foo` from the surrounding scope?
17-
= help: add `#![feature(format_args_capture)]` to the crate attributes to enable
15+
= help: if you intended to capture `foo` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes
1816

1917
error: aborting due to 2 previous errors
2018

src/test/ui/if/ifmt-bad-arg.stderr

+5-10
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,23 @@ error: there is no argument named `foo`
6464
LL | format!("{} {foo} {} {bar} {}", 1, 2, 3);
6565
| ^^^^^
6666
|
67-
= note: did you intend to capture a variable `foo` from the surrounding scope?
68-
= help: add `#![feature(format_args_capture)]` to the crate attributes to enable
67+
= help: if you intended to capture `foo` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes
6968

7069
error: there is no argument named `bar`
7170
--> $DIR/ifmt-bad-arg.rs:27:26
7271
|
7372
LL | format!("{} {foo} {} {bar} {}", 1, 2, 3);
7473
| ^^^^^
7574
|
76-
= note: did you intend to capture a variable `bar` from the surrounding scope?
77-
= help: add `#![feature(format_args_capture)]` to the crate attributes to enable
75+
= help: if you intended to capture `bar` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes
7876

7977
error: there is no argument named `foo`
8078
--> $DIR/ifmt-bad-arg.rs:31:14
8179
|
8280
LL | format!("{foo}");
8381
| ^^^^^
8482
|
85-
= note: did you intend to capture a variable `foo` from the surrounding scope?
86-
= help: add `#![feature(format_args_capture)]` to the crate attributes to enable
83+
= help: if you intended to capture `foo` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes
8784

8885
error: multiple unused formatting arguments
8986
--> $DIR/ifmt-bad-arg.rs:32:17
@@ -165,8 +162,7 @@ error: there is no argument named `valueb`
165162
LL | format!("{valuea} {valueb}", valuea=5, valuec=7);
166163
| ^^^^^^^^
167164
|
168-
= note: did you intend to capture a variable `valueb` from the surrounding scope?
169-
= help: add `#![feature(format_args_capture)]` to the crate attributes to enable
165+
= help: if you intended to capture `valueb` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes
170166

171167
error: named argument never used
172168
--> $DIR/ifmt-bad-arg.rs:45:51
@@ -218,8 +214,7 @@ error: there is no argument named `foo`
218214
LL | {foo}
219215
| ^^^^^
220216
|
221-
= note: did you intend to capture a variable `foo` from the surrounding scope?
222-
= help: add `#![feature(format_args_capture)]` to the crate attributes to enable
217+
= help: if you intended to capture `foo` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes
223218

224219
error: invalid format string: expected `'}'`, found `'t'`
225220
--> $DIR/ifmt-bad-arg.rs:75:1

0 commit comments

Comments
 (0)