@@ -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)]" )
0 commit comments