Skip to content

Doctests: Enable running doc tests for perf lints #4327

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
Aug 3, 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
3 changes: 2 additions & 1 deletion clippy_lints/src/bytecount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 18 additions & 7 deletions clippy_lints/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 } => {
Expand All @@ -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 } => {
Expand Down
9 changes: 6 additions & 3 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
/// }
Expand Down Expand Up @@ -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();
/// ```
Expand Down
24 changes: 18 additions & 6 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions clippy_lints/src/mutex_atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// # use std::sync::Mutex;
/// # let y = 1;
/// let x = Mutex::new(&y);
/// ```
pub MUTEX_ATOMIC,
Expand Down
2 changes: 2 additions & 0 deletions clippy_lints/src/slow_vector_initialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
///
Expand Down
15 changes: 8 additions & 7 deletions clippy_lints/src/trivially_copy_pass_by_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ declare_clippy_lint! {
/// each other.
///
/// **Example:**
///
/// ```rust
/// // Bad
/// fn foo(v: &u32) {}
/// ```
///
/// ```rust
/// fn foo(v: &u32) {
/// assert_eq!(v, 42);
/// }
/// // should be
/// fn foo(v: u32) {
/// assert_eq!(v, 42);
/// }
/// // Better
/// fn foo(v: u32) {}
/// ```
pub TRIVIALLY_COPY_PASS_BY_REF,
perf,
Expand Down