Improve lint doc consistency

This commit is contained in:
Serial
2022-06-05 15:24:41 -04:00
parent 3e52dee646
commit 9aeed6b9bf
64 changed files with 631 additions and 437 deletions

View File

@@ -14,9 +14,6 @@ declare_clippy_lint! {
/// Will be optimized out by the compiler or should probably be replaced by a /// Will be optimized out by the compiler or should probably be replaced by a
/// `panic!()` or `unreachable!()` /// `panic!()` or `unreachable!()`
/// ///
/// ### Known problems
/// None
///
/// ### Example /// ### Example
/// ```rust,ignore /// ```rust,ignore
/// assert!(false) /// assert!(false)

View File

@@ -24,6 +24,7 @@ declare_clippy_lint! {
/// }; /// };
/// } /// }
/// ``` /// ```
///
/// Use instead: /// Use instead:
/// ```rust /// ```rust
/// async fn foo() {} /// async fn foo() {}

View File

@@ -140,8 +140,6 @@ declare_clippy_lint! {
/// from a memory access perspective but will cause bugs at runtime if they /// from a memory access perspective but will cause bugs at runtime if they
/// are held in such a way. /// are held in such a way.
/// ///
/// ### Known problems
///
/// ### Example /// ### Example
/// ///
/// ```toml /// ```toml

View File

@@ -17,11 +17,12 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// assert_eq!("a".is_empty(), false); /// assert_eq!("a".is_empty(), false);
/// assert_ne!("a".is_empty(), true); /// assert_ne!("a".is_empty(), true);
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// assert!(!"a".is_empty()); /// assert!(!"a".is_empty());
/// ``` /// ```
#[clippy::version = "1.53.0"] #[clippy::version = "1.53.0"]

View File

@@ -18,7 +18,7 @@ declare_clippy_lint! {
/// Dereferencing and then borrowing a reference value has no effect in most cases. /// Dereferencing and then borrowing a reference value has no effect in most cases.
/// ///
/// ### Known problems /// ### Known problems
/// false negative on such code: /// False negative on such code:
/// ``` /// ```
/// let x = &12; /// let x = &12;
/// let addr_x = &x as *const _ as usize; /// let addr_x = &x as *const _ as usize;
@@ -29,17 +29,20 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// fn foo(_x: &str) {}
///
/// let s = &String::new(); /// let s = &String::new();
/// ///
/// // Bad
/// let a: &String = &* s; /// let a: &String = &* s;
/// foo(&*s); /// foo(&*s);
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # fn foo(_x: &str) {}
/// # let s = &String::new();
/// let a: &String = s; /// let a: &String = s;
/// foo(&**s); /// foo(&**s);
///
/// fn foo(_: &str){ }
/// ``` /// ```
#[clippy::version = "1.59.0"] #[clippy::version = "1.59.0"]
pub BORROW_DEREF_REF, pub BORROW_DEREF_REF,

View File

@@ -219,13 +219,16 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// fn fun() -> i32 { 1 } /// fn fun() -> i32 { 1 }
/// let a = fun as i64; /// # let _ =
/// fun as i64;
/// ```
/// ///
/// // Good /// Use instead:
/// fn fun2() -> i32 { 1 } /// ```rust
/// let a = fun2 as usize; /// # fn fun() -> i32 { 1 }
/// # let _ =
/// fun as usize;
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub FN_TO_NUMERIC_CAST, pub FN_TO_NUMERIC_CAST,
@@ -245,17 +248,20 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// fn fn1() -> i16 { /// fn fn1() -> i16 {
/// 1 /// 1
/// }; /// };
/// let _ = fn1 as i32; /// # let _ =
/// fn1 as i32;
/// ```
/// ///
/// // Better: Cast to usize first, then comment with the reason for the truncation /// Use instead:
/// fn fn2() -> i16 { /// ```rust
/// // Cast to usize first, then comment with the reason for the truncation
/// fn fn1() -> i16 {
/// 1 /// 1
/// }; /// };
/// let fn_ptr = fn2 as usize; /// let fn_ptr = fn1 as usize;
/// let fn_ptr_truncated = fn_ptr as i32; /// let fn_ptr_truncated = fn_ptr as i32;
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -277,23 +283,31 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad: fn1 is cast as `usize` /// // fn1 is cast as `usize`
/// fn fn1() -> u16 { /// fn fn1() -> u16 {
/// 1 /// 1
/// }; /// };
/// let _ = fn1 as usize; /// # let _ =
/// fn1 as usize;
/// ```
/// ///
/// // Good: maybe you intended to call the function? /// Use instead:
/// ```rust
/// // maybe you intended to call the function?
/// fn fn2() -> u16 { /// fn fn2() -> u16 {
/// 1 /// 1
/// }; /// };
/// let _ = fn2() as usize; /// # let _ =
/// fn2() as usize;
/// ///
/// // Good: maybe you intended to cast it to a function type? /// // or
///
/// // maybe you intended to cast it to a function type?
/// fn fn3() -> u16 { /// fn fn3() -> u16 {
/// 1 /// 1
/// } /// }
/// let _ = fn3 as fn() -> u16; /// # let _ =
/// fn3 as fn() -> u16;
/// ``` /// ```
#[clippy::version = "1.58.0"] #[clippy::version = "1.58.0"]
pub FN_TO_NUMERIC_CAST_ANY, pub FN_TO_NUMERIC_CAST_ANY,

View File

@@ -35,7 +35,6 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
///
/// ```rust,ignore /// ```rust,ignore
/// use std::cmp::Ordering; /// use std::cmp::Ordering;
/// # fn a() {} /// # fn a() {}

View File

@@ -18,10 +18,11 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust,ignore /// ```rust,ignore
/// // Bad
/// dbg!(true) /// dbg!(true)
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust,ignore
/// true /// true
/// ``` /// ```
#[clippy::version = "1.34.0"] #[clippy::version = "1.34.0"]

View File

@@ -18,15 +18,16 @@ declare_clippy_lint! {
/// Checks for literal calls to `Default::default()`. /// Checks for literal calls to `Default::default()`.
/// ///
/// ### Why is this bad? /// ### Why is this bad?
/// It's more clear to the reader to use the name of the type whose default is /// It's easier for the reader if the name of the type is used, rather than the
/// being gotten than the generic `Default`. /// generic `Default`.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// let s: String = Default::default(); /// let s: String = Default::default();
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// let s = String::default(); /// let s = String::default();
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -47,13 +48,13 @@ declare_clippy_lint! {
/// Assignments to patterns that are of tuple type are not linted. /// Assignments to patterns that are of tuple type are not linted.
/// ///
/// ### Example /// ### Example
/// Bad:
/// ``` /// ```
/// # #[derive(Default)] /// # #[derive(Default)]
/// # struct A { i: i32 } /// # struct A { i: i32 }
/// let mut a: A = Default::default(); /// let mut a: A = Default::default();
/// a.i = 42; /// a.i = 42;
/// ``` /// ```
///
/// Use instead: /// Use instead:
/// ``` /// ```
/// # #[derive(Default)] /// # #[derive(Default)]

View File

@@ -30,13 +30,14 @@ declare_clippy_lint! {
/// let a: &mut String = &mut String::from("foo"); /// let a: &mut String = &mut String::from("foo");
/// let b: &str = a.deref(); /// let b: &str = a.deref();
/// ``` /// ```
/// Could be written as: ///
/// Use instead:
/// ```rust /// ```rust
/// let a: &mut String = &mut String::from("foo"); /// let a: &mut String = &mut String::from("foo");
/// let b = &*a; /// let b = &*a;
/// ``` /// ```
/// ///
/// This lint excludes /// This lint excludes:
/// ```rust,ignore /// ```rust,ignore
/// let _ = d.unwrap().deref(); /// let _ = d.unwrap().deref();
/// ``` /// ```
@@ -59,11 +60,13 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// fn fun(_a: &i32) {} /// fn fun(_a: &i32) {}
/// ///
/// // Bad
/// let x: &i32 = &&&&&&5; /// let x: &i32 = &&&&&&5;
/// fun(&x); /// fun(&x);
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # fn fun(_a: &i32) {}
/// let x: &i32 = &5; /// let x: &i32 = &5;
/// fun(x); /// fun(x);
/// ``` /// ```
@@ -82,13 +85,14 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// let x = Some(""); /// let x = Some("");
/// if let Some(ref x) = x { /// if let Some(ref x) = x {
/// // use `x` here /// // use `x` here
/// } /// }
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// let x = Some(""); /// let x = Some("");
/// if let Some(x) = x { /// if let Some(x) = x {
/// // use `&x` here /// // use `&x` here

View File

@@ -30,8 +30,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// ///
/// Could be written as: /// Use instead:
///
/// ```rust /// ```rust
/// #[derive(Default)] /// #[derive(Default)]
/// struct Foo { /// struct Foo {
@@ -45,7 +44,6 @@ declare_clippy_lint! {
/// specialized than what derive will produce. This lint can't detect the manual `impl` /// specialized than what derive will produce. This lint can't detect the manual `impl`
/// has exactly equal bounds, and therefore this lint is disabled for types with /// has exactly equal bounds, and therefore this lint is disabled for types with
/// generic parameters. /// generic parameters.
///
#[clippy::version = "1.57.0"] #[clippy::version = "1.57.0"]
pub DERIVABLE_IMPLS, pub DERIVABLE_IMPLS,
complexity, complexity,

View File

@@ -60,7 +60,8 @@ declare_clippy_lint! {
/// struct BlackForestCake; /// struct BlackForestCake;
/// } /// }
/// ``` /// ```
/// Could be written as: ///
/// Use instead:
/// ```rust /// ```rust
/// mod cake { /// mod cake {
/// struct BlackForest; /// struct BlackForest;

View File

@@ -52,15 +52,13 @@ declare_clippy_lint! {
/// ### Why is this bad? /// ### Why is this bad?
/// It is more idiomatic to dereference the other argument. /// It is more idiomatic to dereference the other argument.
/// ///
/// ### Known problems
/// None
///
/// ### Example /// ### Example
/// ```ignore /// ```rust,ignore
/// // Bad
/// &x == y /// &x == y
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust,ignore
/// x == *y /// x == *y
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]

View File

@@ -34,14 +34,14 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust,ignore /// ```rust,ignore
/// // Bad
/// xs.map(|x| foo(x)) /// xs.map(|x| foo(x))
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust,ignore
/// // where `foo(_)` is a plain function that takes the exact argument type of `x`.
/// xs.map(foo) /// xs.map(foo)
/// ``` /// ```
/// where `foo(_)` is a plain function that takes the exact argument type of
/// `x`.
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub REDUNDANT_CLOSURE, pub REDUNDANT_CLOSURE,
style, style,

View File

@@ -54,12 +54,11 @@ declare_clippy_lint! {
/// API easier to use. /// API easier to use.
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust,ignore /// ```rust,ignore
/// fn f(is_round: bool, is_hot: bool) { ... } /// fn f(is_round: bool, is_hot: bool) { ... }
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust,ignore /// ```rust,ignore
/// enum Shape { /// enum Shape {
/// Round, /// Round,

View File

@@ -45,10 +45,11 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// let _: f32 = 16_777_217.0; // 16_777_216.0 /// let _: f32 = 16_777_217.0; // 16_777_216.0
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// let _: f32 = 16_777_216.0; /// let _: f32 = 16_777_216.0;
/// let _: f64 = 16_777_217.0; /// let _: f64 = 16_777_217.0;
/// ``` /// ```

View File

@@ -76,12 +76,13 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust,ignore /// ```rust,ignore
/// // Bad
/// pub fn foo(x: *const u8) { /// pub fn foo(x: *const u8) {
/// println!("{}", unsafe { *x }); /// println!("{}", unsafe { *x });
/// } /// }
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust,ignore
/// pub unsafe fn foo(x: *const u8) { /// pub unsafe fn foo(x: *const u8) {
/// println!("{}", unsafe { *x }); /// println!("{}", unsafe { *x });
/// } /// }

View File

@@ -20,13 +20,12 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// let x = vec![2, 3, 5]; /// let x = vec![2, 3, 5];
/// let first_element = x.get(0); /// let first_element = x.get(0);
/// ``` /// ```
///
/// Use instead: /// Use instead:
/// ```rust /// ```rust
/// // Good
/// let x = vec![2, 3, 5]; /// let x = vec![2, 3, 5];
/// let first_element = x.first(); /// let first_element = x.first();
/// ``` /// ```

View File

@@ -16,17 +16,15 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// let end: u32 = 10; /// # let mut i: u32 = 0;
/// let start: u32 = 5;
///
/// let mut i: u32 = end - start;
///
/// // Bad
/// if i != 0 { /// if i != 0 {
/// i -= 1; /// i -= 1;
/// } /// }
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # let mut i: u32 = 0;
/// i = i.saturating_sub(1); /// i = i.saturating_sub(1);
/// ``` /// ```
#[clippy::version = "1.44.0"] #[clippy::version = "1.44.0"]
@@ -48,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
// Check if the conditional expression is a binary operation // Check if the conditional expression is a binary operation
if let ExprKind::Binary(ref cond_op, cond_left, cond_right) = cond.kind; if let ExprKind::Binary(ref cond_op, cond_left, cond_right) = cond.kind;
// Ensure that the binary operator is >, != and < // Ensure that the binary operator is >, !=, or <
if BinOpKind::Ne == cond_op.node || BinOpKind::Gt == cond_op.node || BinOpKind::Lt == cond_op.node; if BinOpKind::Ne == cond_op.node || BinOpKind::Gt == cond_op.node || BinOpKind::Lt == cond_op.node;
// Check if assign operation is done // Check if assign operation is done

View File

@@ -17,19 +17,20 @@ declare_clippy_lint! {
/// ### Why is this bad? /// ### Why is this bad?
/// This will always panic at runtime. /// This will always panic at runtime.
/// ///
/// ### Known problems
/// Hopefully none.
///
/// ### Example /// ### Example
/// ```no_run /// ```rust,no_run
/// # #![allow(const_err)] /// # #![allow(const_err)]
/// let x = [1, 2, 3, 4]; /// let x = [1, 2, 3, 4];
/// ///
/// // Bad
/// x[9]; /// x[9];
/// &x[2..9]; /// &x[2..9];
/// ```
///
/// Use instead:
/// ```rust
/// # let x = [1, 2, 3, 4];
/// // Index within bounds
/// ///
/// // Good
/// x[0]; /// x[0];
/// x[3]; /// x[3];
/// ``` /// ```
@@ -49,42 +50,34 @@ declare_clippy_lint! {
/// Indexing and slicing can panic at runtime and there are /// Indexing and slicing can panic at runtime and there are
/// safe alternatives. /// safe alternatives.
/// ///
/// ### Known problems
/// Hopefully none.
///
/// ### Example /// ### Example
/// ```rust,no_run /// ```rust,no_run
/// // Vector /// // Vector
/// let x = vec![0; 5]; /// let x = vec![0; 5];
/// ///
/// // Bad
/// x[2]; /// x[2];
/// &x[2..100]; /// &x[2..100];
/// &x[2..];
/// &x[..100];
///
/// // Good
/// x.get(2);
/// x.get(2..100);
/// x.get(2..);
/// x.get(..100);
/// ///
/// // Array /// // Array
/// let y = [0, 1, 2, 3]; /// let y = [0, 1, 2, 3];
/// ///
/// // Bad
/// &y[10..100]; /// &y[10..100];
/// &y[10..]; /// &y[10..];
/// &y[..100]; /// ```
/// ///
/// // Good /// Use instead:
/// &y[2..]; /// ```rust
/// &y[..2]; /// # let x = vec![0; 5];
/// &y[0..3]; /// # let y = [0, 1, 2, 3];
/// # let _ =
/// x.get(2);
/// # let _ =
/// x.get(2..100);
///
/// # let _ =
/// y.get(10); /// y.get(10);
/// # let _ =
/// y.get(10..100); /// y.get(10..100);
/// y.get(10..);
/// y.get(..100);
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub INDEXING_SLICING, pub INDEXING_SLICING,

View File

@@ -41,6 +41,7 @@ declare_clippy_lint! {
/// ### Example /// ### Example
/// ```rust /// ```rust
/// let infinite_iter = 0..; /// let infinite_iter = 0..;
/// # let _ =
/// [0..].iter().zip(infinite_iter.take_while(|x| *x > 5)); /// [0..].iter().zip(infinite_iter.take_while(|x| *x > 5));
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]

View File

@@ -14,12 +14,8 @@ declare_clippy_lint! {
/// ### Why is this bad? /// ### Why is this bad?
/// This method is also implicitly defined if a type implements the `Display` trait. As the functionality of `Display` is much more versatile, it should be preferred. /// This method is also implicitly defined if a type implements the `Display` trait. As the functionality of `Display` is much more versatile, it should be preferred.
/// ///
/// ### Known problems
/// None
///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// pub struct A; /// pub struct A;
/// ///
/// impl A { /// impl A {
@@ -29,8 +25,8 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// ///
/// Use instead:
/// ```rust /// ```rust
/// // Good
/// use std::fmt; /// use std::fmt;
/// ///
/// pub struct A; /// pub struct A;
@@ -54,12 +50,8 @@ declare_clippy_lint! {
/// ### Why is this bad? /// ### Why is this bad?
/// This method is also implicitly defined if a type implements the `Display` trait. The less versatile inherent method will then shadow the implementation introduced by `Display`. /// This method is also implicitly defined if a type implements the `Display` trait. The less versatile inherent method will then shadow the implementation introduced by `Display`.
/// ///
/// ### Known problems
/// None
///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// use std::fmt; /// use std::fmt;
/// ///
/// pub struct A; /// pub struct A;
@@ -77,8 +69,8 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// ///
/// Use instead:
/// ```rust /// ```rust
/// // Good
/// use std::fmt; /// use std::fmt;
/// ///
/// pub struct A; /// pub struct A;

View File

@@ -21,8 +21,7 @@ declare_clippy_lint! {
/// if x >= y + 1 {} /// if x >= y + 1 {}
/// ``` /// ```
/// ///
/// Could be written as: /// Use instead:
///
/// ```rust /// ```rust
/// # let x = 1; /// # let x = 1;
/// # let y = 1; /// # let y = 1;

View File

@@ -15,11 +15,12 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// let x = 3 / 2; /// let x = 3 / 2;
/// println!("{}", x); /// println!("{}", x);
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// let x = 3f32 / 2f32; /// let x = 3f32 / 2f32;
/// println!("{}", x); /// println!("{}", x);
/// ``` /// ```

View File

@@ -17,7 +17,6 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// fn foo() { /// fn foo() {
/// println!("cake"); /// println!("cake");
/// } /// }
@@ -31,8 +30,8 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// ///
/// Use instead:
/// ```rust /// ```rust
/// // Good
/// fn foo() { /// fn foo() {
/// println!("cake"); /// println!("cake");
/// } /// }

View File

@@ -21,10 +21,11 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust,ignore /// ```rust,ignore
/// // Bad
/// pub const a = [0u32; 1_000_000]; /// pub const a = [0u32; 1_000_000];
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust.ignore
/// pub static a = [0u32; 1_000_000]; /// pub static a = [0u32; 1_000_000];
/// ``` /// ```
#[clippy::version = "1.44.0"] #[clippy::version = "1.44.0"]

View File

@@ -38,12 +38,14 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// enum Test { /// enum Test {
/// A(i32), /// A(i32),
/// B([i32; 8000]), /// B([i32; 8000]),
/// } /// }
/// ```
/// ///
/// Use instead:
/// ```rust
/// // Possibly better /// // Possibly better
/// enum Test2 { /// enum Test2 {
/// A(i32), /// A(i32),

View File

@@ -45,13 +45,11 @@ declare_clippy_lint! {
/// `std::mem::drop` conveys your intention better and is less error-prone. /// `std::mem::drop` conveys your intention better and is less error-prone.
/// ///
/// ### Example /// ### Example
///
/// Bad:
/// ```rust,ignore /// ```rust,ignore
/// let _ = mutex.lock(); /// let _ = mutex.lock();
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust,ignore /// ```rust,ignore
/// let _lock = mutex.lock(); /// let _lock = mutex.lock();
/// ``` /// ```
@@ -75,24 +73,20 @@ declare_clippy_lint! {
/// better and is less error-prone. /// better and is less error-prone.
/// ///
/// ### Example /// ### Example
/// /// ```rust
/// Bad: /// # struct DroppableItem;
/// ```rust,ignore
/// struct Droppable;
/// impl Drop for Droppable {
/// fn drop(&mut self) {}
/// }
/// { /// {
/// let _ = Droppable; /// let _ = DroppableItem;
/// // ^ dropped here /// // ^ dropped here
/// /* more code */ /// /* more code */
/// } /// }
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust,ignore /// ```rust
/// # struct DroppableItem;
/// { /// {
/// let _droppable = Droppable; /// let _droppable = DroppableItem;
/// /* more code */ /// /* more code */
/// // dropped at end of scope /// // dropped at end of scope
/// } /// }

View File

@@ -88,10 +88,11 @@ use rustc_session::Session;
/// /// /// ///
/// /// ### Example /// /// ### Example
/// /// ```rust /// /// ```rust
/// /// // Bad
/// /// Insert a short example of code that triggers the lint /// /// Insert a short example of code that triggers the lint
/// /// ```
/// /// /// ///
/// /// // Good /// /// Use instead:
/// /// ```rust
/// /// Insert a short example of improved code that doesn't trigger the lint /// /// Insert a short example of improved code that doesn't trigger the lint
/// /// ``` /// /// ```
/// pub LINT_NAME, /// pub LINT_NAME,

View File

@@ -36,12 +36,14 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad: unnecessary lifetime annotations /// // Unnecessary lifetime annotations
/// fn in_and_out<'a>(x: &'a u8, y: u8) -> &'a u8 { /// fn in_and_out<'a>(x: &'a u8, y: u8) -> &'a u8 {
/// x /// x
/// } /// }
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// fn elided(x: &u8, y: u8) -> &u8 { /// fn elided(x: &u8, y: u8) -> &u8 {
/// x /// x
/// } /// }
@@ -65,12 +67,14 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad: unnecessary lifetimes /// // unnecessary lifetimes
/// fn unused_lifetime<'a>(x: u8) { /// fn unused_lifetime<'a>(x: u8) {
/// // .. /// // ..
/// } /// }
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// fn no_lifetime(x: u8) { /// fn no_lifetime(x: u8) {
/// // ... /// // ...
/// } /// }

View File

@@ -22,11 +22,16 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad /// # let _: u64 =
/// let x: u64 = 61864918973511; /// 61864918973511
/// # ;
/// ```
/// ///
/// // Good /// Use instead:
/// let x: u64 = 61_864_918_973_511; /// ```rust
/// # let _: u64 =
/// 61_864_918_973_511
/// # ;
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub UNREADABLE_LITERAL, pub UNREADABLE_LITERAL,
@@ -66,11 +71,16 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad /// # let _: u64 =
/// let x: u64 = 618_64_9189_73_511; /// 618_64_9189_73_511
/// # ;
/// ```
/// ///
/// // Good /// Use instead:
/// let x: u64 = 61_864_918_973_511; /// ```rust
/// # let _: u64 =
/// 61_864_918_973_511
/// # ;
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub INCONSISTENT_DIGIT_GROUPING, pub INCONSISTENT_DIGIT_GROUPING,
@@ -125,9 +135,11 @@ declare_clippy_lint! {
/// readable than a decimal representation. /// readable than a decimal representation.
/// ///
/// ### Example /// ### Example
/// ```text
/// `255` => `0xFF` /// `255` => `0xFF`
/// `65_535` => `0xFFFF` /// `65_535` => `0xFFFF`
/// `4_042_322_160` => `0xF0F0_F0F0` /// `4_042_322_160` => `0xF0F0_F0F0`
/// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub DECIMAL_LITERAL_REPRESENTATION, pub DECIMAL_LITERAL_REPRESENTATION,
restriction, restriction,

View File

@@ -42,7 +42,8 @@ declare_clippy_lint! {
/// dst[i + 64] = src[i]; /// dst[i + 64] = src[i];
/// } /// }
/// ``` /// ```
/// Could be written as: ///
/// Use instead:
/// ```rust /// ```rust
/// # let src = vec![1]; /// # let src = vec![1];
/// # let mut dst = vec![0; 65]; /// # let mut dst = vec![0; 65];
@@ -70,7 +71,8 @@ declare_clippy_lint! {
/// println!("{}", vec[i]); /// println!("{}", vec[i]);
/// } /// }
/// ``` /// ```
/// Could be written as: ///
/// Use instead:
/// ```rust /// ```rust
/// let vec = vec!['a', 'b', 'c']; /// let vec = vec!['a', 'b', 'c'];
/// for i in vec { /// for i in vec {
@@ -103,7 +105,8 @@ declare_clippy_lint! {
/// // .. /// // ..
/// } /// }
/// ``` /// ```
/// can be rewritten to ///
/// Use instead:
/// ```rust /// ```rust
/// # let y = vec![1]; /// # let y = vec![1];
/// for x in &y { /// for x in &y {
@@ -286,7 +289,8 @@ declare_clippy_lint! {
/// i += 1; /// i += 1;
/// } /// }
/// ``` /// ```
/// Could be written as ///
/// Use instead:
/// ```rust /// ```rust
/// # let v = vec![1]; /// # let v = vec![1];
/// # fn bar(bar: usize, baz: usize) {} /// # fn bar(bar: usize, baz: usize) {}
@@ -473,7 +477,7 @@ declare_clippy_lint! {
/// ///
/// ### Why is this bad? /// ### Why is this bad?
/// This kind of operation can be expressed more succinctly with /// This kind of operation can be expressed more succinctly with
/// `vec![item;SIZE]` or `vec.resize(NEW_SIZE, item)` and using these alternatives may also /// `vec![item; SIZE]` or `vec.resize(NEW_SIZE, item)` and using these alternatives may also
/// have better performance. /// have better performance.
/// ///
/// ### Example /// ### Example
@@ -488,7 +492,8 @@ declare_clippy_lint! {
/// vec.push(item2); /// vec.push(item2);
/// } /// }
/// ``` /// ```
/// could be written as ///
/// Use instead:
/// ```rust /// ```rust
/// let item1 = 2; /// let item1 = 2;
/// let item2 = 3; /// let item2 = 3;
@@ -516,7 +521,8 @@ declare_clippy_lint! {
/// println!("{}", item); /// println!("{}", item);
/// } /// }
/// ``` /// ```
/// could be written as ///
/// Use instead:
/// ```rust /// ```rust
/// let item1 = 2; /// let item1 = 2;
/// let item = &item1; /// let item = &item1;

View File

@@ -43,13 +43,16 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// # fn bar(stool: &str) {} /// # fn bar(stool: &str) {}
/// # let x = Some("abc"); /// # let x = Some("abc");
/// // Bad
/// match x { /// match x {
/// Some(ref foo) => bar(foo), /// Some(ref foo) => bar(foo),
/// _ => (), /// _ => (),
/// } /// }
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # fn bar(stool: &str) {}
/// # let x = Some("abc");
/// if let Some(ref foo) = x { /// if let Some(ref foo) = x {
/// bar(foo); /// bar(foo);
/// } /// }
@@ -114,14 +117,15 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust,ignore /// ```rust,ignore
/// // Bad
/// match x { /// match x {
/// &A(ref y) => foo(y), /// &A(ref y) => foo(y),
/// &B => bar(), /// &B => bar(),
/// _ => frob(&x), /// _ => frob(&x),
/// } /// }
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust,ignore
/// match *x { /// match *x {
/// A(ref y) => foo(y), /// A(ref y) => foo(y),
/// B => bar(), /// B => bar(),
@@ -227,13 +231,16 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// let x: Option<()> = None; /// let x: Option<()> = None;
/// ///
/// // Bad
/// let r: Option<&()> = match x { /// let r: Option<&()> = match x {
/// None => None, /// None => None,
/// Some(ref v) => Some(v), /// Some(ref v) => Some(v),
/// }; /// };
/// ```
///
/// Use instead:
/// ```rust
/// let x: Option<()> = None;
/// ///
/// // Good
/// let r: Option<&()> = x.as_ref(); /// let r: Option<&()> = x.as_ref();
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -257,13 +264,16 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// # enum Foo { A(usize), B(usize) } /// # enum Foo { A(usize), B(usize) }
/// # let x = Foo::B(1); /// # let x = Foo::B(1);
/// // Bad
/// match x { /// match x {
/// Foo::A(_) => {}, /// Foo::A(_) => {},
/// _ => {}, /// _ => {},
/// } /// }
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # enum Foo { A(usize), B(usize) }
/// # let x = Foo::B(1);
/// match x { /// match x {
/// Foo::A(_) => {}, /// Foo::A(_) => {},
/// Foo::B(_) => {}, /// Foo::B(_) => {},
@@ -290,14 +300,17 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// # enum Foo { A, B, C } /// # enum Foo { A, B, C }
/// # let x = Foo::B; /// # let x = Foo::B;
/// // Bad
/// match x { /// match x {
/// Foo::A => {}, /// Foo::A => {},
/// Foo::B => {}, /// Foo::B => {},
/// _ => {}, /// _ => {},
/// } /// }
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # enum Foo { A, B, C }
/// # let x = Foo::B;
/// match x { /// match x {
/// Foo::A => {}, /// Foo::A => {},
/// Foo::B => {}, /// Foo::B => {},
@@ -320,14 +333,17 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad /// # let s = "foo";
/// match "foo" { /// match s {
/// "a" => {}, /// "a" => {},
/// "bar" | _ => {}, /// "bar" | _ => {},
/// } /// }
/// ```
/// ///
/// // Good /// Use instead:
/// match "foo" { /// ```rust
/// # let s = "foo";
/// match s {
/// "a" => {}, /// "a" => {},
/// _ => {}, /// _ => {},
/// } /// }
@@ -389,15 +405,17 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// # let a = 1; /// # let a = 1;
/// # let b = 2; /// # let b = 2;
///
/// // Bad
/// match (a, b) { /// match (a, b) {
/// (c, d) => { /// (c, d) => {
/// // useless match /// // useless match
/// } /// }
/// } /// }
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # let a = 1;
/// # let b = 2;
/// let (c, d) = (a, b); /// let (c, d) = (a, b);
/// ``` /// ```
#[clippy::version = "1.43.0"] #[clippy::version = "1.43.0"]
@@ -419,13 +437,16 @@ declare_clippy_lint! {
/// # struct A { a: i32 } /// # struct A { a: i32 }
/// let a = A { a: 5 }; /// let a = A { a: 5 };
/// ///
/// // Bad
/// match a { /// match a {
/// A { a: 5, .. } => {}, /// A { a: 5, .. } => {},
/// _ => {}, /// _ => {},
/// } /// }
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # struct A { a: i32 }
/// # let a = A { a: 5 };
/// match a { /// match a {
/// A { a: 5 } => {}, /// A { a: 5 } => {},
/// _ => {}, /// _ => {},
@@ -509,7 +530,6 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// let x = Some(5); /// let x = Some(5);
/// ///
/// // Bad
/// let a = match x { /// let a = match x {
/// Some(0) => true, /// Some(0) => true,
/// _ => false, /// _ => false,
@@ -520,8 +540,11 @@ declare_clippy_lint! {
/// } else { /// } else {
/// false /// false
/// }; /// };
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// let x = Some(5);
/// let a = matches!(x, Some(0)); /// let a = matches!(x, Some(0));
/// ``` /// ```
#[clippy::version = "1.47.0"] #[clippy::version = "1.47.0"]
@@ -695,19 +718,18 @@ declare_clippy_lint! {
/// let arr = vec![0, 1, 2, 3]; /// let arr = vec![0, 1, 2, 3];
/// let idx = 1; /// let idx = 1;
/// ///
/// // Bad
/// match arr[idx] { /// match arr[idx] {
/// 0 => println!("{}", 0), /// 0 => println!("{}", 0),
/// 1 => println!("{}", 3), /// 1 => println!("{}", 3),
/// _ => {}, /// _ => {},
/// } /// }
/// ``` /// ```
///
/// Use instead: /// Use instead:
/// ```rust, no_run /// ```rust, no_run
/// let arr = vec![0, 1, 2, 3]; /// let arr = vec![0, 1, 2, 3];
/// let idx = 1; /// let idx = 1;
/// ///
/// // Good
/// match arr.get(idx) { /// match arr.get(idx) {
/// Some(0) => println!("{}", 0), /// Some(0) => println!("{}", 0),
/// Some(1) => println!("{}", 3), /// Some(1) => println!("{}", 3),

View File

@@ -124,27 +124,27 @@ declare_clippy_lint! {
/// It's often inefficient to clone all elements of an iterator, when eventually, only some /// It's often inefficient to clone all elements of an iterator, when eventually, only some
/// of them will be consumed. /// of them will be consumed.
/// ///
/// ### Examples
/// ```rust
/// # let vec = vec!["string".to_string()];
///
/// // Bad
/// vec.iter().cloned().take(10);
///
/// // Good
/// vec.iter().take(10).cloned();
///
/// // Bad
/// vec.iter().cloned().last();
///
/// // Good
/// vec.iter().last().cloned();
///
/// ```
/// ### Known Problems /// ### Known Problems
/// This `lint` removes the side of effect of cloning items in the iterator. /// This `lint` removes the side of effect of cloning items in the iterator.
/// A code that relies on that side-effect could fail. /// A code that relies on that side-effect could fail.
/// ///
/// ### Examples
/// ```rust
/// # let vec = vec!["string".to_string()];
/// # let _ =
/// vec.iter().cloned().take(10);
/// # let _ =
/// vec.iter().cloned().last();
/// ```
///
/// Use instead:
/// ```rust
/// # let vec = vec!["string".to_string()];
/// # let _ =
/// vec.iter().take(10).cloned();
/// # let _ =
/// vec.iter().last().cloned();
/// ```
#[clippy::version = "1.59.0"] #[clippy::version = "1.59.0"]
pub ITER_OVEREAGER_CLONED, pub ITER_OVEREAGER_CLONED,
perf, perf,
@@ -342,11 +342,12 @@ declare_clippy_lint! {
/// ### Example /// ### Example
/// ```rust /// ```rust
/// # let x = Ok::<_, ()>(()); /// # let x = Ok::<_, ()>(());
///
/// // Bad
/// x.ok().expect("why did I do this again?"); /// x.ok().expect("why did I do this again?");
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # let x = Ok::<_, ()>(());
/// x.expect("why did I do this again?"); /// x.expect("why did I do this again?");
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -390,12 +391,13 @@ declare_clippy_lint! {
/// ### Examples /// ### Examples
/// ```rust /// ```rust
/// # let x = Some(1); /// # let x = Some(1);
///
/// // Bad
/// x.unwrap_or_else(Default::default); /// x.unwrap_or_else(Default::default);
/// x.unwrap_or_else(u32::default); /// x.unwrap_or_else(u32::default);
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # let x = Some(1);
/// x.unwrap_or_default(); /// x.unwrap_or_default();
/// ``` /// ```
#[clippy::version = "1.56.0"] #[clippy::version = "1.56.0"]
@@ -453,11 +455,12 @@ declare_clippy_lint! {
/// ### Example /// ### Example
/// ```rust /// ```rust
/// # let opt = Some(1); /// # let opt = Some(1);
///
/// // Bad
/// opt.map_or(None, |a| Some(a + 1)); /// opt.map_or(None, |a| Some(a + 1));
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # let opt = Some(1);
/// opt.and_then(|a| Some(a + 1)); /// opt.and_then(|a| Some(a + 1));
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -475,13 +478,12 @@ declare_clippy_lint! {
/// `_.ok()`. /// `_.ok()`.
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust /// ```rust
/// # let r: Result<u32, &str> = Ok(1); /// # let r: Result<u32, &str> = Ok(1);
/// assert_eq!(Some(1), r.map_or(None, Some)); /// assert_eq!(Some(1), r.map_or(None, Some));
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust /// ```rust
/// # let r: Result<u32, &str> = Ok(1); /// # let r: Result<u32, &str> = Ok(1);
/// assert_eq!(Some(1), r.ok()); /// assert_eq!(Some(1), r.ok());
@@ -538,7 +540,8 @@ declare_clippy_lint! {
/// # let vec = vec![1]; /// # let vec = vec![1];
/// vec.iter().filter(|x| **x == 0).next(); /// vec.iter().filter(|x| **x == 0).next();
/// ``` /// ```
/// Could be written as ///
/// Use instead:
/// ```rust /// ```rust
/// # let vec = vec![1]; /// # let vec = vec![1];
/// vec.iter().find(|x| **x == 0); /// vec.iter().find(|x| **x == 0);
@@ -562,7 +565,8 @@ declare_clippy_lint! {
/// # let vec = vec![1]; /// # let vec = vec![1];
/// vec.iter().skip_while(|x| **x == 0).next(); /// vec.iter().skip_while(|x| **x == 0).next();
/// ``` /// ```
/// Could be written as ///
/// Use instead:
/// ```rust /// ```rust
/// # let vec = vec![1]; /// # let vec = vec![1];
/// vec.iter().find(|x| **x != 0); /// vec.iter().find(|x| **x != 0);
@@ -586,11 +590,16 @@ declare_clippy_lint! {
/// let vec = vec![vec![1]]; /// let vec = vec![vec![1]];
/// let opt = Some(5); /// let opt = Some(5);
/// ///
/// // Bad /// # let _ =
/// vec.iter().map(|x| x.iter()).flatten(); /// vec.iter().map(|x| x.iter()).flatten();
/// opt.map(|x| Some(x * 2)).flatten(); /// opt.map(|x| Some(x * 2)).flatten();
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # let vec = vec![vec![1]];
/// # let opt = Some(5);
/// # let _ =
/// vec.iter().flat_map(|x| x.iter()); /// vec.iter().flat_map(|x| x.iter());
/// opt.and_then(|x| Some(x * 2)); /// opt.and_then(|x| Some(x * 2));
/// ``` /// ```
@@ -610,15 +619,16 @@ declare_clippy_lint! {
/// less performant. /// less performant.
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust /// ```rust
/// # let _ =
/// (0_i32..10) /// (0_i32..10)
/// .filter(|n| n.checked_add(1).is_some()) /// .filter(|n| n.checked_add(1).is_some())
/// .map(|n| n.checked_add(1).unwrap()); /// .map(|n| n.checked_add(1).unwrap());
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust /// ```rust
/// # let _ =
/// (0_i32..10).filter_map(|n| n.checked_add(1)); /// (0_i32..10).filter_map(|n| n.checked_add(1));
/// ``` /// ```
#[clippy::version = "1.51.0"] #[clippy::version = "1.51.0"]
@@ -637,14 +647,13 @@ declare_clippy_lint! {
/// less performant. /// less performant.
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust /// ```rust
/// (0_i32..10) /// (0_i32..10)
/// .find(|n| n.checked_add(1).is_some()) /// .find(|n| n.checked_add(1).is_some())
/// .map(|n| n.checked_add(1).unwrap()); /// .map(|n| n.checked_add(1).unwrap());
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust /// ```rust
/// (0_i32..10).find_map(|n| n.checked_add(1)); /// (0_i32..10).find_map(|n| n.checked_add(1));
/// ``` /// ```
@@ -713,16 +722,20 @@ declare_clippy_lint! {
/// ### Example /// ### Example
/// ```rust /// ```rust
/// let vec = vec![1]; /// let vec = vec![1];
/// # let _ =
/// vec.iter().find(|x| **x == 0).is_some(); /// vec.iter().find(|x| **x == 0).is_some();
/// ///
/// let _ = "hello world".find("world").is_none(); /// # let _ =
/// "hello world".find("world").is_none();
/// ``` /// ```
/// Could be written as ///
/// Use instead:
/// ```rust /// ```rust
/// let vec = vec![1]; /// let vec = vec![1];
/// vec.iter().any(|x| *x == 0); /// vec.iter().any(|x| *x == 0);
/// ///
/// let _ = !"hello world".contains("world"); /// # let _ =
/// !"hello world".contains("world");
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub SEARCH_IS_SOME, pub SEARCH_IS_SOME,
@@ -744,7 +757,8 @@ declare_clippy_lint! {
/// let name = "foo"; /// let name = "foo";
/// if name.chars().next() == Some('_') {}; /// if name.chars().next() == Some('_') {};
/// ``` /// ```
/// Could be written as ///
/// Use instead:
/// ```rust /// ```rust
/// let name = "foo"; /// let name = "foo";
/// if name.starts_with('_') {}; /// if name.starts_with('_') {};
@@ -899,10 +913,13 @@ declare_clippy_lint! {
/// # use std::rc::Rc; /// # use std::rc::Rc;
/// let x = Rc::new(1); /// let x = Rc::new(1);
/// ///
/// // Bad
/// x.clone(); /// x.clone();
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # use std::rc::Rc;
/// # let x = Rc::new(1);
/// Rc::clone(&x); /// Rc::clone(&x);
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -1034,11 +1051,13 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust,ignore /// ```rust,ignore
/// // Bad
/// _.split("x"); /// _.split("x");
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust,ignore
/// _.split('x'); /// _.split('x');
/// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub SINGLE_CHAR_PATTERN, pub SINGLE_CHAR_PATTERN,
perf, perf,
@@ -1099,12 +1118,14 @@ declare_clippy_lint! {
/// ### Example /// ### Example
/// ```rust /// ```rust
/// # use std::collections::HashSet; /// # use std::collections::HashSet;
/// // Bad
/// # let mut s = HashSet::new(); /// # let mut s = HashSet::new();
/// # s.insert(1); /// # s.insert(1);
/// let x = s.iter().nth(0); /// let x = s.iter().nth(0);
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # use std::collections::HashSet;
/// # let mut s = HashSet::new(); /// # let mut s = HashSet::new();
/// # s.insert(1); /// # s.insert(1);
/// let x = s.iter().next(); /// let x = s.iter().next();
@@ -1210,11 +1231,12 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// let x = vec![2, 3, 5]; /// let x = vec![2, 3, 5];
/// let last_element = x.get(x.len() - 1); /// let last_element = x.get(x.len() - 1);
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// let x = vec![2, 3, 5]; /// let x = vec![2, 3, 5];
/// let last_element = x.last(); /// let last_element = x.last();
/// ``` /// ```
@@ -1273,10 +1295,14 @@ declare_clippy_lint! {
/// let mut a = vec![1, 2, 3]; /// let mut a = vec![1, 2, 3];
/// let mut b = vec![4, 5, 6]; /// let mut b = vec![4, 5, 6];
/// ///
/// // Bad
/// a.extend(b.drain(..)); /// a.extend(b.drain(..));
/// ```
///
/// Use instead:
/// ```rust
/// let mut a = vec![1, 2, 3];
/// let mut b = vec![4, 5, 6];
/// ///
/// // Good
/// a.append(&mut b); /// a.append(&mut b);
/// ``` /// ```
#[clippy::version = "1.55.0"] #[clippy::version = "1.55.0"]
@@ -1351,11 +1377,12 @@ declare_clippy_lint! {
/// ### Example /// ### Example
/// ```rust /// ```rust
/// # let name = "_"; /// # let name = "_";
///
/// // Bad
/// name.chars().last() == Some('_') || name.chars().next_back() == Some('-'); /// name.chars().last() == Some('_') || name.chars().next_back() == Some('-');
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # let name = "_";
/// name.ends_with('_') || name.ends_with('-'); /// name.ends_with('_') || name.ends_with('-');
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -1401,11 +1428,14 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// let _ = (0..3).fold(false, |acc, x| acc || x > 2); /// # let _ =
/// (0..3).fold(false, |acc, x| acc || x > 2);
/// ``` /// ```
/// This could be written as: ///
/// Use instead:
/// ```rust /// ```rust
/// let _ = (0..3).any(|x| x > 2); /// # let _ =
/// (0..3).any(|x| x > 2);
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub UNNECESSARY_FOLD, pub UNNECESSARY_FOLD,
@@ -1485,11 +1515,14 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad /// # let _ =
/// let _ = (&vec![3, 4, 5]).into_iter(); /// (&vec![3, 4, 5]).into_iter();
/// ```
/// ///
/// // Good /// Use instead:
/// let _ = (&vec![3, 4, 5]).iter(); /// ```rust
/// # let _ =
/// (&vec![3, 4, 5]).iter();
/// ``` /// ```
#[clippy::version = "1.32.0"] #[clippy::version = "1.32.0"]
pub INTO_ITER_ON_REF, pub INTO_ITER_ON_REF,
@@ -1704,13 +1737,14 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// let mut string = String::new(); /// # let mut string = String::new();
/// string.insert_str(0, "R"); /// string.insert_str(0, "R");
/// string.push_str("R"); /// string.push_str("R");
/// ``` /// ```
/// Could be written as ///
/// Use instead:
/// ```rust /// ```rust
/// let mut string = String::new(); /// # let mut string = String::new();
/// string.insert(0, 'R'); /// string.insert(0, 'R');
/// string.push('R'); /// string.push('R');
/// ``` /// ```
@@ -1897,11 +1931,14 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad /// # let _ =
/// let _ = "Hello".bytes().nth(3); /// "Hello".bytes().nth(3);
/// ```
/// ///
/// // Good /// Use instead:
/// let _ = "Hello".as_bytes().get(3); /// ```rust
/// # let _ =
/// "Hello".as_bytes().get(3);
/// ``` /// ```
#[clippy::version = "1.52.0"] #[clippy::version = "1.52.0"]
pub BYTES_NTH, pub BYTES_NTH,
@@ -1945,15 +1982,20 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// let some_vec = vec![0, 1, 2, 3]; /// let some_vec = vec![0, 1, 2, 3];
/// let _ = some_vec.iter().count(); /// # let _ =
/// let _ = &some_vec[..].iter().count(); /// some_vec.iter().count();
/// # let _ =
/// &some_vec[..].iter().count();
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// let some_vec = vec![0, 1, 2, 3]; /// let some_vec = vec![0, 1, 2, 3];
/// let _ = some_vec.len(); /// # let _ =
/// let _ = &some_vec[..].len(); /// some_vec.len();
/// # let _ =
/// &some_vec[..].len();
/// ``` /// ```
#[clippy::version = "1.52.0"] #[clippy::version = "1.52.0"]
pub ITER_COUNT, pub ITER_COUNT,
@@ -1973,16 +2015,17 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad /// # let s = "";
/// let s = "";
/// for x in s.splitn(1, ":") { /// for x in s.splitn(1, ":") {
/// // use x /// // ..
/// } /// }
/// ```
/// ///
/// // Good /// Use instead:
/// let s = ""; /// ```rust
/// # let s = "";
/// for x in s.splitn(2, ":") { /// for x in s.splitn(2, ":") {
/// // use x /// // ..
/// } /// }
/// ``` /// ```
#[clippy::version = "1.54.0"] #[clippy::version = "1.54.0"]
@@ -2000,10 +2043,11 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// let x: String = std::iter::repeat('x').take(10).collect(); /// let x: String = std::iter::repeat('x').take(10).collect();
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// let x: String = "x".repeat(10); /// let x: String = "x".repeat(10);
/// ``` /// ```
#[clippy::version = "1.54.0"] #[clippy::version = "1.54.0"]
@@ -2021,7 +2065,6 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust,ignore /// ```rust,ignore
/// // Bad
/// let s = "key=value=add"; /// let s = "key=value=add";
/// let (key, value) = s.splitn(2, '=').next_tuple()?; /// let (key, value) = s.splitn(2, '=').next_tuple()?;
/// let value = s.splitn(2, '=').nth(1)?; /// let value = s.splitn(2, '=').nth(1)?;
@@ -2030,9 +2073,9 @@ declare_clippy_lint! {
/// let key = parts.next()?; /// let key = parts.next()?;
/// let value = parts.next()?; /// let value = parts.next()?;
/// ``` /// ```
///
/// Use instead: /// Use instead:
/// ```rust,ignore /// ```rust,ignore
/// // Good
/// let s = "key=value=add"; /// let s = "key=value=add";
/// let (key, value) = s.split_once('=')?; /// let (key, value) = s.split_once('=')?;
/// let value = s.split_once('=')?.1; /// let value = s.split_once('=')?.1;
@@ -2057,13 +2100,12 @@ declare_clippy_lint! {
/// that both functions return a lazy iterator. /// that both functions return a lazy iterator.
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// let str = "key=value=add"; /// let str = "key=value=add";
/// let _ = str.splitn(3, '=').next().unwrap(); /// let _ = str.splitn(3, '=').next().unwrap();
/// ``` /// ```
///
/// Use instead: /// Use instead:
/// ```rust /// ```rust
/// // Good
/// let str = "key=value=add"; /// let str = "key=value=add";
/// let _ = str.split('=').next().unwrap(); /// let _ = str.split('=').next().unwrap();
/// ``` /// ```
@@ -2149,7 +2191,8 @@ declare_clippy_lint! {
/// let a = Some(&1); /// let a = Some(&1);
/// let b = a.as_deref(); // goes from Option<&i32> to Option<&i32> /// let b = a.as_deref(); // goes from Option<&i32> to Option<&i32>
/// ``` /// ```
/// Could be written as: ///
/// Use instead:
/// ```rust /// ```rust
/// let a = Some(&1); /// let a = Some(&1);
/// let b = a; /// let b = a;

View File

@@ -45,16 +45,13 @@ declare_clippy_lint! {
/// dereferences, e.g., changing `*x` to `x` within the function. /// dereferences, e.g., changing `*x` to `x` within the function.
/// ///
/// ### Example /// ### Example
/// ```rust,ignore /// ```rust
/// // Bad /// fn foo(ref _x: u8) {}
/// fn foo(ref x: u8) -> bool { /// ```
/// true
/// }
/// ///
/// // Good /// Use instead:
/// fn foo(x: &u8) -> bool { /// ```rust
/// true /// fn foo(_x: &u8) {}
/// }
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub TOPLEVEL_REF_ARG, pub TOPLEVEL_REF_ARG,
@@ -73,11 +70,12 @@ declare_clippy_lint! {
/// ### Example /// ### Example
/// ```rust /// ```rust
/// # let x = 1.0; /// # let x = 1.0;
///
/// // Bad
/// if x == f32::NAN { } /// if x == f32::NAN { }
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # let x = 1.0f32;
/// if x.is_nan() { } /// if x.is_nan() { }
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -139,7 +137,8 @@ declare_clippy_lint! {
/// # let y = String::from("foo"); /// # let y = String::from("foo");
/// if x.to_owned() == y {} /// if x.to_owned() == y {}
/// ``` /// ```
/// Could be written as ///
/// Use instead:
/// ```rust /// ```rust
/// # let x = "foo"; /// # let x = "foo";
/// # let y = String::from("foo"); /// # let y = String::from("foo");
@@ -232,10 +231,11 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// let a = 0 as *const u32; /// let a = 0 as *const u32;
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// let a = std::ptr::null::<u32>(); /// let a = std::ptr::null::<u32>();
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]

View File

@@ -34,13 +34,21 @@ declare_clippy_lint! {
/// # } /// # }
/// let f = Foo { a: 0, b: 0, c: 0 }; /// let f = Foo { a: 0, b: 0, c: 0 };
/// ///
/// // Bad
/// match f { /// match f {
/// Foo { a: _, b: 0, .. } => {}, /// Foo { a: _, b: 0, .. } => {},
/// Foo { a: _, b: _, c: _ } => {}, /// Foo { a: _, b: _, c: _ } => {},
/// } /// }
/// ```
///
/// Use instead:
/// ```rust
/// # struct Foo {
/// # a: i32,
/// # b: i32,
/// # c: i32,
/// # }
/// let f = Foo { a: 0, b: 0, c: 0 };
/// ///
/// // Good
/// match f { /// match f {
/// Foo { b: 0, .. } => {}, /// Foo { b: 0, .. } => {},
/// Foo { .. } => {}, /// Foo { .. } => {},
@@ -62,10 +70,11 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// fn foo(a: i32, _a: i32) {} /// fn foo(a: i32, _a: i32) {}
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// fn bar(a: i32, _b: i32) {} /// fn bar(a: i32, _b: i32) {}
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -103,11 +112,16 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad /// # let _ =
/// let y = 0x1a9BAcD; /// 0x1a9BAcD
/// # ;
/// ```
/// ///
/// // Good /// Use instead:
/// let y = 0x1A9BACD; /// ```rust
/// # let _ =
/// 0x1A9BACD
/// # ;
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub MIXED_CASE_HEX_LITERALS, pub MIXED_CASE_HEX_LITERALS,
@@ -127,11 +141,16 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad /// # let _ =
/// let y = 123832i32; /// 123832i32
/// # ;
/// ```
/// ///
/// // Good /// Use instead:
/// let y = 123832_i32; /// ```rust
/// # let _ =
/// 123832_i32
/// # ;
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub UNSEPARATED_LITERAL_SUFFIX, pub UNSEPARATED_LITERAL_SUFFIX,
@@ -150,11 +169,16 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad /// # let _ =
/// let y = 123832_i32; /// 123832_i32
/// # ;
/// ```
/// ///
/// // Good /// Use instead:
/// let y = 123832i32; /// ```rust
/// # let _ =
/// 123832i32
/// # ;
/// ``` /// ```
#[clippy::version = "1.58.0"] #[clippy::version = "1.58.0"]
pub SEPARATED_LITERAL_SUFFIX, pub SEPARATED_LITERAL_SUFFIX,
@@ -234,14 +258,15 @@ declare_clippy_lint! {
/// ### Example /// ### Example
/// ```rust /// ```rust
/// # let v = Some("abc"); /// # let v = Some("abc");
///
/// // Bad
/// match v { /// match v {
/// Some(x) => (), /// Some(x) => (),
/// y @ _ => (), /// y @ _ => (),
/// } /// }
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # let v = Some("abc");
/// match v { /// match v {
/// Some(x) => (), /// Some(x) => (),
/// y => (), /// y => (),
@@ -262,6 +287,7 @@ declare_clippy_lint! {
/// means there are 0 or more elements left. This can make a difference /// means there are 0 or more elements left. This can make a difference
/// when refactoring, but shouldn't result in errors in the refactored code, /// when refactoring, but shouldn't result in errors in the refactored code,
/// since the wildcard pattern isn't used anyway. /// since the wildcard pattern isn't used anyway.
///
/// ### Why is this bad? /// ### Why is this bad?
/// The wildcard pattern is unneeded as the rest pattern /// The wildcard pattern is unneeded as the rest pattern
/// can match that element as well. /// can match that element as well.
@@ -270,13 +296,16 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// # struct TupleStruct(u32, u32, u32); /// # struct TupleStruct(u32, u32, u32);
/// # let t = TupleStruct(1, 2, 3); /// # let t = TupleStruct(1, 2, 3);
/// // Bad
/// match t { /// match t {
/// TupleStruct(0, .., _) => (), /// TupleStruct(0, .., _) => (),
/// _ => (), /// _ => (),
/// } /// }
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # struct TupleStruct(u32, u32, u32);
/// # let t = TupleStruct(1, 2, 3);
/// match t { /// match t {
/// TupleStruct(0, ..) => (), /// TupleStruct(0, ..) => (),
/// _ => (), /// _ => (),

View File

@@ -25,14 +25,16 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// let mut x = 0; /// let mut x = 0;
/// ///
/// // Bad
/// let a = { /// let a = {
/// x = 1; /// x = 1;
/// 1 /// 1
/// } + x; /// } + x;
/// // Unclear whether a is 1 or 2. /// // Unclear whether a is 1 or 2.
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # let mut x = 0;
/// let tmp = { /// let tmp = {
/// x = 1; /// x = 1;
/// 1 /// 1

View File

@@ -16,12 +16,17 @@ declare_clippy_lint! {
/// the value. Also the code misleads about the intent of the call site. /// the value. Also the code misleads about the intent of the call site.
/// ///
/// ### Example /// ### Example
/// ```ignore /// ```rust
/// // Bad /// # let mut vec = Vec::new();
/// my_vec.push(&mut value) /// # let mut value = 5;
/// vec.push(&mut value);
/// ```
/// ///
/// // Good /// Use instead:
/// my_vec.push(&value) /// ```rust
/// # let mut vec = Vec::new();
/// # let value = 5;
/// vec.push(&value);
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub UNNECESSARY_MUT_PASSED, pub UNNECESSARY_MUT_PASSED,

View File

@@ -27,12 +27,13 @@ declare_clippy_lint! {
/// ### Example /// ### Example
/// ```rust /// ```rust
/// # let y = true; /// # let y = true;
///
/// // Bad
/// # use std::sync::Mutex; /// # use std::sync::Mutex;
/// let x = Mutex::new(&y); /// let x = Mutex::new(&y);
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # let y = true;
/// # use std::sync::atomic::AtomicBool; /// # use std::sync::atomic::AtomicBool;
/// let x = AtomicBool::new(y); /// let x = AtomicBool::new(y);
/// ``` /// ```
@@ -60,8 +61,10 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// # use std::sync::Mutex; /// # use std::sync::Mutex;
/// let x = Mutex::new(0usize); /// let x = Mutex::new(0usize);
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # use std::sync::atomic::AtomicUsize; /// # use std::sync::atomic::AtomicUsize;
/// let x = AtomicUsize::new(0usize); /// let x = AtomicUsize::new(0usize);
/// ``` /// ```

View File

@@ -30,16 +30,22 @@ declare_clippy_lint! {
/// shorter code. /// shorter code.
/// ///
/// ### Example /// ### Example
/// ```rust,ignore /// ```rust
/// # let x = true;
/// if x { /// if x {
/// false /// false
/// # ;
/// } else { /// } else {
/// true /// true
/// # ;
/// } /// }
/// ``` /// ```
/// Could be written as ///
/// ```rust,ignore /// Use instead:
/// ```rust
/// # let x = true;
/// !x /// !x
/// # ;
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub NEEDLESS_BOOL, pub NEEDLESS_BOOL,

View File

@@ -27,16 +27,17 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust /// ```rust
/// let mut v = Vec::<String>::new(); /// let mut v = Vec::<String>::new();
/// let _ = v.iter_mut().filter(|&ref a| a.is_empty()); /// # let _ =
/// v.iter_mut().filter(|&ref a| a.is_empty());
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust /// ```rust
/// let mut v = Vec::<String>::new(); /// let mut v = Vec::<String>::new();
/// let _ = v.iter_mut().filter(|a| a.is_empty()); /// # let _ =
/// v.iter_mut().filter(|a| a.is_empty());
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub NEEDLESS_BORROWED_REFERENCE, pub NEEDLESS_BORROWED_REFERENCE,

View File

@@ -24,16 +24,17 @@ declare_clippy_lint! {
/// # z: i32, /// # z: i32,
/// # } /// # }
/// # let zero_point = Point { x: 0, y: 0, z: 0 }; /// # let zero_point = Point { x: 0, y: 0, z: 0 };
///
/// // Bad
/// Point { /// Point {
/// x: 1, /// x: 1,
/// y: 1, /// y: 1,
/// z: 1, /// z: 1,
/// ..zero_point /// ..zero_point
/// }; /// };
/// ```
/// ///
/// // Ok /// Use instead:
/// ```rust,ignore
/// // Missing field `z`
/// Point { /// Point {
/// x: 1, /// x: 1,
/// y: 1, /// y: 1,

View File

@@ -19,17 +19,17 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// let a = 1.0;
/// let b = f64::NAN;
///
/// let not_less_or_equal = !(a <= b);
/// ```
///
/// Use instead:
/// ```rust
/// use std::cmp::Ordering; /// use std::cmp::Ordering;
/// /// # let a = 1.0;
/// // Bad /// # let b = f64::NAN;
/// let a = 1.0;
/// let b = f64::NAN;
///
/// let _not_less_or_equal = !(a <= b);
///
/// // Good
/// let a = 1.0;
/// let b = f64::NAN;
/// ///
/// let _not_less_or_equal = match a.partial_cmp(&b) { /// let _not_less_or_equal = match a.partial_cmp(&b) {
/// None | Some(Ordering::Greater) => true, /// None | Some(Ordering::Greater) => true,

View File

@@ -19,12 +19,13 @@ declare_clippy_lint! {
/// This only catches integers (for now). /// This only catches integers (for now).
/// ///
/// ### Example /// ### Example
/// ```ignore /// ```rust,ignore
/// // Bad
/// let a = x * -1; /// let a = x * -1;
/// ```
/// ///
/// // Good /// Use instead:
/// let b = -x; /// ```rust,ignore
/// let a = -x;
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub NEG_MULTIPLY, pub NEG_MULTIPLY,

View File

@@ -58,12 +58,14 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; /// use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
/// ///
/// // Bad.
/// const CONST_ATOM: AtomicUsize = AtomicUsize::new(12); /// const CONST_ATOM: AtomicUsize = AtomicUsize::new(12);
/// CONST_ATOM.store(6, SeqCst); // the content of the atomic is unchanged /// CONST_ATOM.store(6, SeqCst); // the content of the atomic is unchanged
/// assert_eq!(CONST_ATOM.load(SeqCst), 12); // because the CONST_ATOM in these lines are distinct /// assert_eq!(CONST_ATOM.load(SeqCst), 12); // because the CONST_ATOM in these lines are distinct
/// ```
/// ///
/// // Good. /// Use instead:
/// ```rust
/// # use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
/// static STATIC_ATOM: AtomicUsize = AtomicUsize::new(15); /// static STATIC_ATOM: AtomicUsize = AtomicUsize::new(15);
/// STATIC_ATOM.store(9, SeqCst); /// STATIC_ATOM.store(9, SeqCst);
/// assert_eq!(STATIC_ATOM.load(SeqCst), 9); // use a `static` item to refer to the same instance /// assert_eq!(STATIC_ATOM.load(SeqCst), 9); // use a `static` item to refer to the same instance
@@ -104,11 +106,15 @@ declare_clippy_lint! {
/// use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; /// use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
/// const CONST_ATOM: AtomicUsize = AtomicUsize::new(12); /// const CONST_ATOM: AtomicUsize = AtomicUsize::new(12);
/// ///
/// // Bad.
/// CONST_ATOM.store(6, SeqCst); // the content of the atomic is unchanged /// CONST_ATOM.store(6, SeqCst); // the content of the atomic is unchanged
/// assert_eq!(CONST_ATOM.load(SeqCst), 12); // because the CONST_ATOM in these lines are distinct /// assert_eq!(CONST_ATOM.load(SeqCst), 12); // because the CONST_ATOM in these lines are distinct
/// ```
///
/// Use instead:
/// ```rust
/// use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
/// const CONST_ATOM: AtomicUsize = AtomicUsize::new(12);
/// ///
/// // Good.
/// static STATIC_ATOM: AtomicUsize = CONST_ATOM; /// static STATIC_ATOM: AtomicUsize = CONST_ATOM;
/// STATIC_ATOM.store(9, SeqCst); /// STATIC_ATOM.store(9, SeqCst);
/// assert_eq!(STATIC_ATOM.load(SeqCst), 9); // use a `static` item to refer to the same instance /// assert_eq!(STATIC_ATOM.load(SeqCst), 9); // use a `static` item to refer to the same instance

View File

@@ -33,11 +33,12 @@ declare_clippy_lint! {
/// ///
/// # Example /// # Example
/// ```rust /// ```rust
/// // Bad
/// let one = "\033[1m Bold? \033[0m"; // \033 intended as escape /// let one = "\033[1m Bold? \033[0m"; // \033 intended as escape
/// let two = "\033\0"; // \033 intended as null-3-3 /// let two = "\033\0"; // \033 intended as null-3-3
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// let one = "\x1b[1mWill this be bold?\x1b[0m"; /// let one = "\x1b[1mWill this be bold?\x1b[0m";
/// let two = "\x0033\x00"; /// let two = "\x0033\x00";
/// ``` /// ```

View File

@@ -57,12 +57,11 @@ declare_clippy_lint! {
/// ### Example /// ### Example
/// ///
/// ```rust /// ```rust
/// // Bad
/// fn foo(v: &u32) {} /// fn foo(v: &u32) {}
/// ``` /// ```
/// ///
/// Use instead:
/// ```rust /// ```rust
/// // Better
/// fn foo(v: u32) {} /// fn foo(v: u32) {}
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -89,14 +88,13 @@ declare_clippy_lint! {
/// #[derive(Clone, Copy)] /// #[derive(Clone, Copy)]
/// struct TooLarge([u8; 2048]); /// struct TooLarge([u8; 2048]);
/// ///
/// // Bad
/// fn foo(v: TooLarge) {} /// fn foo(v: TooLarge) {}
/// ``` /// ```
/// ```rust
/// #[derive(Clone, Copy)]
/// struct TooLarge([u8; 2048]);
/// ///
/// // Good /// Use instead:
/// ```rust
/// # #[derive(Clone, Copy)]
/// # struct TooLarge([u8; 2048]);
/// fn foo(v: &TooLarge) {} /// fn foo(v: &TooLarge) {}
/// ``` /// ```
#[clippy::version = "1.49.0"] #[clippy::version = "1.49.0"]

View File

@@ -48,10 +48,11 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```ignore /// ```ignore
/// // Bad
/// fn foo(&Vec<u32>) { .. } /// fn foo(&Vec<u32>) { .. }
/// ```
/// ///
/// // Good /// Use instead:
/// ```ignore
/// fn foo(&[u32]) { .. } /// fn foo(&[u32]) { .. }
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -70,15 +71,18 @@ declare_clippy_lint! {
/// method instead /// method instead
/// ///
/// ### Example /// ### Example
/// ```ignore /// ```rust,ignore
/// // Bad /// use std::ptr;
/// if x == ptr::null {
/// ..
/// }
/// ///
/// // Good /// if x == ptr::null {
/// // ..
/// }
/// ```
///
/// Use instead:
/// ```rust,ignore
/// if x.is_null() { /// if x.is_null() {
/// .. /// // ..
/// } /// }
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -129,12 +133,12 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```ignore /// ```ignore
/// // Bad. Undefined behavior /// // Undefined behavior
/// unsafe { std::slice::from_raw_parts(ptr::null(), 0); } /// unsafe { std::slice::from_raw_parts(ptr::null(), 0); }
/// ``` /// ```
/// ///
/// Use instead:
/// ```ignore /// ```ignore
/// // Good
/// unsafe { std::slice::from_raw_parts(NonNull::dangling().as_ptr(), 0); } /// unsafe { std::slice::from_raw_parts(NonNull::dangling().as_ptr(), 0); }
/// ``` /// ```
#[clippy::version = "1.53.0"] #[clippy::version = "1.53.0"]

View File

@@ -27,11 +27,14 @@ declare_clippy_lint! {
/// ### Example /// ### Example
/// ```rust /// ```rust
/// # let x = vec![1]; /// # let x = vec![1];
/// # let _ =
/// x.iter().zip(0..x.len()); /// x.iter().zip(0..x.len());
/// ``` /// ```
/// Could be written as ///
/// Use instead:
/// ```rust /// ```rust
/// # let x = vec![1]; /// # let x = vec![1];
/// # let _ =
/// x.iter().enumerate(); /// x.iter().enumerate();
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -65,12 +68,21 @@ declare_clippy_lint! {
/// ([#3307](https://github.com/rust-lang/rust-clippy/issues/3307)). /// ([#3307](https://github.com/rust-lang/rust-clippy/issues/3307)).
/// ///
/// ### Example /// ### Example
/// ```rust,ignore /// ```rust
/// for x..(y+1) { .. } /// # let x = 0;
/// # let y = 1;
/// for i in x..(y+1) {
/// // ..
/// }
/// ``` /// ```
/// Could be written as ///
/// ```rust,ignore /// Use instead:
/// for x..=y { .. } /// ```rust
/// # let x = 0;
/// # let y = 1;
/// for i in x..=y {
/// // ..
/// }
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub RANGE_PLUS_ONE, pub RANGE_PLUS_ONE,
@@ -94,12 +106,21 @@ declare_clippy_lint! {
/// ([#3307](https://github.com/rust-lang/rust-clippy/issues/3307)). /// ([#3307](https://github.com/rust-lang/rust-clippy/issues/3307)).
/// ///
/// ### Example /// ### Example
/// ```rust,ignore /// ```rust
/// for x..=(y-1) { .. } /// # let x = 0;
/// # let y = 1;
/// for i in x..=(y-1) {
/// // ..
/// }
/// ``` /// ```
/// Could be written as ///
/// ```rust,ignore /// Use instead:
/// for x..y { .. } /// ```rust
/// # let x = 0;
/// # let y = 1;
/// for i in x..y {
/// // ..
/// }
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub RANGE_MINUS_ONE, pub RANGE_MINUS_ONE,

View File

@@ -23,12 +23,13 @@ declare_clippy_lint! {
/// complexity. /// complexity.
/// ///
/// ### Example /// ### Example
/// ```rust,ignore /// ```rust
/// // Bad /// let a = (|| 42)();
/// let a = (|| 42)() /// ```
/// ///
/// // Good /// Use instead:
/// let a = 42 /// ```rust
/// let a = 42;
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub REDUNDANT_CLOSURE_CALL, pub REDUNDANT_CLOSURE_CALL,

View File

@@ -21,11 +21,12 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust,ignore /// ```rust,ignore
/// // Bad
/// let a = f(*&mut b); /// let a = f(*&mut b);
/// let c = *&d; /// let c = *&d;
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust,ignore
/// let a = f(b); /// let a = f(b);
/// let c = d; /// let c = d;
/// ``` /// ```

View File

@@ -26,19 +26,20 @@ declare_clippy_lint! {
/// if it was added on constructors for example. /// if it was added on constructors for example.
/// ///
/// ### Example /// ### Example
/// Missing attribute
/// ```rust /// ```rust
/// pub struct Bar; /// pub struct Bar;
/// impl Bar { /// impl Bar {
/// // Bad /// // Missing attribute
/// pub fn bar(&self) -> Self { /// pub fn bar(&self) -> Self {
/// Self /// Self
/// } /// }
/// } /// }
/// ``` /// ```
/// ///
/// It's better to have the `#[must_use]` attribute on the method like this: /// Use instead:
/// ```rust /// ```rust
/// # {
/// // It's better to have the `#[must_use]` attribute on the method like this:
/// pub struct Bar; /// pub struct Bar;
/// impl Bar { /// impl Bar {
/// #[must_use] /// #[must_use]
@@ -46,10 +47,10 @@ declare_clippy_lint! {
/// Self /// Self
/// } /// }
/// } /// }
/// ``` /// # }
/// ///
/// Or on the type definition like this: /// # {
/// ```rust /// // Or on the type definition like this:
/// #[must_use] /// #[must_use]
/// pub struct Bar; /// pub struct Bar;
/// impl Bar { /// impl Bar {
@@ -57,6 +58,7 @@ declare_clippy_lint! {
/// Self /// Self
/// } /// }
/// } /// }
/// # }
/// ``` /// ```
#[clippy::version = "1.59.0"] #[clippy::version = "1.59.0"]
pub RETURN_SELF_NOT_MUST_USE, pub RETURN_SELF_NOT_MUST_USE,

View File

@@ -23,10 +23,12 @@ declare_clippy_lint! {
/// ### Example /// ### Example
/// ```rust /// ```rust
/// # let x = 1; /// # let x = 1;
/// // Bad
/// let x = &x; /// let x = &x;
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # let x = 1;
/// let y = &x; // use different variable name /// let y = &x; // use different variable name
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -79,11 +81,14 @@ declare_clippy_lint! {
/// # let y = 1; /// # let y = 1;
/// # let z = 2; /// # let z = 2;
/// let x = y; /// let x = y;
///
/// // Bad
/// let x = z; // shadows the earlier binding /// let x = z; // shadows the earlier binding
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # let y = 1;
/// # let z = 2;
/// let x = y;
/// let w = z; // use different variable name /// let w = z; // use different variable name
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]

View File

@@ -23,15 +23,16 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// # use core::iter::repeat; /// # use core::iter::repeat;
/// # let len = 4; /// # let len = 4;
///
/// // Bad
/// let mut vec1 = Vec::with_capacity(len); /// let mut vec1 = Vec::with_capacity(len);
/// vec1.resize(len, 0); /// vec1.resize(len, 0);
/// ///
/// let mut vec2 = Vec::with_capacity(len); /// let mut vec2 = Vec::with_capacity(len);
/// vec2.extend(repeat(0).take(len)); /// vec2.extend(repeat(0).take(len));
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # let len = 4;
/// let mut vec1 = vec![0; len]; /// let mut vec1 = vec![0; len];
/// let mut vec2 = vec![0; len]; /// let mut vec2 = vec![0; len];
/// ``` /// ```

View File

@@ -99,11 +99,12 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad /// let bstr = "a byte string".as_bytes();
/// let bs = "a byte string".as_bytes(); /// ```
/// ///
/// // Good /// Use instead:
/// let bs = b"a byte string"; /// ```rust
/// let bstr = b"a byte string";
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub STRING_LIT_AS_BYTES, pub STRING_LIT_AS_BYTES,
@@ -223,11 +224,14 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// let _ = std::str::from_utf8(&"Hello World!".as_bytes()[6..11]).unwrap(); /// # let _ =
/// std::str::from_utf8(&"Hello World!".as_bytes()[6..11]).unwrap();
/// ``` /// ```
/// could be written as ///
/// Use instead:
/// ```rust /// ```rust
/// let _ = &"Hello World!"[6..11]; /// # let _ =
/// &"Hello World!"[6..11];
/// ``` /// ```
#[clippy::version = "1.50.0"] #[clippy::version = "1.50.0"]
pub STRING_FROM_UTF8_AS_BYTES, pub STRING_FROM_UTF8_AS_BYTES,

View File

@@ -29,8 +29,7 @@ declare_clippy_lint! {
/// pub fn foo<T>(t: T) where T: Copy, T: Clone {} /// pub fn foo<T>(t: T) where T: Copy, T: Clone {}
/// ``` /// ```
/// ///
/// Could be written as: /// Use instead:
///
/// ```rust /// ```rust
/// pub fn foo<T>(t: T) where T: Copy + Clone {} /// pub fn foo<T>(t: T) where T: Copy + Clone {}
/// ``` /// ```

View File

@@ -41,7 +41,8 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// let x = String::from("€"); /// let x = String::from("€");
/// ``` /// ```
/// Could be written as: ///
/// Use instead:
/// ```rust /// ```rust
/// let x = String::from("\u{20ac}"); /// let x = String::from("\u{20ac}");
/// ``` /// ```

View File

@@ -17,13 +17,14 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// async fn get_random_number() -> i64 { /// async fn get_random_number() -> i64 {
/// 4 // Chosen by fair dice roll. Guaranteed to be random. /// 4 // Chosen by fair dice roll. Guaranteed to be random.
/// } /// }
/// let number_future = get_random_number(); /// let number_future = get_random_number();
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// fn get_random_number_improved() -> i64 { /// fn get_random_number_improved() -> i64 {
/// 4 // Chosen by fair dice roll. Guaranteed to be random. /// 4 // Chosen by fair dice roll. Guaranteed to be random.
/// } /// }

View File

@@ -21,11 +21,12 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// // format!() returns a `String` /// // format!() returns a `String`
/// let s: String = format!("hello").into(); /// let s: String = format!("hello").into();
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// let s: String = format!("hello"); /// let s: String = format!("hello");
/// ``` /// ```
#[clippy::version = "1.45.0"] #[clippy::version = "1.45.0"]

View File

@@ -89,12 +89,11 @@ declare_clippy_lint! {
/// warning/error messages. /// warning/error messages.
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust,ignore /// ```rust,ignore
/// cx.span_lint(LINT_NAME, "message"); /// cx.span_lint(LINT_NAME, "message");
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust,ignore /// ```rust,ignore
/// utils::span_lint(cx, LINT_NAME, "message"); /// utils::span_lint(cx, LINT_NAME, "message");
/// ``` /// ```
@@ -112,12 +111,11 @@ declare_clippy_lint! {
/// `cx.outer_expn_data()` is faster and more concise. /// `cx.outer_expn_data()` is faster and more concise.
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust,ignore /// ```rust,ignore
/// expr.span.ctxt().outer().expn_data() /// expr.span.ctxt().outer().expn_data()
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust,ignore /// ```rust,ignore
/// expr.span.ctxt().outer_expn_data() /// expr.span.ctxt().outer_expn_data()
/// ``` /// ```
@@ -135,7 +133,6 @@ declare_clippy_lint! {
/// ICE in large quantities can damage your teeth /// ICE in large quantities can damage your teeth
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust,ignore /// ```rust,ignore
/// 🍦🍦🍦🍦🍦 /// 🍦🍦🍦🍦🍦
/// ``` /// ```
@@ -153,12 +150,11 @@ declare_clippy_lint! {
/// Indicates that the lint is not finished. /// Indicates that the lint is not finished.
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust,ignore /// ```rust,ignore
/// declare_lint! { pub COOL_LINT, nursery, "default lint description" } /// declare_lint! { pub COOL_LINT, nursery, "default lint description" }
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust,ignore /// ```rust,ignore
/// declare_lint! { pub COOL_LINT, nursery, "a great new lint" } /// declare_lint! { pub COOL_LINT, nursery, "a great new lint" }
/// ``` /// ```
@@ -183,7 +179,6 @@ declare_clippy_lint! {
/// convenient, readable and less error prone. /// convenient, readable and less error prone.
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust,ignore /// ```rust,ignore
/// span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |diag| { /// span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |diag| {
/// diag.span_suggestion( /// diag.span_suggestion(
@@ -207,7 +202,7 @@ declare_clippy_lint! {
/// }); /// });
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust,ignore /// ```rust,ignore
/// span_lint_and_sugg( /// span_lint_and_sugg(
/// cx, /// cx,
@@ -237,12 +232,11 @@ declare_clippy_lint! {
/// `utils::is_type_diagnostic_item()` does not require hardcoded paths. /// `utils::is_type_diagnostic_item()` does not require hardcoded paths.
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust,ignore /// ```rust,ignore
/// utils::match_type(cx, ty, &paths::VEC) /// utils::match_type(cx, ty, &paths::VEC)
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust,ignore /// ```rust,ignore
/// utils::is_type_diagnostic_item(cx, ty, sym::Vec) /// utils::is_type_diagnostic_item(cx, ty, sym::Vec)
/// ``` /// ```
@@ -273,12 +267,11 @@ declare_clippy_lint! {
/// It's faster and easier to use the symbol constant. /// It's faster and easier to use the symbol constant.
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust,ignore /// ```rust,ignore
/// let _ = sym!(f32); /// let _ = sym!(f32);
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust,ignore /// ```rust,ignore
/// let _ = sym::f32; /// let _ = sym::f32;
/// ``` /// ```
@@ -295,12 +288,11 @@ declare_clippy_lint! {
/// It's faster use symbols directly instead of strings. /// It's faster use symbols directly instead of strings.
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust,ignore /// ```rust,ignore
/// symbol.as_str() == "clippy"; /// symbol.as_str() == "clippy";
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust,ignore /// ```rust,ignore
/// symbol == sym::clippy; /// symbol == sym::clippy;
/// ``` /// ```

View File

@@ -28,12 +28,14 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// # fn foo(my_vec: &[u8]) {} /// fn foo(_x: &[u8]) {}
/// ///
/// // Bad
/// foo(&vec![1, 2]); /// foo(&vec![1, 2]);
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # fn foo(_x: &[u8]) {}
/// foo(&[1, 2]); /// foo(&[1, 2]);
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]

View File

@@ -26,13 +26,18 @@ declare_clippy_lint! {
/// still around. /// still around.
/// ///
/// ### Example /// ### Example
/// ```rust,ignore /// ```rust
/// // Bad
/// use std::cmp::Ordering::*; /// use std::cmp::Ordering::*;
/// foo(Less);
/// ///
/// // Good /// # fn foo(_: std::cmp::Ordering) {}
/// foo(Less);
/// ```
///
/// Use instead:
/// ```rust
/// use std::cmp::Ordering; /// use std::cmp::Ordering;
///
/// # fn foo(_: Ordering) {}
/// foo(Ordering::Less) /// foo(Ordering::Less)
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -76,14 +81,13 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust,ignore /// ```rust,ignore
/// // Bad
/// use crate1::*; /// use crate1::*;
/// ///
/// foo(); /// foo();
/// ``` /// ```
/// ///
/// Use instead:
/// ```rust,ignore /// ```rust,ignore
/// // Good
/// use crate1::foo; /// use crate1::foo;
/// ///
/// foo(); /// foo();

View File

@@ -25,10 +25,11 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// println!(""); /// println!("");
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// println!(); /// println!();
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -177,10 +178,15 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// # use std::fmt::Write; /// # use std::fmt::Write;
/// # let mut buf = String::new(); /// # let mut buf = String::new();
/// // Bad /// # let _ =
/// writeln!(buf, ""); /// writeln!(buf, "");
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # use std::fmt::Write;
/// # let mut buf = String::new();
/// # let _ =
/// writeln!(buf); /// writeln!(buf);
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -204,10 +210,16 @@ declare_clippy_lint! {
/// # use std::fmt::Write; /// # use std::fmt::Write;
/// # let mut buf = String::new(); /// # let mut buf = String::new();
/// # let name = "World"; /// # let name = "World";
/// // Bad /// # let _ =
/// write!(buf, "Hello {}!\n", name); /// write!(buf, "Hello {}!\n", name);
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # use std::fmt::Write;
/// # let mut buf = String::new();
/// # let name = "World";
/// # let _ =
/// writeln!(buf, "Hello {}!", name); /// writeln!(buf, "Hello {}!", name);
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@@ -233,10 +245,15 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// # use std::fmt::Write; /// # use std::fmt::Write;
/// # let mut buf = String::new(); /// # let mut buf = String::new();
/// // Bad /// # let _ =
/// writeln!(buf, "{}", "foo"); /// writeln!(buf, "{}", "foo");
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # use std::fmt::Write;
/// # let mut buf = String::new();
/// # let _ =
/// writeln!(buf, "foo"); /// writeln!(buf, "foo");
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]

View File

@@ -14,10 +14,11 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// let nan = 0.0f32 / 0.0; /// let nan = 0.0f32 / 0.0;
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// let nan = f32::NAN; /// let nan = f32::NAN;
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]