-
Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
A-libtestArea: `#[test]` / the `test` libraryArea: `#[test]` / the `test` libraryA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.L-dead_codeLint: dead_codeLint: dead_codeT-cargoRelevant to the cargo team, which will review and decide on the PR/issue.Relevant to the cargo team, which will review and decide on the PR/issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
fn foobar() {
panic!();
}
fn main() {
foobar();
}Current output
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.15sDesired output
warning: function `foobar` is never used
--> tests/foo.rs:1:4
|
1 | fn foobar() {
| ^^^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: function `main` is never used
--> tests/foo.rs:5:4
|
5 | fn main() {
| ^^^^^
warning: `test-rust-test` (test "foo") generated 2 warningsRationale and extra context
In an integration tests (such as, by default, the files in a workspace's tests/ folder), the main function is usually replaced by the standard test harness.
When that happens, the main function should be marked as dead code, or more specifically, it shouldn't be included in the roots during liveness analysis.
(This is obviously different in cases where e.g. harness = false)
Rust Version
rustc 1.90.0 (1159e78c4 2025-09-14)
binary: rustc
commit-hash: 1159e78c4747b02ef996e55082b704c09b970588
commit-date: 2025-09-14
host: x86_64-unknown-linux-gnu
release: 1.90.0
LLVM version: 20.1.8Metadata
Metadata
Assignees
Labels
A-libtestArea: `#[test]` / the `test` libraryArea: `#[test]` / the `test` libraryA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.L-dead_codeLint: dead_codeLint: dead_codeT-cargoRelevant to the cargo team, which will review and decide on the PR/issue.Relevant to the cargo team, which will review and decide on the PR/issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Status
No status