What's the correct procedure to add functionalities to the compiler?

When I am writing a new module or functions etc from ground up, I want to continuously compile to ensure there is no type error in the code. However, the compiler now throws an error saying my methods or functions are not used. Is there a recommended way to get around this?

The compiler will only “warn” about unused functions, not “error” (the distinction is that warnings don’t make the compilation fail). If the warnings are in your way, you can disable them. Note that this is only recommendable during development, don’t forget to re-enable them when your code is done. Also, since warnings don’t influence compilation success, you could just as well try to simply ignore the warnings about unused functions, types, etc. since you know that you’re going to add code that uses them later.

If you really want to, one way to disable such warnings would be to place the line #![allow(dead_code)] at the beginning of your source file.

Also note that a better place to ask questions about how to use Rust would be users.rust-lang.org.

I am asking a question about compiler development, that's why I ask here:

error: method is never used: `variable`
...
error: aborting due to 14 previous errors

error: could not compile `rustc_codegen_llvm`.

an example error is here. The build of the compiler ends with errors saying I have unused code. Am I missing anything?

This forum, IRLO, would be the appropriate forum for queries about plugins for rustc or about modifying MIR. However your question seems to be a general question about programming in Rust (because the rustc compiler is written in Rust). Those questions belong in URLO.

For a query in URLO, you need to supply sufficient details that someone might be able to help you. Given the specific details that you have provided, the best response actually is the one given in the prior post:

1 Like

One thing that makes this question more specific to rustc is that we #![deny(warnings)] so unused variables and unused functions are treated as errors and break the build.

One simple thing you might try is to mark some of those functions as pub. Any externally visible pub functions are treated as used and any code called by them are transitively considered used as well. A well placed pub might make all those errors go away.

I would recommend settings deny-warnings=false in your local config.toml. You'll still need to fix all warnings for CI to pass, but they won't break your build locally.

6 Likes

I see. I might have not really read the title of your original post / this thread. Nonetheless, being more explicit about that you're trying to work on rustc, and also including the error message, might have helped avoid some confusion.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.