Skip to content

Commit a2c0a21

Browse files
committed
feat(rust): Disallows Debug format derivation and Debug formatting in release code.
1 parent 641ef69 commit a2c0a21

File tree

6 files changed

+17
-1
lines changed

6 files changed

+17
-1
lines changed

earthly/rust/stdcfgs/cargo_manifest/project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ unchecked_duration_subtraction = "deny"
3636
unreachable = "deny"
3737
missing_docs_in_private_items = "deny"
3838
arithmetic_side_effects = "deny"
39+
use_debug = "deny"
40+
disallowed-macros = "deny"

earthly/rust/stdcfgs/cargo_manifest/workspace.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ unchecked_duration_subtraction = "deny"
3636
unreachable = "deny"
3737
missing_docs_in_private_items = "deny"
3838
arithmetic_side_effects = "deny"
39+
use_debug = "deny"
40+
disallowed-macros = "deny"

earthly/rust/stdcfgs/clippy.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ allow-unwrap-in-tests = true
22
allow-expect-in-tests = true
33
allow-panic-in-tests = true
44
arithmetic-side-effects-allowed = ["num_bigint::BigInt"]
5+
disallowed-macros = [
6+
{ path = "std::fmt::Debug", reason = "Debug Formatting not permitted in production release code.\nUse #[cfg_attr(debug_assertions, derive(Debug)] instead." },
7+
]

examples/rust/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ unchecked_duration_subtraction = "deny"
4545
unreachable = "deny"
4646
missing_docs_in_private_items = "deny"
4747
arithmetic_side_effects = "deny"
48+
use_debug = "deny"
49+
disallowed-macros = "deny"

examples/rust/clippy.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ allow-unwrap-in-tests = true
22
allow-expect-in-tests = true
33
allow-panic-in-tests = true
44
arithmetic-side-effects-allowed = ["num_bigint::BigInt"]
5+
disallowed-macros = [
6+
{ path = "std::fmt::Debug", reason = "Debug Formatting not permitted in production release code.\nUse #[cfg_attr(debug_assertions, derive(Debug)] instead." },
7+
]

examples/rust/crates/foo/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use clap::Parser;
55
use foo::fmt_hello;
66

77
/// Simple program to greet a person
8-
#[derive(Parser, Debug)]
8+
#[cfg_attr(debug_assertions, derive(Debug))]
9+
#[derive(Parser)]
910
#[command(author, version, about, long_about = None)]
1011
struct Args {
1112
/// Name of the person to greet
@@ -21,6 +22,9 @@ struct Args {
2122
fn main() {
2223
let args = Args::parse();
2324

25+
#[cfg(debug_assertions)]
26+
println!("{args:?}");
27+
2428
for cnt in 0..args.count {
2529
println!("{}", fmt_hello(&args.name, cnt));
2630
}

0 commit comments

Comments
 (0)