mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 05:03:21 +00:00
docs: add more suggestions on how to fix clippy findings to the online lint list.
This commit is contained in:
parent
82e9f5ffa3
commit
88d693918f
8 changed files with 55 additions and 3 deletions
|
@ -22,6 +22,12 @@ use crate::utils::{get_item_name, in_macro, snippet, span_lint, span_lint_and_su
|
|||
/// **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 @@ declare_clippy_lint! {
|
|||
/// // 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 @@ declare_clippy_lint! {
|
|||
/// // 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 @@ declare_clippy_lint! {
|
|||
/// 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 @@ declare_clippy_lint! {
|
|||
/// **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 @@ declare_clippy_lint! {
|
|||
/// ```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 @@ use crate::utils::{span_lint_and_sugg};
|
|||
///
|
||||
/// 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 @@ use crate::utils::{in_macro, match_path_ast, snippet_opt, span_lint_and_then, sp
|
|||
/// ```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 @@ declare_clippy_lint! {
|
|||
///
|
||||
/// **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 @@ declare_clippy_lint! {
|
|||
/// ```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 @@ declare_clippy_lint! {
|
|||
/// ```rust
|
||||
/// print!("Hello {}!\n", name);
|
||||
/// ```
|
||||
/// use println!() instead
|
||||
/// ```rust
|
||||
/// println!("Hello {}!", name);
|
||||
/// ```
|
||||
declare_clippy_lint! {
|
||||
pub PRINT_WITH_NEWLINE,
|
||||
style,
|
||||
|
@ -88,6 +92,10 @@ declare_clippy_lint! {
|
|||
/// ```rust
|
||||
/// println!("{}", "foo");
|
||||
/// ```
|
||||
/// use the literal without formatting:
|
||||
/// ```rust
|
||||
/// println!("foo");
|
||||
/// ```
|
||||
declare_clippy_lint! {
|
||||
pub PRINT_LITERAL,
|
||||
style,
|
||||
|
|
Loading…
Reference in a new issue