]> git.proxmox.com Git - rustc.git/blob - src/test/ui/lint/lint-missing-doc.rs
New upstream version 1.64.0+dfsg1
[rustc.git] / src / test / ui / lint / lint-missing-doc.rs
1 // When denying at the crate level, be sure to not get random warnings from the
2 // injected intrinsics by the compiler.
3 #![deny(missing_docs)]
4 #![allow(dead_code)]
5 #![feature(associated_type_defaults, extern_types)]
6
7 //! Some garbage docs for the crate here
8 #![doc="More garbage"]
9
10 type Typedef = String;
11 pub type PubTypedef = String; //~ ERROR: missing documentation for a type alias
12
13 struct Foo {
14 a: isize,
15 b: isize,
16 }
17
18 pub struct PubFoo { //~ ERROR: missing documentation for a struct
19 pub a: isize, //~ ERROR: missing documentation for a struct field
20 b: isize,
21 }
22
23 #[allow(missing_docs)]
24 pub struct PubFoo2 {
25 pub a: isize,
26 pub c: isize,
27 }
28
29 mod module_no_dox {}
30 pub mod pub_module_no_dox {} //~ ERROR: missing documentation for a module
31
32 /// dox
33 pub fn foo() {}
34 pub fn foo2() {} //~ ERROR: missing documentation for a function
35 fn foo3() {}
36 #[allow(missing_docs)] pub fn foo4() {}
37
38 /// dox
39 pub trait A {
40 /// dox
41 fn foo(&self);
42 /// dox
43 fn foo_with_impl(&self) {}
44 }
45
46 #[allow(missing_docs)]
47 trait B {
48 fn foo(&self);
49 fn foo_with_impl(&self) {}
50 }
51
52 pub trait C { //~ ERROR: missing documentation for a trait
53 fn foo(&self); //~ ERROR: missing documentation for an associated function
54 fn foo_with_impl(&self) {} //~ ERROR: missing documentation for an associated function
55 }
56
57 #[allow(missing_docs)]
58 pub trait D {
59 fn dummy(&self) { }
60 }
61
62 /// dox
63 pub trait E: Sized {
64 type AssociatedType; //~ ERROR: missing documentation for an associated type
65 type AssociatedTypeDef = Self; //~ ERROR: missing documentation for an associated type
66
67 /// dox
68 type DocumentedType;
69 /// dox
70 type DocumentedTypeDef = Self;
71 /// dox
72 fn dummy(&self) {}
73 }
74
75 impl Foo {
76 pub fn foo() {}
77 fn bar() {}
78 }
79
80 impl PubFoo {
81 pub fn foo() {} //~ ERROR: missing documentation for an associated function
82 /// dox
83 pub fn foo1() {}
84 fn foo2() {}
85 #[allow(missing_docs)] pub fn foo3() {}
86 }
87
88 #[allow(missing_docs)]
89 trait F {
90 fn a();
91 fn b(&self);
92 }
93
94 // should need to redefine documentation for implementations of traits
95 impl F for Foo {
96 fn a() {}
97 fn b(&self) {}
98 }
99
100 // It sure is nice if doc(hidden) implies allow(missing_docs), and that it
101 // applies recursively
102 #[doc(hidden)]
103 mod a {
104 pub fn baz() {}
105 pub mod b {
106 pub fn baz() {}
107 }
108 }
109
110 enum Baz {
111 BazA {
112 a: isize,
113 b: isize
114 },
115 BarB
116 }
117
118 pub enum PubBaz { //~ ERROR: missing documentation for an enum
119 PubBazA { //~ ERROR: missing documentation for a variant
120 a: isize, //~ ERROR: missing documentation for a struct field
121 },
122 }
123
124 /// dox
125 pub enum PubBaz2 {
126 /// dox
127 PubBaz2A {
128 /// dox
129 a: isize,
130 },
131 }
132
133 #[allow(missing_docs)]
134 pub enum PubBaz3 {
135 PubBaz3A {
136 b: isize
137 },
138 }
139
140 #[doc(hidden)]
141 pub fn baz() {}
142
143
144 const FOO: u32 = 0;
145 /// dox
146 pub const FOO1: u32 = 0;
147 #[allow(missing_docs)]
148 pub const FOO2: u32 = 0;
149 #[doc(hidden)]
150 pub const FOO3: u32 = 0;
151 pub const FOO4: u32 = 0; //~ ERROR: missing documentation for a const
152
153
154 static BAR: u32 = 0;
155 /// dox
156 pub static BAR1: u32 = 0;
157 #[allow(missing_docs)]
158 pub static BAR2: u32 = 0;
159 #[doc(hidden)]
160 pub static BAR3: u32 = 0;
161 pub static BAR4: u32 = 0; //~ ERROR: missing documentation for a static
162
163
164 mod internal_impl {
165 /// dox
166 pub fn documented() {}
167 pub fn undocumented1() {} //~ ERROR: missing documentation for a function
168 pub fn undocumented2() {} //~ ERROR: missing documentation for a function
169 fn undocumented3() {}
170 /// dox
171 pub mod globbed {
172 /// dox
173 pub fn also_documented() {}
174 pub fn also_undocumented1() {} //~ ERROR: missing documentation for a function
175 fn also_undocumented2() {}
176 }
177 }
178 /// dox
179 pub mod public_interface {
180 pub use internal_impl::documented as foo;
181 pub use internal_impl::undocumented1 as bar;
182 pub use internal_impl::{documented, undocumented2};
183 pub use internal_impl::globbed::*;
184 }
185
186 extern "C" {
187 /// dox
188 pub fn extern_fn_documented(f: f32) -> f32;
189 pub fn extern_fn_undocumented(f: f32) -> f32;
190 //~^ ERROR: missing documentation for a function
191
192 /// dox
193 pub static EXTERN_STATIC_DOCUMENTED: u8;
194 pub static EXTERN_STATIC_UNDOCUMENTED: u8;
195 //~^ ERROR: missing documentation for a static
196
197 /// dox
198 pub type ExternTyDocumented;
199 pub type ExternTyUndocumented;
200 //~^ ERROR: missing documentation for a foreign type
201 }
202
203 fn main() {}