Skip to content

rustdoc warns main is never used #13894

Closed

Description

@gifnksm

rustdoc warns that main is never used.

// hello.rs
#![crate_id="hello"]

fn main() {}
$ rustdoc hello.rs
hello.rs:3:1: 3:13 warning: code is never used: `main`, #[warn(dead_code)] on by default
hello.rs:3 fn main() {}
           ^~~~~~~~~~~~

I think rustdoc shouldn't warn about it, because rustc doesn't warn.

$ rustc hello.rs
# no output

If the main is pub, rustdoc doesn't warn about it. Shoulud all mains mark as pub?

// pubhello.rs
#![crate_id="hello"]

pub fn main() {}
$ rustdoc pubhello.rs
# no output
$ rustc --version
rustc 0.11-pre (9f836d5 2014-05-01 16:06:48 -0700)
host: x86_64-unknown-linux-gnu

$ rustdoc --version
rustdoc 0.11-pre (9f836d5 2014-05-01 16:06:48 -0700)
host: x86_64-unknown-linux-gnu

Activity

  1. alexcrichton commented on May 2, 2014

    @alexcrichton
    Member

    This is currently intended behavior, rustdoc compiles crates as if it were compiling a library. If you compile rustdoc --crate-type=dylib hello.rs you'll get the same warning.

  2. added 2 commits that reference this issue on May 3, 2014
    5d145c1
  3. added a commit that references this issue on Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions