forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#74019 - Manishearth:rollup-2st3jsk, r=Manishe…
…arth Rollup of 12 pull requests Successful merges: - rust-lang#73140 (Fallback to xml.etree.ElementTree) - rust-lang#73670 (Add `format_args_capture` feature) - rust-lang#73693 (Use exhaustive match in const_prop.rs) - rust-lang#73845 (Use &raw in A|Rc::as_ptr) - rust-lang#73861 (Create E0768) - rust-lang#73881 (Standardize bibliographic citations in rustc API docs) - rust-lang#73925 (Improve comments from rust-lang#72617, as suggested by RalfJung) - rust-lang#73949 ([mir-opt] Fix mis-optimization and other issues with the SimplifyArmIdentity pass) - rust-lang#73984 (Edit docs for rustc_data_structures::graph::scc) - rust-lang#73985 (Fix "getting started" link) - rust-lang#73997 (fix typo) - rust-lang#73999 (Bump mingw-check CI image from Ubuntu 16.04 to 18.04.) Failed merges: - rust-lang#74000 (add `lazy_normalization_consts` feature gate) r? @ghost
- Loading branch information
Showing
45 changed files
with
1,859 additions
and
123 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM ubuntu:16.04 | ||
FROM ubuntu:18.04 | ||
|
||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
g++ \ | ||
|
47 changes: 47 additions & 0 deletions
47
src/doc/unstable-book/src/library-features/format-args-capture.md
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,47 @@ | ||
# `format_args_capture` | ||
|
||
The tracking issue for this feature is: [#67984] | ||
|
||
[#67984]: https://github.com/rust-lang/rust/issues/67984 | ||
|
||
------------------------ | ||
|
||
Enables `format_args!` (and macros which use `format_args!` in their implementation, such | ||
as `format!`, `print!` and `panic!`) to capture variables from the surrounding scope. | ||
This avoids the need to pass named parameters when the binding in question | ||
already exists in scope. | ||
|
||
```rust | ||
#![feature(format_args_capture)] | ||
|
||
let (person, species, name) = ("Charlie Brown", "dog", "Snoopy"); | ||
|
||
// captures named argument `person` | ||
print!("Hello {person}"); | ||
|
||
// captures named arguments `species` and `name` | ||
format!("The {species}'s name is {name}."); | ||
``` | ||
|
||
This also works for formatting parameters such as width and precision: | ||
|
||
```rust | ||
#![feature(format_args_capture)] | ||
|
||
let precision = 2; | ||
let s = format!("{:.precision$}", 1.324223); | ||
|
||
assert_eq!(&s, "1.32"); | ||
``` | ||
|
||
A non-exhaustive list of macros which benefit from this functionality include: | ||
- `format!` | ||
- `print!` and `println!` | ||
- `eprint!` and `eprintln!` | ||
- `write!` and `writeln!` | ||
- `panic!` | ||
- `unreachable!` | ||
- `unimplemented!` | ||
- `todo!` | ||
- `assert!` and similar | ||
- macros in many thirdparty crates, such as `log` |
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
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
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
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
Oops, something went wrong.