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 vs. question mark operator #4906

Closed
niklasf opened this issue Dec 16, 2019 · 8 comments · Fixed by #5912
Closed

needless_doctest_main vs. question mark operator #4906

niklasf opened this issue Dec 16, 2019 · 8 comments · Fixed by #5912
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy

Comments

@niklasf
Copy link
Contributor

niklasf commented Dec 16, 2019

I am currently using main with return type Result<(), Box<Error>> in order to be able to use the question mark operator in examples.

This is recommended in the API guidelines: https://rust-lang.github.io/api-guidelines/documentation.html#examples-use--not-try-not-unwrap-c-question-mark

Clippy should not suggest removing main() in this case.

/// # Example
///
/// ```
/// # use std::error::Error;
/// #
/// # fn try_main() -> Result<(), Box<Error>> {
/// use shakmaty::fen::Fen;
///
/// let fen = Fen::from_ascii(b"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1")?;
/// assert_eq!(fen, Fen::default());
/// #
/// #     Ok(())
/// # }
/// #
/// # fn main() {
/// #     try_main().unwrap();
/// # }
/// ```
@niklasf
Copy link
Contributor Author

niklasf commented Dec 16, 2019

Sorry, nevermind. This was only happening because I was still using the old try_main pattern.

@niklasf niklasf closed this as completed Dec 16, 2019
@llogiq
Copy link
Contributor

llogiq commented Dec 16, 2019

Yeah, we should detect this. You can just do the following:

/// # Example
///
/// ```
/// # use std::error::Error;
/// use shakmaty::fen::Fen;
///
/// let fen = Fen::from_ascii(b"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1")?;
/// assert_eq!(fen, Fen::default());
/// # Ok::<(), Box<Error>(())
/// ```

@niklasf niklasf reopened this Dec 16, 2019
@niklasf
Copy link
Contributor Author

niklasf commented Dec 16, 2019

Oh, suggesting that would be nice. Reopening.

@flip1995 flip1995 added good-first-issue These issues are a good way to get started with Clippy C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Dec 21, 2019
@xiongmao86
Copy link
Contributor

I am a little bit confused, what does this issue suggest we do, to detect and lint for appearance of main(), or not to detect and lint for appearance of main() in this case?

@xiongmao86
Copy link
Contributor

xiongmao86 commented Apr 12, 2020

@llogiq, do you suggest detecting main() -> Result<(), Box<Error>> { ?

@llogiq
Copy link
Contributor

llogiq commented Apr 13, 2020

We could certainly do that. I have a branch open that should be easier to extend in that regard, but it failed CI for some reason.

@xiongmao86
Copy link
Contributor

Oh, thanks for replying.

@pickfire
Copy link
Contributor

@llogiq are you working on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants