@@ -41,6 +41,16 @@ mod includes;
4141mod keywords;
4242mod 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
169183fn 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} {{" ,
0 commit comments