Skip to content

Commit 9db1903

Browse files
committed
auto merge of #7823 : pnkfelix/rust/issue7821-document-lint-attributes, r=graydon
r? anyone Fix #7821.
2 parents ad212ec + 8515abe commit 9db1903

File tree

1 file changed

+71
-2
lines changed

1 file changed

+71
-2
lines changed

doc/rust.md

+71-2
Original file line numberDiff line numberDiff line change
@@ -1417,14 +1417,83 @@ names are effectively reserved. Some significant attributes include:
14171417
* The `lang` attribute, for custom definitions of traits and functions that are known to the Rust compiler (see [Language items](#language-items)).
14181418
* The `link` attribute, for describing linkage metadata for a crate.
14191419
* The `test` attribute, for marking functions as unit tests.
1420-
* The `allow`, `warn`, `forbid`, and `deny` attributes, for controlling lint checks. Lint checks supported
1421-
by the compiler can be found via `rustc -W help`.
1420+
* The `allow`, `warn`, `forbid`, and `deny` attributes, for
1421+
controlling lint checks (see [Lint check attributes](#lint-check-attributes)).
14221422
* The `deriving` attribute, for automatically generating
14231423
implementations of certain traits.
14241424
* The `static_assert` attribute, for asserting that a static bool is true at compiletime
14251425

14261426
Other attributes may be added or removed during development of the language.
14271427

1428+
### Lint check attributes
1429+
1430+
A lint check names a potentially undesirable coding pattern, such as
1431+
unreachable code or omitted documentation, for the static entity to
1432+
which the attribute applies.
1433+
1434+
For any lint check `C`:
1435+
1436+
* `warn(C)` warns about violations of `C` but continues compilation,
1437+
* `deny(C)` signals an error after encountering a violation of `C`,
1438+
* `allow(C)` overrides the check for `C` so that violations will go
1439+
unreported,
1440+
* `forbid(C)` is the same as `deny(C)`, but also forbids uses of
1441+
`allow(C)` within the entity.
1442+
1443+
The lint checks supported by the compiler can be found via `rustc -W help`,
1444+
along with their default settings.
1445+
1446+
~~~{.xfail-test}
1447+
mod m1 {
1448+
// Missing documentation is ignored here
1449+
#[allow(missing_doc)]
1450+
pub fn undocumented_one() -> int { 1 }
1451+
1452+
// Missing documentation signals a warning here
1453+
#[warn(missing_doc)]
1454+
pub fn undocumented_too() -> int { 2 }
1455+
1456+
// Missing documentation signals an error here
1457+
#[deny(missing_doc)]
1458+
pub fn undocumented_end() -> int { 3 }
1459+
}
1460+
~~~
1461+
1462+
This example shows how one can use `allow` and `warn` to toggle
1463+
a particular check on and off.
1464+
1465+
~~~
1466+
#[warn(missing_doc)]
1467+
mod m2{
1468+
#[allow(missing_doc)]
1469+
mod nested {
1470+
// Missing documentation is ignored here
1471+
pub fn undocumented_one() -> int { 1 }
1472+
1473+
// Missing documentation signals a warning here,
1474+
// despite the allow above.
1475+
#[warn(missing_doc)]
1476+
pub fn undocumented_two() -> int { 2 }
1477+
}
1478+
1479+
// Missing documentation signals a warning here
1480+
pub fn undocumented_too() -> int { 3 }
1481+
}
1482+
~~~
1483+
1484+
This example shows how one can use `forbid` to disallow uses
1485+
of `allow` for that lint check.
1486+
1487+
~~~{.xfail-test}
1488+
#[forbid(missing_doc)]
1489+
mod m3 {
1490+
// Attempting to toggle warning signals an error here
1491+
#[allow(missing_doc)]
1492+
/// Returns 2.
1493+
pub fn undocumented_too() -> int { 2 }
1494+
}
1495+
~~~
1496+
14281497
### Language items
14291498

14301499
Some primitive Rust operations are defined in Rust code,

0 commit comments

Comments
 (0)