Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

needless_doctest_main reports wrong line if there are imports #5236

Closed
matthiaskrgr opened this issue Feb 27, 2020 · 2 comments
Closed

needless_doctest_main reports wrong line if there are imports #5236

matthiaskrgr opened this issue Feb 27, 2020 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@matthiaskrgr
Copy link
Member

/// # 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)

@matthiaskrgr matthiaskrgr added the C-bug Category: Clippy is not doing the correct thing label Feb 27, 2020
@llogiq
Copy link
Contributor

llogiq commented Feb 28, 2020

I think I know the solution for this...let me code it up, just a sec.

@llogiq
Copy link
Contributor

llogiq commented May 28, 2020

(fix was wrongly marked closed by github)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants