Skip to content

Run more doc tests #3865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions clippy_lints/src/bit_mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions clippy_lints/src/eq_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 11 additions & 5 deletions clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
/// _ => (),
Expand Down Expand Up @@ -59,7 +61,7 @@ declare_clippy_lint! {
///
/// Using `if let` with `else`:
///
/// ```ignore
/// ```rust
/// if let Some(ref foo) = x {
/// bar(foo);
/// } else {
Expand All @@ -82,7 +84,7 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```ignore
/// ```rust,ignore
/// match x {
/// &A(ref y) => foo(y),
/// &B => bar(),
Expand All @@ -103,15 +105,19 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```ignore
/// ```rust
/// # fn foo() {}
/// # fn bar() {}
/// let condition: bool = true;
/// match condition {
/// true => foo(),
/// false => bar(),
/// }
/// ```
/// Use if/else instead:
/// ```ignore
/// ```rust
/// # fn foo() {}
/// # fn bar() {}
/// let condition: bool = true;
/// if condition {
/// foo();
Expand Down
28 changes: 18 additions & 10 deletions clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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`,
Expand Down Expand Up @@ -194,8 +202,8 @@ declare_clippy_lint! {
///
/// **Example:**
///
/// ```ignore
/// 0 as *const u32
/// ```rust
/// let a = 0 as *const u32;
/// ```
pub ZERO_PTR,
style,
Expand Down
20 changes: 13 additions & 7 deletions clippy_lints/src/needless_continue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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");
Expand Down Expand Up @@ -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;
/// }
Expand Down
6 changes: 4 additions & 2 deletions clippy_lints/src/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```rust,ignore
/// ```rust
/// let t = b;
/// b = a;
/// a = t;
Expand All @@ -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;
/// ```
Expand Down
39 changes: 26 additions & 13 deletions clippy_lints/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,10 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```ignore
/// ```rust
/// # fn foo() {};
/// # fn bar() {};
/// # fn baz() {};
/// if {
/// foo();
/// } == {
Expand All @@ -521,7 +524,10 @@ declare_clippy_lint! {
/// }
/// ```
/// is equal to
/// ```ignore
/// ```rust
/// # fn foo() {};
/// # fn bar() {};
/// # fn baz() {};
/// {
/// foo();
/// bar();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
26 changes: 19 additions & 7 deletions clippy_lints/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down