Skip to content

Commit b20f95c

Browse files
committed
Combine doc examples
1 parent adafb6c commit b20f95c

File tree

11 files changed

+88
-110
lines changed

11 files changed

+88
-110
lines changed

clippy_lints/src/as_conversions.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ declare_clippy_lint! {
3232
/// Use instead:
3333
/// ```rust,ignore
3434
/// f(a.try_into()?);
35-
/// ```
36-
/// or
37-
/// ```rust,ignore
35+
///
36+
/// // or
37+
///
3838
/// f(a.try_into().expect("Unexpected u16 overflow in f"));
3939
/// ```
40-
///
4140
#[clippy::version = "1.41.0"]
4241
pub AS_CONVERSIONS,
4342
restriction,

clippy_lints/src/attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,13 @@ declare_clippy_lint! {
241241
///
242242
/// Use instead:
243243
/// ```rust
244+
/// # mod hidden {
244245
/// #[cfg(target_os = "linux")]
245246
/// fn conditional() { }
246-
/// ```
247+
/// # }
247248
///
248-
/// or
249+
/// // or
249250
///
250-
/// ```rust
251251
/// #[cfg(unix)]
252252
/// fn conditional() { }
253253
/// ```

clippy_lints/src/blocks_in_if_conditions.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,17 @@ declare_clippy_lint! {
2222
///
2323
/// ### Examples
2424
/// ```rust
25-
/// // Bad
25+
/// # fn somefunc() -> bool { true };
2626
/// if { true } { /* ... */ }
2727
///
28-
/// // Good
29-
/// if true { /* ... */ }
28+
/// if { let x = somefunc(); x } { /* ... */ }
3029
/// ```
3130
///
32-
/// or
33-
///
31+
/// Use instead:
3432
/// ```rust
3533
/// # fn somefunc() -> bool { true };
36-
/// // Bad
37-
/// if { let x = somefunc(); x } { /* ... */ }
34+
/// if true { /* ... */ }
3835
///
39-
/// // Good
4036
/// let res = { let x = somefunc(); x };
4137
/// if res { /* ... */ }
4238
/// ```

clippy_lints/src/double_parens.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,21 @@ declare_clippy_lint! {
1313
///
1414
/// ### Example
1515
/// ```rust
16-
/// // Bad
1716
/// fn simple_double_parens() -> i32 {
1817
/// ((0))
1918
/// }
2019
///
21-
/// // Good
20+
/// # fn foo(bar: usize) {}
21+
/// foo((0));
22+
/// ```
23+
///
24+
/// Use instead:
25+
/// ```rust
2226
/// fn simple_no_parens() -> i32 {
2327
/// 0
2428
/// }
2529
///
26-
/// // or
27-
///
2830
/// # fn foo(bar: usize) {}
29-
/// // Bad
30-
/// foo((0));
31-
///
32-
/// // Good
3331
/// foo(0);
3432
/// ```
3533
#[clippy::version = "pre 1.29.0"]

clippy_lints/src/eq_op.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ declare_clippy_lint! {
3030
/// ```rust
3131
/// # let x = 1;
3232
/// if x + 1 == x + 1 {}
33-
/// ```
34-
/// or
35-
/// ```rust
33+
///
34+
/// // or
35+
///
3636
/// # let a = 3;
3737
/// # let b = 4;
3838
/// assert_eq!(a, a);

clippy_lints/src/loops/mod.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,29 +180,24 @@ declare_clippy_lint! {
180180
/// ### Example
181181
/// ```rust
182182
/// # let opt = Some(1);
183-
///
184-
/// // Bad
183+
/// # let res: Result<i32, std::io::Error> = Ok(1);
185184
/// for x in opt {
186185
/// // ..
187186
/// }
188187
///
189-
/// // Good
190-
/// if let Some(x) = opt {
188+
/// for x in &res {
191189
/// // ..
192190
/// }
193191
/// ```
194192
///
195-
/// or
196-
///
193+
/// Use instead:
197194
/// ```rust
195+
/// # let opt = Some(1);
198196
/// # let res: Result<i32, std::io::Error> = Ok(1);
199-
///
200-
/// // Bad
201-
/// for x in &res {
197+
/// if let Some(x) = opt {
202198
/// // ..
203199
/// }
204200
///
205-
/// // Good
206201
/// if let Ok(x) = res {
207202
/// // ..
208203
/// }

clippy_lints/src/methods/mod.rs

Lines changed: 40 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -194,25 +194,18 @@ declare_clippy_lint! {
194194
///
195195
/// ### Examples
196196
/// ```rust
197-
/// # let opt = Some(1);
198-
///
199-
/// // Bad
200-
/// opt.unwrap();
201-
///
202-
/// // Good
203-
/// opt.expect("more helpful message");
197+
/// # let option = Some(1);
198+
/// # let result: Result<usize, ()> = Ok(1);
199+
/// option.unwrap();
200+
/// result.unwrap();
204201
/// ```
205202
///
206-
/// or
207-
///
203+
/// Use instead:
208204
/// ```rust
209-
/// # let res: Result<usize, ()> = Ok(1);
210-
///
211-
/// // Bad
212-
/// res.unwrap();
213-
///
214-
/// // Good
215-
/// res.expect("more helpful message");
205+
/// # let option = Some(1);
206+
/// # let result: Result<usize, ()> = Ok(1);
207+
/// option.expect("more helpful message");
208+
/// result.expect("more helpful message");
216209
/// ```
217210
#[clippy::version = "1.45.0"]
218211
pub UNWRAP_USED,
@@ -235,27 +228,21 @@ declare_clippy_lint! {
235228
///
236229
/// ### Examples
237230
/// ```rust,ignore
238-
/// # let opt = Some(1);
239-
///
240-
/// // Bad
241-
/// opt.expect("one");
242-
///
243-
/// // Good
244-
/// let opt = Some(1);
245-
/// opt?;
231+
/// # let option = Some(1);
232+
/// # let result: Result<usize, ()> = Ok(1);
233+
/// option.expect("one");
234+
/// result.expect("one");
246235
/// ```
247236
///
248-
/// or
249-
///
250-
/// ```rust
251-
/// # let res: Result<usize, ()> = Ok(1);
237+
/// Use instead:
238+
/// ```rust,ignore
239+
/// # let option = Some(1);
240+
/// # let result: Result<usize, ()> = Ok(1);
241+
/// option?;
252242
///
253-
/// // Bad
254-
/// res.expect("one");
243+
/// // or
255244
///
256-
/// // Good
257-
/// res?;
258-
/// # Ok::<(), ()>(())
245+
/// result?;
259246
/// ```
260247
#[clippy::version = "1.45.0"]
261248
pub EXPECT_USED,
@@ -431,26 +418,20 @@ declare_clippy_lint! {
431418
///
432419
/// ### Examples
433420
/// ```rust
434-
/// # let x = Some(1);
435-
///
436-
/// // Bad
437-
/// x.map(|a| a + 1).unwrap_or(0);
438-
///
439-
/// // Good
440-
/// x.map_or(0, |a| a + 1);
421+
/// # let option = Some(1);
422+
/// # let result: Result<usize, ()> = Ok(1);
423+
/// # fn some_function(foo: ()) -> usize { 1 }
424+
/// option.map(|a| a + 1).unwrap_or(0);
425+
/// result.map(|a| a + 1).unwrap_or_else(some_function);
441426
/// ```
442427
///
443-
/// or
444-
///
428+
/// Use instead:
445429
/// ```rust
446-
/// # let x: Result<usize, ()> = Ok(1);
430+
/// # let option = Some(1);
431+
/// # let result: Result<usize, ()> = Ok(1);
447432
/// # fn some_function(foo: ()) -> usize { 1 }
448-
///
449-
/// // Bad
450-
/// x.map(|a| a + 1).unwrap_or_else(some_function);
451-
///
452-
/// // Good
453-
/// x.map_or_else(some_function, |a| a + 1);
433+
/// option.map_or(0, |a| a + 1);
434+
/// result.map_or_else(some_function, |a| a + 1);
454435
/// ```
455436
#[clippy::version = "1.45.0"]
456437
pub MAP_UNWRAP_OR,
@@ -793,13 +774,14 @@ declare_clippy_lint! {
793774
/// # let foo = Some(String::new());
794775
/// foo.unwrap_or(String::new());
795776
/// ```
796-
/// this can instead be written:
777+
///
778+
/// Use instead:
797779
/// ```rust
798780
/// # let foo = Some(String::new());
799781
/// foo.unwrap_or_else(String::new);
800-
/// ```
801-
/// or
802-
/// ```rust
782+
///
783+
/// // or
784+
///
803785
/// # let foo = Some(String::new());
804786
/// foo.unwrap_or_default();
805787
/// ```
@@ -863,15 +845,14 @@ declare_clippy_lint! {
863845
/// # let err_code = "418";
864846
/// # let err_msg = "I'm a teapot";
865847
/// foo.expect(&format!("Err {}: {}", err_code, err_msg));
866-
/// ```
867-
/// or
868-
/// ```rust
848+
///
849+
/// // or
850+
///
869851
/// # let foo = Some(String::new());
870-
/// # let err_code = "418";
871-
/// # let err_msg = "I'm a teapot";
872852
/// foo.expect(format!("Err {}: {}", err_code, err_msg).as_str());
873853
/// ```
874-
/// this can instead be written:
854+
///
855+
/// Use instead:
875856
/// ```rust
876857
/// # let foo = Some(String::new());
877858
/// # let err_code = "418";

clippy_lints/src/minmax.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ declare_clippy_lint! {
1818
/// the least it hurts readability of the code.
1919
///
2020
/// ### Example
21-
/// ```ignore
21+
/// ```rust,ignore
2222
/// min(0, max(100, x))
23-
/// ```
24-
/// or
25-
/// ```ignore
23+
///
24+
/// // or
25+
///
2626
/// x.max(100).min(0)
2727
/// ```
2828
/// It will always be equal to `0`. Probably the author meant to clamp the value

clippy_lints/src/misc.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,14 @@ declare_clippy_lint! {
103103
/// let x = 1.2331f64;
104104
/// let y = 1.2332f64;
105105
///
106-
/// // Bad
107106
/// if y == 1.23f64 { }
108107
/// if y != x {} // where both are floats
108+
/// ```
109109
///
110-
/// // Good
110+
/// Use instead:
111+
/// ```rust
112+
/// # let x = 1.2331f64;
113+
/// # let y = 1.2332f64;
111114
/// let error_margin = f64::EPSILON; // Use an epsilon for comparison
112115
/// // Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead.
113116
/// // let error_margin = std::f64::EPSILON;
@@ -258,10 +261,13 @@ declare_clippy_lint! {
258261
/// let x: f64 = 1.0;
259262
/// const ONE: f64 = 1.00;
260263
///
261-
/// // Bad
262264
/// if x == ONE { } // where both are floats
265+
/// ```
263266
///
264-
/// // Good
267+
/// Use instead:
268+
/// ```rust
269+
/// # let x: f64 = 1.0;
270+
/// # const ONE: f64 = 1.00;
265271
/// let error_margin = f64::EPSILON; // Use an epsilon for comparison
266272
/// // Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead.
267273
/// // let error_margin = std::f64::EPSILON;

clippy_lints/src/mutable_debug_assertion.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ declare_clippy_lint! {
2222
/// ### Example
2323
/// ```rust,ignore
2424
/// debug_assert_eq!(vec![3].pop(), Some(3));
25+
///
2526
/// // or
26-
/// fn take_a_mut_parameter(_: &mut u32) -> bool { unimplemented!() }
27-
/// debug_assert!(take_a_mut_parameter(&mut 5));
27+
///
28+
/// # let mut x = 5;
29+
/// # fn takes_a_mut_parameter(_: &mut u32) -> bool { unimplemented!() }
30+
/// debug_assert!(takes_a_mut_parameter(&mut x));
2831
/// ```
2932
#[clippy::version = "1.40.0"]
3033
pub DEBUG_ASSERT_WITH_MUT_CALL,

clippy_lints/src/trait_bounds.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ declare_clippy_lint! {
5454
/// fn func<T: Clone + Default>(arg: T) where T: Clone + Default {}
5555
/// ```
5656
///
57-
/// Could be written as:
58-
///
57+
/// Use instead:
5958
/// ```rust
59+
/// # mod hidden {
6060
/// fn func<T: Clone + Default>(arg: T) {}
61-
/// ```
62-
/// or
61+
/// # }
62+
///
63+
/// // or
6364
///
64-
/// ```rust
6565
/// fn func<T>(arg: T) where T: Clone + Default {}
6666
/// ```
6767
#[clippy::version = "1.47.0"]

0 commit comments

Comments
 (0)