Skip to content

Add test for issue #101532: dead code warnings in const _#154246

Open
JumpiiX wants to merge 1 commit intorust-lang:mainfrom
JumpiiX:fix-101532-dead-code-warnings
Open

Add test for issue #101532: dead code warnings in const _#154246
JumpiiX wants to merge 1 commit intorust-lang:mainfrom
JumpiiX:fix-101532-dead-code-warnings

Conversation

@JumpiiX
Copy link

@JumpiiX JumpiiX commented Mar 23, 2026

Closes #101532

This PR adds a regression test for dead code warnings inside const _ blocks. The issue has already been fixed, but was marked E-needs-test to ensure we
have test coverage.

What this PR does:

  • Adds test file tests/ui/lint/dead-code/issue-101532.rs
  • Adds expected output tests/ui/lint/dead-code/issue-101532.stderr
  • Verifies that dead code warnings correctly work inside const _ blocks

The test confirms all items (structs, enums, functions, constants) inside const _ now properly trigger dead code warnings as expected.

r? rust-lang/compiler

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 23, 2026
@rustbot

This comment has been minimized.

@JumpiiX JumpiiX force-pushed the fix-101532-dead-code-warnings branch from ebdf48f to 0b9eac8 Compare March 23, 2026 09:48
@rust-log-analyzer

This comment has been minimized.

@JumpiiX JumpiiX force-pushed the fix-101532-dead-code-warnings branch from 0b9eac8 to 6d8bcd1 Compare March 23, 2026 10:06
@rustbot

This comment has been minimized.

@JumpiiX JumpiiX force-pushed the fix-101532-dead-code-warnings branch from 6d8bcd1 to 4975cd0 Compare March 23, 2026 10:32
@rust-log-analyzer

This comment has been minimized.

@JumpiiX JumpiiX force-pushed the fix-101532-dead-code-warnings branch from 4975cd0 to d06b0db Compare March 23, 2026 11:11
@rust-log-analyzer

This comment has been minimized.

@JumpiiX JumpiiX force-pushed the fix-101532-dead-code-warnings branch from d06b0db to cb34b4e Compare March 23, 2026 12:08
@rust-log-analyzer

This comment has been minimized.

Tests that dead code warnings work correctly inside const _ blocks.
Issue was already fixed, adding regression test as requested.
@JumpiiX JumpiiX force-pushed the fix-101532-dead-code-warnings branch from cb34b4e to 1017004 Compare March 23, 2026 12:44
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
##[endgroup]
Executing "/scripts/stage_2_test_set1.sh"
+ /scripts/stage_2_test_set1.sh
+ '[' 1 == 1 ']'
+ echo 'PR_CI_JOB set; skipping tidy'
+ SKIP_TIDY='--skip tidy'
+ ../x.py --stage 2 test --skip tidy --skip compiler --skip src
PR_CI_JOB set; skipping tidy
##[group]Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.04s
##[endgroup]
---
-    |
-    = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
- help: if this is intentional, prefix it with an underscore
-    |
- LL |     let _a: ();
-    |         +
- 
13 warning: struct `B` is never constructed
-   --> $DIR/const-underscore-issue-101532.rs:7:12
+   --> $DIR/const-underscore-issue-101532.rs:8:12
---
To only update this specific test, also pass `--test-args lint/dead-code/const-underscore-issue-101532.rs`

error: 1 errors occurred comparing output.
status: exit status: 0
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/lint/dead-code/const-underscore-issue-101532.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/lint/dead-code/const-underscore-issue-101532" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
warning: struct `B` is never constructed
##[warning]  --> /checkout/tests/ui/lint/dead-code/const-underscore-issue-101532.rs:8:12
   |
LL |     struct B {} //~ WARN struct `B` is never constructed
   |            ^
   |
note: the lint level is defined here
  --> /checkout/tests/ui/lint/dead-code/const-underscore-issue-101532.rs:4:9
   |
LL | #![warn(dead_code)]
   |         ^^^^^^^^^

warning: enum `C` is never used
##[warning]  --> /checkout/tests/ui/lint/dead-code/const-underscore-issue-101532.rs:9:10
   |
LL |     enum C {}   //~ WARN enum `C` is never used
   |          ^

warning: function `d` is never used
##[warning]  --> /checkout/tests/ui/lint/dead-code/const-underscore-issue-101532.rs:10:8
   |
LL |     fn d() {}   //~ WARN function `d` is never used
   |        ^

warning: constant `E` is never used
##[warning]  --> /checkout/tests/ui/lint/dead-code/const-underscore-issue-101532.rs:11:11
   |
LL |     const E: () = {}; //~ WARN constant `E` is never used
   |           ^

warning: 4 warnings emitted
------------------------------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Most dead code warnings don't work inside const _

4 participants