Skip to content

Commit 3dc9183

Browse files
committed
Auto merge of #4325 - phansch:doctests_complexity, r=flip1995
Doctests: Enable running doc tests for complexity lints changelog: none master: `113 passed; 0 failed; 91 ignored; 0 measured; 0 filtered out` this PR: `181 passed; 0 failed; 110 ignored; 0 measured; 0 filtered out` cc #4319
2 parents a24c704 + eb68dc9 commit 3dc9183

33 files changed

+157
-85
lines changed

clippy_lints/src/assign_ops.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ declare_clippy_lint! {
4545
/// **Example:**
4646
/// ```rust
4747
/// let mut a = 5;
48-
/// ...
48+
/// let b = 2;
49+
/// // ...
4950
/// a += a + b;
5051
/// ```
5152
pub MISREFACTORED_ASSIGN_OP,

clippy_lints/src/double_comparison.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ declare_clippy_lint! {
1818
///
1919
/// **Example:**
2020
/// ```rust
21-
/// x == y || x < y
21+
/// # let x = 1;
22+
/// # let y = 2;
23+
/// if x == y || x < y {}
2224
/// ```
2325
///
2426
/// Could be written as:
2527
///
2628
/// ```rust
27-
/// x <= y
29+
/// # let x = 1;
30+
/// # let y = 2;
31+
/// if x <= y {}
2832
/// ```
2933
pub DOUBLE_COMPARISONS,
3034
complexity,

clippy_lints/src/double_parens.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ declare_clippy_lint! {
1313
///
1414
/// **Example:**
1515
/// ```rust
16-
/// ((0))
17-
/// foo((0))
18-
/// ((1, 2))
16+
/// # fn foo(bar: usize) {}
17+
/// ((0));
18+
/// foo((0));
19+
/// ((1, 2));
1920
/// ```
2021
pub DOUBLE_PARENS,
2122
complexity,

clippy_lints/src/duration_subsec.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ declare_clippy_lint! {
2020
///
2121
/// **Example:**
2222
/// ```rust
23+
/// # use std::time::Duration;
2324
/// let dur = Duration::new(5, 0);
2425
/// let _micros = dur.subsec_nanos() / 1_000;
2526
/// let _millis = dur.subsec_nanos() / 1_000_000;

clippy_lints/src/eval_order_dependence.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ declare_clippy_lint! {
4242
/// shorthand.
4343
///
4444
/// **Example:**
45-
/// ```rust
45+
/// ```rust,no_run
46+
/// # fn b() -> bool { true }
47+
/// # fn c() -> bool { true }
4648
/// let a = b() || panic!() || c();
4749
/// // `c()` is dead, `panic!()` is only called if `b()` returns `false`
4850
/// let x = (a, b, c, panic!());

clippy_lints/src/explicit_write.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ declare_clippy_lint! {
1616
///
1717
/// **Example:**
1818
/// ```rust
19+
/// # use std::io::Write;
20+
/// # let bar = "furchtbar";
1921
/// // this would be clearer as `eprintln!("foo: {:?}", bar);`
20-
/// writeln!(&mut io::stderr(), "foo: {:?}", bar).unwrap();
22+
/// writeln!(&mut std::io::stderr(), "foo: {:?}", bar).unwrap();
2123
/// ```
2224
pub EXPLICIT_WRITE,
2325
complexity,

clippy_lints/src/format.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ declare_clippy_lint! {
2626
///
2727
/// **Examples:**
2828
/// ```rust
29-
/// format!("foo")
30-
/// format!("{}", foo)
29+
/// # let foo = "foo";
30+
/// format!("foo");
31+
/// format!("{}", foo);
3132
/// ```
3233
pub USELESS_FORMAT,
3334
complexity,

clippy_lints/src/functions.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ declare_clippy_lint! {
2323
///
2424
/// **Example:**
2525
/// ```rust
26+
/// # struct Color;
2627
/// fn foo(x: u32, y: u32, name: &str, c: Color, w: f32, h: f32, a: f32, b: f32) {
27-
/// ..
28+
/// // ..
2829
/// }
2930
/// ```
3031
pub TOO_MANY_ARGUMENTS,

clippy_lints/src/identity_op.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ declare_clippy_lint! {
1717
///
1818
/// **Example:**
1919
/// ```rust
20-
/// x / 1 + 0 * 1 - 0 | 0
20+
/// # let x = 1;
21+
/// x / 1 + 0 * 1 - 0 | 0;
2122
/// ```
2223
pub IDENTITY_OP,
2324
complexity,

clippy_lints/src/int_plus_one.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ declare_clippy_lint! {
1717
///
1818
/// **Example:**
1919
/// ```rust
20-
/// x >= y + 1
20+
/// # let x = 1;
21+
/// # let y = 1;
22+
/// if x >= y + 1 {}
2123
/// ```
2224
///
23-
/// Could be written:
25+
/// Could be written as:
2426
///
2527
/// ```rust
26-
/// x > y
28+
/// # let x = 1;
29+
/// # let y = 1;
30+
/// if x > y {}
2731
/// ```
2832
pub INT_PLUS_ONE,
2933
complexity,

clippy_lints/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ macro_rules! declare_clippy_lint {
100100
};
101101
{ $(#[$attr:meta])* pub $name:tt, complexity, $description:tt } => {
102102
declare_tool_lint! {
103-
pub clippy::$name, Warn, $description, report_in_external_macro: true
103+
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
104104
}
105105
};
106106
{ $(#[$attr:meta])* pub $name:tt, perf, $description:tt } => {
@@ -130,12 +130,12 @@ macro_rules! declare_clippy_lint {
130130
};
131131
{ $(#[$attr:meta])* pub $name:tt, internal, $description:tt } => {
132132
declare_tool_lint! {
133-
pub clippy::$name, Allow, $description, report_in_external_macro: true
133+
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
134134
}
135135
};
136136
{ $(#[$attr:meta])* pub $name:tt, internal_warn, $description:tt } => {
137137
declare_tool_lint! {
138-
pub clippy::$name, Warn, $description, report_in_external_macro: true
138+
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
139139
}
140140
};
141141
}

clippy_lints/src/lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ declare_clippy_lint! {
4747
/// **Example:**
4848
/// ```rust
4949
/// fn unused_lifetime<'a>(x: u8) {
50-
/// ..
50+
/// // ..
5151
/// }
5252
/// ```
5353
pub EXTRA_UNUSED_LIFETIMES,

clippy_lints/src/loops.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,19 @@ declare_clippy_lint! {
217217
/// **Known problems:** Sometimes the wrong binding is displayed (#383).
218218
///
219219
/// **Example:**
220-
/// ```rust
220+
/// ```rust,no_run
221+
/// # let y = Some(1);
221222
/// loop {
222223
/// let x = match y {
223224
/// Some(x) => x,
224225
/// None => break,
225-
/// }
226+
/// };
226227
/// // .. do something with x
227228
/// }
228229
/// // is easier written as
229230
/// while let Some(x) = y {
230231
/// // .. do something with x
231-
/// }
232+
/// };
232233
/// ```
233234
pub WHILE_LET_LOOP,
234235
complexity,
@@ -309,8 +310,11 @@ declare_clippy_lint! {
309310
/// **Known problems:** None.
310311
///
311312
/// **Example:**
312-
/// ```ignore
313-
/// for i in 0..v.len() { foo(v[i]);
313+
/// ```rust
314+
/// # let v = vec![1];
315+
/// # fn foo(bar: usize) {}
316+
/// # fn bar(bar: usize, baz: usize) {}
317+
/// for i in 0..v.len() { foo(v[i]); }
314318
/// for i in 0..v.len() { bar(i, v[i]); }
315319
/// ```
316320
pub EXPLICIT_COUNTER_LOOP,

clippy_lints/src/map_unit_fn.rs

+29-12
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,29 @@ declare_clippy_lint! {
2020
/// **Example:**
2121
///
2222
/// ```rust
23-
/// let x: Option<&str> = do_stuff();
23+
/// # fn do_stuff() -> Option<String> { Some(String::new()) }
24+
/// # fn log_err_msg(foo: String) -> Option<String> { Some(foo) }
25+
/// # fn format_msg(foo: String) -> String { String::new() }
26+
/// let x: Option<String> = do_stuff();
2427
/// x.map(log_err_msg);
25-
/// x.map(|msg| log_err_msg(format_msg(msg)))
28+
/// # let x: Option<String> = do_stuff();
29+
/// x.map(|msg| log_err_msg(format_msg(msg)));
2630
/// ```
2731
///
2832
/// The correct use would be:
2933
///
3034
/// ```rust
31-
/// let x: Option<&str> = do_stuff();
35+
/// # fn do_stuff() -> Option<String> { Some(String::new()) }
36+
/// # fn log_err_msg(foo: String) -> Option<String> { Some(foo) }
37+
/// # fn format_msg(foo: String) -> String { String::new() }
38+
/// let x: Option<String> = do_stuff();
3239
/// if let Some(msg) = x {
33-
/// log_err_msg(msg)
40+
/// log_err_msg(msg);
3441
/// }
42+
///
43+
/// # let x: Option<String> = do_stuff();
3544
/// if let Some(msg) = x {
36-
/// log_err_msg(format_msg(msg))
45+
/// log_err_msg(format_msg(msg));
3746
/// }
3847
/// ```
3948
pub OPTION_MAP_UNIT_FN,
@@ -53,21 +62,29 @@ declare_clippy_lint! {
5362
/// **Example:**
5463
///
5564
/// ```rust
56-
/// let x: Result<&str, &str> = do_stuff();
65+
/// # fn do_stuff() -> Result<String, String> { Ok(String::new()) }
66+
/// # fn log_err_msg(foo: String) -> Result<String, String> { Ok(foo) }
67+
/// # fn format_msg(foo: String) -> String { String::new() }
68+
/// let x: Result<String, String> = do_stuff();
5769
/// x.map(log_err_msg);
58-
/// x.map(|msg| log_err_msg(format_msg(msg)))
70+
/// # let x: Result<String, String> = do_stuff();
71+
/// x.map(|msg| log_err_msg(format_msg(msg)));
5972
/// ```
6073
///
6174
/// The correct use would be:
6275
///
6376
/// ```rust
64-
/// let x: Result<&str, &str> = do_stuff();
77+
/// # fn do_stuff() -> Result<String, String> { Ok(String::new()) }
78+
/// # fn log_err_msg(foo: String) -> Result<String, String> { Ok(foo) }
79+
/// # fn format_msg(foo: String) -> String { String::new() }
80+
/// let x: Result<String, String> = do_stuff();
6581
/// if let Ok(msg) = x {
66-
/// log_err_msg(msg)
67-
/// }
82+
/// log_err_msg(msg);
83+
/// };
84+
/// # let x: Result<String, String> = do_stuff();
6885
/// if let Ok(msg) = x {
69-
/// log_err_msg(format_msg(msg))
70-
/// }
86+
/// log_err_msg(format_msg(msg));
87+
/// };
7188
/// ```
7289
pub RESULT_MAP_UNIT_FN,
7390
complexity,

clippy_lints/src/methods/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ declare_clippy_lint! {
247247
///
248248
/// **Example:**
249249
/// ```rust
250-
/// iter.filter(|x| x == 0).next()
250+
/// # let vec = vec![1];
251+
/// vec.iter().filter(|x| **x == 0).next();
251252
/// ```
252253
pub FILTER_NEXT,
253254
complexity,
@@ -345,7 +346,8 @@ declare_clippy_lint! {
345346
///
346347
/// **Example:**
347348
/// ```rust
348-
/// iter.find(|x| x == 0).is_some()
349+
/// # let vec = vec![1];
350+
/// vec.iter().find(|x| **x == 0).is_some();
349351
/// ```
350352
pub SEARCH_IS_SOME,
351353
complexity,
@@ -363,7 +365,8 @@ declare_clippy_lint! {
363365
///
364366
/// **Example:**
365367
/// ```rust
366-
/// name.chars().next() == Some('_')
368+
/// let name = "foo";
369+
/// name.chars().next() == Some('_');
367370
/// ```
368371
pub CHARS_NEXT_CMP,
369372
complexity,
@@ -434,7 +437,7 @@ declare_clippy_lint! {
434437
///
435438
/// **Example:**
436439
/// ```rust
437-
/// 42u64.clone()
440+
/// 42u64.clone();
438441
/// ```
439442
pub CLONE_ON_COPY,
440443
complexity,
@@ -708,11 +711,13 @@ declare_clippy_lint! {
708711
///
709712
/// **Example:**
710713
/// ```rust
714+
/// # fn do_stuff(x: &[i32]) {}
711715
/// let x: &[i32] = &[1, 2, 3, 4, 5];
712716
/// do_stuff(x.as_ref());
713717
/// ```
714718
/// The correct use would be:
715719
/// ```rust
720+
/// # fn do_stuff(x: &[i32]) {}
716721
/// let x: &[i32] = &[1, 2, 3, 4, 5];
717722
/// do_stuff(x);
718723
/// ```

clippy_lints/src/misc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ declare_clippy_lint! {
184184
/// **Known problems:** None.
185185
///
186186
/// **Example:**
187-
/// ```rust
187+
/// ```rust,ignore
188188
/// f() && g(); // We should write `if f() { g(); }`.
189189
/// ```
190190
pub SHORT_CIRCUIT_STATEMENT,

clippy_lints/src/misc_early.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ declare_clippy_lint! {
5353
/// **Known problems:** None.
5454
///
5555
/// **Example:**
56-
/// ```rust
56+
/// ```rust,ignore
5757
/// (|| 42)()
5858
/// ```
5959
pub REDUNDANT_CLOSURE_CALL,

clippy_lints/src/needless_bool.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ declare_clippy_lint! {
2424
/// shorter code.
2525
///
2626
/// **Example:**
27-
/// ```rust
27+
/// ```rust,ignore
2828
/// if x {
2929
/// false
3030
/// } else {
@@ -46,7 +46,7 @@ declare_clippy_lint! {
4646
/// **Known problems:** None.
4747
///
4848
/// **Example:**
49-
/// ```rust
49+
/// ```rust,ignore
5050
/// if x == true {} // could be `if x { }`
5151
/// ```
5252
pub BOOL_COMPARISON,

clippy_lints/src/needless_borrowed_ref.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ declare_clippy_lint! {
1818
///
1919
/// **Known problems:** It seems that the `&ref` pattern is sometimes useful.
2020
/// For instance in the following snippet:
21-
/// ```rust
21+
/// ```rust,ignore
2222
/// enum Animal {
2323
/// Cat(u64),
2424
/// Dog(u64),
2525
/// }
2626
///
2727
/// fn foo(a: &Animal, b: &Animal) {
2828
/// match (a, b) {
29-
/// (&Animal::Cat(v), k) | (k, &Animal::Cat(v)) => (), // lifetime
30-
/// mismatch error
29+
/// (&Animal::Cat(v), k) | (k, &Animal::Cat(v)) => (), // lifetime mismatch error
3130
/// (&Animal::Dog(ref c), &Animal::Dog(_)) => ()
3231
/// }
3332
/// }

clippy_lints/src/needless_update.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ declare_clippy_lint! {
1515
///
1616
/// **Example:**
1717
/// ```rust
18+
/// # struct Point {
19+
/// # x: i32,
20+
/// # y: i32,
21+
/// # z: i32,
22+
/// # }
23+
/// # let zero_point = Point { x: 0, y: 0, z: 0 };
1824
/// Point {
1925
/// x: 1,
20-
/// y: 0,
26+
/// y: 1,
2127
/// ..zero_point
22-
/// }
28+
/// };
2329
/// ```
2430
pub NEEDLESS_UPDATE,
2531
complexity,

0 commit comments

Comments
 (0)