Skip to content

Commit c832357

Browse files
committed
Run more doc tests
This executes some more doc tests that were ignored before.
1 parent 00baf7a commit c832357

File tree

8 files changed

+104
-54
lines changed

8 files changed

+104
-54
lines changed

clippy_lints/src/bit_mask.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ declare_clippy_lint! {
3737
/// **Known problems:** None.
3838
///
3939
/// **Example:**
40-
/// ```ignore
41-
/// if (x & 1 == 2) { … }
40+
/// ```rust
41+
/// # let x = 1;
42+
/// if (x & 1 == 2) { }
4243
/// ```
4344
pub BAD_BIT_MASK,
4445
correctness,
@@ -65,8 +66,9 @@ declare_clippy_lint! {
6566
/// uncommon).
6667
///
6768
/// **Example:**
68-
/// ```ignore
69-
/// if (x | 1 > 3) { … }
69+
/// ```rust
70+
/// # let x = 1;
71+
/// if (x | 1 > 3) { }
7072
/// ```
7173
pub INEFFECTIVE_BIT_MASK,
7274
correctness,
@@ -83,8 +85,9 @@ declare_clippy_lint! {
8385
/// **Known problems:** llvm generates better code for `x & 15 == 0` on x86
8486
///
8587
/// **Example:**
86-
/// ```ignore
87-
/// x & 0x1111 == 0
88+
/// ```rust
89+
/// # let x = 1;
90+
/// if x & 0x1111 == 0 { }
8891
/// ```
8992
pub VERBOSE_BIT_MASK,
9093
style,

clippy_lints/src/eq_op.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ declare_clippy_lint! {
1919
/// calls. We may introduce a whitelist of known pure functions in the future.
2020
///
2121
/// **Example:**
22-
/// ```ignore
23-
/// x + 1 == x + 1
22+
/// ```rust
23+
/// # let x = 1;
24+
/// if x + 1 == x + 1 {}
2425
/// ```
2526
pub EQ_OP,
2627
correctness,

clippy_lints/src/matches.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ declare_clippy_lint! {
2727
/// **Known problems:** None.
2828
///
2929
/// **Example:**
30-
/// ```ignore
30+
/// ```rust
31+
/// # fn bar(stool: &str) {}
32+
/// # let x = Some("abc");
3133
/// match x {
3234
/// Some(ref foo) => bar(foo),
3335
/// _ => (),
@@ -59,7 +61,7 @@ declare_clippy_lint! {
5961
///
6062
/// Using `if let` with `else`:
6163
///
62-
/// ```ignore
64+
/// ```rust
6365
/// if let Some(ref foo) = x {
6466
/// bar(foo);
6567
/// } else {
@@ -82,7 +84,7 @@ declare_clippy_lint! {
8284
/// **Known problems:** None.
8385
///
8486
/// **Example:**
85-
/// ```ignore
87+
/// ```rust,ignore
8688
/// match x {
8789
/// &A(ref y) => foo(y),
8890
/// &B => bar(),
@@ -103,15 +105,19 @@ declare_clippy_lint! {
103105
/// **Known problems:** None.
104106
///
105107
/// **Example:**
106-
/// ```ignore
108+
/// ```rust
109+
/// # fn foo() {}
110+
/// # fn bar() {}
107111
/// let condition: bool = true;
108112
/// match condition {
109113
/// true => foo(),
110114
/// false => bar(),
111115
/// }
112116
/// ```
113117
/// Use if/else instead:
114-
/// ```ignore
118+
/// ```rust
119+
/// # fn foo() {}
120+
/// # fn bar() {}
115121
/// let condition: bool = true;
116122
/// if condition {
117123
/// foo();

clippy_lints/src/misc.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ declare_clippy_lint! {
3434
/// dereferences, e.g. changing `*x` to `x` within the function.
3535
///
3636
/// **Example:**
37-
/// ```ignore
37+
/// ```rust
3838
/// fn foo(ref x: u8) -> bool {
39-
/// ..
39+
/// true
4040
/// }
4141
/// ```
4242
pub TOPLEVEL_REF_ARG,
@@ -53,8 +53,11 @@ declare_clippy_lint! {
5353
/// **Known problems:** None.
5454
///
5555
/// **Example:**
56-
/// ```ignore
57-
/// x == NAN
56+
/// ```rust
57+
/// # use core::f32::NAN;
58+
/// # let x = 1.0;
59+
///
60+
/// if x == NAN { }
5861
/// ```
5962
pub CMP_NAN,
6063
correctness,
@@ -74,9 +77,11 @@ declare_clippy_lint! {
7477
/// **Known problems:** None.
7578
///
7679
/// **Example:**
77-
/// ```ignore
78-
/// y == 1.23f64
79-
/// y != x // where both are floats
80+
/// ```rust
81+
/// let x = 1.2331f64;
82+
/// let y = 1.2332f64;
83+
/// if y == 1.23f64 { }
84+
/// if y != x {} // where both are floats
8085
/// ```
8186
pub FLOAT_CMP,
8287
correctness,
@@ -113,8 +118,9 @@ declare_clippy_lint! {
113118
/// **Known problems:** None.
114119
///
115120
/// **Example:**
116-
/// ```ignore
117-
/// x % 1
121+
/// ```rust
122+
/// # let x = 1;
123+
/// let a = x % 1;
118124
/// ```
119125
pub MODULO_ONE,
120126
correctness,
@@ -130,7 +136,9 @@ declare_clippy_lint! {
130136
/// **Known problems:** None.
131137
///
132138
/// **Example:**
133-
/// ```ignore
139+
/// ```rust
140+
/// # let v = Some("abc");
141+
///
134142
/// match v {
135143
/// Some(x) => (),
136144
/// y @ _ => (), // easier written as `y`,
@@ -193,8 +201,8 @@ declare_clippy_lint! {
193201
///
194202
/// **Example:**
195203
///
196-
/// ```ignore
197-
/// 0 as *const u32
204+
/// ```rust
205+
/// let a = 0 as *const u32;
198206
/// ```
199207
pub ZERO_PTR,
200208
style,

clippy_lints/src/needless_continue.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
//!
33
//! For example, the lint would catch
44
//!
5-
//! ```ignore
6-
//! while condition() {
7-
//! update_condition();
5+
//! ```rust
6+
//! let mut a = 1;
7+
//! let x = true;
8+
//!
9+
//! while a < 5 {
10+
//! a = 6;
811
//! if x {
912
//! // ...
1013
//! } else {
@@ -16,9 +19,12 @@
1619
//!
1720
//! And suggest something like this:
1821
//!
19-
//! ```ignore
20-
//! while condition() {
21-
//! update_condition();
22+
//! ```rust
23+
//! let mut a = 1;
24+
//! let x = true;
25+
//!
26+
//! while a < 5 {
27+
//! a = 6;
2228
//! if x {
2329
//! // ...
2430
//! println!("Hello, world");
@@ -374,7 +380,7 @@ fn check_and_warn<'a>(ctx: &EarlyContext<'_>, expr: &'a ast::Expr) {
374380
/// continues eating till a non-whitespace character is found.
375381
/// e.g., the string
376382
///
377-
/// ```
383+
/// ```rust
378384
/// {
379385
/// let x = 5;
380386
/// }

clippy_lints/src/swap.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ declare_clippy_lint! {
1919
/// **Known problems:** None.
2020
///
2121
/// **Example:**
22-
/// ```rust,ignore
22+
/// ```rust
2323
/// let t = b;
2424
/// b = a;
2525
/// a = t;
@@ -41,7 +41,9 @@ declare_clippy_lint! {
4141
/// **Known problems:** None.
4242
///
4343
/// **Example:**
44-
/// ```rust,ignore
44+
/// ```rust
45+
/// # let mut a = 1;
46+
/// # let mut b = 2;
4547
/// a = b;
4648
/// b = a;
4749
/// ```

clippy_lints/src/types.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,10 @@ declare_clippy_lint! {
509509
/// **Known problems:** None.
510510
///
511511
/// **Example:**
512-
/// ```ignore
512+
/// ```rust
513+
/// # fn foo() {};
514+
/// # fn bar() {};
515+
/// # fn baz() {};
513516
/// if {
514517
/// foo();
515518
/// } == {
@@ -519,7 +522,10 @@ declare_clippy_lint! {
519522
/// }
520523
/// ```
521524
/// is equal to
522-
/// ```ignore
525+
/// ```rust
526+
/// # fn foo() {};
527+
/// # fn bar() {};
528+
/// # fn baz() {};
523529
/// {
524530
/// foo();
525531
/// bar();
@@ -848,13 +854,13 @@ declare_clippy_lint! {
848854
///
849855
/// **Example**
850856
///
851-
/// ```ignore
857+
/// ```rust
852858
/// // Bad
853-
/// fn fun() -> i32 {}
859+
/// fn fun() -> i32 { 1 }
854860
/// let a = fun as i64;
855861
///
856862
/// // Good
857-
/// fn fun2() -> i32 {}
863+
/// fn fun2() -> i32 { 1 }
858864
/// let a = fun2 as usize;
859865
/// ```
860866
pub FN_TO_NUMERIC_CAST,
@@ -1536,9 +1542,10 @@ declare_clippy_lint! {
15361542
/// like `#[cfg(target_pointer_width = "64")] ..` instead.
15371543
///
15381544
/// **Example:**
1539-
/// ```ignore
1540-
/// vec.len() <= 0
1541-
/// 100 > std::i32::MAX
1545+
/// ```rust
1546+
/// let vec: Vec<isize> = vec![];
1547+
/// if vec.len() <= 0 {}
1548+
/// if 100 > std::i32::MAX {}
15421549
/// ```
15431550
pub ABSURD_EXTREME_COMPARISONS,
15441551
correctness,
@@ -1961,10 +1968,13 @@ declare_clippy_lint! {
19611968
/// pieces of code, possibly including external crates.
19621969
///
19631970
/// **Example:**
1964-
/// ```ignore
1965-
/// impl<K: Hash + Eq, V> Serialize for HashMap<K, V> { ... }
1971+
/// ```rust
1972+
/// # use std::collections::HashMap;
1973+
/// # use std::hash::Hash;
1974+
/// # trait Serialize {};
1975+
/// impl<K: Hash + Eq, V> Serialize for HashMap<K, V> { }
19661976
///
1967-
/// pub foo(map: &mut HashMap<i32, i32>) { .. }
1977+
/// pub fn foo(map: &mut HashMap<i32, i32>) { }
19681978
/// ```
19691979
pub IMPLICIT_HASHER,
19701980
style,
@@ -2302,7 +2312,7 @@ declare_clippy_lint! {
23022312
/// **Known problems:** None.
23032313
///
23042314
/// **Example:**
2305-
/// ```ignore
2315+
/// ```rust,ignore
23062316
/// fn x(r: &i32) {
23072317
/// unsafe {
23082318
/// *(r as *const _ as *mut _) += 1;
@@ -2312,7 +2322,9 @@ declare_clippy_lint! {
23122322
///
23132323
/// Instead consider using interior mutability types.
23142324
///
2315-
/// ```ignore
2325+
/// ```rust
2326+
/// use std::cell::UnsafeCell;
2327+
///
23162328
/// fn x(r: &UnsafeCell<i32>) {
23172329
/// unsafe {
23182330
/// *r.get() += 1;

clippy_lints/src/write.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ declare_clippy_lint! {
3535
/// **Known problems:** None.
3636
///
3737
/// **Example:**
38-
/// ```ignore
38+
/// ```rust
39+
/// # let name = "World";
3940
/// print!("Hello {}!\n", name);
4041
/// ```
4142
/// use println!() instead
42-
/// ```ignore
43+
/// ```rust
44+
/// # let name = "World";
4345
/// println!("Hello {}!", name);
4446
/// ```
4547
pub PRINT_WITH_NEWLINE,
@@ -113,7 +115,9 @@ declare_clippy_lint! {
113115
/// **Known problems:** None.
114116
///
115117
/// **Example:**
116-
/// ```ignore
118+
/// ```rust
119+
/// # use std::fmt::Write;
120+
/// # let mut buf = String::new();
117121
/// writeln!(buf, "");
118122
/// ```
119123
pub WRITELN_EMPTY_STRING,
@@ -132,7 +136,10 @@ declare_clippy_lint! {
132136
/// **Known problems:** None.
133137
///
134138
/// **Example:**
135-
/// ```ignore
139+
/// ```rust
140+
/// # use std::fmt::Write;
141+
/// # let mut buf = String::new();
142+
/// # let name = "World";
136143
/// write!(buf, "Hello {}!\n", name);
137144
/// ```
138145
pub WRITE_WITH_NEWLINE,
@@ -151,7 +158,9 @@ declare_clippy_lint! {
151158
/// -- e.g., `writeln!(buf, "{}", env!("FOO"))`.
152159
///
153160
/// **Example:**
154-
/// ```ignore
161+
/// ```rust
162+
/// # use std::fmt::Write;
163+
/// # let mut buf = String::new();
155164
/// writeln!(buf, "{}", "foo");
156165
/// ```
157166
pub WRITE_LITERAL,
@@ -259,8 +268,11 @@ impl EarlyLintPass for Pass {
259268
/// Example:
260269
///
261270
/// Calling this function on
262-
/// ```rust,ignore
263-
/// writeln!(buf, "string to write: {}", something)
271+
/// ```rust
272+
/// # use std::fmt::Write;
273+
/// # let mut buf = String::new();
274+
/// # let something = "something";
275+
/// writeln!(buf, "string to write: {}", something);
264276
/// ```
265277
/// will return
266278
/// ```rust,ignore

0 commit comments

Comments
 (0)