-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #4866 - rust-lang:needful-doctest-main, r=flip1995
Less needless_doctest_main false positives This checks if a) the `fn main() {}` function is empty or if the doctest contains a `static`. In both cases don't lint. While this fixes #4858 at the cost of some false negatives, but this seems a better solution than disabling the lint outright. In the long run, using `syn` should solve the issue in the right way. changelog: none
- Loading branch information
Showing
3 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/// This is a test for needless `fn main()` in doctests. | ||
/// | ||
/// # Examples | ||
/// | ||
/// This should lint | ||
/// ``` | ||
/// fn main() { | ||
/// unimplemented!(); | ||
/// } | ||
/// ``` | ||
fn bad_doctest() {} | ||
|
||
/// # Examples | ||
/// | ||
/// This shouldn't lint, because the `main` is empty: | ||
/// ``` | ||
/// fn main(){} | ||
/// ``` | ||
/// | ||
/// This shouldn't lint either, because there's a `static`: | ||
/// ``` | ||
/// static ANSWER: i32 = 42; | ||
/// | ||
/// fn main() { | ||
/// assert_eq!(42, ANSWER); | ||
/// } | ||
/// ``` | ||
fn no_false_positives() {} | ||
|
||
fn main() { | ||
bad_doctest(); | ||
no_false_positives(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: needless `fn main` in doctest | ||
--> $DIR/needless_doc_main.rs:7:4 | ||
| | ||
LL | /// fn main() { | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::needless-doctest-main` implied by `-D warnings` | ||
|
||
error: aborting due to previous error | ||
|