Skip to content

Commit

Permalink
Improve messaging from PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Jun 27, 2020
1 parent 6b95f31 commit 8caf604
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
14 changes: 5 additions & 9 deletions src/librustc_builtin_macros/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions src/test/ui/fmt/feature-gate-format-args-capture.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ 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
|
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

15 changes: 5 additions & 10 deletions src/test/ui/if/ifmt-bad-arg.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,23 @@ 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
|
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
|
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8caf604

Please sign in to comment.