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 @@ use crate::utils::{get_item_name, in_macro, snippet, span_lint, span_lint_and_su
|
|||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// if x.len() == 0 { .. }
|
/// if x.len() == 0 { .. }
|
||||||
|
/// if y.len() != 0 { .. }
|
||||||
|
/// ```
|
||||||
|
/// instead use
|
||||||
|
/// ```rust
|
||||||
|
/// if x.len().is_empty() { .. }
|
||||||
|
/// if !y.len().is_empty() { .. }
|
||||||
/// ```
|
/// ```
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
pub LEN_ZERO,
|
pub LEN_ZERO,
|
||||||
|
@ -80,6 +80,10 @@ declare_clippy_lint! {
|
|||||||
/// // with `y` a `Vec` or slice:
|
/// // with `y` a `Vec` or slice:
|
||||||
/// for x in y.iter() { .. }
|
/// for x in y.iter() { .. }
|
||||||
/// ```
|
/// ```
|
||||||
|
/// can be rewritten to
|
||||||
|
/// ```rust
|
||||||
|
/// for x in &y { .. }
|
||||||
|
/// ```
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
pub EXPLICIT_ITER_LOOP,
|
pub EXPLICIT_ITER_LOOP,
|
||||||
style,
|
style,
|
||||||
@ -98,6 +102,10 @@ declare_clippy_lint! {
|
|||||||
/// // with `y` a `Vec` or slice:
|
/// // with `y` a `Vec` or slice:
|
||||||
/// for x in y.into_iter() { .. }
|
/// for x in y.into_iter() { .. }
|
||||||
/// ```
|
/// ```
|
||||||
|
/// can be rewritten to
|
||||||
|
/// ```rust
|
||||||
|
/// for x in y { .. }
|
||||||
|
/// ```
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
pub EXPLICIT_INTO_ITER_LOOP,
|
pub EXPLICIT_INTO_ITER_LOOP,
|
||||||
style,
|
style,
|
||||||
|
@ -93,6 +93,15 @@ declare_clippy_lint! {
|
|||||||
/// false => bar(),
|
/// false => bar(),
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
/// Use if/else instead:
|
||||||
|
/// ```rust
|
||||||
|
/// let condition: bool = true;
|
||||||
|
/// if condition {
|
||||||
|
/// foo();
|
||||||
|
/// } else {
|
||||||
|
/// bar();
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
pub MATCH_BOOL,
|
pub MATCH_BOOL,
|
||||||
style,
|
style,
|
||||||
|
@ -448,7 +448,7 @@ declare_clippy_lint! {
|
|||||||
/// **Known problems:** Does not catch multi-byte unicode characters.
|
/// **Known problems:** Does not catch multi-byte unicode characters.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// `_.split("x")` could be `_.split('x')
|
/// `_.split("x")` could be `_.split('x')`
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
pub SINGLE_CHAR_PATTERN,
|
pub SINGLE_CHAR_PATTERN,
|
||||||
perf,
|
perf,
|
||||||
@ -468,7 +468,7 @@ declare_clippy_lint! {
|
|||||||
/// ```rust,ignore
|
/// ```rust,ignore
|
||||||
/// let c_str = CString::new("foo").unwrap().as_ptr();
|
/// let c_str = CString::new("foo").unwrap().as_ptr();
|
||||||
/// unsafe {
|
/// 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:
|
/// Here `c_str` point to a freed address. The correct use would be:
|
||||||
|
@ -21,6 +21,10 @@ use crate::utils::{span_lint_and_sugg};
|
|||||||
///
|
///
|
||||||
/// let foo = Foo{ bar: bar }
|
/// let foo = Foo{ bar: bar }
|
||||||
/// ```
|
/// ```
|
||||||
|
/// the last line can be simplified to
|
||||||
|
/// ```rust
|
||||||
|
/// let foo = Foo{ bar }
|
||||||
|
/// ```
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
pub REDUNDANT_FIELD_NAMES,
|
pub REDUNDANT_FIELD_NAMES,
|
||||||
style,
|
style,
|
||||||
|
@ -19,6 +19,10 @@ use crate::utils::{in_macro, match_path_ast, snippet_opt, span_lint_and_then, sp
|
|||||||
/// ```rust
|
/// ```rust
|
||||||
/// fn foo(x: usize) { return x; }
|
/// fn foo(x: usize) { return x; }
|
||||||
/// ```
|
/// ```
|
||||||
|
/// simplify to
|
||||||
|
/// ```rust
|
||||||
|
/// fn foo(x: usize) { x }
|
||||||
|
/// ```
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
pub NEEDLESS_RETURN,
|
pub NEEDLESS_RETURN,
|
||||||
style,
|
style,
|
||||||
@ -35,7 +39,16 @@ declare_clippy_lint! {
|
|||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// { let x = ..; x }
|
/// fn foo() -> String {
|
||||||
|
/// let x = String::new();
|
||||||
|
/// x
|
||||||
|
///}
|
||||||
|
/// ```
|
||||||
|
/// instead, use
|
||||||
|
/// ```
|
||||||
|
/// fn foo() -> String {
|
||||||
|
/// String::new()
|
||||||
|
///}
|
||||||
/// ```
|
/// ```
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
pub LET_AND_RETURN,
|
pub LET_AND_RETURN,
|
||||||
|
@ -42,6 +42,10 @@ declare_clippy_lint! {
|
|||||||
/// ```rust
|
/// ```rust
|
||||||
/// let x = x + 1;
|
/// let x = x + 1;
|
||||||
/// ```
|
/// ```
|
||||||
|
/// use different variable name:
|
||||||
|
/// ```rust
|
||||||
|
/// let y = x + 1;
|
||||||
|
/// ```
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
pub SHADOW_REUSE,
|
pub SHADOW_REUSE,
|
||||||
restriction,
|
restriction,
|
||||||
|
@ -35,6 +35,10 @@ declare_clippy_lint! {
|
|||||||
/// ```rust
|
/// ```rust
|
||||||
/// print!("Hello {}!\n", name);
|
/// print!("Hello {}!\n", name);
|
||||||
/// ```
|
/// ```
|
||||||
|
/// use println!() instead
|
||||||
|
/// ```rust
|
||||||
|
/// println!("Hello {}!", name);
|
||||||
|
/// ```
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
pub PRINT_WITH_NEWLINE,
|
pub PRINT_WITH_NEWLINE,
|
||||||
style,
|
style,
|
||||||
@ -88,6 +92,10 @@ declare_clippy_lint! {
|
|||||||
/// ```rust
|
/// ```rust
|
||||||
/// println!("{}", "foo");
|
/// println!("{}", "foo");
|
||||||
/// ```
|
/// ```
|
||||||
|
/// use the literal without formatting:
|
||||||
|
/// ```rust
|
||||||
|
/// println!("foo");
|
||||||
|
/// ```
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
pub PRINT_LITERAL,
|
pub PRINT_LITERAL,
|
||||||
style,
|
style,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user