Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Point at named argument not found when using format_args_capture instead of whole format string #76485

Merged
merged 1 commit into from
Sep 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,12 @@ impl<'a, 'b> Context<'a, 'b> {
let idx = self.args.len();
self.arg_types.push(Vec::new());
self.arg_unique_types.push(Vec::new());
self.args.push(
self.ecx.expr_ident(self.fmtsp, Ident::new(name, self.fmtsp)),
);
let span = if self.is_literal {
*self.arg_spans.get(self.curpiece).unwrap_or(&self.fmtsp)
} else {
self.fmtsp
};
self.args.push(self.ecx.expr_ident(span, Ident::new(name, span)));
self.names.insert(name, idx);
self.verify_arg_type(Exact(idx), ty)
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/fmt/format-args-capture-missing-variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn main() {
//~^ ERROR: cannot find value `foo` in this scope
//~^^ ERROR: cannot find value `bar` in this scope

format!("{foo}"); //~ ERROR: cannot find value `foo` in this scope
format!("{foo}"); //~ ERROR: cannot find value `foo` in this scope

format!("{valuea} {valueb}", valuea=5, valuec=7);
//~^ ERROR cannot find value `valueb` in this scope
Expand All @@ -16,7 +16,7 @@ fn main() {
{foo}

"##);
//~^^^^^ ERROR: cannot find value `foo` in this scope
//~^^^ ERROR: cannot find value `foo` in this scope

panic!("{foo} {bar}", bar=1); //~ ERROR: cannot find value `foo` in this scope
panic!("{foo} {bar}", bar=1); //~ ERROR: cannot find value `foo` in this scope
}
31 changes: 13 additions & 18 deletions src/test/ui/fmt/format-args-capture-missing-variables.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,40 @@ LL | format!("{valuea} {valueb}", valuea=5, valuec=7);
| formatting specifier missing

error[E0425]: cannot find value `foo` in this scope
--> $DIR/format-args-capture-missing-variables.rs:4:13
--> $DIR/format-args-capture-missing-variables.rs:4:17
|
LL | format!("{} {foo} {} {bar} {}", 1, 2, 3);
| ^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
| ^^^^^ not found in this scope

error[E0425]: cannot find value `bar` in this scope
--> $DIR/format-args-capture-missing-variables.rs:4:13
--> $DIR/format-args-capture-missing-variables.rs:4:26
|
LL | format!("{} {foo} {} {bar} {}", 1, 2, 3);
| ^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
| ^^^^^ not found in this scope

error[E0425]: cannot find value `foo` in this scope
--> $DIR/format-args-capture-missing-variables.rs:8:13
--> $DIR/format-args-capture-missing-variables.rs:8:14
|
LL | format!("{foo}");
| ^^^^^^^ not found in this scope
| ^^^^^ not found in this scope

error[E0425]: cannot find value `valueb` in this scope
--> $DIR/format-args-capture-missing-variables.rs:10:13
--> $DIR/format-args-capture-missing-variables.rs:10:23
|
LL | format!("{valuea} {valueb}", valuea=5, valuec=7);
| ^^^^^^^^^^^^^^^^^^^ not found in this scope
| ^^^^^^^^ not found in this scope

error[E0425]: cannot find value `foo` in this scope
--> $DIR/format-args-capture-missing-variables.rs:14:13
--> $DIR/format-args-capture-missing-variables.rs:16:9
|
LL | format!(r##"
| _____________^
LL | |
LL | | {foo}
LL | |
LL | | "##);
| |_______^ not found in this scope
LL | {foo}
| ^^^^^ not found in this scope

error[E0425]: cannot find value `foo` in this scope
--> $DIR/format-args-capture-missing-variables.rs:21:12
--> $DIR/format-args-capture-missing-variables.rs:21:13
|
LL | panic!("{foo} {bar}", bar=1);
| ^^^^^^^^^^^^^ not found in this scope
| ^^^^^ not found in this scope

error: aborting due to 7 previous errors

Expand Down