diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index b73f912fad5..081450516bb 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -22,6 +22,12 @@ /// **Example:** /// ```rust /// if x.len() == 0 { .. } +/// if y.len() != 0 { .. } +/// ``` +/// instead use +/// ```rust +/// if x.len().is_empty() { .. } +/// if !y.len().is_empty() { .. } /// ``` declare_clippy_lint! { pub LEN_ZERO, diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 61c35dc33b0..6d3134d2206 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -80,6 +80,10 @@ /// // with `y` a `Vec` or slice: /// for x in y.iter() { .. } /// ``` +/// can be rewritten to +/// ```rust +/// for x in &y { .. } +/// ``` declare_clippy_lint! { pub EXPLICIT_ITER_LOOP, style, @@ -98,6 +102,10 @@ /// // with `y` a `Vec` or slice: /// for x in y.into_iter() { .. } /// ``` +/// can be rewritten to +/// ```rust +/// for x in y { .. } +/// ``` declare_clippy_lint! { pub EXPLICIT_INTO_ITER_LOOP, style, diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index c12389a0a1f..d42355f89f4 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -93,6 +93,15 @@ /// false => bar(), /// } /// ``` +/// Use if/else instead: +/// ```rust +/// let condition: bool = true; +/// if condition { +/// foo(); +/// } else { +/// bar(); +/// } +/// ``` declare_clippy_lint! { pub MATCH_BOOL, style, diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index 25a8e73dd03..69df7f2a1c5 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -448,7 +448,7 @@ /// **Known problems:** Does not catch multi-byte unicode characters. /// /// **Example:** -/// `_.split("x")` could be `_.split('x') +/// `_.split("x")` could be `_.split('x')` declare_clippy_lint! { pub SINGLE_CHAR_PATTERN, perf, @@ -468,7 +468,7 @@ /// ```rust,ignore /// let c_str = CString::new("foo").unwrap().as_ptr(); /// unsafe { -/// call_some_ffi_func(c_str); +/// call_some_ffi_func(c_str); /// } /// ``` /// Here `c_str` point to a freed address. The correct use would be: diff --git a/clippy_lints/src/redundant_field_names.rs b/clippy_lints/src/redundant_field_names.rs index c5cf35edabe..ba8b11e55df 100644 --- a/clippy_lints/src/redundant_field_names.rs +++ b/clippy_lints/src/redundant_field_names.rs @@ -21,6 +21,10 @@ /// /// let foo = Foo{ bar: bar } /// ``` +/// the last line can be simplified to +/// ```rust +/// let foo = Foo{ bar } +/// ``` declare_clippy_lint! { pub REDUNDANT_FIELD_NAMES, style, diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 0ede1bc9727..b2202fb1eff 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -19,6 +19,10 @@ /// ```rust /// fn foo(x: usize) { return x; } /// ``` +/// simplify to +/// ```rust +/// fn foo(x: usize) { x } +/// ``` declare_clippy_lint! { pub NEEDLESS_RETURN, style, @@ -35,7 +39,16 @@ /// /// **Example:** /// ```rust -/// { let x = ..; x } +/// fn foo() -> String { +/// let x = String::new(); +/// x +///} +/// ``` +/// instead, use +/// ``` +/// fn foo() -> String { +/// String::new() +///} /// ``` declare_clippy_lint! { pub LET_AND_RETURN, diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index aab578d6344..a6645e19f02 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -42,6 +42,10 @@ /// ```rust /// let x = x + 1; /// ``` +/// use different variable name: +/// ```rust +/// let y = x + 1; +/// ``` declare_clippy_lint! { pub SHADOW_REUSE, restriction, diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index d8bbf0098d2..915ba832833 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -35,6 +35,10 @@ /// ```rust /// print!("Hello {}!\n", name); /// ``` +/// use println!() instead +/// ```rust +/// println!("Hello {}!", name); +/// ``` declare_clippy_lint! { pub PRINT_WITH_NEWLINE, style, @@ -88,6 +92,10 @@ /// ```rust /// println!("{}", "foo"); /// ``` +/// use the literal without formatting: +/// ```rust +/// println!("foo"); +/// ``` declare_clippy_lint! { pub PRINT_LITERAL, style,