Skip to content

Commit b586d76

Browse files
committed
Auto merge of #3865 - phansch:run_more_doc_tests, r=flip1995
Run more doc tests This executes some more doc tests that were ignored before.
2 parents 94a8d9c + 9ca34e3 commit b586d76

File tree

8 files changed

+103
-52
lines changed

8 files changed

+103
-52
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: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ declare_clippy_lint! {
5454
/// **Known problems:** None.
5555
///
5656
/// **Example:**
57-
/// ```ignore
58-
/// x == NAN
57+
/// ```rust
58+
/// # use core::f32::NAN;
59+
/// # let x = 1.0;
60+
///
61+
/// if x == NAN { }
5962
/// ```
6063
pub CMP_NAN,
6164
correctness,
@@ -75,9 +78,11 @@ declare_clippy_lint! {
7578
/// **Known problems:** None.
7679
///
7780
/// **Example:**
78-
/// ```ignore
79-
/// y == 1.23f64
80-
/// y != x // where both are floats
81+
/// ```rust
82+
/// let x = 1.2331f64;
83+
/// let y = 1.2332f64;
84+
/// if y == 1.23f64 { }
85+
/// if y != x {} // where both are floats
8186
/// ```
8287
pub FLOAT_CMP,
8388
correctness,
@@ -114,8 +119,9 @@ declare_clippy_lint! {
114119
/// **Known problems:** None.
115120
///
116121
/// **Example:**
117-
/// ```ignore
118-
/// x % 1
122+
/// ```rust
123+
/// # let x = 1;
124+
/// let a = x % 1;
119125
/// ```
120126
pub MODULO_ONE,
121127
correctness,
@@ -131,7 +137,9 @@ declare_clippy_lint! {
131137
/// **Known problems:** None.
132138
///
133139
/// **Example:**
134-
/// ```ignore
140+
/// ```rust
141+
/// # let v = Some("abc");
142+
///
135143
/// match v {
136144
/// Some(x) => (),
137145
/// y @ _ => (), // easier written as `y`,
@@ -194,8 +202,8 @@ declare_clippy_lint! {
194202
///
195203
/// **Example:**
196204
///
197-
/// ```ignore
198-
/// 0 as *const u32
205+
/// ```rust
206+
/// let a = 0 as *const u32;
199207
/// ```
200208
pub ZERO_PTR,
201209
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: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,10 @@ declare_clippy_lint! {
511511
/// **Known problems:** None.
512512
///
513513
/// **Example:**
514-
/// ```ignore
514+
/// ```rust
515+
/// # fn foo() {};
516+
/// # fn bar() {};
517+
/// # fn baz() {};
515518
/// if {
516519
/// foo();
517520
/// } == {
@@ -521,7 +524,10 @@ declare_clippy_lint! {
521524
/// }
522525
/// ```
523526
/// is equal to
524-
/// ```ignore
527+
/// ```rust
528+
/// # fn foo() {};
529+
/// # fn bar() {};
530+
/// # fn baz() {};
525531
/// {
526532
/// foo();
527533
/// bar();
@@ -850,13 +856,13 @@ declare_clippy_lint! {
850856
///
851857
/// **Example**
852858
///
853-
/// ```ignore
859+
/// ```rust
854860
/// // Bad
855-
/// fn fun() -> i32 {}
861+
/// fn fun() -> i32 { 1 }
856862
/// let a = fun as i64;
857863
///
858864
/// // Good
859-
/// fn fun2() -> i32 {}
865+
/// fn fun2() -> i32 { 1 }
860866
/// let a = fun2 as usize;
861867
/// ```
862868
pub FN_TO_NUMERIC_CAST,
@@ -1538,9 +1544,11 @@ declare_clippy_lint! {
15381544
/// like `#[cfg(target_pointer_width = "64")] ..` instead.
15391545
///
15401546
/// **Example:**
1541-
/// ```rust,ignore
1542-
/// vec.len() <= 0
1543-
/// 100 > std::i32::MAX
1547+
///
1548+
/// ```rust
1549+
/// let vec: Vec<isize> = vec![];
1550+
/// if vec.len() <= 0 {}
1551+
/// if 100 > std::i32::MAX {}
15441552
/// ```
15451553
pub ABSURD_EXTREME_COMPARISONS,
15461554
correctness,
@@ -1963,10 +1971,13 @@ declare_clippy_lint! {
19631971
/// pieces of code, possibly including external crates.
19641972
///
19651973
/// **Example:**
1966-
/// ```ignore
1967-
/// impl<K: Hash + Eq, V> Serialize for HashMap<K, V> { ... }
1974+
/// ```rust
1975+
/// # use std::collections::HashMap;
1976+
/// # use std::hash::Hash;
1977+
/// # trait Serialize {};
1978+
/// impl<K: Hash + Eq, V> Serialize for HashMap<K, V> { }
19681979
///
1969-
/// pub foo(map: &mut HashMap<i32, i32>) { .. }
1980+
/// pub fn foo(map: &mut HashMap<i32, i32>) { }
19701981
/// ```
19711982
pub IMPLICIT_HASHER,
19721983
style,
@@ -2304,7 +2315,7 @@ declare_clippy_lint! {
23042315
/// **Known problems:** None.
23052316
///
23062317
/// **Example:**
2307-
/// ```ignore
2318+
/// ```rust,ignore
23082319
/// fn x(r: &i32) {
23092320
/// unsafe {
23102321
/// *(r as *const _ as *mut _) += 1;
@@ -2314,7 +2325,9 @@ declare_clippy_lint! {
23142325
///
23152326
/// Instead consider using interior mutability types.
23162327
///
2317-
/// ```ignore
2328+
/// ```rust
2329+
/// use std::cell::UnsafeCell;
2330+
///
23182331
/// fn x(r: &UnsafeCell<i32>) {
23192332
/// unsafe {
23202333
/// *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)