Skip to content

Commit ed9aca3

Browse files
committed
add allows to all impls and structs
1 parent c8b470b commit ed9aca3

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ mod includes;
4141
mod keywords;
4242
mod pad;
4343

44+
static ALLOW_DEADCODE: &str = "#[allow(dead_code)]";
45+
static ALLOW_LINTS: &str = r"#[allow(
46+
clippy::absurd_extreme_comparisons,
47+
clippy::excessive_precision,
48+
clippy::manual_range_contains,
49+
clippy::unnecessary_cast,
50+
clippy::useless_conversion,
51+
unused_comparisons,
52+
)]";
53+
4454
/// Code generator configuration. See module-level docs for an example.
4555
#[derive(TypedBuilder)]
4656
#[non_exhaustive]
@@ -84,6 +94,10 @@ pub struct Config<'a> {
8494
/// Optional: Validate min and max values in generated signal setters. Default: `Always`
8595
#[builder(default = FeatureConfig::Always)]
8696
pub check_ranges: FeatureConfig<'a>,
97+
98+
/// Optional: Allow dead code in the generated module. Default: `false`.
99+
#[builder(default)]
100+
pub allow_dead_code: bool,
87101
}
88102

89103
/// Configuration for including features in the codegenerator.
@@ -168,6 +182,10 @@ fn render_dbc(mut w: impl Write, config: &Config<'_>, dbc: &Dbc) -> Result<()> {
168182

169183
fn render_root_enum(mut w: impl Write, dbc: &Dbc, config: &Config<'_>) -> Result<()> {
170184
writeln!(w, "/// All messages")?;
185+
writeln!(w, "{ALLOW_LINTS}")?;
186+
if config.allow_dead_code {
187+
writeln!(&mut w, "{ALLOW_DEADCODE}")?;
188+
}
171189
writeln!(w, "#[derive(Clone)]")?;
172190
config.impl_debug.fmt_attr(&mut w, "derive(Debug)")?;
173191
config
@@ -186,6 +204,7 @@ fn render_root_enum(mut w: impl Write, dbc: &Dbc, config: &Config<'_>) -> Result
186204
writeln!(&mut w, "}}")?;
187205
writeln!(&mut w)?;
188206

207+
writeln!(w, "{ALLOW_LINTS}")?;
189208
writeln!(w, "impl Messages {{")?;
190209
{
191210
let mut w = PadAdapter::wrap(&mut w);
@@ -253,6 +272,7 @@ fn render_message(mut w: impl Write, config: &Config<'_>, msg: &Message, dbc: &D
253272
writeln!(w, "}}")?;
254273
writeln!(w)?;
255274

275+
writeln!(w, "{ALLOW_LINTS}")?;
256276
writeln!(w, "impl {} {{", type_name(&msg.name))?;
257277
{
258278
let mut w = PadAdapter::wrap(&mut w);
@@ -932,6 +952,10 @@ fn write_enum(
932952
let signal_rust_type = signal_to_rust_type(signal);
933953

934954
writeln!(w, "/// Defined values for {}", signal.name)?;
955+
writeln!(w, "{ALLOW_LINTS}")?;
956+
if config.allow_dead_code {
957+
writeln!(&mut w, "{ALLOW_DEADCODE}")?;
958+
}
935959
writeln!(w, "#[derive(Clone, Copy, PartialEq)]")?;
936960
config.impl_debug.fmt_attr(&mut w, "derive(Debug)")?;
937961
config
@@ -1399,6 +1423,10 @@ fn render_multiplexor_enums(
13991423
}
14001424

14011425
writeln!(w, "/// Defined values for multiplexed signal {}", msg.name)?;
1426+
writeln!(w, "{ALLOW_LINTS}")?;
1427+
if config.allow_dead_code {
1428+
writeln!(&mut w, "{ALLOW_DEADCODE}")?;
1429+
}
14021430

14031431
config.impl_debug.fmt_attr(&mut w, "derive(Debug)")?;
14041432
config
@@ -1430,6 +1458,10 @@ fn render_multiplexor_enums(
14301458
for (switch_index, multiplexed_signals) in &multiplexed_signals {
14311459
let struct_name = multiplexed_enum_variant_name(msg, multiplexor_signal, *switch_index)?;
14321460

1461+
writeln!(w, "{ALLOW_LINTS}")?;
1462+
if config.allow_dead_code {
1463+
writeln!(&mut w, "{ALLOW_DEADCODE}")?;
1464+
}
14331465
config.impl_debug.fmt_attr(&mut w, "derive(Debug)")?;
14341466
config
14351467
.impl_defmt
@@ -1440,6 +1472,7 @@ fn render_multiplexor_enums(
14401472
writeln!(w, "pub struct {struct_name} {{ raw: [u8; {}] }}", msg.size)?;
14411473
writeln!(w)?;
14421474

1475+
writeln!(w, "{ALLOW_LINTS}")?;
14431476
writeln!(w, "impl {struct_name} {{")?;
14441477

14451478
writeln!(
@@ -1466,6 +1499,7 @@ fn render_arbitrary(mut w: impl Write, config: &Config<'_>, msg: &Message) -> Re
14661499
FeatureConfig::Never => return Ok(()),
14671500
}
14681501

1502+
writeln!(w, "{ALLOW_LINTS}")?;
14691503
writeln!(
14701504
w,
14711505
"impl<'a> Arbitrary<'a> for {typ} {{",

testing/can-embedded/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ fn main() -> Result<()> {
1414
.dbc_name("example.dbc")
1515
.dbc_content(&dbc_file)
1616
.debug_prints(true)
17+
.allow_dead_code(true)
1718
.impl_debug(FeatureConfig::Always)
1819
.impl_defmt(FeatureConfig::Always)
1920
.impl_error(FeatureConfig::Gated("std"))

testing/can-embedded/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#![no_std]
22

3-
#[rustfmt::skip]
4-
#[expect(dead_code, unused_comparisons)]
5-
#[expect(clippy::excessive_precision, clippy::manual_range_contains, clippy::useless_conversion, clippy::absurd_extreme_comparisons, clippy::unnecessary_cast, clippy::disallowed_names)]
3+
// #[expect(dead_code, unused_comparisons)]
4+
// #[expect(clippy::excessive_precision, clippy::manual_range_contains, clippy::useless_conversion, clippy::absurd_extreme_comparisons, clippy::unnecessary_cast, clippy::disallowed_names)]
65
mod messages {
76
include!(concat!(env!("OUT_DIR"), "/messages.rs"));
87
}

testing/can-messages/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ fn main() -> Result<()> {
1414
.dbc_name("example.dbc")
1515
.dbc_content(&dbc_file)
1616
.debug_prints(true)
17+
.allow_dead_code(true)
1718
.impl_debug(FeatureConfig::Always)
1819
.impl_defmt(FeatureConfig::Always)
1920
.impl_error(FeatureConfig::Gated("std"))

testing/can-messages/src/lib.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
#[expect(unused_comparisons)]
2-
#[expect(
3-
clippy::excessive_precision,
4-
clippy::manual_range_contains,
5-
clippy::useless_conversion,
6-
clippy::absurd_extreme_comparisons,
7-
clippy::unnecessary_cast,
8-
clippy::disallowed_names
9-
)]
101
mod messages {
112
include!(concat!(env!("OUT_DIR"), "/messages.rs"));
123
}

0 commit comments

Comments
 (0)