Skip to content

Commit 183e3c6

Browse files
committed
Align Rust lint attributes
1 parent b506bd6 commit 183e3c6

2 files changed

Lines changed: 35 additions & 6 deletions

File tree

packTab/__init__.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,35 @@ class LanguageRust(Language):
353353
def print_preamble(self, *, print=print):
354354
pass
355355

356+
def _print_allow(self, lints, *, print=print):
357+
print("#[allow(%s)]" % ", ".join(lints))
358+
359+
def _array_lints(self, *, private):
360+
lints = [
361+
"dead_code",
362+
"non_upper_case_globals",
363+
"clippy::allow_attributes_without_reason",
364+
]
365+
if not private:
366+
lints.append("missing_docs")
367+
return lints
368+
369+
def _function_lints(self, *, private):
370+
lints = [
371+
"dead_code",
372+
"unused_parens",
373+
"trivial_numeric_casts",
374+
"clippy::allow_attributes_without_reason",
375+
"clippy::unseparated_literal_suffix",
376+
"clippy::double_parens",
377+
"clippy::unnecessary_cast",
378+
]
379+
if self.unsafe_array_access:
380+
lints.extend(["unsafe_code", "unused_unsafe"])
381+
if not private:
382+
lints.append("missing_docs")
383+
return lints
384+
356385
def cast(self, typ, expr):
357386
return "(%s) as %s" % (expr, typ)
358387

@@ -379,11 +408,12 @@ def declare_function(self, linkage, retType, name, args):
379408
args = ", ".join("%s: %s" % (n, t) for t, n in args)
380409
return "%sfn %s (%s) -> %s" % (linkage, name, args, retType)
381410

411+
def print_array(self, name, array, *, print=print, private=True):
412+
self._print_allow(self._array_lints(private=private), print=print)
413+
super().print_array(name, array, print=print, private=private)
414+
382415
def print_function(self, name, function, *, print=print):
383-
if self.unsafe_array_access:
384-
print("#[allow(dead_code, unused_parens, unused_unsafe)]")
385-
else:
386-
print("#[allow(dead_code, unused_parens)]")
416+
self._print_allow(self._function_lints(private=function.private), print=print)
387417
# Add #[inline] attribute for better optimization hints
388418
if function.inline_always:
389419
print("#[inline(always)]")

packTab/test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,7 @@ def _compile_and_run_rust(rs_code, data, default):
658658
checks.append(" assert_eq!(data_get(%d) as i64, %di64);" % (i, default))
659659

660660
full = (
661-
"#[allow(dead_code, unused_parens, overflowing_literals)]\n\n"
662-
+ rs_code
661+
rs_code
663662
+ "\nfn main() {\n"
664663
+ "\n".join(checks)
665664
+ '\n println!("PASS");\n}\n'

0 commit comments

Comments
 (0)