Skip to content

needless_doctest_main reports wrong line if there are imports #5236

@matthiaskrgr

Description

@matthiaskrgr
/// # Examples
///
/// ```
/// use std::path::PathBuf;
/// use std::vec;
///
/// fn main() {
/// }
///
/// ```

fn main() {
    println!("Hello, world!");
}

It looks like the lint assumes the fn main() will always be in the first line of the code block..?

warning: needless `fn main` in doctest
 --> src/main.rs:4:4
  |
4 | /// use std::path::PathBuf;
  |    ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(clippy::needless_doctest_main)]` on by default

This causes strange looking warnings.

clippy 0.0.212 (fc5d0cc 2020-02-24)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions