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