Improve messaging from PR feedback

This commit is contained in:
David Hewitt 2020-06-27 18:13:47 +01:00
parent 6b95f3102d
commit 8caf604070
3 changed files with 12 additions and 23 deletions

View File

@ -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();

View File

@ -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

View File

@ -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