about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPhilipp Krones <hello@philkrones.com>2019-08-05 10:50:06 +0200
committerGitHub <noreply@github.com>2019-08-05 10:50:06 +0200
commit93c3da223f6b152859a3f246795b1cbdb2ca3aa7 (patch)
treeced08914bcdef4a510053788e5b4074f06a97123
parentf5db24a59fa34f93cfc1369df8f13384936170bf (diff)
parentb608e02e1cedb99ee8a069e3647dde5316b41968 (diff)
downloadrust-93c3da223f6b152859a3f246795b1cbdb2ca3aa7.tar.gz
rust-93c3da223f6b152859a3f246795b1cbdb2ca3aa7.zip
Rollup merge of #4331 - phansch:doctests_restriction, r=flip1995
Doctests: Enable running doc tests for restriction lints

changelog: Enabled remaining doc tests for lint documentation page

master: 202 passed; 0 failed; 122 ignored; 0 measured; 0 filtered out
this PR: 231 passed; 0 failed; 123 ignored; 0 measured; 0 filtered out

Closes #4319 (assuming this is merged after #4329 and #4330)
-rw-r--r--clippy_lints/src/arithmetic.rs6
-rw-r--r--clippy_lints/src/else_if_without_else.rs6
-rw-r--r--clippy_lints/src/indexing_slicing.rs2
-rw-r--r--clippy_lints/src/lib.rs2
-rw-r--r--clippy_lints/src/matches.rs2
-rw-r--r--clippy_lints/src/mem_forget.rs2
-rw-r--r--clippy_lints/src/methods/mod.rs36
-rw-r--r--clippy_lints/src/misc.rs5
-rw-r--r--clippy_lints/src/missing_inline.rs6
-rw-r--r--clippy_lints/src/shadow.rs3
-rw-r--r--clippy_lints/src/strings.rs2
-rw-r--r--clippy_lints/src/write.rs1
12 files changed, 57 insertions, 16 deletions
diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs
index d94cd668bdd..9e0d114569e 100644
--- a/clippy_lints/src/arithmetic.rs
+++ b/clippy_lints/src/arithmetic.rs
@@ -16,7 +16,8 @@ declare_clippy_lint! {
     ///
     /// **Example:**
     /// ```rust
-    /// a + 1
+    /// # let a = 0;
+    /// a + 1;
     /// ```
     pub INTEGER_ARITHMETIC,
     restriction,
@@ -33,7 +34,8 @@ declare_clippy_lint! {
     ///
     /// **Example:**
     /// ```rust
-    /// a + 1.0
+    /// # let a = 0.0;
+    /// a + 1.0;
     /// ```
     pub FLOAT_ARITHMETIC,
     restriction,
diff --git a/clippy_lints/src/else_if_without_else.rs b/clippy_lints/src/else_if_without_else.rs
index 25a1cde6e5e..6daf204a5f1 100644
--- a/clippy_lints/src/else_if_without_else.rs
+++ b/clippy_lints/src/else_if_without_else.rs
@@ -16,6 +16,9 @@ declare_clippy_lint! {
     ///
     /// **Example:**
     /// ```rust
+    /// # fn a() {}
+    /// # fn b() {}
+    /// # let x: i32 = 1;
     /// if x.is_positive() {
     ///     a();
     /// } else if x.is_negative() {
@@ -26,6 +29,9 @@ declare_clippy_lint! {
     /// Could be written:
     ///
     /// ```rust
+    /// # fn a() {}
+    /// # fn b() {}
+    /// # let x: i32 = 1;
     /// if x.is_positive() {
     ///     a();
     /// } else if x.is_negative() {
diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs
index d90efd2ea96..06e5458c185 100644
--- a/clippy_lints/src/indexing_slicing.rs
+++ b/clippy_lints/src/indexing_slicing.rs
@@ -47,7 +47,7 @@ declare_clippy_lint! {
     /// **Known problems:** Hopefully none.
     ///
     /// **Example:**
-    /// ```rust
+    /// ```rust,no_run
     /// // Vector
     /// let x = vec![0; 5];
     ///
diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs
index cc314e789e7..8e234017541 100644
--- a/clippy_lints/src/lib.rs
+++ b/clippy_lints/src/lib.rs
@@ -115,7 +115,7 @@ macro_rules! declare_clippy_lint {
     };
     { $(#[$attr:meta])* pub $name:tt, restriction, $description:tt } => {
         declare_tool_lint! {
-            pub clippy::$name, Allow, $description, report_in_external_macro: true
+            $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
         }
     };
     { $(#[$attr:meta])* pub $name:tt, cargo, $description:tt } => {
diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs
index 6558a254878..8a6f6970e1b 100644
--- a/clippy_lints/src/matches.rs
+++ b/clippy_lints/src/matches.rs
@@ -211,6 +211,8 @@ declare_clippy_lint! {
     ///
     /// **Example:**
     /// ```rust
+    /// # enum Foo { A(usize), B(usize) }
+    /// # let x = Foo::B(1);
     /// match x {
     ///     A => {},
     ///     _ => {},
diff --git a/clippy_lints/src/mem_forget.rs b/clippy_lints/src/mem_forget.rs
index 55673c43047..54b0a61937e 100644
--- a/clippy_lints/src/mem_forget.rs
+++ b/clippy_lints/src/mem_forget.rs
@@ -14,6 +14,8 @@ declare_clippy_lint! {
     ///
     /// **Example:**
     /// ```rust
+    /// # use std::mem;
+    /// # use std::rc::Rc;
     /// mem::forget(Rc::new(55))
     /// ```
     pub MEM_FORGET,
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index bfdd3e08591..5bb5ebc83a4 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -40,8 +40,19 @@ declare_clippy_lint! {
     /// **Known problems:** None.
     ///
     /// **Example:**
+    ///
+    /// Using unwrap on an `Option`:
+    ///
     /// ```rust
-    /// x.unwrap()
+    /// let opt = Some(1);
+    /// opt.unwrap();
+    /// ```
+    ///
+    /// Better:
+    ///
+    /// ```rust
+    /// let opt = Some(1);
+    /// opt.expect("more helpful message");
     /// ```
     pub OPTION_UNWRAP_USED,
     restriction,
@@ -62,8 +73,18 @@ declare_clippy_lint! {
     /// **Known problems:** None.
     ///
     /// **Example:**
+    /// Using unwrap on an `Option`:
+    ///
     /// ```rust
-    /// x.unwrap()
+    /// let res: Result<usize, ()> = Ok(1);
+    /// res.unwrap();
+    /// ```
+    ///
+    /// Better:
+    ///
+    /// ```rust
+    /// let res: Result<usize, ()> = Ok(1);
+    /// res.expect("more helpful message");
     /// ```
     pub RESULT_UNWRAP_USED,
     restriction,
@@ -141,9 +162,10 @@ declare_clippy_lint! {
     ///
     /// **Example:**
     /// ```rust
-    /// impl X {
-    ///     pub fn as_str(self) -> &str {
-    ///         ..
+    /// # struct X;
+    /// impl<'a> X {
+    ///     pub fn as_str(self) -> &'a str {
+    ///         "foo"
     ///     }
     /// }
     /// ```
@@ -474,7 +496,9 @@ declare_clippy_lint! {
     ///
     /// **Example:**
     /// ```rust
-    /// x.clone()
+    /// # use std::rc::Rc;
+    /// let x = Rc::new(1);
+    /// x.clone();
     /// ```
     pub CLONE_ON_REF_PTR,
     restriction,
diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs
index dec3cd0fb42..f8a24982934 100644
--- a/clippy_lints/src/misc.rs
+++ b/clippy_lints/src/misc.rs
@@ -226,8 +226,9 @@ declare_clippy_lint! {
     ///
     /// **Example:**
     /// ```rust
-    /// const ONE = 1.00f64;
-    /// x == ONE  // where both are floats
+    /// let x: f64 = 1.0;
+    /// const ONE: f64 = 1.00;
+    /// x == ONE;  // where both are floats
     /// ```
     pub FLOAT_CMP_CONST,
     restriction,
diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs
index e738fd55456..865543ce3d8 100644
--- a/clippy_lints/src/missing_inline.rs
+++ b/clippy_lints/src/missing_inline.rs
@@ -33,7 +33,7 @@ declare_clippy_lint! {
     ///
     /// struct Baz;
     /// impl Baz {
-    ///    fn priv() {} // ok
+    ///    fn private() {} // ok
     /// }
     ///
     /// impl Bar for Baz {
@@ -42,8 +42,8 @@ declare_clippy_lint! {
     ///
     /// pub struct PubBaz;
     /// impl PubBaz {
-    ///    fn priv() {} // ok
-    ///    pub not_ptriv() {} // missing #[inline]
+    ///    fn private() {} // ok
+    ///    pub fn not_ptrivate() {} // missing #[inline]
     /// }
     ///
     /// impl Bar for PubBaz {
diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs
index 45d6a7f71a9..0e75f85cccb 100644
--- a/clippy_lints/src/shadow.rs
+++ b/clippy_lints/src/shadow.rs
@@ -20,6 +20,7 @@ declare_clippy_lint! {
     ///
     /// **Example:**
     /// ```rust
+    /// # let x = 1;
     /// let x = &x;
     /// ```
     pub SHADOW_SAME,
@@ -41,10 +42,12 @@ declare_clippy_lint! {
     ///
     /// **Example:**
     /// ```rust
+    /// let x = 2;
     /// let x = x + 1;
     /// ```
     /// use different variable name:
     /// ```rust
+    /// let x = 2;
     /// let y = x + 1;
     /// ```
     pub SHADOW_REUSE,
diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs
index 57f63a600a7..0de63b5ff3e 100644
--- a/clippy_lints/src/strings.rs
+++ b/clippy_lints/src/strings.rs
@@ -48,7 +48,7 @@ declare_clippy_lint! {
     ///
     /// ```rust
     /// let x = "Hello".to_owned();
-    /// x + ", World"
+    /// x + ", World";
     /// ```
     pub STRING_ADD,
     restriction,
diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs
index 9b30708b22c..9e26b3e5b9c 100644
--- a/clippy_lints/src/write.rs
+++ b/clippy_lints/src/write.rs
@@ -77,6 +77,7 @@ declare_clippy_lint! {
     ///
     /// **Example:**
     /// ```rust
+    /// # let foo = "bar";
     /// println!("{:?}", foo);
     /// ```
     pub USE_DEBUG,