forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#93394 - m-ou-se:fix-93378, r=estebank
Don't allow {} to refer to implicit captures in format_args. Fixes rust-lang#93378
- Loading branch information
Showing
4 changed files
with
65 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
fn main() { | ||
let a = "a"; | ||
let b = "b"; | ||
|
||
println!("{a} {b} {} {} {c} {}", c = "c"); | ||
//~^ ERROR: invalid reference to positional arguments 1 and 2 (there is 1 argument) | ||
|
||
let n = 1; | ||
println!("{a:.n$} {b:.*}"); | ||
//~^ ERROR: invalid reference to positional argument 0 (no arguments were given) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error: invalid reference to positional arguments 1 and 2 (there is 1 argument) | ||
--> $DIR/format-args-capture-issue-93378.rs:5:26 | ||
| | ||
LL | println!("{a} {b} {} {} {c} {}", c = "c"); | ||
| ^^ ^^ | ||
| | ||
= note: positional arguments are zero-based | ||
|
||
error: invalid reference to positional argument 0 (no arguments were given) | ||
--> $DIR/format-args-capture-issue-93378.rs:9:23 | ||
| | ||
LL | println!("{a:.n$} {b:.*}"); | ||
| ------- ^^^--^ | ||
| | | | ||
| | this precision flag adds an extra required argument at position 0, which is why there are 3 arguments expected | ||
| this parameter corresponds to the precision flag | ||
| | ||
= note: positional arguments are zero-based | ||
= note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters