Run more doc tests

This executes some more doc tests that were ignored before.
This commit is contained in:
Philipp Hansch
2019-03-09 08:51:23 +01:00
parent 1cdac4a9c7
commit 9ca34e37fa
8 changed files with 103 additions and 52 deletions
+9 -6
View File
@@ -37,8 +37,9 @@
/// **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 @@
/// uncommon).
///
/// **Example:**
/// ```ignore
/// if (x | 1 > 3) { … }
/// ```rust
/// # let x = 1;
/// if (x | 1 > 3) { }
/// ```
pub INEFFECTIVE_BIT_MASK,
correctness,
@@ -83,8 +85,9 @@
/// **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,
+3 -2
View File
@@ -19,8 +19,9 @@
/// 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,
+11 -5
View File
@@ -27,7 +27,9 @@
/// **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 @@
///
/// Using `if let` with `else`:
///
/// ```ignore
/// ```rust
/// if let Some(ref foo) = x {
/// bar(foo);
/// } else {
@@ -82,7 +84,7 @@
/// **Known problems:** None.
///
/// **Example:**
/// ```ignore
/// ```rust,ignore
/// match x {
/// &A(ref y) => foo(y),
/// &B => bar(),
@@ -103,7 +105,9 @@
/// **Known problems:** None.
///
/// **Example:**
/// ```ignore
/// ```rust
/// # fn foo() {}
/// # fn bar() {}
/// let condition: bool = true;
/// match condition {
/// true => foo(),
@@ -111,7 +115,9 @@
/// }
/// ```
/// Use if/else instead:
/// ```ignore
/// ```rust
/// # fn foo() {}
/// # fn bar() {}
/// let condition: bool = true;
/// if condition {
/// foo();
+18 -10
View File
@@ -54,8 +54,11 @@
/// **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 @@
/// **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 @@
/// **Known problems:** None.
///
/// **Example:**
/// ```ignore
/// x % 1
/// ```rust
/// # let x = 1;
/// let a = x % 1;
/// ```
pub MODULO_ONE,
correctness,
@@ -131,7 +137,9 @@
/// **Known problems:** None.
///
/// **Example:**
/// ```ignore
/// ```rust
/// # let v = Some("abc");
///
/// match v {
/// Some(x) => (),
/// y @ _ => (), // easier written as `y`,
@@ -194,8 +202,8 @@
///
/// **Example:**
///
/// ```ignore
/// 0 as *const u32
/// ```rust
/// let a = 0 as *const u32;
/// ```
pub ZERO_PTR,
style,
+13 -7
View File
@@ -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;
/// }
+4 -2
View File
@@ -19,7 +19,7 @@
/// **Known problems:** None.
///
/// **Example:**
/// ```rust,ignore
/// ```rust
/// let t = b;
/// b = a;
/// a = t;
@@ -41,7 +41,9 @@
/// **Known problems:** None.
///
/// **Example:**
/// ```rust,ignore
/// ```rust
/// # let mut a = 1;
/// # let mut b = 2;
/// a = b;
/// b = a;
/// ```
+26 -13
View File
@@ -511,7 +511,10 @@ fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
/// **Known problems:** None.
///
/// **Example:**
/// ```ignore
/// ```rust
/// # fn foo() {};
/// # fn bar() {};
/// # fn baz() {};
/// if {
/// foo();
/// } == {
@@ -521,7 +524,10 @@ fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
/// }
/// ```
/// is equal to
/// ```ignore
/// ```rust
/// # fn foo() {};
/// # fn bar() {};
/// # fn baz() {};
/// {
/// foo();
/// bar();
@@ -850,13 +856,13 @@ fn is_unit_literal(expr: &Expr) -> bool {
///
/// **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 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
/// 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 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
/// 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 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
/// **Known problems:** None.
///
/// **Example:**
/// ```ignore
/// ```rust,ignore
/// fn x(r: &i32) {
/// unsafe {
/// *(r as *const _ as *mut _) += 1;
@@ -2314,7 +2325,9 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
///
/// Instead consider using interior mutability types.
///
/// ```ignore
/// ```rust
/// use std::cell::UnsafeCell;
///
/// fn x(r: &UnsafeCell<i32>) {
/// unsafe {
/// *r.get() += 1;
+19 -7
View File
@@ -35,11 +35,13 @@
/// **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 @@
/// **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 @@
/// **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 @@
/// -- 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 @@ fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &Mac) {
/// 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