summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/needless_doc_main.rs
blob: 83e9bbaa3af43dc1bdc1f8c60f77130b42c9bcb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/// This is a test for needless `fn main()` in doctests.
///
/// # Examples
///
/// This should lint
/// ```
/// fn main() {
///     unimplemented!();
/// }
/// ```
///
/// With an explicit return type it should lint too
/// ```edition2015
/// fn main() -> () {
///     unimplemented!();
/// }
/// ```
///
/// This should, too.
/// ```rust
/// fn main() {
///     unimplemented!();
/// }
/// ```
///
/// This one too.
/// ```no_run
/// fn main() {
///     unimplemented!();
/// }
/// ```
fn bad_doctests() {}

/// # Examples
///
/// This shouldn't lint, because the `main` is empty:
/// ```
/// fn main(){}
/// ```
///
/// This shouldn't lint either, because main is async:
/// ```edition2018
/// async fn main() {
///     assert_eq!(42, ANSWER);
/// }
/// ```
///
/// Same here, because the return type is not the unit type:
/// ```
/// fn main() -> Result<()> {
///     Ok(())
/// }
/// ```
///
/// This shouldn't lint either, because there's a `static`:
/// ```
/// static ANSWER: i32 = 42;
///
/// fn main() {
///     assert_eq!(42, ANSWER);
/// }
/// ```
///
/// This shouldn't lint either, because there's a `const`:
/// ```
/// fn main() {
///     assert_eq!(42, ANSWER);
/// }
///
/// const ANSWER: i32 = 42;
/// ```
///
/// Neither should this lint because of `extern crate`:
/// ```
/// #![feature(test)]
/// extern crate test;
/// fn main() {
///     assert_eq(1u8, test::black_box(1));
/// }
/// ```
///
/// Neither should this lint because it has an extern block:
/// ```
/// extern {}
/// fn main() {
///     unimplemented!();
/// }
/// ```
///
/// This should not lint because there is another function defined:
/// ```
/// fn fun() {}
///
/// fn main() {
///     unimplemented!();
/// }
/// ```
///
/// We should not lint inside raw strings ...
/// ```
/// let string = r#"
/// fn main() {
///     unimplemented!();
/// }
/// "#;
/// ```
///
/// ... or comments
/// ```
/// // fn main() {
/// //     let _inception = 42;
/// // }
/// let _inception = 42;
/// ```
///
/// We should not lint ignored examples:
/// ```rust,ignore
/// fn main() {
///     unimplemented!();
/// }
/// ```
///
/// Or even non-rust examples:
/// ```text
/// fn main() {
///     is what starts the program
/// }
/// ```
fn no_false_positives() {}

/// Yields a parse error when interpreted as rust code:
/// ```
/// r#"hi"
/// ```
fn issue_6022() {}

fn main() {
    bad_doctests();
    no_false_positives();
}