1
Fork 0

Set existing doc-tests to no_run

This commit is contained in:
Alex Macleod 2023-10-23 13:49:18 +00:00
parent 56ece10c88
commit 7347c1803f
232 changed files with 989 additions and 989 deletions

View file

@ -774,7 +774,7 @@ Additional dotfiles (files or directories starting with a dot) to allow
## `enforce-iter-loop-reborrow` ## `enforce-iter-loop-reborrow`
#### Example #### Example
``` ```no_run
let mut vec = vec![1, 2, 3]; let mut vec = vec![1, 2, 3];
let rmvec = &mut vec; let rmvec = &mut vec;
for _ in rmvec.iter() {} for _ in rmvec.iter() {}
@ -782,7 +782,7 @@ for _ in rmvec.iter_mut() {}
``` ```
Use instead: Use instead:
``` ```no_run
let mut vec = vec![1, 2, 3]; let mut vec = vec![1, 2, 3];
let rmvec = &mut vec; let rmvec = &mut vec;
for _ in &*rmvec {} for _ in &*rmvec {}

View file

@ -24,11 +24,11 @@ declare_clippy_lint! {
/// using absolute paths is the proper way of referencing items in one. /// using absolute paths is the proper way of referencing items in one.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let x = std::f64::consts::PI; /// let x = std::f64::consts::PI;
/// ``` /// ```
/// Use any of the below instead, or anything else: /// Use any of the below instead, or anything else:
/// ```rust /// ```no_run
/// use std::f64; /// use std::f64;
/// use std::f64::consts; /// use std::f64::consts;
/// use std::f64::consts::PI; /// use std::f64::consts::PI;

View file

@ -17,11 +17,11 @@ declare_clippy_lint! {
/// This (`'a'..'z'`) is almost certainly a typo meant to include all letters. /// This (`'a'..'z'`) is almost certainly a typo meant to include all letters.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let _ = 'a'..'z'; /// let _ = 'a'..'z';
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let _ = 'a'..='z'; /// let _ = 'a'..='z';
/// ``` /// ```
#[clippy::version = "1.68.0"] #[clippy::version = "1.68.0"]

View file

@ -24,12 +24,12 @@ declare_clippy_lint! {
/// issue](https://github.com/rust-lang/rust/issues). /// issue](https://github.com/rust-lang/rust/issues).
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let x = 3.14; /// let x = 3.14;
/// let y = 1_f64 / x; /// let y = 1_f64 / x;
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let x = std::f32::consts::PI; /// let x = std::f32::consts::PI;
/// let y = std::f64::consts::FRAC_1_PI; /// let y = std::f64::consts::FRAC_1_PI;
/// ``` /// ```

View file

@ -18,7 +18,7 @@ declare_clippy_lint! {
/// either `T` should be made `Send + Sync` or an `Rc` should be used instead of an `Arc` /// either `T` should be made `Send + Sync` or an `Rc` should be used instead of an `Arc`
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # use std::cell::RefCell; /// # use std::cell::RefCell;
/// # use std::sync::Arc; /// # use std::sync::Arc;
/// ///

View file

@ -15,7 +15,7 @@ declare_clippy_lint! {
/// An await is likely missing. /// An await is likely missing.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// async fn foo() {} /// async fn foo() {}
/// ///
/// fn bar() { /// fn bar() {
@ -26,7 +26,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// async fn foo() {} /// async fn foo() {}
/// ///
/// fn bar() { /// fn bar() {

View file

@ -129,7 +129,7 @@ declare_clippy_lint! {
/// a valid semver. Failing that, the contained information is useless. /// a valid semver. Failing that, the contained information is useless.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// #[deprecated(since = "forever")] /// #[deprecated(since = "forever")]
/// fn something_else() { /* ... */ } /// fn something_else() { /* ... */ }
/// ``` /// ```
@ -156,14 +156,14 @@ declare_clippy_lint! {
/// currently works for basic cases but is not perfect. /// currently works for basic cases but is not perfect.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// #[allow(dead_code)] /// #[allow(dead_code)]
/// ///
/// fn not_quite_good_code() { } /// fn not_quite_good_code() { }
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// // Good (as inner attribute) /// // Good (as inner attribute)
/// #![allow(dead_code)] /// #![allow(dead_code)]
/// ///
@ -198,25 +198,25 @@ declare_clippy_lint! {
/// Does not detect empty lines after doc attributes (e.g. `#[doc = ""]`). /// Does not detect empty lines after doc attributes (e.g. `#[doc = ""]`).
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// /// Some doc comment with a blank line after it. /// /// Some doc comment with a blank line after it.
/// ///
/// fn not_quite_good_code() { } /// fn not_quite_good_code() { }
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// /// Good (no blank line) /// /// Good (no blank line)
/// fn this_is_fine() { } /// fn this_is_fine() { }
/// ``` /// ```
/// ///
/// ```rust /// ```no_run
/// // Good (convert to a regular comment) /// // Good (convert to a regular comment)
/// ///
/// fn this_is_fine_too() { } /// fn this_is_fine_too() { }
/// ``` /// ```
/// ///
/// ```rust /// ```no_run
/// //! Good (convert to a comment on an inner attribute) /// //! Good (convert to a comment on an inner attribute)
/// ///
/// fn this_is_fine_as_well() { } /// fn this_is_fine_as_well() { }
@ -236,12 +236,12 @@ declare_clippy_lint! {
/// These lints should only be enabled on a lint-by-lint basis and with careful consideration. /// These lints should only be enabled on a lint-by-lint basis and with careful consideration.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// #![deny(clippy::restriction)] /// #![deny(clippy::restriction)]
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// #![deny(clippy::as_conversions)] /// #![deny(clippy::as_conversions)]
/// ``` /// ```
#[clippy::version = "1.47.0"] #[clippy::version = "1.47.0"]
@ -265,13 +265,13 @@ declare_clippy_lint! {
/// [#3123](https://github.com/rust-lang/rust-clippy/pull/3123#issuecomment-422321765) /// [#3123](https://github.com/rust-lang/rust-clippy/pull/3123#issuecomment-422321765)
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// #[cfg_attr(rustfmt, rustfmt_skip)] /// #[cfg_attr(rustfmt, rustfmt_skip)]
/// fn main() { } /// fn main() { }
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// #[rustfmt::skip] /// #[rustfmt::skip]
/// fn main() { } /// fn main() { }
/// ``` /// ```
@ -290,13 +290,13 @@ declare_clippy_lint! {
/// by the conditional compilation engine. /// by the conditional compilation engine.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// #[cfg(linux)] /// #[cfg(linux)]
/// fn conditional() { } /// fn conditional() { }
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # mod hidden { /// # mod hidden {
/// #[cfg(target_os = "linux")] /// #[cfg(target_os = "linux")]
/// fn conditional() { } /// fn conditional() { }
@ -325,14 +325,14 @@ declare_clippy_lint! {
/// ensure that others understand the reasoning /// ensure that others understand the reasoning
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// #![feature(lint_reasons)] /// #![feature(lint_reasons)]
/// ///
/// #![allow(clippy::some_lint)] /// #![allow(clippy::some_lint)]
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// #![feature(lint_reasons)] /// #![feature(lint_reasons)]
/// ///
/// #![allow(clippy::some_lint, reason = "False positive rust-lang/rust-clippy#1002020")] /// #![allow(clippy::some_lint, reason = "False positive rust-lang/rust-clippy#1002020")]
@ -352,7 +352,7 @@ declare_clippy_lint! {
/// panicking with the expected message, and not another unrelated panic. /// panicking with the expected message, and not another unrelated panic.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// fn random() -> i32 { 0 } /// fn random() -> i32 { 0 }
/// ///
/// #[should_panic] /// #[should_panic]
@ -363,7 +363,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// fn random() -> i32 { 0 } /// fn random() -> i32 { 0 }
/// ///
/// #[should_panic = "attempt to divide by zero"] /// #[should_panic = "attempt to divide by zero"]
@ -386,13 +386,13 @@ declare_clippy_lint! {
/// If there is only one condition, no need to wrap it into `any` or `all` combinators. /// If there is only one condition, no need to wrap it into `any` or `all` combinators.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// #[cfg(any(unix))] /// #[cfg(any(unix))]
/// pub struct Bar; /// pub struct Bar;
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// #[cfg(unix)] /// #[cfg(unix)]
/// pub struct Bar; /// pub struct Bar;
/// ``` /// ```
@ -412,13 +412,13 @@ declare_clippy_lint! {
/// may cause conditional compilation not work quitely. /// may cause conditional compilation not work quitely.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// #[cfg(features = "some-feature")] /// #[cfg(features = "some-feature")]
/// fn conditional() { } /// fn conditional() { }
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// #[cfg(feature = "some-feature")] /// #[cfg(feature = "some-feature")]
/// fn conditional() { } /// fn conditional() { }
/// ``` /// ```

View file

@ -29,7 +29,7 @@ declare_clippy_lint! {
/// to wrap the `.lock()` call in a block instead of explicitly dropping the guard. /// to wrap the `.lock()` call in a block instead of explicitly dropping the guard.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # use std::sync::Mutex; /// # use std::sync::Mutex;
/// # async fn baz() {} /// # async fn baz() {}
/// async fn foo(x: &Mutex<u32>) { /// async fn foo(x: &Mutex<u32>) {
@ -47,7 +47,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # use std::sync::Mutex; /// # use std::sync::Mutex;
/// # async fn baz() {} /// # async fn baz() {}
/// async fn foo(x: &Mutex<u32>) { /// async fn foo(x: &Mutex<u32>) {
@ -87,7 +87,7 @@ declare_clippy_lint! {
/// to wrap the `.borrow[_mut]()` call in a block instead of explicitly dropping the ref. /// to wrap the `.borrow[_mut]()` call in a block instead of explicitly dropping the ref.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # use std::cell::RefCell; /// # use std::cell::RefCell;
/// # async fn baz() {} /// # async fn baz() {}
/// async fn foo(x: &RefCell<u32>) { /// async fn foo(x: &RefCell<u32>) {
@ -105,7 +105,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # use std::cell::RefCell; /// # use std::cell::RefCell;
/// # async fn baz() {} /// # async fn baz() {}
/// async fn foo(x: &RefCell<u32>) { /// async fn foo(x: &RefCell<u32>) {
@ -151,7 +151,7 @@ declare_clippy_lint! {
/// ] /// ]
/// ``` /// ```
/// ///
/// ```rust /// ```no_run
/// # async fn baz() {} /// # async fn baz() {}
/// struct CustomLockType; /// struct CustomLockType;
/// struct OtherCustomLockType; /// struct OtherCustomLockType;

View file

@ -21,7 +21,7 @@ declare_clippy_lint! {
/// Style, using blocks in the condition makes it hard to read. /// Style, using blocks in the condition makes it hard to read.
/// ///
/// ### Examples /// ### Examples
/// ```rust /// ```no_run
/// # fn somefunc() -> bool { true }; /// # fn somefunc() -> bool { true };
/// if { true } { /* ... */ } /// if { true } { /* ... */ }
/// ///
@ -29,7 +29,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # fn somefunc() -> bool { true }; /// # fn somefunc() -> bool { true };
/// if true { /* ... */ } /// if true { /* ... */ }
/// ///

View file

@ -18,13 +18,13 @@ declare_clippy_lint! {
/// It is shorter to use the equivalent. /// It is shorter to use the equivalent.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// assert_eq!("a".is_empty(), false); /// assert_eq!("a".is_empty(), false);
/// assert_ne!("a".is_empty(), true); /// assert_ne!("a".is_empty(), true);
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// assert!(!"a".is_empty()); /// assert!(!"a".is_empty());
/// ``` /// ```
#[clippy::version = "1.53.0"] #[clippy::version = "1.53.0"]

View file

@ -21,7 +21,7 @@ declare_clippy_lint! {
/// See https://doc.rust-lang.org/std/primitive.bool.html#impl-From%3Cbool%3E /// See https://doc.rust-lang.org/std/primitive.bool.html#impl-From%3Cbool%3E
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # let condition = false; /// # let condition = false;
/// if condition { /// if condition {
/// 1_i64 /// 1_i64
@ -30,12 +30,12 @@ declare_clippy_lint! {
/// }; /// };
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let condition = false; /// # let condition = false;
/// i64::from(condition); /// i64::from(condition);
/// ``` /// ```
/// or /// or
/// ```rust /// ```no_run
/// # let condition = false; /// # let condition = false;
/// condition as i64; /// condition as i64;
/// ``` /// ```

View file

@ -19,7 +19,7 @@ declare_clippy_lint! {
/// ///
/// ### Known problems /// ### Known problems
/// False negative on such code: /// False negative on such code:
/// ``` /// ```no_run
/// let x = &12; /// let x = &12;
/// let addr_x = &x as *const _ as usize; /// let addr_x = &x as *const _ as usize;
/// let addr_y = &&*x as *const _ as usize; // assert ok now, and lint triggered. /// let addr_y = &&*x as *const _ as usize; // assert ok now, and lint triggered.
@ -28,14 +28,14 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let s = &String::new(); /// let s = &String::new();
/// ///
/// let a: &String = &* s; /// let a: &String = &* s;
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let s = &String::new(); /// # let s = &String::new();
/// let a: &String = s; /// let a: &String = s;
/// ``` /// ```

View file

@ -24,11 +24,11 @@ declare_clippy_lint! {
/// [in certain cases](https://nnethercote.github.io/perf-book/standard-library-types.html#box). /// [in certain cases](https://nnethercote.github.io/perf-book/standard-library-types.html#box).
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let x: Box<String> = Box::new(Default::default()); /// let x: Box<String> = Box::new(Default::default());
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let x: Box<String> = Box::default(); /// let x: Box<String> = Box::default();
/// ``` /// ```
#[clippy::version = "1.66.0"] #[clippy::version = "1.66.0"]

View file

@ -45,7 +45,7 @@ declare_clippy_lint! {
/// those places in the code. /// those places in the code.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let x = u64::MAX; /// let x = u64::MAX;
/// x as f64; /// x as f64;
/// ``` /// ```
@ -67,7 +67,7 @@ declare_clippy_lint! {
/// as a one-time check to see where numerical wrapping can arise. /// as a one-time check to see where numerical wrapping can arise.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let y: i8 = -1; /// let y: i8 = -1;
/// y as u128; // will return 18446744073709551615 /// y as u128; // will return 18446744073709551615
/// ``` /// ```
@ -90,13 +90,13 @@ declare_clippy_lint! {
/// checks could be beneficial. /// checks could be beneficial.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// fn as_u8(x: u64) -> u8 { /// fn as_u8(x: u64) -> u8 {
/// x as u8 /// x as u8
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ``` /// ```no_run
/// fn as_u8(x: u64) -> u8 { /// fn as_u8(x: u64) -> u8 {
/// if let Ok(x) = u8::try_from(x) { /// if let Ok(x) = u8::try_from(x) {
/// x /// x
@ -132,7 +132,7 @@ declare_clippy_lint! {
/// example below. /// example below.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// u32::MAX as i32; // will yield a value of `-1` /// u32::MAX as i32; // will yield a value of `-1`
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@ -155,7 +155,7 @@ declare_clippy_lint! {
/// people reading the code to know that the conversion is lossless. /// people reading the code to know that the conversion is lossless.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// fn as_u64(x: u8) -> u64 { /// fn as_u64(x: u8) -> u64 {
/// x as u64 /// x as u64
/// } /// }
@ -163,7 +163,7 @@ declare_clippy_lint! {
/// ///
/// Using `::from` would look like this: /// Using `::from` would look like this:
/// ///
/// ```rust /// ```no_run
/// fn as_u64(x: u8) -> u64 { /// fn as_u64(x: u8) -> u64 {
/// u64::from(x) /// u64::from(x)
/// } /// }
@ -191,14 +191,14 @@ declare_clippy_lint! {
/// intermediate references, raw pointers and trait objects may or may not work. /// intermediate references, raw pointers and trait objects may or may not work.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let _ = 2i32 as i32; /// let _ = 2i32 as i32;
/// let _ = 0.5 as f32; /// let _ = 0.5 as f32;
/// ``` /// ```
/// ///
/// Better: /// Better:
/// ///
/// ```rust /// ```no_run
/// let _ = 2_i32; /// let _ = 2_i32;
/// let _ = 0.5_f32; /// let _ = 0.5_f32;
/// ``` /// ```
@ -223,7 +223,7 @@ declare_clippy_lint! {
/// u64-> u8 -> u16 can be fine. Miri is able to do a more in-depth analysis. /// u64-> u8 -> u16 can be fine. Miri is able to do a more in-depth analysis.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let _ = (&1u8 as *const u8) as *const u16; /// let _ = (&1u8 as *const u8) as *const u16;
/// let _ = (&mut 1u8 as *mut u8) as *mut u16; /// let _ = (&mut 1u8 as *mut u8) as *mut u16;
/// ///
@ -249,13 +249,13 @@ declare_clippy_lint! {
/// Casting to isize also doesn't make sense since there are no signed addresses. /// Casting to isize also doesn't make sense since there are no signed addresses.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// fn fun() -> i32 { 1 } /// fn fun() -> i32 { 1 }
/// let _ = fun as i64; /// let _ = fun as i64;
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # fn fun() -> i32 { 1 } /// # fn fun() -> i32 { 1 }
/// let _ = fun as usize; /// let _ = fun as usize;
/// ``` /// ```
@ -276,7 +276,7 @@ declare_clippy_lint! {
/// a comment) to perform the truncation. /// a comment) to perform the truncation.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// fn fn1() -> i16 { /// fn fn1() -> i16 {
/// 1 /// 1
/// }; /// };
@ -284,7 +284,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// // Cast to usize first, then comment with the reason for the truncation /// // Cast to usize first, then comment with the reason for the truncation
/// fn fn1() -> i16 { /// fn fn1() -> i16 {
/// 1 /// 1
@ -310,7 +310,7 @@ declare_clippy_lint! {
/// pointer casts in your code. /// pointer casts in your code.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// // fn1 is cast as `usize` /// // fn1 is cast as `usize`
/// fn fn1() -> u16 { /// fn fn1() -> u16 {
/// 1 /// 1
@ -319,7 +319,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// // maybe you intended to call the function? /// // maybe you intended to call the function?
/// fn fn2() -> u16 { /// fn fn2() -> u16 {
/// 1 /// 1
@ -378,14 +378,14 @@ declare_clippy_lint! {
/// it cannot accidentally change the pointer's mutability nor cast the pointer to other types like `usize`. /// it cannot accidentally change the pointer's mutability nor cast the pointer to other types like `usize`.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let ptr: *const u32 = &42_u32; /// let ptr: *const u32 = &42_u32;
/// let mut_ptr: *mut u32 = &mut 42_u32; /// let mut_ptr: *mut u32 = &mut 42_u32;
/// let _ = ptr as *const i32; /// let _ = ptr as *const i32;
/// let _ = mut_ptr as *mut i32; /// let _ = mut_ptr as *mut i32;
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let ptr: *const u32 = &42_u32; /// let ptr: *const u32 = &42_u32;
/// let mut_ptr: *mut u32 = &mut 42_u32; /// let mut_ptr: *mut u32 = &mut 42_u32;
/// let _ = ptr.cast::<i32>(); /// let _ = ptr.cast::<i32>();
@ -408,13 +408,13 @@ declare_clippy_lint! {
/// type. /// type.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let ptr: *const u32 = &42_u32; /// let ptr: *const u32 = &42_u32;
/// let mut_ptr = ptr as *mut u32; /// let mut_ptr = ptr as *mut u32;
/// let ptr = mut_ptr as *const u32; /// let ptr = mut_ptr as *const u32;
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let ptr: *const u32 = &42_u32; /// let ptr: *const u32 = &42_u32;
/// let mut_ptr = ptr.cast_mut(); /// let mut_ptr = ptr.cast_mut();
/// let ptr = mut_ptr.cast_const(); /// let ptr = mut_ptr.cast_const();
@ -434,7 +434,7 @@ declare_clippy_lint! {
/// The resulting integral value will not match the value of the variant it came from. /// The resulting integral value will not match the value of the variant it came from.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// enum E { X = 256 }; /// enum E { X = 256 };
/// let _ = E::X as u8; /// let _ = E::X as u8;
/// ``` /// ```
@ -457,7 +457,7 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// // Missing data /// // Missing data
/// ```rust /// ```no_run
/// let a = [1_i32, 2, 3, 4]; /// let a = [1_i32, 2, 3, 4];
/// let p = &a as *const [i32] as *const [u8]; /// let p = &a as *const [i32] as *const [u8];
/// unsafe { /// unsafe {
@ -465,7 +465,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// // Undefined Behavior (note: also potential alignment issues) /// // Undefined Behavior (note: also potential alignment issues)
/// ```rust /// ```no_run
/// let a = [1_u8, 2, 3, 4]; /// let a = [1_u8, 2, 3, 4];
/// let p = &a as *const [u8] as *const [u32]; /// let p = &a as *const [u8] as *const [u32];
/// unsafe { /// unsafe {
@ -473,7 +473,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Instead use `ptr::slice_from_raw_parts` to construct a slice from a data pointer and the correct length /// Instead use `ptr::slice_from_raw_parts` to construct a slice from a data pointer and the correct length
/// ```rust /// ```no_run
/// let a = [1_i32, 2, 3, 4]; /// let a = [1_i32, 2, 3, 4];
/// let old_ptr = &a as *const [i32]; /// let old_ptr = &a as *const [i32];
/// // The data pointer is cast to a pointer to the target `u8` not `[u8]` /// // The data pointer is cast to a pointer to the target `u8` not `[u8]`
@ -497,7 +497,7 @@ declare_clippy_lint! {
/// The cast is easily confused with casting a c-like enum value to an integer. /// The cast is easily confused with casting a c-like enum value to an integer.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// enum E { X(i32) }; /// enum E { X(i32) };
/// let _ = E::X as usize; /// let _ = E::X as usize;
/// ``` /// ```
@ -515,12 +515,12 @@ declare_clippy_lint! {
/// The `unsigned_abs()` method avoids panic when called on the MIN value. /// The `unsigned_abs()` method avoids panic when called on the MIN value.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let x: i32 = -42; /// let x: i32 = -42;
/// let y: u32 = x.abs() as u32; /// let y: u32 = x.abs() as u32;
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let x: i32 = -42; /// let x: i32 = -42;
/// let y: u32 = x.unsigned_abs(); /// let y: u32 = x.unsigned_abs();
/// ``` /// ```
@ -541,13 +541,13 @@ declare_clippy_lint! {
/// The lint is allowed by default as using `_` is less wordy than always specifying the type. /// The lint is allowed by default as using `_` is less wordy than always specifying the type.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// fn foo(n: usize) {} /// fn foo(n: usize) {}
/// let n: u16 = 256; /// let n: u16 = 256;
/// foo(n as _); /// foo(n as _);
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// fn foo(n: usize) {} /// fn foo(n: usize) {}
/// let n: u16 = 256; /// let n: u16 = 256;
/// foo(n as usize); /// foo(n as usize);
@ -570,7 +570,7 @@ declare_clippy_lint! {
/// Read the `ptr::addr_of` docs for more information. /// Read the `ptr::addr_of` docs for more information.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let val = 1; /// let val = 1;
/// let p = &val as *const i32; /// let p = &val as *const i32;
/// ///
@ -578,7 +578,7 @@ declare_clippy_lint! {
/// let p_mut = &mut val_mut as *mut i32; /// let p_mut = &mut val_mut as *mut i32;
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let val = 1; /// let val = 1;
/// let p = std::ptr::addr_of!(val); /// let p = std::ptr::addr_of!(val);
/// ///
@ -627,13 +627,13 @@ declare_clippy_lint! {
/// mutability is used, making it unlikely that having it as a mutable pointer is correct. /// mutability is used, making it unlikely that having it as a mutable pointer is correct.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let mut vec = Vec::<u8>::with_capacity(1); /// let mut vec = Vec::<u8>::with_capacity(1);
/// let ptr = vec.as_ptr() as *mut u8; /// let ptr = vec.as_ptr() as *mut u8;
/// unsafe { ptr.write(4) }; // UNDEFINED BEHAVIOUR /// unsafe { ptr.write(4) }; // UNDEFINED BEHAVIOUR
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let mut vec = Vec::<u8>::with_capacity(1); /// let mut vec = Vec::<u8>::with_capacity(1);
/// let ptr = vec.as_mut_ptr(); /// let ptr = vec.as_mut_ptr();
/// unsafe { ptr.write(4) }; /// unsafe { ptr.write(4) };
@ -675,12 +675,12 @@ declare_clippy_lint! {
/// {`std`, `core`}`::ptr::`{`null`, `null_mut`}. /// {`std`, `core`}`::ptr::`{`null`, `null_mut`}.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let a = 0 as *const u32; /// let a = 0 as *const u32;
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// 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

@ -19,13 +19,13 @@ declare_clippy_lint! {
/// Reduces the readability of statements & is error prone. /// Reduces the readability of statements & is error prone.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # let foo: u32 = 5; /// # let foo: u32 = 5;
/// foo <= i32::MAX as u32; /// foo <= i32::MAX as u32;
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let foo = 1; /// # let foo = 1;
/// # #[allow(unused)] /// # #[allow(unused)]
/// i32::try_from(foo).is_ok(); /// i32::try_from(foo).is_ok();

View file

@ -32,7 +32,7 @@ declare_clippy_lint! {
/// makes code look more complex than it really is. /// makes code look more complex than it really is.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # let (x, y) = (true, true); /// # let (x, y) = (true, true);
/// if x { /// if x {
/// if y { /// if y {
@ -42,7 +42,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let (x, y) = (true, true); /// # let (x, y) = (true, true);
/// if x && y { /// if x && y {
/// // … /// // …

View file

@ -20,7 +20,7 @@ declare_clippy_lint! {
/// instead. /// instead.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # let samples = vec![3, 1, 2]; /// # let samples = vec![3, 1, 2];
/// let mut sorted_samples = samples.clone(); /// let mut sorted_samples = samples.clone();
/// sorted_samples.sort(); /// sorted_samples.sort();
@ -29,7 +29,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let samples = vec![3, 1, 2]; /// # let samples = vec![3, 1, 2];
/// let mut sorted_samples = samples.clone(); /// let mut sorted_samples = samples.clone();
/// sorted_samples.sort(); /// sorted_samples.sort();

View file

@ -18,7 +18,7 @@ declare_clippy_lint! {
/// https://doc.rust-lang.org/reference/macros-by-example.html#hygiene /// https://doc.rust-lang.org/reference/macros-by-example.html#hygiene
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// #[macro_export] /// #[macro_export]
/// macro_rules! print_message { /// macro_rules! print_message {
/// () => { /// () => {
@ -28,7 +28,7 @@ declare_clippy_lint! {
/// pub const MESSAGE: &str = "Hello!"; /// pub const MESSAGE: &str = "Hello!";
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// #[macro_export] /// #[macro_export]
/// macro_rules! print_message { /// macro_rules! print_message {
/// () => { /// () => {

View file

@ -23,12 +23,12 @@ declare_clippy_lint! {
/// generic `Default`. /// generic `Default`.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let s: String = Default::default(); /// let s: String = Default::default();
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let s = String::default(); /// let s = String::default();
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
@ -49,7 +49,7 @@ 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
/// ``` /// ```no_run
/// # #[derive(Default)] /// # #[derive(Default)]
/// # struct A { i: i32 } /// # struct A { i: i32 }
/// let mut a: A = Default::default(); /// let mut a: A = Default::default();
@ -57,7 +57,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ``` /// ```no_run
/// # #[derive(Default)] /// # #[derive(Default)]
/// # struct A { i: i32 } /// # struct A { i: i32 }
/// let a = A { /// let a = A {

View file

@ -17,7 +17,7 @@ declare_clippy_lint! {
/// This adds code complexity and an unnecessary function call. /// This adds code complexity and an unnecessary function call.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # use std::marker::PhantomData; /// # use std::marker::PhantomData;
/// #[derive(Default)] /// #[derive(Default)]
/// struct S<T> { /// struct S<T> {
@ -29,7 +29,7 @@ declare_clippy_lint! {
/// }; /// };
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # use std::marker::PhantomData; /// # use std::marker::PhantomData;
/// struct S<T> { /// struct S<T> {
/// _marker: PhantomData<T> /// _marker: PhantomData<T>

View file

@ -14,12 +14,12 @@ declare_clippy_lint! {
/// ### Why is this bad? /// ### Why is this bad?
/// `std::iter::empty()` is the more idiomatic way. /// `std::iter::empty()` is the more idiomatic way.
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let _ = std::iter::Empty::<usize>::default(); /// let _ = std::iter::Empty::<usize>::default();
/// let iter: std::iter::Empty<usize> = std::iter::Empty::default(); /// let iter: std::iter::Empty<usize> = std::iter::Empty::default();
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let _ = std::iter::empty::<usize>(); /// let _ = std::iter::empty::<usize>();
/// let iter: std::iter::Empty<usize> = std::iter::empty(); /// let iter: std::iter::Empty<usize> = std::iter::empty();
/// ``` /// ```

View file

@ -31,13 +31,13 @@ declare_clippy_lint! {
/// This lint can only be allowed at the function level or above. /// This lint can only be allowed at the function level or above.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let i = 10; /// let i = 10;
/// let f = 1.23; /// let f = 1.23;
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let i = 10i32; /// let i = 10i32;
/// let f = 1.23f64; /// let f = 1.23f64;
/// ``` /// ```

View file

@ -17,7 +17,7 @@ declare_clippy_lint! {
/// specified layout. These cases may lead to undefined behavior in unsafe blocks. /// specified layout. These cases may lead to undefined behavior in unsafe blocks.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// union Foo { /// union Foo {
/// a: i32, /// a: i32,
/// b: u32, /// b: u32,
@ -30,7 +30,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// #[repr(C)] /// #[repr(C)]
/// union Foo { /// union Foo {
/// a: i32, /// a: i32,

View file

@ -29,14 +29,14 @@ declare_clippy_lint! {
/// when not part of a method chain. /// when not part of a method chain.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// use std::ops::Deref; /// use std::ops::Deref;
/// 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();
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let a: &mut String = &mut String::from("foo"); /// let a: &mut String = &mut String::from("foo");
/// let b = &*a; /// let b = &*a;
/// ``` /// ```
@ -68,7 +68,7 @@ declare_clippy_lint! {
/// in such a case can change the semantics of the code. /// in such a case can change the semantics of the code.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// fn fun(_a: &i32) {} /// fn fun(_a: &i32) {}
/// ///
/// let x: &i32 = &&&&&&5; /// let x: &i32 = &&&&&&5;
@ -76,7 +76,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # fn fun(_a: &i32) {} /// # fn fun(_a: &i32) {}
/// let x: &i32 = &5; /// let x: &i32 = &5;
/// fun(x); /// fun(x);
@ -95,7 +95,7 @@ declare_clippy_lint! {
/// The address-of operator at the use site is clearer about the need for a reference. /// The address-of operator at the use site is clearer about the need for a reference.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let x = Some(""); /// let x = Some("");
/// if let Some(ref x) = x { /// if let Some(ref x) = x {
/// // use `x` here /// // use `x` here
@ -103,7 +103,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let x = Some(""); /// let x = Some("");
/// if let Some(x) = x { /// if let Some(x) = x {
/// // use `&x` here /// // use `&x` here
@ -123,12 +123,12 @@ declare_clippy_lint! {
/// This unnecessarily complicates the code. /// This unnecessarily complicates the code.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let x = String::new(); /// let x = String::new();
/// let y: &str = &*x; /// let y: &str = &*x;
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let x = String::new(); /// let x = String::new();
/// let y: &str = &x; /// let y: &str = &x;
/// ``` /// ```

View file

@ -21,7 +21,7 @@ declare_clippy_lint! {
/// It is less concise. /// It is less concise.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// struct Foo { /// struct Foo {
/// bar: bool /// bar: bool
/// } /// }
@ -36,7 +36,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// #[derive(Default)] /// #[derive(Default)]
/// struct Foo { /// struct Foo {
/// bar: bool /// bar: bool

View file

@ -173,7 +173,7 @@ declare_clippy_lint! {
/// `Eq` themselves. /// `Eq` themselves.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// #[derive(PartialEq)] /// #[derive(PartialEq)]
/// struct Foo { /// struct Foo {
/// i_am_eq: i32, /// i_am_eq: i32,
@ -181,7 +181,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// #[derive(PartialEq, Eq)] /// #[derive(PartialEq, Eq)]
/// struct Foo { /// struct Foo {
/// i_am_eq: i32, /// i_am_eq: i32,

View file

@ -35,7 +35,7 @@ declare_clippy_lint! {
/// { path = "serde::Serialize", reason = "no serializing" }, /// { path = "serde::Serialize", reason = "no serializing" },
/// ] /// ]
/// ``` /// ```
/// ``` /// ```no_run
/// use serde::Serialize; /// use serde::Serialize;
/// ///
/// // Example code where clippy issues a warning /// // Example code where clippy issues a warning

View file

@ -15,7 +15,7 @@ declare_clippy_lint! {
/// avoided. /// avoided.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let foo = 3.14; /// let foo = 3.14;
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]

View file

@ -30,7 +30,7 @@ declare_clippy_lint! {
/// [`non_ascii_idents`]: https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#non-ascii-idents /// [`non_ascii_idents`]: https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#non-ascii-idents
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// // Assuming that `clippy.toml` contains the following line: /// // Assuming that `clippy.toml` contains the following line:
/// // allowed-scripts = ["Latin", "Cyrillic"] /// // allowed-scripts = ["Latin", "Cyrillic"]
/// let counter = 10; // OK, latin is allowed. /// let counter = 10; // OK, latin is allowed.

View file

@ -58,14 +58,14 @@ declare_clippy_lint! {
/// would fail. /// would fail.
/// ///
/// ### Examples /// ### Examples
/// ```rust /// ```no_run
/// /// Do something with the foo_bar parameter. See also /// /// Do something with the foo_bar parameter. See also
/// /// that::other::module::foo. /// /// that::other::module::foo.
/// // ^ `foo_bar` and `that::other::module::foo` should be ticked. /// // ^ `foo_bar` and `that::other::module::foo` should be ticked.
/// fn doit(foo_bar: usize) {} /// fn doit(foo_bar: usize) {}
/// ``` /// ```
/// ///
/// ```rust /// ```no_run
/// // Link text with `[]` brackets should be written as following: /// // Link text with `[]` brackets should be written as following:
/// /// Consume the array and return the inner /// /// Consume the array and return the inner
/// /// [`SmallVec<[T; INLINE_CAPACITY]>`][SmallVec]. /// /// [`SmallVec<[T; INLINE_CAPACITY]>`][SmallVec].
@ -88,7 +88,7 @@ declare_clippy_lint! {
/// preconditions, so that users can be sure they are using them safely. /// preconditions, so that users can be sure they are using them safely.
/// ///
/// ### Examples /// ### Examples
/// ```rust /// ```no_run
///# type Universe = (); ///# type Universe = ();
/// /// This function should really be documented /// /// This function should really be documented
/// pub unsafe fn start_apocalypse(u: &mut Universe) { /// pub unsafe fn start_apocalypse(u: &mut Universe) {
@ -98,7 +98,7 @@ declare_clippy_lint! {
/// ///
/// At least write a line about safety: /// At least write a line about safety:
/// ///
/// ```rust /// ```no_run
///# type Universe = (); ///# type Universe = ();
/// /// # Safety /// /// # Safety
/// /// /// ///
@ -126,7 +126,7 @@ declare_clippy_lint! {
/// Since the following function returns a `Result` it has an `# Errors` section in /// Since the following function returns a `Result` it has an `# Errors` section in
/// its doc comment: /// its doc comment:
/// ///
/// ```rust /// ```no_run
///# use std::io; ///# use std::io;
/// /// # Errors /// /// # Errors
/// /// /// ///
@ -155,7 +155,7 @@ declare_clippy_lint! {
/// Since the following function may panic it has a `# Panics` section in /// Since the following function may panic it has a `# Panics` section in
/// its doc comment: /// its doc comment:
/// ///
/// ```rust /// ```no_run
/// /// # Panics /// /// # Panics
/// /// /// ///
/// /// Will panic if y is 0 /// /// Will panic if y is 0
@ -182,7 +182,7 @@ declare_clippy_lint! {
/// if the `fn main()` is left implicit. /// if the `fn main()` is left implicit.
/// ///
/// ### Examples /// ### Examples
/// ```rust /// ```no_run
/// /// An example of a doctest with a `main()` function /// /// An example of a doctest with a `main()` function
/// /// /// ///
/// /// # Examples /// /// # Examples
@ -210,12 +210,12 @@ declare_clippy_lint! {
/// It is likely a typo when defining an intra-doc link /// It is likely a typo when defining an intra-doc link
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// /// See also: ['foo'] /// /// See also: ['foo']
/// fn bar() {} /// fn bar() {}
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// /// See also: [`foo`] /// /// See also: [`foo`]
/// fn bar() {} /// fn bar() {}
/// ``` /// ```
@ -235,7 +235,7 @@ declare_clippy_lint! {
/// need to describe safety preconditions that users are required to uphold. /// need to describe safety preconditions that users are required to uphold.
/// ///
/// ### Examples /// ### Examples
/// ```rust /// ```no_run
///# type Universe = (); ///# type Universe = ();
/// /// # Safety /// /// # Safety
/// /// /// ///
@ -248,7 +248,7 @@ declare_clippy_lint! {
/// The function is safe, so there shouldn't be any preconditions /// The function is safe, so there shouldn't be any preconditions
/// that have to be explained for safety reasons. /// that have to be explained for safety reasons.
/// ///
/// ```rust /// ```no_run
///# type Universe = (); ///# type Universe = ();
/// /// This function should really be documented /// /// This function should really be documented
/// pub fn start_apocalypse(u: &mut Universe) { /// pub fn start_apocalypse(u: &mut Universe) {

View file

@ -12,7 +12,7 @@ declare_clippy_lint! {
/// mistake. /// mistake.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// fn simple_double_parens() -> i32 { /// fn simple_double_parens() -> i32 {
/// ((0)) /// ((0))
/// } /// }
@ -22,7 +22,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// fn simple_no_parens() -> i32 { /// fn simple_no_parens() -> i32 {
/// 0 /// 0
/// } /// }

View file

@ -16,7 +16,7 @@ declare_clippy_lint! {
/// have been intended. /// have been intended.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// struct Foo; /// struct Foo;
/// let x = Foo; /// let x = Foo;
/// std::mem::drop(x); /// std::mem::drop(x);
@ -36,7 +36,7 @@ declare_clippy_lint! {
/// have been intended. /// have been intended.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// struct Foo; /// struct Foo;
/// let x = Foo; /// let x = Foo;
/// std::mem::forget(x); /// std::mem::forget(x);
@ -57,7 +57,7 @@ declare_clippy_lint! {
/// destructor, possibly causing leaks. /// destructor, possibly causing leaks.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # use std::mem; /// # use std::mem;
/// # use std::rc::Rc; /// # use std::rc::Rc;
/// mem::forget(Rc::new(55)) /// mem::forget(Rc::new(55))

View file

@ -15,7 +15,7 @@ declare_clippy_lint! {
/// Some coding guidelines require this (e.g., MISRA-C:2004 Rule 14.10). /// Some coding guidelines require this (e.g., MISRA-C:2004 Rule 14.10).
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # fn a() {} /// # fn a() {}
/// # fn b() {} /// # fn b() {}
/// # let x: i32 = 1; /// # let x: i32 = 1;
@ -28,7 +28,7 @@ declare_clippy_lint! {
/// ///
/// Use instead: /// Use instead:
/// ///
/// ```rust /// ```no_run
/// # fn a() {} /// # fn a() {}
/// # fn b() {} /// # fn b() {}
/// # let x: i32 = 1; /// # let x: i32 = 1;

View file

@ -16,7 +16,7 @@ declare_clippy_lint! {
/// destructured, which might be the intention behind adding the implementation as a marker. /// destructured, which might be the intention behind adding the implementation as a marker.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// struct S; /// struct S;
/// ///
/// impl Drop for S { /// impl Drop for S {
@ -24,7 +24,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// struct S; /// struct S;
/// ``` /// ```
#[clippy::version = "1.62.0"] #[clippy::version = "1.62.0"]

View file

@ -23,12 +23,12 @@ declare_clippy_lint! {
/// ///
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// enum Test {} /// enum Test {}
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// #![feature(never_type)] /// #![feature(never_type)]
/// ///
/// struct Test(!); /// struct Test(!);

View file

@ -15,11 +15,11 @@ declare_clippy_lint! {
/// Empty brackets after a struct declaration can be omitted. /// Empty brackets after a struct declaration can be omitted.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// struct Cookie {} /// struct Cookie {}
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// struct Cookie; /// struct Cookie;
/// ``` /// ```
#[clippy::version = "1.62.0"] #[clippy::version = "1.62.0"]

View file

@ -23,7 +23,7 @@ declare_clippy_lint! {
/// ///
/// ### Known problems /// ### Known problems
/// The suggestion may have type inference errors in some cases. e.g. /// The suggestion may have type inference errors in some cases. e.g.
/// ```rust /// ```no_run
/// let mut map = std::collections::HashMap::new(); /// let mut map = std::collections::HashMap::new();
/// let _ = if !map.contains_key(&0) { /// let _ = if !map.contains_key(&0) {
/// map.insert(0, 0) /// map.insert(0, 0)
@ -33,7 +33,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # use std::collections::HashMap; /// # use std::collections::HashMap;
/// # let mut map = HashMap::new(); /// # let mut map = HashMap::new();
/// # let k = 1; /// # let k = 1;
@ -43,7 +43,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # use std::collections::HashMap; /// # use std::collections::HashMap;
/// # let mut map = HashMap::new(); /// # let mut map = HashMap::new();
/// # let k = 1; /// # let k = 1;

View file

@ -19,7 +19,7 @@ declare_clippy_lint! {
/// architectures, but works fine on 64 bit. /// architectures, but works fine on 64 bit.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # #[cfg(target_pointer_width = "64")] /// # #[cfg(target_pointer_width = "64")]
/// #[repr(usize)] /// #[repr(usize)]
/// enum NonPortable { /// enum NonPortable {

View file

@ -28,12 +28,12 @@ declare_clippy_lint! {
/// into something. /// into something.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// fn foo(x: Box<u32>) {} /// fn foo(x: Box<u32>) {}
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// fn foo(x: u32) {} /// fn foo(x: u32) {}
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]

View file

@ -22,7 +22,7 @@ declare_clippy_lint! {
/// readability and API. /// readability and API.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// struct S { /// struct S {
/// is_pending: bool, /// is_pending: bool,
/// is_processing: bool, /// is_processing: bool,
@ -31,7 +31,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// enum S { /// enum S {
/// Pending, /// Pending,
/// Processing, /// Processing,

View file

@ -17,14 +17,14 @@ declare_clippy_lint! {
/// disable them by default. /// disable them by default.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// enum Foo { /// enum Foo {
/// Bar, /// Bar,
/// Baz /// Baz
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// #[non_exhaustive] /// #[non_exhaustive]
/// enum Foo { /// enum Foo {
/// Bar, /// Bar,
@ -47,14 +47,14 @@ declare_clippy_lint! {
/// disable them by default. /// disable them by default.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// struct Foo { /// struct Foo {
/// bar: u8, /// bar: u8,
/// baz: String, /// baz: String,
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// #[non_exhaustive] /// #[non_exhaustive]
/// struct Foo { /// struct Foo {
/// bar: u8, /// bar: u8,

View file

@ -17,7 +17,7 @@ declare_clippy_lint! {
/// the main function. /// the main function.
/// ///
/// ### Example /// ### Example
/// ``` /// ```no_run
/// std::process::exit(0) /// std::process::exit(0)
/// ``` /// ```
/// ///

View file

@ -19,7 +19,7 @@ declare_clippy_lint! {
/// Using `(e)println! is clearer and more concise /// Using `(e)println! is clearer and more concise
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # use std::io::Write; /// # use std::io::Write;
/// # let bar = "furchtbar"; /// # let bar = "furchtbar";
/// writeln!(&mut std::io::stderr(), "foo: {:?}", bar).unwrap(); /// writeln!(&mut std::io::stderr(), "foo: {:?}", bar).unwrap();
@ -27,7 +27,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # use std::io::Write; /// # use std::io::Write;
/// # let bar = "furchtbar"; /// # let bar = "furchtbar";
/// eprintln!("foo: {:?}", bar); /// eprintln!("foo: {:?}", bar);

View file

@ -23,13 +23,13 @@ declare_clippy_lint! {
/// requires using a turbofish, which serves no purpose but to satisfy the compiler. /// requires using a turbofish, which serves no purpose but to satisfy the compiler.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// fn unused_ty<T>(x: u8) { /// fn unused_ty<T>(x: u8) {
/// // .. /// // ..
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// fn no_unused_ty(x: u8) { /// fn no_unused_ty(x: u8) {
/// // .. /// // ..
/// } /// }

View file

@ -17,7 +17,7 @@ declare_clippy_lint! {
/// `TryFrom` should be used if there's a possibility of failure. /// `TryFrom` should be used if there's a possibility of failure.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// struct Foo(i32); /// struct Foo(i32);
/// ///
/// impl From<String> for Foo { /// impl From<String> for Foo {
@ -28,7 +28,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// struct Foo(i32); /// struct Foo(i32);
/// ///
/// impl TryFrom<String> for Foo { /// impl TryFrom<String> for Foo {

View file

@ -18,13 +18,13 @@ declare_clippy_lint! {
/// Rust will truncate the literal silently. /// Rust will truncate the literal silently.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let v: f32 = 0.123_456_789_9; /// let v: f32 = 0.123_456_789_9;
/// println!("{}", v); // 0.123_456_789 /// println!("{}", v); // 0.123_456_789
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let v: f64 = 0.123_456_789_9; /// let v: f64 = 0.123_456_789_9;
/// println!("{}", v); // 0.123_456_789_9 /// println!("{}", v); // 0.123_456_789_9
/// ``` /// ```
@ -44,12 +44,12 @@ declare_clippy_lint! {
/// conversion to a float. /// conversion to a float.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let _: f32 = 16_777_217.0; // 16_777_216.0 /// let _: f32 = 16_777_217.0; // 16_777_216.0
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// 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

@ -27,7 +27,7 @@ declare_clippy_lint! {
/// Negatively impacts accuracy. /// Negatively impacts accuracy.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let a = 3f32; /// let a = 3f32;
/// let _ = a.powf(1.0 / 3.0); /// let _ = a.powf(1.0 / 3.0);
/// let _ = (1.0 + a).ln(); /// let _ = (1.0 + a).ln();
@ -35,7 +35,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let a = 3f32; /// let a = 3f32;
/// let _ = a.cbrt(); /// let _ = a.cbrt();
/// let _ = a.ln_1p(); /// let _ = a.ln_1p();
@ -57,7 +57,7 @@ declare_clippy_lint! {
/// Negatively impacts accuracy and performance. /// Negatively impacts accuracy and performance.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// use std::f32::consts::E; /// use std::f32::consts::E;
/// ///
/// let a = 3f32; /// let a = 3f32;
@ -83,7 +83,7 @@ declare_clippy_lint! {
/// ///
/// is better expressed as /// is better expressed as
/// ///
/// ```rust /// ```no_run
/// use std::f32::consts::E; /// use std::f32::consts::E;
/// ///
/// let a = 3f32; /// let a = 3f32;

View file

@ -23,13 +23,13 @@ declare_clippy_lint! {
/// if `foo: &str`. /// if `foo: &str`.
/// ///
/// ### Examples /// ### Examples
/// ```rust /// ```no_run
/// let foo = "foo"; /// let foo = "foo";
/// format!("{}", foo); /// format!("{}", foo);
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let foo = "foo"; /// let foo = "foo";
/// foo.to_owned(); /// foo.to_owned();
/// ``` /// ```

View file

@ -35,12 +35,12 @@ declare_clippy_lint! {
/// The recommended code is both shorter and avoids a temporary allocation. /// The recommended code is both shorter and avoids a temporary allocation.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # use std::panic::Location; /// # use std::panic::Location;
/// println!("error: {}", format!("something failed at {}", Location::caller())); /// println!("error: {}", format!("something failed at {}", Location::caller()));
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # use std::panic::Location; /// # use std::panic::Location;
/// println!("error: something failed at {}", Location::caller()); /// println!("error: something failed at {}", Location::caller());
/// ``` /// ```
@ -61,12 +61,12 @@ declare_clippy_lint! {
/// unnecessary. /// unnecessary.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # use std::panic::Location; /// # use std::panic::Location;
/// println!("error: something failed at {}", Location::caller().to_string()); /// println!("error: something failed at {}", Location::caller().to_string());
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # use std::panic::Location; /// # use std::panic::Location;
/// println!("error: something failed at {}", Location::caller()); /// println!("error: something failed at {}", Location::caller());
/// ``` /// ```
@ -87,7 +87,7 @@ declare_clippy_lint! {
/// The inlined syntax, where allowed, is simpler. /// The inlined syntax, where allowed, is simpler.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # let var = 42; /// # let var = 42;
/// # let width = 1; /// # let width = 1;
/// # let prec = 2; /// # let prec = 2;
@ -98,7 +98,7 @@ declare_clippy_lint! {
/// format!("{:.*}", prec, var); /// format!("{:.*}", prec, var);
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let var = 42; /// # let var = 42;
/// # let width = 1; /// # let width = 1;
/// # let prec = 2; /// # let prec = 2;
@ -111,12 +111,12 @@ declare_clippy_lint! {
/// ///
/// If allow-mixed-uninlined-format-args is set to false in clippy.toml, /// If allow-mixed-uninlined-format-args is set to false in clippy.toml,
/// the following code will also trigger the lint: /// the following code will also trigger the lint:
/// ```rust /// ```no_run
/// # let var = 42; /// # let var = 42;
/// format!("{} {}", var, 1+2); /// format!("{} {}", var, 1+2);
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let var = 42; /// # let var = 42;
/// format!("{var} {}", 1+2); /// format!("{var} {}", 1+2);
/// ``` /// ```
@ -141,13 +141,13 @@ declare_clippy_lint! {
/// an expected formatting operation such as adding padding isn't happening. /// an expected formatting operation such as adding padding isn't happening.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// println!("{:.}", 1.0); /// println!("{:.}", 1.0);
/// ///
/// println!("not padded: {:5}", format_args!("...")); /// println!("not padded: {:5}", format_args!("..."));
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// println!("{}", 1.0); /// println!("{}", 1.0);
/// ///
/// println!("not padded: {}", format_args!("...")); /// println!("not padded: {}", format_args!("..."));

View file

@ -21,7 +21,7 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ///
/// ```rust /// ```no_run
/// use std::fmt; /// use std::fmt;
/// ///
/// struct Structure(i32); /// struct Structure(i32);
@ -33,7 +33,7 @@ declare_clippy_lint! {
/// ///
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// use std::fmt; /// use std::fmt;
/// ///
/// struct Structure(i32); /// struct Structure(i32);
@ -59,7 +59,7 @@ declare_clippy_lint! {
/// should write to the `Formatter`, not stdout/stderr. /// should write to the `Formatter`, not stdout/stderr.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// use std::fmt::{Display, Error, Formatter}; /// use std::fmt::{Display, Error, Formatter};
/// ///
/// struct S; /// struct S;
@ -72,7 +72,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// use std::fmt::{Display, Error, Formatter}; /// use std::fmt::{Display, Error, Formatter};
/// ///
/// struct S; /// struct S;

View file

@ -21,13 +21,13 @@ declare_clippy_lint! {
/// While using `write!` in the suggested way should never fail, this isn't necessarily clear to the programmer. /// While using `write!` in the suggested way should never fail, this isn't necessarily clear to the programmer.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let mut s = String::new(); /// let mut s = String::new();
/// s += &format!("0x{:X}", 1024); /// s += &format!("0x{:X}", 1024);
/// s.push_str(&format!("0x{:X}", 1024)); /// s.push_str(&format!("0x{:X}", 1024));
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// use std::fmt::Write as _; // import without risk of name clashing /// use std::fmt::Write as _; // import without risk of name clashing
/// ///
/// let mut s = String::new(); /// let mut s = String::new();

View file

@ -37,7 +37,7 @@ declare_clippy_lint! {
/// This is either a typo in the binary operator or confusing. /// This is either a typo in the binary operator or confusing.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # let foo = true; /// # let foo = true;
/// # let bar = false; /// # let bar = false;
/// // &&! looks like a different operator /// // &&! looks like a different operator
@ -45,7 +45,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let foo = true; /// # let foo = true;
/// # let bar = false; /// # let bar = false;
/// if foo && !bar {} /// if foo && !bar {}

View file

@ -14,7 +14,7 @@ declare_clippy_lint! {
/// comment. /// comment.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// //// My amazing data structure /// //// My amazing data structure
/// pub struct Foo { /// pub struct Foo {
/// // ... /// // ...
@ -22,7 +22,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// /// My amazing data structure /// /// My amazing data structure
/// pub struct Foo { /// pub struct Foo {
/// // ... /// // ...

View file

@ -24,7 +24,7 @@ declare_clippy_lint! {
/// According the std docs implementing `From<..>` is preferred since it gives you `Into<..>` for free where the reverse isn't true. /// According the std docs implementing `From<..>` is preferred since it gives you `Into<..>` for free where the reverse isn't true.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// struct StringWrapper(String); /// struct StringWrapper(String);
/// ///
/// impl Into<StringWrapper> for String { /// impl Into<StringWrapper> for String {
@ -34,7 +34,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// struct StringWrapper(String); /// struct StringWrapper(String);
/// ///
/// impl From<String> for StringWrapper { /// impl From<String> for StringWrapper {

View file

@ -18,13 +18,13 @@ declare_clippy_lint! {
/// For this to be safe, `c_void` would need to have the same memory layout as the original type, which is often not the case. /// For this to be safe, `c_void` would need to have the same memory layout as the original type, which is often not the case.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # use std::ffi::c_void; /// # use std::ffi::c_void;
/// let ptr = Box::into_raw(Box::new(42usize)) as *mut c_void; /// let ptr = Box::into_raw(Box::new(42usize)) as *mut c_void;
/// let _ = unsafe { Box::from_raw(ptr) }; /// let _ = unsafe { Box::from_raw(ptr) };
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # use std::ffi::c_void; /// # use std::ffi::c_void;
/// # let ptr = Box::into_raw(Box::new(42usize)) as *mut c_void; /// # let ptr = Box::into_raw(Box::new(42usize)) as *mut c_void;
/// let _ = unsafe { Box::from_raw(ptr as *mut usize) }; /// let _ = unsafe { Box::from_raw(ptr as *mut usize) };

View file

@ -23,7 +23,7 @@ declare_clippy_lint! {
/// grouping some parameters into a new type. /// grouping some parameters into a new type.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # struct Color; /// # struct Color;
/// fn foo(x: u32, y: u32, name: &str, c: Color, w: f32, h: f32, a: f32, b: f32) { /// fn foo(x: u32, y: u32, name: &str, c: Color, w: f32, h: f32, a: f32, b: f32) {
/// // .. /// // ..
@ -46,7 +46,7 @@ declare_clippy_lint! {
/// multiple functions. /// multiple functions.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// fn im_too_long() { /// fn im_too_long() {
/// println!(""); /// println!("");
/// // ... 100 more LoC /// // ... 100 more LoC
@ -129,7 +129,7 @@ declare_clippy_lint! {
/// a remnant of a refactoring that removed the return type. /// a remnant of a refactoring that removed the return type.
/// ///
/// ### Examples /// ### Examples
/// ```rust /// ```no_run
/// #[must_use] /// #[must_use]
/// fn useless() { } /// fn useless() { }
/// ``` /// ```
@ -151,7 +151,7 @@ declare_clippy_lint! {
/// attribute to improve the lint message. /// attribute to improve the lint message.
/// ///
/// ### Examples /// ### Examples
/// ```rust /// ```no_run
/// #[must_use] /// #[must_use]
/// fn double_must_use() -> Result<(), ()> { /// fn double_must_use() -> Result<(), ()> {
/// unimplemented!(); /// unimplemented!();
@ -183,7 +183,7 @@ declare_clippy_lint! {
/// `#[must_use]`. /// `#[must_use]`.
/// ///
/// ### Examples /// ### Examples
/// ```rust /// ```no_run
/// // this could be annotated with `#[must_use]`. /// // this could be annotated with `#[must_use]`.
/// pub fn id<T>(t: T) -> T { t } /// pub fn id<T>(t: T) -> T { t }
/// ``` /// ```
@ -211,7 +211,7 @@ declare_clippy_lint! {
/// instead. /// instead.
/// ///
/// ### Examples /// ### Examples
/// ```rust /// ```no_run
/// pub fn read_u8() -> Result<u8, ()> { Err(()) } /// pub fn read_u8() -> Result<u8, ()> { Err(()) }
/// ``` /// ```
/// should become /// should become
@ -262,7 +262,7 @@ declare_clippy_lint! {
/// The size determined by Clippy is platform-dependent. /// The size determined by Clippy is platform-dependent.
/// ///
/// ### Examples /// ### Examples
/// ```rust /// ```no_run
/// pub enum ParseError { /// pub enum ParseError {
/// UnparsedBytes([u8; 512]), /// UnparsedBytes([u8; 512]),
/// UnexpectedEof, /// UnexpectedEof,
@ -274,7 +274,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// should be /// should be
/// ``` /// ```no_run
/// pub enum ParseError { /// pub enum ParseError {
/// UnparsedBytes(Box<[u8; 512]>), /// UnparsedBytes(Box<[u8; 512]>),
/// UnexpectedEof, /// UnexpectedEof,
@ -301,7 +301,7 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// struct A { /// struct A {
/// a: String, /// a: String,
/// b: String, /// b: String,
@ -315,7 +315,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// struct A { /// struct A {
/// a: String, /// a: String,
/// b: String, /// b: String,
@ -340,14 +340,14 @@ declare_clippy_lint! {
/// Turbofish syntax (`::<>`) cannot be used when `impl Trait` is being used, making `impl Trait` less powerful. Readability may also be a factor. /// Turbofish syntax (`::<>`) cannot be used when `impl Trait` is being used, making `impl Trait` less powerful. Readability may also be a factor.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// trait MyTrait {} /// trait MyTrait {}
/// fn foo(a: impl MyTrait) { /// fn foo(a: impl MyTrait) {
/// // [...] /// // [...]
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// trait MyTrait {} /// trait MyTrait {}
/// fn foo<T: MyTrait>(a: T) { /// fn foo<T: MyTrait>(a: T) {
/// // [...] /// // [...]

View file

@ -34,11 +34,11 @@ declare_clippy_lint! {
/// produced. /// produced.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// async fn not_send(bytes: std::rc::Rc<[u8]>) {} /// async fn not_send(bytes: std::rc::Rc<[u8]>) {}
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// async fn is_send(bytes: std::sync::Arc<[u8]>) {} /// async fn is_send(bytes: std::sync::Arc<[u8]>) {}
/// ``` /// ```
#[clippy::version = "1.44.0"] #[clippy::version = "1.44.0"]

View file

@ -17,7 +17,7 @@ declare_clippy_lint! {
/// Negations reduce the readability of statements. /// Negations reduce the readability of statements.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # let v: Vec<usize> = vec![]; /// # let v: Vec<usize> = vec![];
/// # fn a() {} /// # fn a() {}
/// # fn b() {} /// # fn b() {}
@ -30,7 +30,7 @@ declare_clippy_lint! {
/// ///
/// Could be written: /// Could be written:
/// ///
/// ```rust /// ```no_run
/// # let v: Vec<usize> = vec![]; /// # let v: Vec<usize> = vec![];
/// # fn a() {} /// # fn a() {}
/// # fn b() {} /// # fn b() {}

View file

@ -21,7 +21,7 @@ declare_clippy_lint! {
/// in comparison to `bool::then`. /// in comparison to `bool::then`.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # let v = vec![0]; /// # let v = vec![0];
/// let a = if v.is_empty() { /// let a = if v.is_empty() {
/// println!("true!"); /// println!("true!");
@ -33,7 +33,7 @@ declare_clippy_lint! {
/// ///
/// Could be written: /// Could be written:
/// ///
/// ```rust /// ```no_run
/// # let v = vec![0]; /// # let v = vec![0];
/// let a = v.is_empty().then(|| { /// let a = v.is_empty().then(|| {
/// println!("true!"); /// println!("true!");

View file

@ -15,14 +15,14 @@ declare_clippy_lint! {
/// would detect a type change that `_` would ignore. /// would detect a type change that `_` would ignore.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// match std::fs::create_dir("tmp-work-dir") { /// match std::fs::create_dir("tmp-work-dir") {
/// Ok(_) => println!("Working directory created"), /// Ok(_) => println!("Working directory created"),
/// Err(s) => eprintln!("Could not create directory: {s}"), /// Err(s) => eprintln!("Could not create directory: {s}"),
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// match std::fs::create_dir("tmp-work-dir") { /// match std::fs::create_dir("tmp-work-dir") {
/// Ok(()) => println!("Working directory created"), /// Ok(()) => println!("Working directory created"),
/// Err(s) => eprintln!("Could not create directory: {s}"), /// Err(s) => eprintln!("Could not create directory: {s}"),

View file

@ -35,7 +35,7 @@ declare_clippy_lint! {
/// pieces of code, possibly including external crates. /// pieces of code, possibly including external crates.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # use std::collections::HashMap; /// # use std::collections::HashMap;
/// # use std::hash::{Hash, BuildHasher}; /// # use std::hash::{Hash, BuildHasher};
/// # trait Serialize {}; /// # trait Serialize {};
@ -44,7 +44,7 @@ declare_clippy_lint! {
/// pub fn foo(map: &mut HashMap<i32, i32>) { } /// pub fn foo(map: &mut HashMap<i32, i32>) { }
/// ``` /// ```
/// could be rewritten as /// could be rewritten as
/// ```rust /// ```no_run
/// # use std::collections::HashMap; /// # use std::collections::HashMap;
/// # use std::hash::{Hash, BuildHasher}; /// # use std::hash::{Hash, BuildHasher};
/// # trait Serialize {}; /// # trait Serialize {};

View file

@ -24,13 +24,13 @@ declare_clippy_lint! {
/// corresponding statements. /// corresponding statements.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// fn foo(x: usize) -> usize { /// fn foo(x: usize) -> usize {
/// x /// x
/// } /// }
/// ``` /// ```
/// add return /// add return
/// ```rust /// ```no_run
/// fn foo(x: usize) -> usize { /// fn foo(x: usize) -> usize {
/// return x; /// return x;
/// } /// }

View file

@ -18,7 +18,7 @@ declare_clippy_lint! {
/// The built-in function is more readable and may be faster. /// The built-in function is more readable and may be faster.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
///let mut u:u32 = 7000; ///let mut u:u32 = 7000;
/// ///
/// if u != u32::MAX { /// if u != u32::MAX {
@ -26,7 +26,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
///let mut u:u32 = 7000; ///let mut u:u32 = 7000;
/// ///
/// u = u.saturating_add(1); /// u = u.saturating_add(1);

View file

@ -15,7 +15,7 @@ declare_clippy_lint! {
/// Simplicity and readability. Instead we can easily use an builtin function. /// Simplicity and readability. Instead we can easily use an builtin function.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # let end: u32 = 10; /// # let end: u32 = 10;
/// # let start: u32 = 5; /// # let start: u32 = 5;
/// let mut i: u32 = end - start; /// let mut i: u32 = end - start;
@ -26,7 +26,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let end: u32 = 10; /// # let end: u32 = 10;
/// # let start: u32 = 5; /// # let start: u32 = 5;
/// let mut i: u32 = end - start; /// let mut i: u32 = end - start;

View file

@ -29,7 +29,7 @@ declare_clippy_lint! {
/// (e.g. `trait A {} trait B: A {} trait C: B {}`, then having an `fn() -> impl A + C`) /// (e.g. `trait A {} trait B: A {} trait C: B {}`, then having an `fn() -> impl A + C`)
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # use std::ops::{Deref,DerefMut}; /// # use std::ops::{Deref,DerefMut};
/// fn f() -> impl Deref<Target = i32> + DerefMut<Target = i32> { /// fn f() -> impl Deref<Target = i32> + DerefMut<Target = i32> {
/// // ^^^^^^^^^^^^^^^^^^^ unnecessary bound, already implied by the `DerefMut` trait bound /// // ^^^^^^^^^^^^^^^^^^^ unnecessary bound, already implied by the `DerefMut` trait bound
@ -37,7 +37,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # use std::ops::{Deref,DerefMut}; /// # use std::ops::{Deref,DerefMut};
/// fn f() -> impl DerefMut<Target = i32> { /// fn f() -> impl DerefMut<Target = i32> {
/// Box::new(123) /// Box::new(123)

View file

@ -19,7 +19,7 @@ declare_clippy_lint! {
/// Since the order of fields in a constructor doesn't affect the /// Since the order of fields in a constructor doesn't affect the
/// resulted instance as the below example indicates, /// resulted instance as the below example indicates,
/// ///
/// ```rust /// ```no_run
/// #[derive(Debug, PartialEq, Eq)] /// #[derive(Debug, PartialEq, Eq)]
/// struct Foo { /// struct Foo {
/// x: i32, /// x: i32,
@ -35,7 +35,7 @@ declare_clippy_lint! {
/// inconsistent order can be confusing and decreases readability and consistency. /// inconsistent order can be confusing and decreases readability and consistency.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// struct Foo { /// struct Foo {
/// x: i32, /// x: i32,
/// y: i32, /// y: i32,
@ -47,7 +47,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # struct Foo { /// # struct Foo {
/// # x: i32, /// # x: i32,
/// # y: i32, /// # y: i32,

View file

@ -31,7 +31,7 @@ declare_clippy_lint! {
/// patterns. /// patterns.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let slice: Option<&[u32]> = Some(&[1, 2, 3]); /// let slice: Option<&[u32]> = Some(&[1, 2, 3]);
/// ///
/// if let Some(slice) = slice { /// if let Some(slice) = slice {
@ -39,7 +39,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let slice: Option<&[u32]> = Some(&[1, 2, 3]); /// let slice: Option<&[u32]> = Some(&[1, 2, 3]);
/// ///
/// if let Some(&[first, ..]) = slice { /// if let Some(&[first, ..]) = slice {

View file

@ -26,7 +26,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let x = [1, 2, 3, 4]; /// # let x = [1, 2, 3, 4];
/// // Index within bounds /// // Index within bounds
/// ///
@ -65,7 +65,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # #![allow(unused)] /// # #![allow(unused)]
/// ///
/// # let x = vec![0; 5]; /// # let x = vec![0; 5];

View file

@ -39,7 +39,7 @@ declare_clippy_lint! {
/// this lint is not clever enough to analyze it. /// this lint is not clever enough to analyze it.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let infinite_iter = 0..; /// let infinite_iter = 0..;
/// # #[allow(unused)] /// # #[allow(unused)]
/// [0..].iter().zip(infinite_iter.take_while(|x| *x > 5)); /// [0..].iter().zip(infinite_iter.take_while(|x| *x > 5));

View file

@ -18,7 +18,7 @@ declare_clippy_lint! {
/// Splitting the implementation of a type makes the code harder to navigate. /// Splitting the implementation of a type makes the code harder to navigate.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// struct X; /// struct X;
/// impl X { /// impl X {
/// fn one() {} /// fn one() {}
@ -30,7 +30,7 @@ declare_clippy_lint! {
/// ///
/// Could be written: /// Could be written:
/// ///
/// ```rust /// ```no_run
/// struct X; /// struct X;
/// impl X { /// impl X {
/// fn one() {} /// fn one() {}

View file

@ -15,7 +15,7 @@ declare_clippy_lint! {
/// 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.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// pub struct A; /// pub struct A;
/// ///
/// impl A { /// impl A {
@ -26,7 +26,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// use std::fmt; /// use std::fmt;
/// ///
/// pub struct A; /// pub struct A;
@ -51,7 +51,7 @@ declare_clippy_lint! {
/// 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`.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// use std::fmt; /// use std::fmt;
/// ///
/// pub struct A; /// pub struct A;
@ -70,7 +70,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// use std::fmt; /// use std::fmt;
/// ///
/// pub struct A; /// pub struct A;

View file

@ -20,7 +20,7 @@ declare_clippy_lint! {
/// benefit as opposed to tuple initializers /// benefit as opposed to tuple initializers
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// struct TupleStruct(u8, u16); /// struct TupleStruct(u8, u16);
/// ///
/// let _ = TupleStruct { /// let _ = TupleStruct {

View file

@ -18,7 +18,7 @@ declare_clippy_lint! {
/// The inline attribute is ignored for trait methods without bodies. /// The inline attribute is ignored for trait methods without bodies.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// trait Animal { /// trait Animal {
/// #[inline] /// #[inline]
/// fn name(&self) -> &'static str; /// fn name(&self) -> &'static str;

View file

@ -21,13 +21,13 @@ declare_clippy_lint! {
/// `prev_instant.elapsed()` also more clearly signals intention. /// `prev_instant.elapsed()` also more clearly signals intention.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// use std::time::Instant; /// use std::time::Instant;
/// let prev_instant = Instant::now(); /// let prev_instant = Instant::now();
/// let duration = Instant::now() - prev_instant; /// let duration = Instant::now() - prev_instant;
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// use std::time::Instant; /// use std::time::Instant;
/// let prev_instant = Instant::now(); /// let prev_instant = Instant::now();
/// let duration = prev_instant.elapsed(); /// let duration = prev_instant.elapsed();
@ -47,13 +47,13 @@ declare_clippy_lint! {
/// unintentional panics. /// unintentional panics.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # use std::time::{Instant, Duration}; /// # use std::time::{Instant, Duration};
/// let time_passed = Instant::now() - Duration::from_secs(5); /// let time_passed = Instant::now() - Duration::from_secs(5);
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # use std::time::{Instant, Duration}; /// # use std::time::{Instant, Duration};
/// let time_passed = Instant::now().checked_sub(Duration::from_secs(5)); /// let time_passed = Instant::now().checked_sub(Duration::from_secs(5));
/// ``` /// ```

View file

@ -16,14 +16,14 @@ declare_clippy_lint! {
/// Readability -- better to use `> y` instead of `>= y + 1`. /// Readability -- better to use `> y` instead of `>= y + 1`.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # let x = 1; /// # let x = 1;
/// # let y = 1; /// # let y = 1;
/// if x >= y + 1 {} /// if x >= y + 1 {}
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let x = 1; /// # let x = 1;
/// # let y = 1; /// # let y = 1;
/// if x > y {} /// if x > y {}

View file

@ -26,7 +26,7 @@ declare_clippy_lint! {
/// https://github.com/rust-lang/rust-clippy/issues/886 /// https://github.com/rust-lang/rust-clippy/issues/886
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let x: u8 = 1; /// let x: u8 = 1;
/// (x as u32) > 300; /// (x as u32) > 300;
/// ``` /// ```

View file

@ -26,7 +26,7 @@ declare_clippy_lint! {
/// (the prefixes are `Foo1` and `Foo2` respectively), as also `Bar螃`, `Bar蟹` /// (the prefixes are `Foo1` and `Foo2` respectively), as also `Bar螃`, `Bar蟹`
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// enum Cake { /// enum Cake {
/// BlackForestCake, /// BlackForestCake,
/// HummingbirdCake, /// HummingbirdCake,
@ -34,7 +34,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// enum Cake { /// enum Cake {
/// BlackForest, /// BlackForest,
/// Hummingbird, /// Hummingbird,
@ -56,14 +56,14 @@ declare_clippy_lint! {
/// It requires the user to type the module name twice. /// It requires the user to type the module name twice.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// mod cake { /// mod cake {
/// struct BlackForestCake; /// struct BlackForestCake;
/// } /// }
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// mod cake { /// mod cake {
/// struct BlackForest; /// struct BlackForest;
/// } /// }
@ -119,7 +119,7 @@ declare_clippy_lint! {
/// (the prefixes are `foo1` and `foo2` respectively), as also `bar螃`, `bar蟹` /// (the prefixes are `foo1` and `foo2` respectively), as also `bar螃`, `bar蟹`
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// struct Cake { /// struct Cake {
/// cake_sugar: u8, /// cake_sugar: u8,
/// cake_flour: u8, /// cake_flour: u8,
@ -127,7 +127,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// struct Cake { /// struct Cake {
/// sugar: u8, /// sugar: u8,
/// flour: u8, /// flour: u8,

View file

@ -16,7 +16,7 @@ declare_clippy_lint! {
/// it's hard to figure out which item is meant in a statement. /// it's hard to figure out which item is meant in a statement.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// fn foo() { /// fn foo() {
/// println!("cake"); /// println!("cake");
/// } /// }
@ -31,7 +31,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// fn foo() { /// fn foo() {
/// println!("cake"); /// println!("cake");
/// } /// }

View file

@ -14,7 +14,7 @@ declare_clippy_lint! {
/// ### Why is this bad? /// ### Why is this bad?
/// Having items declared after the testing module is confusing and may lead to bad test coverage. /// Having items declared after the testing module is confusing and may lead to bad test coverage.
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// #[cfg(test)] /// #[cfg(test)]
/// mod tests { /// mod tests {
/// // [...] /// // [...]
@ -25,7 +25,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// fn my_function() { /// fn my_function() {
/// // [...] /// // [...]
/// } /// }

View file

@ -15,7 +15,7 @@ declare_clippy_lint! {
/// Methods named `iter` or `iter_mut` conventionally return an `Iterator`. /// Methods named `iter` or `iter_mut` conventionally return an `Iterator`.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// // `String` does not implement `Iterator` /// // `String` does not implement `Iterator`
/// struct Data {} /// struct Data {}
/// impl Data { /// impl Data {
@ -25,7 +25,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// use std::str::Chars; /// use std::str::Chars;
/// struct Data {} /// struct Data {}
/// impl Data { /// impl Data {

View file

@ -20,7 +20,7 @@ declare_clippy_lint! {
/// (`for val in &iter {}`), without having to first call `iter()` or `iter_mut()`. /// (`for val in &iter {}`), without having to first call `iter()` or `iter_mut()`.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// struct MySlice<'a>(&'a [u8]); /// struct MySlice<'a>(&'a [u8]);
/// impl<'a> MySlice<'a> { /// impl<'a> MySlice<'a> {
/// pub fn iter(&self) -> std::slice::Iter<'a, u8> { /// pub fn iter(&self) -> std::slice::Iter<'a, u8> {
@ -29,7 +29,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// struct MySlice<'a>(&'a [u8]); /// struct MySlice<'a>(&'a [u8]);
/// impl<'a> MySlice<'a> { /// impl<'a> MySlice<'a> {
/// pub fn iter(&self) -> std::slice::Iter<'a, u8> { /// pub fn iter(&self) -> std::slice::Iter<'a, u8> {
@ -62,7 +62,7 @@ declare_clippy_lint! {
/// in case of ambiguity with another `IntoIterator` impl. /// in case of ambiguity with another `IntoIterator` impl.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// struct MySlice<'a>(&'a [u8]); /// struct MySlice<'a>(&'a [u8]);
/// impl<'a> IntoIterator for &MySlice<'a> { /// impl<'a> IntoIterator for &MySlice<'a> {
/// type Item = &'a u8; /// type Item = &'a u8;
@ -73,7 +73,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// struct MySlice<'a>(&'a [u8]); /// struct MySlice<'a>(&'a [u8]);
/// impl<'a> MySlice<'a> { /// impl<'a> MySlice<'a> {
/// pub fn iter(&self) -> std::slice::Iter<'a, u8> { /// pub fn iter(&self) -> std::slice::Iter<'a, u8> {

View file

@ -38,7 +38,7 @@ declare_clippy_lint! {
/// this may lead to a false positive. /// this may lead to a false positive.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// enum Test { /// enum Test {
/// A(i32), /// A(i32),
/// B([i32; 8000]), /// B([i32; 8000]),
@ -46,7 +46,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// // Possibly better /// // Possibly better
/// enum Test2 { /// enum Test2 {
/// A(i32), /// A(i32),

View file

@ -16,7 +16,7 @@ declare_clippy_lint! {
/// large size of a `Future` may cause stack overflows. /// large size of a `Future` may cause stack overflows.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// async fn large_future(_x: [u8; 16 * 1024]) {} /// async fn large_future(_x: [u8; 16 * 1024]) {}
/// ///
/// pub async fn trigger() { /// pub async fn trigger() {
@ -26,7 +26,7 @@ declare_clippy_lint! {
/// ///
/// `Box::pin` the big future instead. /// `Box::pin` the big future instead.
/// ///
/// ```rust /// ```no_run
/// async fn large_future(_x: [u8; 16 * 1024]) {} /// async fn large_future(_x: [u8; 16 * 1024]) {}
/// ///
/// pub async fn trigger() { /// pub async fn trigger() {

View file

@ -49,7 +49,7 @@ declare_clippy_lint! {
/// ### Example /// ### Example
/// This function creates four 500 KB arrays on the stack. Quite big but just small enough to not trigger `large_stack_arrays`. /// This function creates four 500 KB arrays on the stack. Quite big but just small enough to not trigger `large_stack_arrays`.
/// However, looking at the function as a whole, it's clear that this uses a lot of stack space. /// However, looking at the function as a whole, it's clear that this uses a lot of stack space.
/// ```rust /// ```no_run
/// struct QuiteLargeType([u8; 500_000]); /// struct QuiteLargeType([u8; 500_000]);
/// fn foo() { /// fn foo() {
/// // ... some function that uses a lot of stack space ... /// // ... some function that uses a lot of stack space ...
@ -62,7 +62,7 @@ declare_clippy_lint! {
/// ///
/// Instead of doing this, allocate the arrays on the heap. /// Instead of doing this, allocate the arrays on the heap.
/// This currently requires going through a `Vec` first and then converting it to a `Box`: /// This currently requires going through a `Vec` first and then converting it to a `Box`:
/// ```rust /// ```no_run
/// struct NotSoLargeType(Box<[u8]>); /// struct NotSoLargeType(Box<[u8]>);
/// ///
/// fn foo() { /// fn foo() {

View file

@ -17,7 +17,7 @@ declare_clippy_lint! {
/// expr /// expr
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// fn f() -> Result<u32, u32> { /// fn f() -> Result<u32, u32> {
/// Ok(0) /// Ok(0)
/// } /// }
@ -69,7 +69,7 @@ declare_clippy_lint! {
/// and ignore the resulting value. /// and ignore the resulting value.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// async fn foo() -> Result<(), ()> { /// async fn foo() -> Result<(), ()> {
/// Ok(()) /// Ok(())
/// } /// }
@ -77,7 +77,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # async fn context() { /// # async fn context() {
/// async fn foo() -> Result<(), ()> { /// async fn foo() -> Result<(), ()> {
/// Ok(()) /// Ok(())
@ -107,14 +107,14 @@ declare_clippy_lint! {
/// lints. /// lints.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// fn foo() -> Result<u32, ()> { /// fn foo() -> Result<u32, ()> {
/// Ok(123) /// Ok(123)
/// } /// }
/// let _ = foo(); /// let _ = foo();
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// fn foo() -> Result<u32, ()> { /// fn foo() -> Result<u32, ()> {
/// Ok(123) /// Ok(123)
/// } /// }

View file

@ -38,7 +38,7 @@ declare_clippy_lint! {
/// are mentioned due to potential false positives. /// are mentioned due to potential false positives.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// // 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
@ -46,7 +46,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// fn elided(x: &u8, y: u8) -> &u8 { /// fn elided(x: &u8, y: u8) -> &u8 {
/// x /// x
/// } /// }
@ -69,7 +69,7 @@ declare_clippy_lint! {
/// them leads to more readable code. /// them leads to more readable code.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// // unnecessary lifetimes /// // unnecessary lifetimes
/// fn unused_lifetime<'a>(x: u8) { /// fn unused_lifetime<'a>(x: u8) {
/// // .. /// // ..
@ -77,7 +77,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// fn no_lifetime(x: u8) { /// fn no_lifetime(x: u8) {
/// // ... /// // ...
/// } /// }

View file

@ -34,7 +34,7 @@ declare_clippy_lint! {
/// successful results, using `map_while()` would stop at the first error. /// successful results, using `map_while()` would stop at the first error.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # use std::{fs::File, io::{self, BufRead, BufReader}}; /// # use std::{fs::File, io::{self, BufRead, BufReader}};
/// # let _ = || -> io::Result<()> { /// # let _ = || -> io::Result<()> {
/// let mut lines = BufReader::new(File::open("some-path")?).lines().filter_map(Result::ok); /// let mut lines = BufReader::new(File::open("some-path")?).lines().filter_map(Result::ok);
@ -43,7 +43,7 @@ declare_clippy_lint! {
/// # Ok(()) }; /// # Ok(()) };
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # use std::{fs::File, io::{self, BufRead, BufReader}}; /// # use std::{fs::File, io::{self, BufRead, BufReader}};
/// # let _ = || -> io::Result<()> { /// # let _ = || -> io::Result<()> {
/// let mut lines = BufReader::new(File::open("some-path")?).lines().map_while(Result::ok); /// let mut lines = BufReader::new(File::open("some-path")?).lines().map_while(Result::ok);

View file

@ -23,14 +23,14 @@ declare_clippy_lint! {
/// Reading long numbers is difficult without separators. /// Reading long numbers is difficult without separators.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # let _: u64 = /// # let _: u64 =
/// 61864918973511 /// 61864918973511
/// # ; /// # ;
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let _: u64 = /// # let _: u64 =
/// 61_864_918_973_511 /// 61_864_918_973_511
/// # ; /// # ;
@ -73,14 +73,14 @@ declare_clippy_lint! {
/// grouped digits. /// grouped digits.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # let _: u64 = /// # let _: u64 =
/// 618_64_9189_73_511 /// 618_64_9189_73_511
/// # ; /// # ;
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let _: u64 = /// # let _: u64 =
/// 61_864_918_973_511 /// 61_864_918_973_511
/// # ; /// # ;
@ -100,7 +100,7 @@ declare_clippy_lint! {
/// Negatively impacts readability. /// Negatively impacts readability.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let x: u32 = 0xFFF_FFF; /// let x: u32 = 0xFFF_FFF;
/// let y: u8 = 0b01_011_101; /// let y: u8 = 0b01_011_101;
/// ``` /// ```
@ -120,7 +120,7 @@ declare_clippy_lint! {
/// Negatively impacts readability. /// Negatively impacts readability.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let x: u64 = 6186491_8973511; /// let x: u64 = 6186491_8973511;
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]

View file

@ -36,7 +36,7 @@ declare_clippy_lint! {
/// It is not as fast as a memcpy. /// It is not as fast as a memcpy.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # let src = vec![1]; /// # let src = vec![1];
/// # let mut dst = vec![0; 65]; /// # let mut dst = vec![0; 65];
/// for i in 0..src.len() { /// for i in 0..src.len() {
@ -45,7 +45,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let src = vec![1]; /// # let src = vec![1];
/// # let mut dst = vec![0; 65]; /// # let mut dst = vec![0; 65];
/// dst[64..(src.len() + 64)].clone_from_slice(&src[..]); /// dst[64..(src.len() + 64)].clone_from_slice(&src[..]);
@ -67,7 +67,7 @@ declare_clippy_lint! {
/// the bounds check that is done when indexing. /// the bounds check that is done when indexing.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let vec = vec!['a', 'b', 'c']; /// let vec = vec!['a', 'b', 'c'];
/// for i in 0..vec.len() { /// for i in 0..vec.len() {
/// println!("{}", vec[i]); /// println!("{}", vec[i]);
@ -75,7 +75,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let vec = vec!['a', 'b', 'c']; /// let vec = vec!['a', 'b', 'c'];
/// for i in vec { /// for i in vec {
/// println!("{}", i); /// println!("{}", i);
@ -100,7 +100,7 @@ declare_clippy_lint! {
/// types. /// types.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// // with `y` a `Vec` or slice: /// // with `y` a `Vec` or slice:
/// # let y = vec![1]; /// # let y = vec![1];
/// for x in y.iter() { /// for x in y.iter() {
@ -109,7 +109,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let y = vec![1]; /// # let y = vec![1];
/// for x in &y { /// for x in &y {
/// // .. /// // ..
@ -130,7 +130,7 @@ declare_clippy_lint! {
/// Readability. /// Readability.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # let y = vec![1]; /// # let y = vec![1];
/// // with `y` a `Vec` or slice: /// // with `y` a `Vec` or slice:
/// for x in y.into_iter() { /// for x in y.into_iter() {
@ -138,7 +138,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// can be rewritten to /// can be rewritten to
/// ```rust /// ```no_run
/// # let y = vec![1]; /// # let y = vec![1];
/// for x in y { /// for x in y {
/// // .. /// // ..
@ -217,7 +217,7 @@ declare_clippy_lint! {
/// declutters the code and may be faster in some instances. /// declutters the code and may be faster in some instances.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # let v = vec![1]; /// # let v = vec![1];
/// # fn bar(bar: usize, baz: usize) {} /// # fn bar(bar: usize, baz: usize) {}
/// let mut i = 0; /// let mut i = 0;
@ -228,7 +228,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let v = vec![1]; /// # let v = vec![1];
/// # fn bar(bar: usize, baz: usize) {} /// # fn bar(bar: usize, baz: usize) {}
/// for (i, item) in v.iter().enumerate() { bar(i, *item); } /// for (i, item) in v.iter().enumerate() { bar(i, *item); }
@ -339,7 +339,7 @@ declare_clippy_lint! {
/// code. /// code.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// loop { /// loop {
/// ..; /// ..;
/// break; /// break;
@ -362,7 +362,7 @@ declare_clippy_lint! {
/// False positive when mutation is followed by a `break`, but the `break` is not immediately /// False positive when mutation is followed by a `break`, but the `break` is not immediately
/// after the mutation: /// after the mutation:
/// ///
/// ```rust /// ```no_run
/// let mut x = 5; /// let mut x = 5;
/// for _ in 0..x { /// for _ in 0..x {
/// x += 1; // x is a range bound that is mutated /// x += 1; // x is a range bound that is mutated
@ -374,7 +374,7 @@ declare_clippy_lint! {
/// False positive on nested loops ([#6072](https://github.com/rust-lang/rust-clippy/issues/6072)) /// False positive on nested loops ([#6072](https://github.com/rust-lang/rust-clippy/issues/6072))
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let mut foo = 42; /// let mut foo = 42;
/// for i in 0..foo { /// for i in 0..foo {
/// foo -= 1; /// foo -= 1;
@ -402,7 +402,7 @@ declare_clippy_lint! {
/// in the condition and only `Upvar` `b` gets mutated in the body, the lint will not trigger. /// in the condition and only `Upvar` `b` gets mutated in the body, the lint will not trigger.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let i = 0; /// let i = 0;
/// while i > 10 { /// while i > 10 {
/// println!("let me loop forever!"); /// println!("let me loop forever!");
@ -425,7 +425,7 @@ declare_clippy_lint! {
/// have better performance. /// have better performance.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let item1 = 2; /// let item1 = 2;
/// let item2 = 3; /// let item2 = 3;
/// let mut vec: Vec<u8> = Vec::new(); /// let mut vec: Vec<u8> = Vec::new();
@ -438,7 +438,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let item1 = 2; /// let item1 = 2;
/// let item2 = 3; /// let item2 = 3;
/// let mut vec: Vec<u8> = vec![item1; 20]; /// let mut vec: Vec<u8> = vec![item1; 20];
@ -459,7 +459,7 @@ declare_clippy_lint! {
/// single element. /// single element.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let item1 = 2; /// let item1 = 2;
/// for item in &[item1] { /// for item in &[item1] {
/// println!("{}", item); /// println!("{}", item);
@ -467,7 +467,7 @@ declare_clippy_lint! {
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let item1 = 2; /// let item1 = 2;
/// let item = &item1; /// let item = &item1;
/// println!("{}", item); /// println!("{}", item);
@ -489,7 +489,7 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ///
/// ```rust /// ```no_run
/// let x = vec![Some(1), Some(2), Some(3)]; /// let x = vec![Some(1), Some(2), Some(3)];
/// for n in x { /// for n in x {
/// if let Some(n) = n { /// if let Some(n) = n {
@ -498,7 +498,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let x = vec![Some(1), Some(2), Some(3)]; /// let x = vec![Some(1), Some(2), Some(3)];
/// for n in x.into_iter().flatten() { /// for n in x.into_iter().flatten() {
/// println!("{}", n); /// println!("{}", n);
@ -555,7 +555,7 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ///
/// ```rust /// ```no_run
/// fn example(arr: Vec<i32>) -> Option<i32> { /// fn example(arr: Vec<i32>) -> Option<i32> {
/// for el in arr { /// for el in arr {
/// if el == 1 { /// if el == 1 {
@ -566,7 +566,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// fn example(arr: Vec<i32>) -> Option<i32> { /// fn example(arr: Vec<i32>) -> Option<i32> {
/// arr.into_iter().find(|&el| el == 1) /// arr.into_iter().find(|&el| el == 1)
/// } /// }
@ -587,7 +587,7 @@ declare_clippy_lint! {
/// pattern matching on the return value of `Vec::pop()`. /// pattern matching on the return value of `Vec::pop()`.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let mut numbers = vec![1, 2, 3, 4, 5]; /// let mut numbers = vec![1, 2, 3, 4, 5];
/// while !numbers.is_empty() { /// while !numbers.is_empty() {
/// let number = numbers.pop().unwrap(); /// let number = numbers.pop().unwrap();
@ -595,7 +595,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let mut numbers = vec![1, 2, 3, 4, 5]; /// let mut numbers = vec![1, 2, 3, 4, 5];
/// while let Some(number) = numbers.pop() { /// while let Some(number) = numbers.pop() {
/// // use `number` /// // use `number`

View file

@ -16,14 +16,14 @@ declare_clippy_lint! {
/// `assert!` is simpler than `if`-then-`panic!`. /// `assert!` is simpler than `if`-then-`panic!`.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let sad_people: Vec<&str> = vec![]; /// let sad_people: Vec<&str> = vec![];
/// if !sad_people.is_empty() { /// if !sad_people.is_empty() {
/// panic!("there are sad people: {:?}", sad_people); /// panic!("there are sad people: {:?}", sad_people);
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let sad_people: Vec<&str> = vec![]; /// let sad_people: Vec<&str> = vec![];
/// assert!(sad_people.is_empty(), "there are sad people: {:?}", sad_people); /// assert!(sad_people.is_empty(), "there are sad people: {:?}", sad_people);
/// ``` /// ```

View file

@ -20,13 +20,13 @@ declare_clippy_lint! {
/// It's more idiomatic to use the dedicated syntax. /// It's more idiomatic to use the dedicated syntax.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// use std::future::Future; /// use std::future::Future;
/// ///
/// fn foo() -> impl Future<Output = i32> { async { 42 } } /// fn foo() -> impl Future<Output = i32> { async { 42 } }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// async fn foo() -> i32 { 42 } /// async fn foo() -> i32 { 42 }
/// ``` /// ```
#[clippy::version = "1.45.0"] #[clippy::version = "1.45.0"]

View file

@ -20,11 +20,11 @@ declare_clippy_lint! {
/// Can be written as the shorter `T::BITS`. /// Can be written as the shorter `T::BITS`.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// std::mem::size_of::<usize>() * 8; /// std::mem::size_of::<usize>() * 8;
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// usize::BITS as usize; /// usize::BITS as usize;
/// ``` /// ```
#[clippy::version = "1.60.0"] #[clippy::version = "1.60.0"]

View file

@ -38,7 +38,7 @@ declare_clippy_lint! {
/// PR](https://github.com/rust-lang/rust-clippy/pull/9484#issuecomment-1278922613). /// PR](https://github.com/rust-lang/rust-clippy/pull/9484#issuecomment-1278922613).
/// ///
/// ### Examples /// ### Examples
/// ```rust /// ```no_run
/// # let (input, min, max) = (0, -2, 1); /// # let (input, min, max) = (0, -2, 1);
/// if input > max { /// if input > max {
/// max /// max
@ -50,13 +50,13 @@ declare_clippy_lint! {
/// # ; /// # ;
/// ``` /// ```
/// ///
/// ```rust /// ```no_run
/// # let (input, min, max) = (0, -2, 1); /// # let (input, min, max) = (0, -2, 1);
/// input.max(min).min(max) /// input.max(min).min(max)
/// # ; /// # ;
/// ``` /// ```
/// ///
/// ```rust /// ```no_run
/// # let (input, min, max) = (0, -2, 1); /// # let (input, min, max) = (0, -2, 1);
/// match input { /// match input {
/// x if x > max => max, /// x if x > max => max,
@ -66,14 +66,14 @@ declare_clippy_lint! {
/// # ; /// # ;
/// ``` /// ```
/// ///
/// ```rust /// ```no_run
/// # let (input, min, max) = (0, -2, 1); /// # let (input, min, max) = (0, -2, 1);
/// let mut x = input; /// let mut x = input;
/// if x < min { x = min; } /// if x < min { x = min; }
/// if x > max { x = max; } /// if x > max { x = max; }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let (input, min, max) = (0, -2, 1); /// # let (input, min, max) = (0, -2, 1);
/// input.clamp(min, max) /// input.clamp(min, max)
/// # ; /// # ;
@ -207,7 +207,7 @@ impl TypeClampability {
/// Targets patterns like /// Targets patterns like
/// ///
/// ``` /// ```no_run
/// # let (input, min, max) = (0, -3, 12); /// # let (input, min, max) = (0, -3, 12);
/// ///
/// if input < min { /// if input < min {
@ -256,7 +256,7 @@ fn is_if_elseif_else_pattern<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx
/// Targets patterns like /// Targets patterns like
/// ///
/// ``` /// ```no_run
/// # let (input, min_value, max_value) = (0, -3, 12); /// # let (input, min_value, max_value) = (0, -3, 12);
/// ///
/// input.max(min_value).min(max_value) /// input.max(min_value).min(max_value)
@ -287,7 +287,7 @@ fn is_max_min_pattern<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> O
/// Targets patterns like /// Targets patterns like
/// ///
/// ``` /// ```no_run
/// # let (input, min_value, max_value) = (0, -3, 12); /// # let (input, min_value, max_value) = (0, -3, 12);
/// # use std::cmp::{max, min}; /// # use std::cmp::{max, min};
/// min(max(input, min_value), max_value) /// min(max(input, min_value), max_value)
@ -369,7 +369,7 @@ fn is_call_max_min_pattern<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>)
/// Targets patterns like /// Targets patterns like
/// ///
/// ``` /// ```no_run
/// # let (input, min, max) = (0, -3, 12); /// # let (input, min, max) = (0, -3, 12);
/// ///
/// match input { /// match input {
@ -428,7 +428,7 @@ fn is_match_pattern<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Opt
/// Targets patterns like /// Targets patterns like
/// ///
/// ``` /// ```no_run
/// # let (input, min, max) = (0, -3, 12); /// # let (input, min, max) = (0, -3, 12);
/// ///
/// let mut x = input; /// let mut x = input;
@ -485,7 +485,7 @@ fn is_two_if_pattern<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) ->
/// Targets patterns like /// Targets patterns like
/// ///
/// ``` /// ```no_run
/// # let (mut input, min, max) = (0, -3, 12); /// # let (mut input, min, max) = (0, -3, 12);
/// ///
/// if input < min { /// if input < min {

View file

@ -17,12 +17,12 @@ declare_clippy_lint! {
/// The method `is_infinite` is shorter and more readable. /// The method `is_infinite` is shorter and more readable.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # let x = 1.0f32; /// # let x = 1.0f32;
/// if x == f32::INFINITY || x == f32::NEG_INFINITY {} /// if x == f32::INFINITY || x == f32::NEG_INFINITY {}
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let x = 1.0f32; /// # let x = 1.0f32;
/// if x.is_infinite() {} /// if x.is_infinite() {}
/// ``` /// ```
@ -40,13 +40,13 @@ declare_clippy_lint! {
/// The method `is_finite` is shorter and more readable. /// The method `is_finite` is shorter and more readable.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// # let x = 1.0f32; /// # let x = 1.0f32;
/// if x != f32::INFINITY && x != f32::NEG_INFINITY {} /// if x != f32::INFINITY && x != f32::NEG_INFINITY {}
/// if x.abs() < f32::INFINITY {} /// if x.abs() < f32::INFINITY {}
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// # let x = 1.0f32; /// # let x = 1.0f32;
/// if x.is_finite() {} /// if x.is_finite() {}
/// if x.is_finite() {} /// if x.is_finite() {}

View file

@ -19,7 +19,7 @@ declare_clippy_lint! {
/// It is more concise to use the `hash_one` method. /// It is more concise to use the `hash_one` method.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// use std::hash::{BuildHasher, Hash, Hasher}; /// use std::hash::{BuildHasher, Hash, Hasher};
/// use std::collections::hash_map::RandomState; /// use std::collections::hash_map::RandomState;
/// ///
@ -31,7 +31,7 @@ declare_clippy_lint! {
/// let hash = hasher.finish(); /// let hash = hasher.finish();
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// use std::hash::BuildHasher; /// use std::hash::BuildHasher;
/// use std::collections::hash_map::RandomState; /// use std::collections::hash_map::RandomState;
/// ///

View file

@ -23,7 +23,7 @@ declare_clippy_lint! {
/// clear that it's not a specific subset of characters, but all /// clear that it's not a specific subset of characters, but all
/// ASCII (lowercase|uppercase|digit|hexdigit) characters. /// ASCII (lowercase|uppercase|digit|hexdigit) characters.
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// fn main() { /// fn main() {
/// assert!(matches!('x', 'a'..='z')); /// assert!(matches!('x', 'a'..='z'));
/// assert!(matches!(b'X', b'A'..=b'Z')); /// assert!(matches!(b'X', b'A'..=b'Z'));
@ -37,7 +37,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// fn main() { /// fn main() {
/// assert!('x'.is_ascii_lowercase()); /// assert!('x'.is_ascii_lowercase());
/// assert!(b'X'.is_ascii_uppercase()); /// assert!(b'X'.is_ascii_uppercase());

View file

@ -30,14 +30,14 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ///
/// ```rust /// ```no_run
/// # let w = Some(0); /// # let w = Some(0);
/// let v = if let Some(v) = w { v } else { return }; /// let v = if let Some(v) = w { v } else { return };
/// ``` /// ```
/// ///
/// Could be written: /// Could be written:
/// ///
/// ```rust /// ```no_run
/// # fn main () { /// # fn main () {
/// # let w = Some(0); /// # let w = Some(0);
/// let Some(v) = w else { return }; /// let Some(v) = w else { return };

View file

@ -19,11 +19,11 @@ declare_clippy_lint! {
/// an extra memory allocation. /// an extra memory allocation.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let s: &str = &std::path::MAIN_SEPARATOR.to_string(); /// let s: &str = &std::path::MAIN_SEPARATOR.to_string();
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let s: &str = std::path::MAIN_SEPARATOR_STR; /// let s: &str = std::path::MAIN_SEPARATOR_STR;
/// ``` /// ```
#[clippy::version = "1.70.0"] #[clippy::version = "1.70.0"]

View file

@ -22,7 +22,7 @@ declare_clippy_lint! {
/// and allows possible optimizations when applied to enums. /// and allows possible optimizations when applied to enums.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// struct S { /// struct S {
/// pub a: i32, /// pub a: i32,
/// pub b: i32, /// pub b: i32,
@ -39,7 +39,7 @@ declare_clippy_lint! {
/// struct T(pub i32, pub i32, ()); /// struct T(pub i32, pub i32, ());
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// #[non_exhaustive] /// #[non_exhaustive]
/// struct S { /// struct S {
/// pub a: i32, /// pub a: i32,

View file

@ -22,12 +22,12 @@ declare_clippy_lint! {
/// in order to support negative numbers. /// in order to support negative numbers.
/// ///
/// ### Example /// ### Example
/// ```rust /// ```no_run
/// let x = 6; /// let x = 6;
/// let foo = matches!(x, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10); /// let foo = matches!(x, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10);
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```no_run
/// let x = 6; /// let x = 6;
/// let foo = matches!(x, 1..=10); /// let foo = matches!(x, 1..=10);
/// ``` /// ```

Some files were not shown because too many files have changed in this diff Show more