Skip to content

Commit

Permalink
Auto merge of #4325 - phansch:doctests_complexity, r=flip1995
Browse files Browse the repository at this point in the history
Doctests: Enable running doc tests for complexity lints

changelog: none

master: `113 passed; 0 failed; 91 ignored; 0 measured; 0 filtered out`
this PR: `181 passed; 0 failed; 110 ignored; 0 measured; 0 filtered out`

cc #4319
  • Loading branch information
bors committed Aug 3, 2019
2 parents a24c704 + eb68dc9 commit 3dc9183
Show file tree
Hide file tree
Showing 33 changed files with 157 additions and 85 deletions.
3 changes: 2 additions & 1 deletion clippy_lints/src/assign_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ declare_clippy_lint! {
/// **Example:**
/// ```rust
/// let mut a = 5;
/// ...
/// let b = 2;
/// // ...
/// a += a + b;
/// ```
pub MISREFACTORED_ASSIGN_OP,
Expand Down
8 changes: 6 additions & 2 deletions clippy_lints/src/double_comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// x == y || x < y
/// # let x = 1;
/// # let y = 2;
/// if x == y || x < y {}
/// ```
///
/// Could be written as:
///
/// ```rust
/// x <= y
/// # let x = 1;
/// # let y = 2;
/// if x <= y {}
/// ```
pub DOUBLE_COMPARISONS,
complexity,
Expand Down
7 changes: 4 additions & 3 deletions clippy_lints/src/double_parens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// ((0))
/// foo((0))
/// ((1, 2))
/// # fn foo(bar: usize) {}
/// ((0));
/// foo((0));
/// ((1, 2));
/// ```
pub DOUBLE_PARENS,
complexity,
Expand Down
1 change: 1 addition & 0 deletions clippy_lints/src/duration_subsec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// # use std::time::Duration;
/// let dur = Duration::new(5, 0);
/// let _micros = dur.subsec_nanos() / 1_000;
/// let _millis = dur.subsec_nanos() / 1_000_000;
Expand Down
4 changes: 3 additions & 1 deletion clippy_lints/src/eval_order_dependence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ declare_clippy_lint! {
/// shorthand.
///
/// **Example:**
/// ```rust
/// ```rust,no_run
/// # fn b() -> bool { true }
/// # fn c() -> bool { true }
/// let a = b() || panic!() || c();
/// // `c()` is dead, `panic!()` is only called if `b()` returns `false`
/// let x = (a, b, c, panic!());
Expand Down
4 changes: 3 additions & 1 deletion clippy_lints/src/explicit_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// # use std::io::Write;
/// # let bar = "furchtbar";
/// // this would be clearer as `eprintln!("foo: {:?}", bar);`
/// writeln!(&mut io::stderr(), "foo: {:?}", bar).unwrap();
/// writeln!(&mut std::io::stderr(), "foo: {:?}", bar).unwrap();
/// ```
pub EXPLICIT_WRITE,
complexity,
Expand Down
5 changes: 3 additions & 2 deletions clippy_lints/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ declare_clippy_lint! {
///
/// **Examples:**
/// ```rust
/// format!("foo")
/// format!("{}", foo)
/// # let foo = "foo";
/// format!("foo");
/// format!("{}", foo);
/// ```
pub USELESS_FORMAT,
complexity,
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// # struct Color;
/// fn foo(x: u32, y: u32, name: &str, c: Color, w: f32, h: f32, a: f32, b: f32) {
/// ..
/// // ..
/// }
/// ```
pub TOO_MANY_ARGUMENTS,
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/identity_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// x / 1 + 0 * 1 - 0 | 0
/// # let x = 1;
/// x / 1 + 0 * 1 - 0 | 0;
/// ```
pub IDENTITY_OP,
complexity,
Expand Down
10 changes: 7 additions & 3 deletions clippy_lints/src/int_plus_one.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// x >= y + 1
/// # let x = 1;
/// # let y = 1;
/// if x >= y + 1 {}
/// ```
///
/// Could be written:
/// Could be written as:
///
/// ```rust
/// x > y
/// # let x = 1;
/// # let y = 1;
/// if x > y {}
/// ```
pub INT_PLUS_ONE,
complexity,
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ macro_rules! declare_clippy_lint {
};
{ $(#[$attr:meta])* pub $name:tt, complexity, $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, perf, $description:tt } => {
Expand Down Expand Up @@ -130,12 +130,12 @@ macro_rules! declare_clippy_lint {
};
{ $(#[$attr:meta])* pub $name:tt, internal, $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, internal_warn, $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
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ declare_clippy_lint! {
/// **Example:**
/// ```rust
/// fn unused_lifetime<'a>(x: u8) {
/// ..
/// // ..
/// }
/// ```
pub EXTRA_UNUSED_LIFETIMES,
Expand Down
14 changes: 9 additions & 5 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,19 @@ declare_clippy_lint! {
/// **Known problems:** Sometimes the wrong binding is displayed (#383).
///
/// **Example:**
/// ```rust
/// ```rust,no_run
/// # let y = Some(1);
/// loop {
/// let x = match y {
/// Some(x) => x,
/// None => break,
/// }
/// };
/// // .. do something with x
/// }
/// // is easier written as
/// while let Some(x) = y {
/// // .. do something with x
/// }
/// };
/// ```
pub WHILE_LET_LOOP,
complexity,
Expand Down Expand Up @@ -309,8 +310,11 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```ignore
/// for i in 0..v.len() { foo(v[i]);
/// ```rust
/// # let v = vec![1];
/// # fn foo(bar: usize) {}
/// # fn bar(bar: usize, baz: usize) {}
/// for i in 0..v.len() { foo(v[i]); }
/// for i in 0..v.len() { bar(i, v[i]); }
/// ```
pub EXPLICIT_COUNTER_LOOP,
Expand Down
41 changes: 29 additions & 12 deletions clippy_lints/src/map_unit_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,29 @@ declare_clippy_lint! {
/// **Example:**
///
/// ```rust
/// let x: Option<&str> = do_stuff();
/// # fn do_stuff() -> Option<String> { Some(String::new()) }
/// # fn log_err_msg(foo: String) -> Option<String> { Some(foo) }
/// # fn format_msg(foo: String) -> String { String::new() }
/// let x: Option<String> = do_stuff();
/// x.map(log_err_msg);
/// x.map(|msg| log_err_msg(format_msg(msg)))
/// # let x: Option<String> = do_stuff();
/// x.map(|msg| log_err_msg(format_msg(msg)));
/// ```
///
/// The correct use would be:
///
/// ```rust
/// let x: Option<&str> = do_stuff();
/// # fn do_stuff() -> Option<String> { Some(String::new()) }
/// # fn log_err_msg(foo: String) -> Option<String> { Some(foo) }
/// # fn format_msg(foo: String) -> String { String::new() }
/// let x: Option<String> = do_stuff();
/// if let Some(msg) = x {
/// log_err_msg(msg)
/// log_err_msg(msg);
/// }
///
/// # let x: Option<String> = do_stuff();
/// if let Some(msg) = x {
/// log_err_msg(format_msg(msg))
/// log_err_msg(format_msg(msg));
/// }
/// ```
pub OPTION_MAP_UNIT_FN,
Expand All @@ -53,21 +62,29 @@ declare_clippy_lint! {
/// **Example:**
///
/// ```rust
/// let x: Result<&str, &str> = do_stuff();
/// # fn do_stuff() -> Result<String, String> { Ok(String::new()) }
/// # fn log_err_msg(foo: String) -> Result<String, String> { Ok(foo) }
/// # fn format_msg(foo: String) -> String { String::new() }
/// let x: Result<String, String> = do_stuff();
/// x.map(log_err_msg);
/// x.map(|msg| log_err_msg(format_msg(msg)))
/// # let x: Result<String, String> = do_stuff();
/// x.map(|msg| log_err_msg(format_msg(msg)));
/// ```
///
/// The correct use would be:
///
/// ```rust
/// let x: Result<&str, &str> = do_stuff();
/// # fn do_stuff() -> Result<String, String> { Ok(String::new()) }
/// # fn log_err_msg(foo: String) -> Result<String, String> { Ok(foo) }
/// # fn format_msg(foo: String) -> String { String::new() }
/// let x: Result<String, String> = do_stuff();
/// if let Ok(msg) = x {
/// log_err_msg(msg)
/// }
/// log_err_msg(msg);
/// };
/// # let x: Result<String, String> = do_stuff();
/// if let Ok(msg) = x {
/// log_err_msg(format_msg(msg))
/// }
/// log_err_msg(format_msg(msg));
/// };
/// ```
pub RESULT_MAP_UNIT_FN,
complexity,
Expand Down
13 changes: 9 additions & 4 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// iter.filter(|x| x == 0).next()
/// # let vec = vec![1];
/// vec.iter().filter(|x| **x == 0).next();
/// ```
pub FILTER_NEXT,
complexity,
Expand Down Expand Up @@ -345,7 +346,8 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// iter.find(|x| x == 0).is_some()
/// # let vec = vec![1];
/// vec.iter().find(|x| **x == 0).is_some();
/// ```
pub SEARCH_IS_SOME,
complexity,
Expand All @@ -363,7 +365,8 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// name.chars().next() == Some('_')
/// let name = "foo";
/// name.chars().next() == Some('_');
/// ```
pub CHARS_NEXT_CMP,
complexity,
Expand Down Expand Up @@ -434,7 +437,7 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// 42u64.clone()
/// 42u64.clone();
/// ```
pub CLONE_ON_COPY,
complexity,
Expand Down Expand Up @@ -708,11 +711,13 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// # fn do_stuff(x: &[i32]) {}
/// let x: &[i32] = &[1, 2, 3, 4, 5];
/// do_stuff(x.as_ref());
/// ```
/// The correct use would be:
/// ```rust
/// # fn do_stuff(x: &[i32]) {}
/// let x: &[i32] = &[1, 2, 3, 4, 5];
/// do_stuff(x);
/// ```
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```rust
/// ```rust,ignore
/// f() && g(); // We should write `if f() { g(); }`.
/// ```
pub SHORT_CIRCUIT_STATEMENT,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/misc_early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```rust
/// ```rust,ignore
/// (|| 42)()
/// ```
pub REDUNDANT_CLOSURE_CALL,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/needless_bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ declare_clippy_lint! {
/// shorter code.
///
/// **Example:**
/// ```rust
/// ```rust,ignore
/// if x {
/// false
/// } else {
Expand All @@ -46,7 +46,7 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```rust
/// ```rust,ignore
/// if x == true {} // could be `if x { }`
/// ```
pub BOOL_COMPARISON,
Expand Down
5 changes: 2 additions & 3 deletions clippy_lints/src/needless_borrowed_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ declare_clippy_lint! {
///
/// **Known problems:** It seems that the `&ref` pattern is sometimes useful.
/// For instance in the following snippet:
/// ```rust
/// ```rust,ignore
/// enum Animal {
/// Cat(u64),
/// Dog(u64),
/// }
///
/// fn foo(a: &Animal, b: &Animal) {
/// match (a, b) {
/// (&Animal::Cat(v), k) | (k, &Animal::Cat(v)) => (), // lifetime
/// mismatch error
/// (&Animal::Cat(v), k) | (k, &Animal::Cat(v)) => (), // lifetime mismatch error
/// (&Animal::Dog(ref c), &Animal::Dog(_)) => ()
/// }
/// }
Expand Down
10 changes: 8 additions & 2 deletions clippy_lints/src/needless_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// # struct Point {
/// # x: i32,
/// # y: i32,
/// # z: i32,
/// # }
/// # let zero_point = Point { x: 0, y: 0, z: 0 };
/// Point {
/// x: 1,
/// y: 0,
/// y: 1,
/// ..zero_point
/// }
/// };
/// ```
pub NEEDLESS_UPDATE,
complexity,
Expand Down
Loading

0 comments on commit 3dc9183

Please sign in to comment.