]> git.lizzy.rs Git - rust.git/blob - tests/ui/needless_doc_main.rs
Auto merge of #8374 - Alexendoo:bless-revisions, r=camsteffen
[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 /// With an explicit return type it should lint too
13 /// ```edition2015
14 /// fn main() -> () {
15 ///     unimplemented!();
16 /// }
17 /// ```
18 ///
19 /// This should, too.
20 /// ```rust
21 /// fn main() {
22 ///     unimplemented!();
23 /// }
24 /// ```
25 ///
26 /// This one too.
27 /// ```no_run
28 /// fn main() {
29 ///     unimplemented!();
30 /// }
31 /// ```
32 fn bad_doctests() {}
33
34 /// # Examples
35 ///
36 /// This shouldn't lint, because the `main` is empty:
37 /// ```
38 /// fn main(){}
39 /// ```
40 ///
41 /// This shouldn't lint either, because main is async:
42 /// ```edition2018
43 /// async fn main() {
44 ///     assert_eq!(42, ANSWER);
45 /// }
46 /// ```
47 ///
48 /// Same here, because the return type is not the unit type:
49 /// ```
50 /// fn main() -> Result<()> {
51 ///     Ok(())
52 /// }
53 /// ```
54 ///
55 /// This shouldn't lint either, because there's a `static`:
56 /// ```
57 /// static ANSWER: i32 = 42;
58 ///
59 /// fn main() {
60 ///     assert_eq!(42, ANSWER);
61 /// }
62 /// ```
63 ///
64 /// This shouldn't lint either, because there's a `const`:
65 /// ```
66 /// fn main() {
67 ///     assert_eq!(42, ANSWER);
68 /// }
69 ///
70 /// const ANSWER: i32 = 42;
71 /// ```
72 ///
73 /// Neither should this lint because of `extern crate`:
74 /// ```
75 /// #![feature(test)]
76 /// extern crate test;
77 /// fn main() {
78 ///     assert_eq(1u8, test::black_box(1));
79 /// }
80 /// ```
81 ///
82 /// Neither should this lint because it has an extern block:
83 /// ```
84 /// extern {}
85 /// fn main() {
86 ///     unimplemented!();
87 /// }
88 /// ```
89 ///
90 /// This should not lint because there is another function defined:
91 /// ```
92 /// fn fun() {}
93 ///
94 /// fn main() {
95 ///     unimplemented!();
96 /// }
97 /// ```
98 ///
99 /// We should not lint inside raw strings ...
100 /// ```
101 /// let string = r#"
102 /// fn main() {
103 ///     unimplemented!();
104 /// }
105 /// "#;
106 /// ```
107 ///
108 /// ... or comments
109 /// ```
110 /// // fn main() {
111 /// //     let _inception = 42;
112 /// // }
113 /// let _inception = 42;
114 /// ```
115 ///
116 /// We should not lint ignored examples:
117 /// ```rust,ignore
118 /// fn main() {
119 ///     unimplemented!();
120 /// }
121 /// ```
122 ///
123 /// Or even non-rust examples:
124 /// ```text
125 /// fn main() {
126 ///     is what starts the program
127 /// }
128 /// ```
129 fn no_false_positives() {}
130
131 /// Yields a parse error when interpreted as rust code:
132 /// ```
133 /// r#"hi"
134 /// ```
135 fn issue_6022() {}
136
137 fn main() {
138     bad_doctests();
139     no_false_positives();
140 }