Skip to content
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

Doctests: Enable running doc tests for complexity lints #4325

Merged
merged 2 commits into from Aug 3, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -45,7 +45,8 @@ declare_clippy_lint! {
/// **Example:**
/// ```rust
/// let mut a = 5;
/// ...
/// let b = 2;
/// // ...
/// a += a + b;
/// ```
pub MISREFACTORED_ASSIGN_OP,
@@ -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,
@@ -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,
@@ -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;
@@ -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!());
@@ -16,8 +16,10 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// # use std::io::Write;
/// # let bar = "furchtbar";
This conversation was marked as resolved by flip1995

This comment has been minimized.

Copy link
@flip1995
/// // 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,
@@ -26,8 +26,9 @@ declare_clippy_lint! {
///
/// **Examples:**
/// ```rust
/// format!("foo")
/// format!("{}", foo)
/// # let foo = "foo";
/// format!("foo");
/// format!("{}", foo);
/// ```
pub USELESS_FORMAT,
complexity,
@@ -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,
@@ -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,
@@ -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,
@@ -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 } => {
@@ -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
}
};
}
@@ -47,7 +47,7 @@ declare_clippy_lint! {
/// **Example:**
/// ```rust
/// fn unused_lifetime<'a>(x: u8) {
/// ..
/// // ..
/// }
/// ```
pub EXTRA_UNUSED_LIFETIMES,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -434,7 +437,7 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// 42u64.clone()
/// 42u64.clone();
/// ```
pub CLONE_ON_COPY,
complexity,
@@ -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);
/// ```
@@ -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,
@@ -53,7 +53,7 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```rust
/// ```rust,ignore
/// (|| 42)()
/// ```
pub REDUNDANT_CLOSURE_CALL,
@@ -24,7 +24,7 @@ declare_clippy_lint! {
/// shorter code.
///
/// **Example:**
/// ```rust
/// ```rust,ignore
/// if x {
/// false
/// } else {
@@ -46,7 +46,7 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```rust
/// ```rust,ignore
/// if x == true {} // could be `if x { }`
/// ```
pub BOOL_COMPARISON,
@@ -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(_)) => ()
/// }
/// }
@@ -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,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.