Implement println! using nested format_args!#987
Merged
kevinaboos merged 1 commit intotheseus-os:theseus_mainfrom Jun 26, 2023
Merged
Implement println! using nested format_args!#987kevinaboos merged 1 commit intotheseus-os:theseus_mainfrom
println! using nested format_args!#987kevinaboos merged 1 commit intotheseus-os:theseus_mainfrom
Conversation
`concat!` prevents `format_args!` from capturing variables from the
surrounding scope. Implementing `println!` using a nested `format_args!`
removes this limitation allowing us to do the following:
```rust
let x = 3;
println!("{x}");
```
Similar to `std::println!`.
Also, the change [does not impact performance][1].
[1]: rust-lang/rust#106824
Signed-off-by: Klimenty Tsoutsman <klim@tsoutsman.com>
kevinaboos
approved these changes
Jun 26, 2023
Member
kevinaboos
left a comment
There was a problem hiding this comment.
Nice, I was wondering about doing that sort of variable capturing in custom format macros!
There are a few other places where we do this similar concat!() pattern, a few I can think of off the top of my head are early_printer, println_log!() in the deps app, etc. Would you mind submitting similar PR(s) for those?
github-actions bot
pushed a commit
that referenced
this pull request
Jun 26, 2023
Our previous usage of `concat!()` prevents `format_args!`
from capturing variables from the surrounding scope.
Implementing `println!` using a nested `format_args!`
removes this limitation allowing us to do the following:
```rust
let x = 3;
println!("{x}");
```
Signed-off-by: Klimenty Tsoutsman <klim@tsoutsman.com> 2d6e8b4
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
concat!preventsformat_args!from capturing variables from the surrounding scope. Implementingprintln!using a nestedformat_args!removes this limitation allowing us to do the following:Similar to
std::println!.Also, the change does not impact performance.