mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-03 18:09:42 +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:**
|
||||
///
|
||||
/// ```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,
|
||||
perf,
|
||||
|
|
|
@ -16,21 +16,32 @@ declare_clippy_lint! {
|
|||
///
|
||||
/// **Known problems:** Some false negatives, eg.:
|
||||
/// ```rust
|
||||
/// let k = &key;
|
||||
/// if !m.contains_key(k) {
|
||||
/// m.insert(k.clone(), v);
|
||||
/// # use std::collections::HashMap;
|
||||
/// # let mut map = HashMap::new();
|
||||
/// # let v = 1;
|
||||
/// # let k = 1;
|
||||
/// if !map.contains_key(&k) {
|
||||
/// map.insert(k.clone(), v);
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// **Example:**
|
||||
/// ```rust
|
||||
/// if !m.contains_key(&k) {
|
||||
/// m.insert(k, v)
|
||||
/// # use std::collections::HashMap;
|
||||
/// # 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
|
||||
/// 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,
|
||||
perf,
|
||||
|
|
|
@ -28,11 +28,10 @@ declare_clippy_lint! {
|
|||
///
|
||||
/// **Example:**
|
||||
/// ```rust
|
||||
/// fn main() {
|
||||
/// let x = Box::new(1);
|
||||
/// foo(*x);
|
||||
/// println!("{}", *x);
|
||||
/// }
|
||||
/// # fn foo(bar: usize) {}
|
||||
/// let x = Box::new(1);
|
||||
/// foo(*x);
|
||||
/// println!("{}", *x);
|
||||
/// ```
|
||||
pub BOXED_LOCAL,
|
||||
perf,
|
||||
|
|
|
@ -105,7 +105,7 @@ macro_rules! declare_clippy_lint {
|
|||
};
|
||||
{ $(#[$attr:meta])* pub $name:tt, perf, $description:tt } => {
|
||||
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 } => {
|
||||
|
@ -120,7 +120,7 @@ macro_rules! declare_clippy_lint {
|
|||
};
|
||||
{ $(#[$attr:meta])* pub $name:tt, cargo, $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, nursery, $description:tt } => {
|
||||
|
|
|
@ -41,7 +41,9 @@ declare_clippy_lint! {
|
|||
/// **Known problems:** None.
|
||||
///
|
||||
/// **Example:**
|
||||
/// ```ignore
|
||||
/// ```rust
|
||||
/// # let src = vec![1];
|
||||
/// # let mut dst = vec![0; 65];
|
||||
/// for i in 0..src.len() {
|
||||
/// dst[i + 64] = src[i];
|
||||
/// }
|
||||
|
@ -264,8 +266,9 @@ declare_clippy_lint! {
|
|||
/// None
|
||||
///
|
||||
/// **Example:**
|
||||
/// ```ignore
|
||||
/// let len = iterator.collect::<Vec<_>>().len();
|
||||
/// ```rust
|
||||
/// # let iterator = vec![1].into_iter();
|
||||
/// let len = iterator.clone().collect::<Vec<_>>().len();
|
||||
/// // should be
|
||||
/// let len = iterator.count();
|
||||
/// ```
|
||||
|
|
|
@ -383,15 +383,18 @@ declare_clippy_lint! {
|
|||
///
|
||||
/// **Example:**
|
||||
/// ```rust
|
||||
/// foo.unwrap_or(String::new())
|
||||
/// # let foo = Some(String::new());
|
||||
/// foo.unwrap_or(String::new());
|
||||
/// ```
|
||||
/// this can instead be written:
|
||||
/// ```rust
|
||||
/// foo.unwrap_or_else(String::new)
|
||||
/// # let foo = Some(String::new());
|
||||
/// foo.unwrap_or_else(String::new);
|
||||
/// ```
|
||||
/// or
|
||||
/// ```rust
|
||||
/// foo.unwrap_or_default()
|
||||
/// # let foo = Some(String::new());
|
||||
/// foo.unwrap_or_default();
|
||||
/// ```
|
||||
pub OR_FUN_CALL,
|
||||
perf,
|
||||
|
@ -409,15 +412,24 @@ declare_clippy_lint! {
|
|||
///
|
||||
/// **Example:**
|
||||
/// ```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
|
||||
/// ```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:
|
||||
/// ```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,
|
||||
perf,
|
||||
|
|
|
@ -101,7 +101,9 @@ declare_clippy_lint! {
|
|||
///
|
||||
/// **Example:**
|
||||
/// ```rust
|
||||
/// x.to_owned() == y
|
||||
/// # let x = "foo";
|
||||
/// # let y = String::from("foo");
|
||||
/// if x.to_owned() == y {}
|
||||
/// ```
|
||||
pub CMP_OWNED,
|
||||
perf,
|
||||
|
|
|
@ -22,6 +22,8 @@ declare_clippy_lint! {
|
|||
///
|
||||
/// **Example:**
|
||||
/// ```rust
|
||||
/// # use std::sync::Mutex;
|
||||
/// # let y = 1;
|
||||
/// let x = Mutex::new(&y);
|
||||
/// ```
|
||||
pub MUTEX_ATOMIC,
|
||||
|
|
|
@ -19,6 +19,8 @@ declare_clippy_lint! {
|
|||
///
|
||||
/// **Example:**
|
||||
/// ```rust
|
||||
/// # use core::iter::repeat;
|
||||
/// # let len = 4;
|
||||
/// let mut vec1 = Vec::with_capacity(len);
|
||||
/// vec1.resize(len, 0);
|
||||
///
|
||||
|
|
|
@ -39,14 +39,15 @@ declare_clippy_lint! {
|
|||
/// each other.
|
||||
///
|
||||
/// **Example:**
|
||||
///
|
||||
/// ```rust
|
||||
/// fn foo(v: &u32) {
|
||||
/// assert_eq!(v, 42);
|
||||
/// }
|
||||
/// // should be
|
||||
/// fn foo(v: u32) {
|
||||
/// assert_eq!(v, 42);
|
||||
/// }
|
||||
/// // Bad
|
||||
/// fn foo(v: &u32) {}
|
||||
/// ```
|
||||
///
|
||||
/// ```rust
|
||||
/// // Better
|
||||
/// fn foo(v: u32) {}
|
||||
/// ```
|
||||
pub TRIVIALLY_COPY_PASS_BY_REF,
|
||||
perf,
|
||||
|
|
Loading…
Reference in a new issue