Where is the rustc lint config?

I am running a build of rustc.
I want to change the identification of unused code not as an error, but as a warning or not display in any way at all.
I don't want to use the allow attribute

Here is a list of possible ways to configure rustc lints:

https://doc.rust-lang.org/rustc/lints/levels.html#configuring-warning-levels

I personally would pass a CLI argument, like rustc --A dead-code ....

I'm not sure which lint you mean, there is no unused code lint AFAIK, only dead_code and a bunch of unused_* lints, like unused_variables, all of which are warnings or allowed by default.

3 Likes

rustc displays unused code as a warning. The rustc build identifies unused code as an error, not a warning. So it is possible to change this, to make it show as a warning?

Do you mean that in the rustc's own code base dead_code lint is set to be an error? Then search for [deny(dead_code)] somewhere in the code base.

1 Like

If you mean x or x.py in the rustc repo, then you can also use --A dead-code as an argument to allow the lint.

it doesn't work

root@mywin:/home/rust# ./x test tests/ui/marker_trait_attr -- --A dead-code
Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.03s
Building stage0 library artifacts (x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized + debuginfo] target(s) in 0.10s
Building compiler artifacts (stage0 -> stage1, x86_64-unknown-linux-gnu)
   Compiling rustc_hir_analysis v0.0.0 (/home/rust/compiler/rustc_hir_analysis)
error: unused `Result` that must be used
   --> compiler/rustc_hir_analysis/src/coherence/mod.rs:156:9
    |
156 |         res.and(check_impl(tcx, impl_def_id, trait_ref, trait_def));
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this `Result` may be an `Err` variant, which should be handled
    = note: `-D unused-must-use` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(unused_must_use)]`
help: use `let _ = ...` to ignore the resulting value
    |
156 |         let _ = res.and(check_impl(tcx, impl_def_id, trait_ref, trait_def));
    |         +++++++

error: could not compile `rustc_hir_analysis` (lib) due to 1 previous error
Build completed unsuccessfully in 0:00:02

The error is for a different lint, you need to add a --A unused-must-use. Please try:

./x test tests/ui/marker_trait_attr --stage 1 --A unused-must-use
root@mywin:/home/rust# ./x test tests/ui/marker_trait_attr --stage 1 --A unused-must-use
Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.03s
error: unexpected argument '--A' found

  tip: to pass '--A' as a value, use '-- --A'

Usage: x.py test --stage <N> <PATHS>... [-- <ARGS>...]

For more information, try '--help'.
Build completed unsuccessfully in 0:00:00
root@mywin:/home/rust# ./x test tests/ui/marker_trait_attr --stage 1 -- --A unused-mu
st-use
Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.03s
Building stage0 library artifacts (x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized + debuginfo] target(s) in 0.11s
Building compiler artifacts (stage0 -> stage1, x86_64-unknown-linux-gnu)
   Compiling rustc_hir_analysis v0.0.0 (/home/rust/compiler/rustc_hir_analysis)
error: unused `Result` that must be used
   --> compiler/rustc_hir_analysis/src/coherence/mod.rs:155:9
    |
155 |         res.and(check_impl(tcx, impl_def_id, trait_ref, trait_def));
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this `Result` may be an `Err` variant, which should be handled
    = note: `-D unused-must-use` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(unused_must_use)]`
help: use `let _ = ...` to ignore the resulting value
    |
155 |         let _ = res.and(check_impl(tcx, impl_def_id, trait_ref, trait_def));
    |         +++++++

error: could not compile `rustc_hir_analysis` (lib) due to 1 previous error
Build completed unsuccessfully in 0:00:02

My bad, didn't realise how outdated my fork was. Looks like you can pass arguments to rustc using the --rustc-args option: ./x test tests/ui/marker_trait_attr --rustc-args="--A unused-must-use".

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.