Can I tell the Rust compiler to ignore warnings only in files matching a specific name?

I use a library that generates a bunch of code for me, and it often really wants to generate methods that I don't use yet. This leads to noisy warnings when creating my project.

The script generates the old old .rs files in my code base, which I then import and invoke like regular code:

mod autogen_code; 
pub use self::autogen_code::*;

I cannot use #![allow(unused_whatever)]for the generated code, because when I rebuild the project, the script generation starts again and there will be no changes. These files .gitignore' d and have great comments at the top, saying: "This is all automatically generated. Do not touch."

I do not want to allow unused things in my entire project, so the placement #![allow(unused_whatever)]at the top of my box is also not a starter.

It is good that the generated files have a predictable name, so I hope there is a way to tell the / rustc load not to give warnings for files matching a specific file name. Is it possible?

+4
source share
1 answer

No, you cannot apply lints using a file name template.

Instead, you can ...

  • Instead of using !#[allow(...)]inside the file, use #[allow(...)]in the declaration mod:

    #[allow(dead_code)]
    mod autogen;
    
  • , . , library-generator foo.input library-generator foo.input && sed -i '' '1s/^/#![allow(whatever)]/' myfile.rs. . " ", . , .

  • , , allow. , , . .

  • "", , , include! . , :

    #![allow(...)]
    
    include!("autogen_real.rs");
    
+9

Source: https://habr.com/ru/post/1687562/


All Articles