Crates.io | everybody_loops |
lib.rs | everybody_loops |
version | 0.1.1 |
source | src |
created_at | 2022-04-17 23:15:38.135354 |
updated_at | 2022-04-17 23:17:34.017496 |
description | A Replacement for the `-Z unpretty=everybody_loops` pass to rustc. |
homepage | |
repository | https://github.com/aDotInTheVoid/everybody_loops |
max_upload_size | |
id | 569614 |
size | 18,105 |
A Replacement for the -Z unpretty=everybody_loops
pass to rustc.
Take a file with a lot of functions, you want to get rid of them.
fn main() {
let x = 1;
let y = 2;
let z = x + y;
}
struct Foo;
impl std::fmt::Debug for Foo {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "Foo")
}
}
impl Foo {
fn boo(&self) {
println!("boo");
}
}
const f: () = {
fn noop() {
let x = 8;
}
}
Just run
everybody_loops file.rs
And now you have a with much simpler code.
fn main() {
loop {}
}
struct Foo;
impl std::fmt::Debug for Foo {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
loop {}
}
}
impl Foo {
fn boo(&self) {
loop {}
}
}
const f: () = {
fn noop() {
loop {}
}
};
cargo install --locked everybody_loops
This will not work for functions with impl Trait
in the return type, as the
compiller needs to ascribe a concreat type.
This used to be a compiller feature, but it was removed in #93913
This post by Felix S Klock II first inroduced me to this technique.
The code is a thin wrapper over syn
and prettyplease
, both by
dtolnay, who diserves far more credit than me
for making this happen.