about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-07-16 12:58:31 -0700
committerbors <bors@rust-lang.org>2013-07-16 12:58:31 -0700
commit9db190305f7562f15b5282fed508aef81cfc9689 (patch)
tree429545aa58b5d388a19b4592cd46b6a58f8d6b8e
parentad212ecee47e8f9126c9fa4ea1679435136e854e (diff)
parent8515abe0d92fb4f0a554e60da41e7ea12deb734e (diff)
auto merge of #7823 : pnkfelix/rust/issue7821-document-lint-attributes, r=graydon
r? anyone

Fix #7821.
-rw-r--r--doc/rust.md73
1 files changed, 71 insertions, 2 deletions
diff --git a/doc/rust.md b/doc/rust.md
index 0a640648222..9948ec79fc6 100644
--- a/doc/rust.md
+++ b/doc/rust.md
@@ -1417,14 +1417,83 @@ names are effectively reserved. Some significant attributes include:
 * The `lang` attribute, for custom definitions of traits and functions that are known to the Rust compiler (see [Language items](#language-items)).
 * The `link` attribute, for describing linkage metadata for a crate.
 * The `test` attribute, for marking functions as unit tests.
-* The `allow`, `warn`, `forbid`, and `deny` attributes, for controlling lint checks. Lint checks supported
-by the compiler can be found via `rustc -W help`.
+* The `allow`, `warn`, `forbid`, and `deny` attributes, for
+  controlling lint checks (see [Lint check attributes](#lint-check-attributes)).
 * The `deriving` attribute, for automatically generating
   implementations of certain traits.
 * The `static_assert` attribute, for asserting that a static bool is true at compiletime
 
 Other attributes may be added or removed during development of the language.
 
+### Lint check attributes
+
+A lint check names a potentially undesirable coding pattern, such as
+unreachable code or omitted documentation, for the static entity to
+which the attribute applies.
+
+For any lint check `C`:
+
+ * `warn(C)` warns about violations of `C` but continues compilation,
+ * `deny(C)` signals an error after encountering a violation of `C`,
+ * `allow(C)` overrides the check for `C` so that violations will go
+    unreported,
+ * `forbid(C)` is the same as `deny(C)`, but also forbids uses of
+   `allow(C)` within the entity.
+
+The lint checks supported by the compiler can be found via `rustc -W help`,
+along with their default settings.
+
+~~~{.xfail-test}
+mod m1 {
+    // Missing documentation is ignored here
+    #[allow(missing_doc)]
+    pub fn undocumented_one() -> int { 1 }
+
+    // Missing documentation signals a warning here
+    #[warn(missing_doc)]
+    pub fn undocumented_too() -> int { 2 }
+
+    // Missing documentation signals an error here
+    #[deny(missing_doc)]
+    pub fn undocumented_end() -> int { 3 }
+}
+~~~
+
+This example shows how one can use `allow` and `warn` to toggle
+a particular check on and off.
+
+~~~
+#[warn(missing_doc)]
+mod m2{
+    #[allow(missing_doc)]
+    mod nested {
+        // Missing documentation is ignored here
+        pub fn undocumented_one() -> int { 1 }
+
+        // Missing documentation signals a warning here,
+        // despite the allow above.
+        #[warn(missing_doc)]
+        pub fn undocumented_two() -> int { 2 }
+    }
+
+    // Missing documentation signals a warning here
+    pub fn undocumented_too() -> int { 3 }
+}
+~~~
+
+This example shows how one can use `forbid` to disallow uses
+of `allow` for that lint check.
+
+~~~{.xfail-test}
+#[forbid(missing_doc)]
+mod m3 {
+    // Attempting to toggle warning signals an error here
+    #[allow(missing_doc)]
+    /// Returns 2.
+    pub fn undocumented_too() -> int { 2 }
+}
+~~~
+
 ### Language items
 
 Some primitive Rust operations are defined in Rust code,