]> git.lizzy.rs Git - rust.git/blob - tests/ui/needless_doc_main.rs
Auto merge of #68717 - petrochenkov:stabexpat, r=varkor
[rust.git] / tests / ui / needless_doc_main.rs
1 /// This is a test for needless `fn main()` in doctests.
2 ///
3 /// # Examples
4 ///
5 /// This should lint
6 /// ```
7 /// fn main() {
8 ///     unimplemented!();
9 /// }
10 /// ```
11 ///
12 /// This should, too.
13 ///
14 /// ```rust
15 /// fn main() {
16 ///     unimplemented!();
17 /// }
18 /// ```
19 ///
20 /// This one too.
21 ///
22 /// ```no_run
23 /// fn main() {
24 ///     unimplemented!();
25 /// }
26 /// ```
27 fn bad_doctests() {}
28
29 /// # Examples
30 ///
31 /// This shouldn't lint, because the `main` is empty:
32 /// ```
33 /// fn main(){}
34 /// ```
35 ///
36 /// This shouldn't lint either, because there's a `static`:
37 /// ```
38 /// static ANSWER: i32 = 42;
39 ///
40 /// fn main() {
41 ///     assert_eq!(42, ANSWER);
42 /// }
43 /// ```
44 ///
45 /// Neither should this lint because of `extern crate`:
46 /// ```
47 /// #![feature(test)]
48 /// extern crate test;
49 /// fn main() {
50 ///     assert_eq(1u8, test::black_box(1));
51 /// }
52 /// ```
53 ///
54 /// We should not lint ignored examples:
55 ///
56 /// ```rust,ignore
57 /// fn main() {
58 ///     unimplemented!();
59 /// }
60 /// ```
61 ///
62 /// Or even non-rust examples:
63 ///
64 /// ```text
65 /// fn main() {
66 ///     is what starts the program
67 /// }
68 /// ```
69 fn no_false_positives() {}
70
71 fn main() {
72     bad_doctests();
73     no_false_positives();
74 }