Skip to content

Commit e6d92f9

Browse files
authored
Merge pull request #3038 from matthiaskrgr/clippy_docs
docs: add more suggestions on how to fix clippy findings to the online lint list
2 parents b6f0878 + 88d6939 commit e6d92f9

File tree

8 files changed

+55
-3
lines changed

8 files changed

+55
-3
lines changed

clippy_lints/src/len_zero.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ use crate::utils::{get_item_name, in_macro, snippet, span_lint, span_lint_and_su
2222
/// **Example:**
2323
/// ```rust
2424
/// if x.len() == 0 { .. }
25+
/// if y.len() != 0 { .. }
26+
/// ```
27+
/// instead use
28+
/// ```rust
29+
/// if x.len().is_empty() { .. }
30+
/// if !y.len().is_empty() { .. }
2531
/// ```
2632
declare_clippy_lint! {
2733
pub LEN_ZERO,

clippy_lints/src/loops.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ declare_clippy_lint! {
8080
/// // with `y` a `Vec` or slice:
8181
/// for x in y.iter() { .. }
8282
/// ```
83+
/// can be rewritten to
84+
/// ```rust
85+
/// for x in &y { .. }
86+
/// ```
8387
declare_clippy_lint! {
8488
pub EXPLICIT_ITER_LOOP,
8589
style,
@@ -98,6 +102,10 @@ declare_clippy_lint! {
98102
/// // with `y` a `Vec` or slice:
99103
/// for x in y.into_iter() { .. }
100104
/// ```
105+
/// can be rewritten to
106+
/// ```rust
107+
/// for x in y { .. }
108+
/// ```
101109
declare_clippy_lint! {
102110
pub EXPLICIT_INTO_ITER_LOOP,
103111
style,

clippy_lints/src/matches.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ declare_clippy_lint! {
9393
/// false => bar(),
9494
/// }
9595
/// ```
96+
/// Use if/else instead:
97+
/// ```rust
98+
/// let condition: bool = true;
99+
/// if condition {
100+
/// foo();
101+
/// } else {
102+
/// bar();
103+
/// }
104+
/// ```
96105
declare_clippy_lint! {
97106
pub MATCH_BOOL,
98107
style,

clippy_lints/src/methods.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ declare_clippy_lint! {
448448
/// **Known problems:** Does not catch multi-byte unicode characters.
449449
///
450450
/// **Example:**
451-
/// `_.split("x")` could be `_.split('x')
451+
/// `_.split("x")` could be `_.split('x')`
452452
declare_clippy_lint! {
453453
pub SINGLE_CHAR_PATTERN,
454454
perf,
@@ -468,7 +468,7 @@ declare_clippy_lint! {
468468
/// ```rust,ignore
469469
/// let c_str = CString::new("foo").unwrap().as_ptr();
470470
/// unsafe {
471-
/// call_some_ffi_func(c_str);
471+
/// call_some_ffi_func(c_str);
472472
/// }
473473
/// ```
474474
/// Here `c_str` point to a freed address. The correct use would be:

clippy_lints/src/redundant_field_names.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ use crate::utils::{span_lint_and_sugg};
2121
///
2222
/// let foo = Foo{ bar: bar }
2323
/// ```
24+
/// the last line can be simplified to
25+
/// ```rust
26+
/// let foo = Foo{ bar }
27+
/// ```
2428
declare_clippy_lint! {
2529
pub REDUNDANT_FIELD_NAMES,
2630
style,

clippy_lints/src/returns.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ use crate::utils::{in_macro, match_path_ast, snippet_opt, span_lint_and_then, sp
1919
/// ```rust
2020
/// fn foo(x: usize) { return x; }
2121
/// ```
22+
/// simplify to
23+
/// ```rust
24+
/// fn foo(x: usize) { x }
25+
/// ```
2226
declare_clippy_lint! {
2327
pub NEEDLESS_RETURN,
2428
style,
@@ -35,7 +39,16 @@ declare_clippy_lint! {
3539
///
3640
/// **Example:**
3741
/// ```rust
38-
/// { let x = ..; x }
42+
/// fn foo() -> String {
43+
/// let x = String::new();
44+
/// x
45+
///}
46+
/// ```
47+
/// instead, use
48+
/// ```
49+
/// fn foo() -> String {
50+
/// String::new()
51+
///}
3952
/// ```
4053
declare_clippy_lint! {
4154
pub LET_AND_RETURN,

clippy_lints/src/shadow.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ declare_clippy_lint! {
4242
/// ```rust
4343
/// let x = x + 1;
4444
/// ```
45+
/// use different variable name:
46+
/// ```rust
47+
/// let y = x + 1;
48+
/// ```
4549
declare_clippy_lint! {
4650
pub SHADOW_REUSE,
4751
restriction,

clippy_lints/src/write.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ declare_clippy_lint! {
3535
/// ```rust
3636
/// print!("Hello {}!\n", name);
3737
/// ```
38+
/// use println!() instead
39+
/// ```rust
40+
/// println!("Hello {}!", name);
41+
/// ```
3842
declare_clippy_lint! {
3943
pub PRINT_WITH_NEWLINE,
4044
style,
@@ -88,6 +92,10 @@ declare_clippy_lint! {
8892
/// ```rust
8993
/// println!("{}", "foo");
9094
/// ```
95+
/// use the literal without formatting:
96+
/// ```rust
97+
/// println!("foo");
98+
/// ```
9199
declare_clippy_lint! {
92100
pub PRINT_LITERAL,
93101
style,

0 commit comments

Comments
 (0)