mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 07:00:55 +00:00
Auto merge of #3865 - phansch:run_more_doc_tests, r=flip1995
Run more doc tests This executes some more doc tests that were ignored before.
This commit is contained in:
commit
b586d76b43
8 changed files with 103 additions and 52 deletions
|
@ -37,8 +37,9 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
/// if (x & 1 == 2) { … }
|
/// # let x = 1;
|
||||||
|
/// if (x & 1 == 2) { }
|
||||||
/// ```
|
/// ```
|
||||||
pub BAD_BIT_MASK,
|
pub BAD_BIT_MASK,
|
||||||
correctness,
|
correctness,
|
||||||
|
@ -65,8 +66,9 @@ declare_clippy_lint! {
|
||||||
/// uncommon).
|
/// uncommon).
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
/// if (x | 1 > 3) { … }
|
/// # let x = 1;
|
||||||
|
/// if (x | 1 > 3) { }
|
||||||
/// ```
|
/// ```
|
||||||
pub INEFFECTIVE_BIT_MASK,
|
pub INEFFECTIVE_BIT_MASK,
|
||||||
correctness,
|
correctness,
|
||||||
|
@ -83,8 +85,9 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** llvm generates better code for `x & 15 == 0` on x86
|
/// **Known problems:** llvm generates better code for `x & 15 == 0` on x86
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
/// x & 0x1111 == 0
|
/// # let x = 1;
|
||||||
|
/// if x & 0x1111 == 0 { }
|
||||||
/// ```
|
/// ```
|
||||||
pub VERBOSE_BIT_MASK,
|
pub VERBOSE_BIT_MASK,
|
||||||
style,
|
style,
|
||||||
|
|
|
@ -19,8 +19,9 @@ declare_clippy_lint! {
|
||||||
/// calls. We may introduce a whitelist of known pure functions in the future.
|
/// calls. We may introduce a whitelist of known pure functions in the future.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
/// x + 1 == x + 1
|
/// # let x = 1;
|
||||||
|
/// if x + 1 == x + 1 {}
|
||||||
/// ```
|
/// ```
|
||||||
pub EQ_OP,
|
pub EQ_OP,
|
||||||
correctness,
|
correctness,
|
||||||
|
|
|
@ -27,7 +27,9 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
|
/// # fn bar(stool: &str) {}
|
||||||
|
/// # let x = Some("abc");
|
||||||
/// match x {
|
/// match x {
|
||||||
/// Some(ref foo) => bar(foo),
|
/// Some(ref foo) => bar(foo),
|
||||||
/// _ => (),
|
/// _ => (),
|
||||||
|
@ -59,7 +61,7 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// Using `if let` with `else`:
|
/// Using `if let` with `else`:
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
/// if let Some(ref foo) = x {
|
/// if let Some(ref foo) = x {
|
||||||
/// bar(foo);
|
/// bar(foo);
|
||||||
/// } else {
|
/// } else {
|
||||||
|
@ -82,7 +84,7 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust,ignore
|
||||||
/// match x {
|
/// match x {
|
||||||
/// &A(ref y) => foo(y),
|
/// &A(ref y) => foo(y),
|
||||||
/// &B => bar(),
|
/// &B => bar(),
|
||||||
|
@ -103,7 +105,9 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
|
/// # fn foo() {}
|
||||||
|
/// # fn bar() {}
|
||||||
/// let condition: bool = true;
|
/// let condition: bool = true;
|
||||||
/// match condition {
|
/// match condition {
|
||||||
/// true => foo(),
|
/// true => foo(),
|
||||||
|
@ -111,7 +115,9 @@ declare_clippy_lint! {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
/// Use if/else instead:
|
/// Use if/else instead:
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
|
/// # fn foo() {}
|
||||||
|
/// # fn bar() {}
|
||||||
/// let condition: bool = true;
|
/// let condition: bool = true;
|
||||||
/// if condition {
|
/// if condition {
|
||||||
/// foo();
|
/// foo();
|
||||||
|
|
|
@ -54,8 +54,11 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
/// x == NAN
|
/// # use core::f32::NAN;
|
||||||
|
/// # let x = 1.0;
|
||||||
|
///
|
||||||
|
/// if x == NAN { }
|
||||||
/// ```
|
/// ```
|
||||||
pub CMP_NAN,
|
pub CMP_NAN,
|
||||||
correctness,
|
correctness,
|
||||||
|
@ -75,9 +78,11 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
/// y == 1.23f64
|
/// let x = 1.2331f64;
|
||||||
/// y != x // where both are floats
|
/// let y = 1.2332f64;
|
||||||
|
/// if y == 1.23f64 { }
|
||||||
|
/// if y != x {} // where both are floats
|
||||||
/// ```
|
/// ```
|
||||||
pub FLOAT_CMP,
|
pub FLOAT_CMP,
|
||||||
correctness,
|
correctness,
|
||||||
|
@ -114,8 +119,9 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
/// x % 1
|
/// # let x = 1;
|
||||||
|
/// let a = x % 1;
|
||||||
/// ```
|
/// ```
|
||||||
pub MODULO_ONE,
|
pub MODULO_ONE,
|
||||||
correctness,
|
correctness,
|
||||||
|
@ -131,7 +137,9 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
|
/// # let v = Some("abc");
|
||||||
|
///
|
||||||
/// match v {
|
/// match v {
|
||||||
/// Some(x) => (),
|
/// Some(x) => (),
|
||||||
/// y @ _ => (), // easier written as `y`,
|
/// y @ _ => (), // easier written as `y`,
|
||||||
|
@ -194,8 +202,8 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
/// 0 as *const u32
|
/// let a = 0 as *const u32;
|
||||||
/// ```
|
/// ```
|
||||||
pub ZERO_PTR,
|
pub ZERO_PTR,
|
||||||
style,
|
style,
|
||||||
|
|
|
@ -2,9 +2,12 @@
|
||||||
//!
|
//!
|
||||||
//! For example, the lint would catch
|
//! For example, the lint would catch
|
||||||
//!
|
//!
|
||||||
//! ```ignore
|
//! ```rust
|
||||||
//! while condition() {
|
//! let mut a = 1;
|
||||||
//! update_condition();
|
//! let x = true;
|
||||||
|
//!
|
||||||
|
//! while a < 5 {
|
||||||
|
//! a = 6;
|
||||||
//! if x {
|
//! if x {
|
||||||
//! // ...
|
//! // ...
|
||||||
//! } else {
|
//! } else {
|
||||||
|
@ -16,9 +19,12 @@
|
||||||
//!
|
//!
|
||||||
//! And suggest something like this:
|
//! And suggest something like this:
|
||||||
//!
|
//!
|
||||||
//! ```ignore
|
//! ```rust
|
||||||
//! while condition() {
|
//! let mut a = 1;
|
||||||
//! update_condition();
|
//! let x = true;
|
||||||
|
//!
|
||||||
|
//! while a < 5 {
|
||||||
|
//! a = 6;
|
||||||
//! if x {
|
//! if x {
|
||||||
//! // ...
|
//! // ...
|
||||||
//! println!("Hello, world");
|
//! 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.
|
/// continues eating till a non-whitespace character is found.
|
||||||
/// e.g., the string
|
/// e.g., the string
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```rust
|
||||||
/// {
|
/// {
|
||||||
/// let x = 5;
|
/// let x = 5;
|
||||||
/// }
|
/// }
|
||||||
|
|
|
@ -19,7 +19,7 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust,ignore
|
/// ```rust
|
||||||
/// let t = b;
|
/// let t = b;
|
||||||
/// b = a;
|
/// b = a;
|
||||||
/// a = t;
|
/// a = t;
|
||||||
|
@ -41,7 +41,9 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust,ignore
|
/// ```rust
|
||||||
|
/// # let mut a = 1;
|
||||||
|
/// # let mut b = 2;
|
||||||
/// a = b;
|
/// a = b;
|
||||||
/// b = a;
|
/// b = a;
|
||||||
/// ```
|
/// ```
|
||||||
|
|
|
@ -511,7 +511,10 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
|
/// # fn foo() {};
|
||||||
|
/// # fn bar() {};
|
||||||
|
/// # fn baz() {};
|
||||||
/// if {
|
/// if {
|
||||||
/// foo();
|
/// foo();
|
||||||
/// } == {
|
/// } == {
|
||||||
|
@ -521,7 +524,10 @@ declare_clippy_lint! {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
/// is equal to
|
/// is equal to
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
|
/// # fn foo() {};
|
||||||
|
/// # fn bar() {};
|
||||||
|
/// # fn baz() {};
|
||||||
/// {
|
/// {
|
||||||
/// foo();
|
/// foo();
|
||||||
/// bar();
|
/// bar();
|
||||||
|
@ -850,13 +856,13 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example**
|
/// **Example**
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
/// // Bad
|
/// // Bad
|
||||||
/// fn fun() -> i32 {}
|
/// fn fun() -> i32 { 1 }
|
||||||
/// let a = fun as i64;
|
/// let a = fun as i64;
|
||||||
///
|
///
|
||||||
/// // Good
|
/// // Good
|
||||||
/// fn fun2() -> i32 {}
|
/// fn fun2() -> i32 { 1 }
|
||||||
/// let a = fun2 as usize;
|
/// let a = fun2 as usize;
|
||||||
/// ```
|
/// ```
|
||||||
pub FN_TO_NUMERIC_CAST,
|
pub FN_TO_NUMERIC_CAST,
|
||||||
|
@ -1538,9 +1544,11 @@ declare_clippy_lint! {
|
||||||
/// like `#[cfg(target_pointer_width = "64")] ..` instead.
|
/// like `#[cfg(target_pointer_width = "64")] ..` instead.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust,ignore
|
///
|
||||||
/// vec.len() <= 0
|
/// ```rust
|
||||||
/// 100 > std::i32::MAX
|
/// let vec: Vec<isize> = vec![];
|
||||||
|
/// if vec.len() <= 0 {}
|
||||||
|
/// if 100 > std::i32::MAX {}
|
||||||
/// ```
|
/// ```
|
||||||
pub ABSURD_EXTREME_COMPARISONS,
|
pub ABSURD_EXTREME_COMPARISONS,
|
||||||
correctness,
|
correctness,
|
||||||
|
@ -1963,10 +1971,13 @@ declare_clippy_lint! {
|
||||||
/// pieces of code, possibly including external crates.
|
/// pieces of code, possibly including external crates.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
/// impl<K: Hash + Eq, V> Serialize for HashMap<K, V> { ... }
|
/// # 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,
|
pub IMPLICIT_HASHER,
|
||||||
style,
|
style,
|
||||||
|
@ -2304,7 +2315,7 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust,ignore
|
||||||
/// fn x(r: &i32) {
|
/// fn x(r: &i32) {
|
||||||
/// unsafe {
|
/// unsafe {
|
||||||
/// *(r as *const _ as *mut _) += 1;
|
/// *(r as *const _ as *mut _) += 1;
|
||||||
|
@ -2314,7 +2325,9 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// Instead consider using interior mutability types.
|
/// Instead consider using interior mutability types.
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
|
/// use std::cell::UnsafeCell;
|
||||||
|
///
|
||||||
/// fn x(r: &UnsafeCell<i32>) {
|
/// fn x(r: &UnsafeCell<i32>) {
|
||||||
/// unsafe {
|
/// unsafe {
|
||||||
/// *r.get() += 1;
|
/// *r.get() += 1;
|
||||||
|
|
|
@ -35,11 +35,13 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
|
/// # let name = "World";
|
||||||
/// print!("Hello {}!\n", name);
|
/// print!("Hello {}!\n", name);
|
||||||
/// ```
|
/// ```
|
||||||
/// use println!() instead
|
/// use println!() instead
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
|
/// # let name = "World";
|
||||||
/// println!("Hello {}!", name);
|
/// println!("Hello {}!", name);
|
||||||
/// ```
|
/// ```
|
||||||
pub PRINT_WITH_NEWLINE,
|
pub PRINT_WITH_NEWLINE,
|
||||||
|
@ -113,7 +115,9 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
|
/// # use std::fmt::Write;
|
||||||
|
/// # let mut buf = String::new();
|
||||||
/// writeln!(buf, "");
|
/// writeln!(buf, "");
|
||||||
/// ```
|
/// ```
|
||||||
pub WRITELN_EMPTY_STRING,
|
pub WRITELN_EMPTY_STRING,
|
||||||
|
@ -132,7 +136,10 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
|
/// # use std::fmt::Write;
|
||||||
|
/// # let mut buf = String::new();
|
||||||
|
/// # let name = "World";
|
||||||
/// write!(buf, "Hello {}!\n", name);
|
/// write!(buf, "Hello {}!\n", name);
|
||||||
/// ```
|
/// ```
|
||||||
pub WRITE_WITH_NEWLINE,
|
pub WRITE_WITH_NEWLINE,
|
||||||
|
@ -151,7 +158,9 @@ declare_clippy_lint! {
|
||||||
/// -- e.g., `writeln!(buf, "{}", env!("FOO"))`.
|
/// -- e.g., `writeln!(buf, "{}", env!("FOO"))`.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
|
/// # use std::fmt::Write;
|
||||||
|
/// # let mut buf = String::new();
|
||||||
/// writeln!(buf, "{}", "foo");
|
/// writeln!(buf, "{}", "foo");
|
||||||
/// ```
|
/// ```
|
||||||
pub WRITE_LITERAL,
|
pub WRITE_LITERAL,
|
||||||
|
@ -259,8 +268,11 @@ impl EarlyLintPass for Pass {
|
||||||
/// Example:
|
/// Example:
|
||||||
///
|
///
|
||||||
/// Calling this function on
|
/// Calling this function on
|
||||||
/// ```rust,ignore
|
/// ```rust
|
||||||
/// writeln!(buf, "string to write: {}", something)
|
/// # use std::fmt::Write;
|
||||||
|
/// # let mut buf = String::new();
|
||||||
|
/// # let something = "something";
|
||||||
|
/// writeln!(buf, "string to write: {}", something);
|
||||||
/// ```
|
/// ```
|
||||||
/// will return
|
/// will return
|
||||||
/// ```rust,ignore
|
/// ```rust,ignore
|
||||||
|
|
Loading…
Reference in a new issue