about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/bit_mask.rs15
-rw-r--r--clippy_lints/src/eq_op.rs5
-rw-r--r--clippy_lints/src/matches.rs16
-rw-r--r--clippy_lints/src/misc.rs28
-rw-r--r--clippy_lints/src/needless_continue.rs20
-rw-r--r--clippy_lints/src/swap.rs6
-rw-r--r--clippy_lints/src/types.rs39
-rw-r--r--clippy_lints/src/write.rs26
8 files changed, 103 insertions, 52 deletions
diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs
index c57b1c5366c..76314a610b1 100644
--- a/clippy_lints/src/bit_mask.rs
+++ b/clippy_lints/src/bit_mask.rs
@@ -37,8 +37,9 @@ declare_clippy_lint! {
     /// **Known problems:** None.
     ///
     /// **Example:**
-    /// ```ignore
-    /// if (x & 1 == 2) { … }
+    /// ```rust
+    /// # let x = 1;
+    /// if (x & 1 == 2) { }
     /// ```
     pub BAD_BIT_MASK,
     correctness,
@@ -65,8 +66,9 @@ declare_clippy_lint! {
     /// uncommon).
     ///
     /// **Example:**
-    /// ```ignore
-    /// if (x | 1 > 3) { … }
+    /// ```rust
+    /// # let x = 1;
+    /// if (x | 1 > 3) {  }
     /// ```
     pub INEFFECTIVE_BIT_MASK,
     correctness,
@@ -83,8 +85,9 @@ declare_clippy_lint! {
     /// **Known problems:** llvm generates better code for `x & 15 == 0` on x86
     ///
     /// **Example:**
-    /// ```ignore
-    /// x & 0x1111 == 0
+    /// ```rust
+    /// # let x = 1;
+    /// if x & 0x1111 == 0 { }
     /// ```
     pub VERBOSE_BIT_MASK,
     style,
diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs
index 903700f1aac..1f42a06fbcd 100644
--- a/clippy_lints/src/eq_op.rs
+++ b/clippy_lints/src/eq_op.rs
@@ -19,8 +19,9 @@ declare_clippy_lint! {
     /// calls. We may introduce a whitelist of known pure functions in the future.
     ///
     /// **Example:**
-    /// ```ignore
-    /// x + 1 == x + 1
+    /// ```rust
+    /// # let x = 1;
+    /// if x + 1 == x + 1 {}
     /// ```
     pub EQ_OP,
     correctness,
diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs
index e7e1df5cfff..7bd3fd7f4c4 100644
--- a/clippy_lints/src/matches.rs
+++ b/clippy_lints/src/matches.rs
@@ -27,7 +27,9 @@ declare_clippy_lint! {
     /// **Known problems:** None.
     ///
     /// **Example:**
-    /// ```ignore
+    /// ```rust
+    /// # fn bar(stool: &str) {}
+    /// # let x = Some("abc");
     /// match x {
     ///     Some(ref foo) => bar(foo),
     ///     _ => (),
@@ -59,7 +61,7 @@ declare_clippy_lint! {
     ///
     /// Using `if let` with `else`:
     ///
-    /// ```ignore
+    /// ```rust
     /// if let Some(ref foo) = x {
     ///     bar(foo);
     /// } else {
@@ -82,7 +84,7 @@ declare_clippy_lint! {
     /// **Known problems:** None.
     ///
     /// **Example:**
-    /// ```ignore
+    /// ```rust,ignore
     /// match x {
     ///     &A(ref y) => foo(y),
     ///     &B => bar(),
@@ -103,7 +105,9 @@ declare_clippy_lint! {
     /// **Known problems:** None.
     ///
     /// **Example:**
-    /// ```ignore
+    /// ```rust
+    /// # fn foo() {}
+    /// # fn bar() {}
     /// let condition: bool = true;
     /// match condition {
     ///     true => foo(),
@@ -111,7 +115,9 @@ declare_clippy_lint! {
     /// }
     /// ```
     /// Use if/else instead:
-    /// ```ignore
+    /// ```rust
+    /// # fn foo() {}
+    /// # fn bar() {}
     /// let condition: bool = true;
     /// if condition {
     ///     foo();
diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs
index 77aee50c6f8..a1e0f9d8345 100644
--- a/clippy_lints/src/misc.rs
+++ b/clippy_lints/src/misc.rs
@@ -54,8 +54,11 @@ declare_clippy_lint! {
     /// **Known problems:** None.
     ///
     /// **Example:**
-    /// ```ignore
-    /// x == NAN
+    /// ```rust
+    /// # use core::f32::NAN;
+    /// # let x = 1.0;
+    ///
+    /// if x == NAN { }
     /// ```
     pub CMP_NAN,
     correctness,
@@ -75,9 +78,11 @@ declare_clippy_lint! {
     /// **Known problems:** None.
     ///
     /// **Example:**
-    /// ```ignore
-    /// y == 1.23f64
-    /// y != x  // where both are floats
+    /// ```rust
+    /// let x = 1.2331f64;
+    /// let y = 1.2332f64;
+    /// if y == 1.23f64 { }
+    /// if y != x {} // where both are floats
     /// ```
     pub FLOAT_CMP,
     correctness,
@@ -114,8 +119,9 @@ declare_clippy_lint! {
     /// **Known problems:** None.
     ///
     /// **Example:**
-    /// ```ignore
-    /// x % 1
+    /// ```rust
+    /// # let x = 1;
+    /// let a = x % 1;
     /// ```
     pub MODULO_ONE,
     correctness,
@@ -131,7 +137,9 @@ declare_clippy_lint! {
     /// **Known problems:** None.
     ///
     /// **Example:**
-    /// ```ignore
+    /// ```rust
+    /// # let v = Some("abc");
+    ///
     /// match v {
     ///     Some(x) => (),
     ///     y @ _ => (), // easier written as `y`,
@@ -194,8 +202,8 @@ declare_clippy_lint! {
     ///
     /// **Example:**
     ///
-    /// ```ignore
-    /// 0 as *const u32
+    /// ```rust
+    /// let a = 0 as *const u32;
     /// ```
     pub ZERO_PTR,
     style,
diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs
index 00394a9e1e2..b54442413ed 100644
--- a/clippy_lints/src/needless_continue.rs
+++ b/clippy_lints/src/needless_continue.rs
@@ -2,9 +2,12 @@
 //!
 //! For example, the lint would catch
 //!
-//! ```ignore
-//! while condition() {
-//!     update_condition();
+//! ```rust
+//! let mut a = 1;
+//! let x = true;
+//!
+//! while a < 5 {
+//!     a = 6;
 //!     if x {
 //!         // ...
 //!     } else {
@@ -16,9 +19,12 @@
 //!
 //! And suggest something like this:
 //!
-//! ```ignore
-//! while condition() {
-//!     update_condition();
+//! ```rust
+//! let mut a = 1;
+//! let x = true;
+//!
+//! while a < 5 {
+//!     a = 6;
 //!     if x {
 //!         // ...
 //!         println!("Hello, world");
@@ -374,7 +380,7 @@ fn check_and_warn<'a>(ctx: &EarlyContext<'_>, expr: &'a ast::Expr) {
 /// continues eating till a non-whitespace character is found.
 /// e.g., the string
 ///
-/// ```
+/// ```rust
 /// {
 ///     let x = 5;
 /// }
diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs
index c7003cfb9f0..32a67f39439 100644
--- a/clippy_lints/src/swap.rs
+++ b/clippy_lints/src/swap.rs
@@ -19,7 +19,7 @@ declare_clippy_lint! {
     /// **Known problems:** None.
     ///
     /// **Example:**
-    /// ```rust,ignore
+    /// ```rust
     /// let t = b;
     /// b = a;
     /// a = t;
@@ -41,7 +41,9 @@ declare_clippy_lint! {
     /// **Known problems:** None.
     ///
     /// **Example:**
-    /// ```rust,ignore
+    /// ```rust
+    /// # let mut a = 1;
+    /// # let mut b = 2;
     /// a = b;
     /// b = a;
     /// ```
diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs
index 5ad999f7095..6f122daf71a 100644
--- a/clippy_lints/src/types.rs
+++ b/clippy_lints/src/types.rs
@@ -511,7 +511,10 @@ declare_clippy_lint! {
     /// **Known problems:** None.
     ///
     /// **Example:**
-    /// ```ignore
+    /// ```rust
+    /// # fn foo() {};
+    /// # fn bar() {};
+    /// # fn baz() {};
     /// if {
     ///     foo();
     /// } == {
@@ -521,7 +524,10 @@ declare_clippy_lint! {
     /// }
     /// ```
     /// is equal to
-    /// ```ignore
+    /// ```rust
+    /// # fn foo() {};
+    /// # fn bar() {};
+    /// # fn baz() {};
     /// {
     ///     foo();
     ///     bar();
@@ -850,13 +856,13 @@ declare_clippy_lint! {
     ///
     /// **Example**
     ///
-    /// ```ignore
+    /// ```rust
     /// // Bad
-    /// fn fun() -> i32 {}
+    /// fn fun() -> i32 { 1 }
     /// let a = fun as i64;
     ///
     /// // Good
-    /// fn fun2() -> i32 {}
+    /// fn fun2() -> i32 { 1 }
     /// let a = fun2 as usize;
     /// ```
     pub FN_TO_NUMERIC_CAST,
@@ -1538,9 +1544,11 @@ declare_clippy_lint! {
     /// like `#[cfg(target_pointer_width = "64")] ..` instead.
     ///
     /// **Example:**
-    /// ```rust,ignore
-    /// vec.len() <= 0
-    /// 100 > std::i32::MAX
+    ///
+    /// ```rust
+    /// let vec: Vec<isize> = vec![];
+    /// if vec.len() <= 0 {}
+    /// if 100 > std::i32::MAX {}
     /// ```
     pub ABSURD_EXTREME_COMPARISONS,
     correctness,
@@ -1963,10 +1971,13 @@ declare_clippy_lint! {
     /// pieces of code, possibly including external crates.
     ///
     /// **Example:**
-    /// ```ignore
-    /// impl<K: Hash + Eq, V> Serialize for HashMap<K, V> { ... }
+    /// ```rust
+    /// # use std::collections::HashMap;
+    /// # use std::hash::Hash;
+    /// # trait Serialize {};
+    /// impl<K: Hash + Eq, V> Serialize for HashMap<K, V> { }
     ///
-    /// pub foo(map: &mut HashMap<i32, i32>) { .. }
+    /// pub fn foo(map: &mut HashMap<i32, i32>) { }
     /// ```
     pub IMPLICIT_HASHER,
     style,
@@ -2304,7 +2315,7 @@ declare_clippy_lint! {
     /// **Known problems:** None.
     ///
     /// **Example:**
-    /// ```ignore
+    /// ```rust,ignore
     /// fn x(r: &i32) {
     ///     unsafe {
     ///         *(r as *const _ as *mut _) += 1;
@@ -2314,7 +2325,9 @@ declare_clippy_lint! {
     ///
     /// Instead consider using interior mutability types.
     ///
-    /// ```ignore
+    /// ```rust
+    /// use std::cell::UnsafeCell;
+    ///
     /// fn x(r: &UnsafeCell<i32>) {
     ///     unsafe {
     ///         *r.get() += 1;
diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs
index 236875f0aca..c0ffb16c357 100644
--- a/clippy_lints/src/write.rs
+++ b/clippy_lints/src/write.rs
@@ -35,11 +35,13 @@ declare_clippy_lint! {
     /// **Known problems:** None.
     ///
     /// **Example:**
-    /// ```ignore
+    /// ```rust
+    /// # let name = "World";
     /// print!("Hello {}!\n", name);
     /// ```
     /// use println!() instead
-    /// ```ignore
+    /// ```rust
+    /// # let name = "World";
     /// println!("Hello {}!", name);
     /// ```
     pub PRINT_WITH_NEWLINE,
@@ -113,7 +115,9 @@ declare_clippy_lint! {
     /// **Known problems:** None.
     ///
     /// **Example:**
-    /// ```ignore
+    /// ```rust
+    /// # use std::fmt::Write;
+    /// # let mut buf = String::new();
     /// writeln!(buf, "");
     /// ```
     pub WRITELN_EMPTY_STRING,
@@ -132,7 +136,10 @@ declare_clippy_lint! {
     /// **Known problems:** None.
     ///
     /// **Example:**
-    /// ```ignore
+    /// ```rust
+    /// # use std::fmt::Write;
+    /// # let mut buf = String::new();
+    /// # let name = "World";
     /// write!(buf, "Hello {}!\n", name);
     /// ```
     pub WRITE_WITH_NEWLINE,
@@ -151,7 +158,9 @@ declare_clippy_lint! {
     /// -- e.g., `writeln!(buf, "{}", env!("FOO"))`.
     ///
     /// **Example:**
-    /// ```ignore
+    /// ```rust
+    /// # use std::fmt::Write;
+    /// # let mut buf = String::new();
     /// writeln!(buf, "{}", "foo");
     /// ```
     pub WRITE_LITERAL,
@@ -259,8 +268,11 @@ impl EarlyLintPass for Pass {
 /// Example:
 ///
 /// Calling this function on
-/// ```rust,ignore
-/// writeln!(buf, "string to write: {}", something)
+/// ```rust
+/// # use std::fmt::Write;
+/// # let mut buf = String::new();
+/// # let something = "something";
+/// writeln!(buf, "string to write: {}", something);
 /// ```
 /// will return
 /// ```rust,ignore