Merge pull request #3038 from matthiaskrgr/clippy_docs
docs: add more suggestions on how to fix clippy findings to the online lint list
This commit is contained in:
commit
e6d92f95c6
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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:
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user