mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-11 22:02:55 +00:00
Doctests: Enable running doc tests for perf lints
This should be possible to merge independently of #4325 cc #4319
This commit is contained in:
parent
18a7dce4da
commit
c0cdfd296e
10 changed files with 65 additions and 32 deletions
|
@ -24,7 +24,8 @@ declare_clippy_lint! {
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// &my_data.filter(|&x| x == 0u8).count() // use bytecount::count instead
|
/// # let vec = vec![1_u8];
|
||||||
|
/// &vec.iter().filter(|x| **x == 0u8).count(); // use bytecount::count instead
|
||||||
/// ```
|
/// ```
|
||||||
pub NAIVE_BYTECOUNT,
|
pub NAIVE_BYTECOUNT,
|
||||||
perf,
|
perf,
|
||||||
|
|
|
@ -16,21 +16,32 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Known problems:** Some false negatives, eg.:
|
/// **Known problems:** Some false negatives, eg.:
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// let k = &key;
|
/// # use std::collections::HashMap;
|
||||||
/// if !m.contains_key(k) {
|
/// # let mut map = HashMap::new();
|
||||||
/// m.insert(k.clone(), v);
|
/// # let v = 1;
|
||||||
|
/// # let k = 1;
|
||||||
|
/// if !map.contains_key(&k) {
|
||||||
|
/// map.insert(k.clone(), v);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// if !m.contains_key(&k) {
|
/// # use std::collections::HashMap;
|
||||||
/// m.insert(k, v)
|
/// # let mut map = HashMap::new();
|
||||||
|
/// # let k = 1;
|
||||||
|
/// # let v = 1;
|
||||||
|
/// if !map.contains_key(&k) {
|
||||||
|
/// map.insert(k, v);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
/// can be rewritten as:
|
/// can both be rewritten as:
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// m.entry(k).or_insert(v);
|
/// # use std::collections::HashMap;
|
||||||
|
/// # let mut map = HashMap::new();
|
||||||
|
/// # let k = 1;
|
||||||
|
/// # let v = 1;
|
||||||
|
/// map.entry(k).or_insert(v);
|
||||||
/// ```
|
/// ```
|
||||||
pub MAP_ENTRY,
|
pub MAP_ENTRY,
|
||||||
perf,
|
perf,
|
||||||
|
|
|
@ -28,11 +28,10 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// fn main() {
|
/// # fn foo(bar: usize) {}
|
||||||
/// let x = Box::new(1);
|
/// let x = Box::new(1);
|
||||||
/// foo(*x);
|
/// foo(*x);
|
||||||
/// println!("{}", *x);
|
/// println!("{}", *x);
|
||||||
/// }
|
|
||||||
/// ```
|
/// ```
|
||||||
pub BOXED_LOCAL,
|
pub BOXED_LOCAL,
|
||||||
perf,
|
perf,
|
||||||
|
|
|
@ -105,7 +105,7 @@ macro_rules! declare_clippy_lint {
|
||||||
};
|
};
|
||||||
{ $(#[$attr:meta])* pub $name:tt, perf, $description:tt } => {
|
{ $(#[$attr:meta])* pub $name:tt, perf, $description:tt } => {
|
||||||
declare_tool_lint! {
|
declare_tool_lint! {
|
||||||
pub clippy::$name, Warn, $description, report_in_external_macro: true
|
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
{ $(#[$attr:meta])* pub $name:tt, pedantic, $description:tt } => {
|
{ $(#[$attr:meta])* pub $name:tt, pedantic, $description:tt } => {
|
||||||
|
@ -120,7 +120,7 @@ macro_rules! declare_clippy_lint {
|
||||||
};
|
};
|
||||||
{ $(#[$attr:meta])* pub $name:tt, cargo, $description:tt } => {
|
{ $(#[$attr:meta])* pub $name:tt, cargo, $description:tt } => {
|
||||||
declare_tool_lint! {
|
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, nursery, $description:tt } => {
|
{ $(#[$attr:meta])* pub $name:tt, nursery, $description:tt } => {
|
||||||
|
|
|
@ -41,7 +41,9 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
|
/// # let src = vec![1];
|
||||||
|
/// # let mut dst = vec![0; 65];
|
||||||
/// for i in 0..src.len() {
|
/// for i in 0..src.len() {
|
||||||
/// dst[i + 64] = src[i];
|
/// dst[i + 64] = src[i];
|
||||||
/// }
|
/// }
|
||||||
|
@ -264,8 +266,9 @@ declare_clippy_lint! {
|
||||||
/// None
|
/// None
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
/// let len = iterator.collect::<Vec<_>>().len();
|
/// # let iterator = vec![1].into_iter();
|
||||||
|
/// let len = iterator.clone().collect::<Vec<_>>().len();
|
||||||
/// // should be
|
/// // should be
|
||||||
/// let len = iterator.count();
|
/// let len = iterator.count();
|
||||||
/// ```
|
/// ```
|
||||||
|
|
|
@ -383,15 +383,18 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// foo.unwrap_or(String::new())
|
/// # let foo = Some(String::new());
|
||||||
|
/// foo.unwrap_or(String::new());
|
||||||
/// ```
|
/// ```
|
||||||
/// this can instead be written:
|
/// this can instead be written:
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// foo.unwrap_or_else(String::new)
|
/// # let foo = Some(String::new());
|
||||||
|
/// foo.unwrap_or_else(String::new);
|
||||||
/// ```
|
/// ```
|
||||||
/// or
|
/// or
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// foo.unwrap_or_default()
|
/// # let foo = Some(String::new());
|
||||||
|
/// foo.unwrap_or_default();
|
||||||
/// ```
|
/// ```
|
||||||
pub OR_FUN_CALL,
|
pub OR_FUN_CALL,
|
||||||
perf,
|
perf,
|
||||||
|
@ -409,15 +412,24 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// foo.expect(&format!("Err {}: {}", err_code, err_msg))
|
/// # let foo = Some(String::new());
|
||||||
|
/// # let err_code = "418";
|
||||||
|
/// # let err_msg = "I'm a teapot";
|
||||||
|
/// foo.expect(&format!("Err {}: {}", err_code, err_msg));
|
||||||
/// ```
|
/// ```
|
||||||
/// or
|
/// or
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// foo.expect(format!("Err {}: {}", err_code, err_msg).as_str())
|
/// # let foo = Some(String::new());
|
||||||
|
/// # let err_code = "418";
|
||||||
|
/// # let err_msg = "I'm a teapot";
|
||||||
|
/// foo.expect(format!("Err {}: {}", err_code, err_msg).as_str());
|
||||||
/// ```
|
/// ```
|
||||||
/// this can instead be written:
|
/// this can instead be written:
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// foo.unwrap_or_else(|_| panic!("Err {}: {}", err_code, err_msg))
|
/// # let foo = Some(String::new());
|
||||||
|
/// # let err_code = "418";
|
||||||
|
/// # let err_msg = "I'm a teapot";
|
||||||
|
/// foo.unwrap_or_else(|| panic!("Err {}: {}", err_code, err_msg));
|
||||||
/// ```
|
/// ```
|
||||||
pub EXPECT_FUN_CALL,
|
pub EXPECT_FUN_CALL,
|
||||||
perf,
|
perf,
|
||||||
|
|
|
@ -101,7 +101,9 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// x.to_owned() == y
|
/// # let x = "foo";
|
||||||
|
/// # let y = String::from("foo");
|
||||||
|
/// if x.to_owned() == y {}
|
||||||
/// ```
|
/// ```
|
||||||
pub CMP_OWNED,
|
pub CMP_OWNED,
|
||||||
perf,
|
perf,
|
||||||
|
|
|
@ -22,6 +22,8 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # use std::sync::Mutex;
|
||||||
|
/// # let y = 1;
|
||||||
/// let x = Mutex::new(&y);
|
/// let x = Mutex::new(&y);
|
||||||
/// ```
|
/// ```
|
||||||
pub MUTEX_ATOMIC,
|
pub MUTEX_ATOMIC,
|
||||||
|
|
|
@ -19,6 +19,8 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # use core::iter::repeat;
|
||||||
|
/// # let len = 4;
|
||||||
/// let mut vec1 = Vec::with_capacity(len);
|
/// let mut vec1 = Vec::with_capacity(len);
|
||||||
/// vec1.resize(len, 0);
|
/// vec1.resize(len, 0);
|
||||||
///
|
///
|
||||||
|
|
|
@ -39,14 +39,15 @@ declare_clippy_lint! {
|
||||||
/// each other.
|
/// each other.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// fn foo(v: &u32) {
|
/// // Bad
|
||||||
/// assert_eq!(v, 42);
|
/// fn foo(v: &u32) {}
|
||||||
/// }
|
/// ```
|
||||||
/// // should be
|
///
|
||||||
/// fn foo(v: u32) {
|
/// ```rust
|
||||||
/// assert_eq!(v, 42);
|
/// // Better
|
||||||
/// }
|
/// fn foo(v: u32) {}
|
||||||
/// ```
|
/// ```
|
||||||
pub TRIVIALLY_COPY_PASS_BY_REF,
|
pub TRIVIALLY_COPY_PASS_BY_REF,
|
||||||
perf,
|
perf,
|
||||||
|
|
Loading…
Reference in a new issue