-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Format core and std macro rules, removing needless surrounding blocks #94868
Conversation
r? @yaahc (rust-highfive has picked a reviewer for you, use r? to override) |
LL ~ Foo(2, b) => println!("{}", b) | ||
LL ~ Foo(2, b) => println!("{}", b), | ||
LL + Foo(_, _) => todo!() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now avoids #94866
r? @Dylan-DPC |
@bors r+ rollup |
📌 Commit af53809 has been approved by |
Format core and std macro rules, removing needless surrounding blocks Many of the asserting and printing macros in `core` and `std` are written with prehistoric-looking formatting, like this: https://github.com/rust-lang/rust/blob/335ffbfa547df94ac236f5c56130cecf99c8d82b/library/std/src/macros.rs#L96-L101 In modern Rust style this would conventionally be written as follows instead, always using braces and a trailing semicolon on the macro arms: https://github.com/rust-lang/rust/blob/af53809c874e0afb7be966df4d3cfcaa05277c53/library/std/src/macros.rs#L98-L105 Getting rid of the unneeded braces inside the expansion reduces extraneous indentation in macro-expanded code. For example: ```rust println!("repro {}", true); ``` ```rust // before: { ::std::io::_print( ::core::fmt::Arguments::new_v1( &["repro ", "\n"], &[::core::fmt::ArgumentV1::new_display(&true)], ), ); }; ``` ```rust // after: ::std::io::_print( ::core::fmt::Arguments::new_v1( &["repro ", "\n"], &[::core::fmt::ArgumentV1::new_display(&true)], ), ); ```
⌛ Testing commit af53809 with merge 28838f68c28e8f45725d715555a73c55dbd9323d... |
💔 Test failed - checks-actions |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to reproduce the run-make-fulldeps/coverage-reports failure on aarch64-gnu, but I noticed this snippet in the logs which looks relevant, so I will try to make the change that it shows.
--- expected_show_coverage.closure.txt 2022-03-13 10:25:55.192734369 +0000
+++ /checkout/obj/build/aarch64-unknown-linux-gnu/test/run-make-fulldeps/coverage-reports/coverage-reports/actual_show_coverage.closure.txt 2022-03-13 11:10:50.435023772 +0000
@@ -116,8 +116,8 @@
116| 1|
117| 1| let
118| 1| _unused_closure
- 119| | =
- 120| | |
+ 119| 1| =
+ 120| 1| |
121| | mut countdown
122| | |
123| 0| {
@@ -173,7 +173,7 @@
169| | ;
170| |
171| 1| let short_used_not_covered_closure_line_break_no_block_embedded_branch =
- 172| | | _unused_arg: u8 |
+ 172| 1| | _unused_arg: u8 |
173| 0| println!(
174| 0| "not called: {}",
175| 0| if is_true { "check" } else { "me" }
@@ -191,7 +191,7 @@
187| | ;
188| |
189| 1| let short_used_covered_closure_line_break_no_block_embedded_branch =
- 190| 1| | _unused_arg: u8 |
+ 190| | | _unused_arg: u8 |
191| 1| println!(
192| 1| "not called: {}",
193| 1| if is_true { "check" } else { "me" }
@bors r=Dylan-DPC |
📌 Commit ac5c657 has been approved by |
Rollup of 5 pull requests Successful merges: - rust-lang#94868 (Format core and std macro rules, removing needless surrounding blocks) - rust-lang#94951 (Extend the irrefutable_let_patterns lint to let chains) - rust-lang#94955 (Refactor: Use `format_args_capture` in some parts of `rustc_parse`) - rust-lang#94957 (Improve the explanation about the behaviour of read_line) - rust-lang#94974 (Ensure that `let_else` does not interact with `let_chains`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…lacrum Make [e]println macros eagerly drop temporaries (for backport) This PR extracts the subset of rust-lang#96455 which is only the parts necessary for fixing the 1.61-beta regressions in rust-lang#96434. My larger PR rust-lang#96455 contains a few other changes relative to the pre-rust-lang#94868 behavior; those are not necessary to backport into 1.61. argument position | before rust-lang#94868 | after rust-lang#94868 | after this PR --- |:---:|:---:|:---: `write!($tmp, "…", …)` | :rage: | :rage: | :rage: `write!(…, "…", $tmp)` | :rage: | :rage: | :rage: `writeln!($tmp, "…", …)` | :rage: | :rage: | :rage: `writeln!(…, "…", $tmp)` | :rage: | :rage: | :rage: `print!("…", $tmp)` | :rage: | :rage: | :rage: `println!("…", $tmp)` | :smiley_cat: | :rage: | :smiley_cat: `eprint!("…", $tmp)` | :rage: | :rage: | :rage: `eprintln!("…", $tmp)` | :smiley_cat: | :rage: | :smiley_cat: `panic!("…", $tmp)` | :smiley_cat: | :smiley_cat: | :smiley_cat:
…lacrum Make [e]println macros eagerly drop temporaries (for backport) This PR extracts the subset of rust-lang#96455 which is only the parts necessary for fixing the 1.61-beta regressions in rust-lang#96434. My larger PR rust-lang#96455 contains a few other changes relative to the pre-rust-lang#94868 behavior; those are not necessary to backport into 1.61. argument position | before rust-lang#94868 | after rust-lang#94868 | after this PR --- |:---:|:---:|:---: `write!($tmp, "…", …)` | :rage: | :rage: | :rage: `write!(…, "…", $tmp)` | :rage: | :rage: | :rage: `writeln!($tmp, "…", …)` | :rage: | :rage: | :rage: `writeln!(…, "…", $tmp)` | :rage: | :rage: | :rage: `print!("…", $tmp)` | :rage: | :rage: | :rage: `println!("…", $tmp)` | :smiley_cat: | :rage: | :smiley_cat: `eprint!("…", $tmp)` | :rage: | :rage: | :rage: `eprintln!("…", $tmp)` | :smiley_cat: | :rage: | :smiley_cat: `panic!("…", $tmp)` | :smiley_cat: | :smiley_cat: | :smiley_cat:
Make write/print macros eagerly drop temporaries This PR fixes the 2 regressions in rust-lang#96434 (`println` and `eprintln`) and changes all the other similar macros (`write`, `writeln`, `print`, `eprint`) to match the old pre-rust-lang#94868 behavior of `println` and `eprintln`. argument position | before rust-lang#94868 | after rust-lang#94868 | after this PR --- |:---:|:---:|:---: `write!($tmp, "…", …)` | :rage: | :rage: | :smiley_cat: `write!(…, "…", $tmp)` | :rage: | :rage: | :smiley_cat: `writeln!($tmp, "…", …)` | :rage: | :rage: | :smiley_cat: `writeln!(…, "…", $tmp)` | :rage: | :rage: | :smiley_cat: `print!("…", $tmp)` | :rage: | :rage: | :smiley_cat: `println!("…", $tmp)` | :smiley_cat: | :rage: | :smiley_cat: `eprint!("…", $tmp)` | :rage: | :rage: | :smiley_cat: `eprintln!("…", $tmp)` | :smiley_cat: | :rage: | :smiley_cat: `panic!("…", $tmp)` | :smiley_cat: | :smiley_cat: | :smiley_cat: Example of code that is affected by this change: ```rust use std::sync::Mutex; fn main() { let mutex = Mutex::new(0); print!("{}", mutex.lock().unwrap()) /* no semicolon */ } ``` You can see several real-world examples like this in the Crater links at the top of rust-lang#96434. This code failed to compile prior to this PR as follows, but works after this PR. ```console error[E0597]: `mutex` does not live long enough --> src/main.rs:5:18 | 5 | print!("{}", mutex.lock().unwrap()) /* no semicolon */ | ^^^^^^^^^^^^--------- | | | borrowed value does not live long enough | a temporary with access to the borrow is created here ... 6 | } | - | | | `mutex` dropped here while still borrowed | ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `MutexGuard` ```
Make write/print macros eagerly drop temporaries This PR fixes the 2 regressions in rust-lang#96434 (`println` and `eprintln`) and changes all the other similar macros (`write`, `writeln`, `print`, `eprint`) to match the old pre-rust-lang#94868 behavior of `println` and `eprintln`. argument position | before rust-lang#94868 | after rust-lang#94868 | after this PR --- |:---:|:---:|:---: `write!($tmp, "…", …)` | :rage: | :rage: | :smiley_cat: `write!(…, "…", $tmp)` | :rage: | :rage: | :smiley_cat: `writeln!($tmp, "…", …)` | :rage: | :rage: | :smiley_cat: `writeln!(…, "…", $tmp)` | :rage: | :rage: | :smiley_cat: `print!("…", $tmp)` | :rage: | :rage: | :smiley_cat: `println!("…", $tmp)` | :smiley_cat: | :rage: | :smiley_cat: `eprint!("…", $tmp)` | :rage: | :rage: | :smiley_cat: `eprintln!("…", $tmp)` | :smiley_cat: | :rage: | :smiley_cat: `panic!("…", $tmp)` | :smiley_cat: | :smiley_cat: | :smiley_cat: Example of code that is affected by this change: ```rust use std::sync::Mutex; fn main() { let mutex = Mutex::new(0); print!("{}", mutex.lock().unwrap()) /* no semicolon */ } ``` You can see several real-world examples like this in the Crater links at the top of rust-lang#96434. This code failed to compile prior to this PR as follows, but works after this PR. ```console error[E0597]: `mutex` does not live long enough --> src/main.rs:5:18 | 5 | print!("{}", mutex.lock().unwrap()) /* no semicolon */ | ^^^^^^^^^^^^--------- | | | borrowed value does not live long enough | a temporary with access to the borrow is created here ... 6 | } | - | | | `mutex` dropped here while still borrowed | ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `MutexGuard` ```
…lacrum Make [e]println macros eagerly drop temporaries (for backport) This PR extracts the subset of rust-lang#96455 which is only the parts necessary for fixing the 1.61-beta regressions in rust-lang#96434. My larger PR rust-lang#96455 contains a few other changes relative to the pre-rust-lang#94868 behavior; those are not necessary to backport into 1.61. argument position | before rust-lang#94868 | after rust-lang#94868 | after this PR --- |:---:|:---:|:---: `write!($tmp, "…", …)` | :rage: | :rage: | :rage: `write!(…, "…", $tmp)` | :rage: | :rage: | :rage: `writeln!($tmp, "…", …)` | :rage: | :rage: | :rage: `writeln!(…, "…", $tmp)` | :rage: | :rage: | :rage: `print!("…", $tmp)` | :rage: | :rage: | :rage: `println!("…", $tmp)` | :smiley_cat: | :rage: | :smiley_cat: `eprint!("…", $tmp)` | :rage: | :rage: | :rage: `eprintln!("…", $tmp)` | :smiley_cat: | :rage: | :smiley_cat: `panic!("…", $tmp)` | :smiley_cat: | :smiley_cat: | :smiley_cat:
Make write/print macros eagerly drop temporaries This PR fixes the 2 regressions in rust-lang#96434 (`println` and `eprintln`) and changes all the other similar macros (`write`, `writeln`, `print`, `eprint`) to match the old pre-rust-lang#94868 behavior of `println` and `eprintln`. argument position | before rust-lang#94868 | after rust-lang#94868 | after this PR --- |:---:|:---:|:---: `write!($tmp, "…", …)` | :rage: | :rage: | :smiley_cat: `write!(…, "…", $tmp)` | :rage: | :rage: | :smiley_cat: `writeln!($tmp, "…", …)` | :rage: | :rage: | :smiley_cat: `writeln!(…, "…", $tmp)` | :rage: | :rage: | :smiley_cat: `print!("…", $tmp)` | :rage: | :rage: | :smiley_cat: `println!("…", $tmp)` | :smiley_cat: | :rage: | :smiley_cat: `eprint!("…", $tmp)` | :rage: | :rage: | :smiley_cat: `eprintln!("…", $tmp)` | :smiley_cat: | :rage: | :smiley_cat: `panic!("…", $tmp)` | :smiley_cat: | :smiley_cat: | :smiley_cat: Example of code that is affected by this change: ```rust use std::sync::Mutex; fn main() { let mutex = Mutex::new(0); print!("{}", mutex.lock().unwrap()) /* no semicolon */ } ``` You can see several real-world examples like this in the Crater links at the top of rust-lang#96434. This code failed to compile prior to this PR as follows, but works after this PR. ```console error[E0597]: `mutex` does not live long enough --> src/main.rs:5:18 | 5 | print!("{}", mutex.lock().unwrap()) /* no semicolon */ | ^^^^^^^^^^^^--------- | | | borrowed value does not live long enough | a temporary with access to the borrow is created here ... 6 | } | - | | | `mutex` dropped here while still borrowed | ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `MutexGuard` ```
Revert `write!` and `writeln!` to late drop temporaries Closes (on master, but not on beta) rust-lang#99684 by reverting the `write!` and `writeln!` parts of rust-lang#96455. argument position | before<br>rust-lang#94868 | after<br>rust-lang#94868 | after<br>rust-lang#96455 | after<br>this PR | desired<br>(unimplementable) --- |:---:|:---:|:---:|:---:|:---: `write!($tmp, "…", …)` | **⸺late** | **⸺late** | *early⸺* | **⸺late** | **⸺late** `write!(…, "…", $tmp)` | **⸺late** | **⸺late** | *early⸺* | **⸺late** | *early⸺* `writeln!($tmp, "…", …)` | **⸺late** | **⸺late** | *early⸺* | **⸺late** | **⸺late** `writeln!(…, "…", $tmp)` | **⸺late** | **⸺late** | *early⸺* | **⸺late** | *early⸺* `print!("…", $tmp)` | **⸺late** | **⸺late** | *early⸺* | *early⸺* | *early⸺* `println!("…", $tmp)` | *early⸺* | **⸺late** | *early⸺* | *early⸺* | *early⸺* `eprint!("…", $tmp)` | **⸺late** | **⸺late** | *early⸺* | *early⸺* | *early⸺* `eprintln!("…", $tmp)` | *early⸺* | **⸺late**| *early⸺* | *early⸺* | *early⸺* `panic!("…", $tmp)` | *early⸺* | *early⸺* | *early⸺* | *early⸺* | *early⸺* "Late drop" refers to dropping temporaries at the nearest semicolon **outside** of the macro invocation. "Early drop" refers to dropping temporaries inside of the macro invocation.
Many of the asserting and printing macros in
core
andstd
are written with prehistoric-looking formatting, like this:rust/library/std/src/macros.rs
Lines 96 to 101 in 335ffbf
In modern Rust style this would conventionally be written as follows instead, always using braces and a trailing semicolon on the macro arms:
rust/library/std/src/macros.rs
Lines 98 to 105 in af53809
Getting rid of the unneeded braces inside the expansion reduces extraneous indentation in macro-expanded code. For example: