Skip to content

Alternatively-named main function used as main marked as dead code #157608

@Omnikar

Description

@Omnikar

Code

// Marked as dead code despite being used as main
fn different_main() {
    println!("Hello from different_main");
}
use different_main as main;

Current output

warning: function `different_main` is never used
 --> src/main.rs:2:4
  |
2 | fn different_main() {
  |    ^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

Desired output

No warning

Rationale and extra context

I am not sure exactly why, but the warning shows up when checking via cargo check --all-targets and not with cargo check.

Other cases

Rust Version

rustc 1.96.0 (ac68faa20 2026-05-25)
binary: rustc
commit-hash: ac68faa20c58cbccd01ee7208bf3b6e93a7d7f96
commit-date: 2026-05-25
host: aarch64-apple-darwin
release: 1.96.0
LLVM version: 22.1.2

Anything else?

No response

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-libtestArea: `#[test]` / the `test` libraryA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.L-dead_codeLint: dead_codeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions