mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Rollup merge of #4329 - phansch:doctests_pedantic, r=flip1995
Doctests: Enable running doc tests for pedantic lints changelog: none master: 202 passed; 0 failed; 122 ignored; 0 measured; 0 filtered out this PR: 254 passed; 0 failed; 131 ignored; 0 measured; 0 filtered out cc #4319
This commit is contained in:
commit
713ad964af
16 changed files with 73 additions and 27 deletions
|
@ -27,6 +27,8 @@ declare_clippy_lint! {
|
||||||
/// Could be written:
|
/// Could be written:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # use std::convert::TryFrom;
|
||||||
|
/// # let foo = 1;
|
||||||
/// # let _ =
|
/// # let _ =
|
||||||
/// i32::try_from(foo).is_ok()
|
/// i32::try_from(foo).is_ok()
|
||||||
/// # ;
|
/// # ;
|
||||||
|
|
|
@ -13,7 +13,7 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust,ignore
|
||||||
/// #[derive(Copy, Clone)]
|
/// #[derive(Copy, Clone)]
|
||||||
/// struct Countdown(u8);
|
/// struct Countdown(u8);
|
||||||
///
|
///
|
||||||
|
|
|
@ -49,12 +49,12 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** Bounds of generic types are sometimes wrong: https://github.com/rust-lang/rust/issues/26925
|
/// **Known problems:** Bounds of generic types are sometimes wrong: https://github.com/rust-lang/rust/issues/26925
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust,ignore
|
||||||
/// #[derive(Copy)]
|
/// #[derive(Copy)]
|
||||||
/// struct Foo;
|
/// struct Foo;
|
||||||
///
|
///
|
||||||
/// impl Clone for Foo {
|
/// impl Clone for Foo {
|
||||||
/// ..
|
/// // ..
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub EXPL_IMPL_CLONE_ON_COPY,
|
pub EXPL_IMPL_CLONE_ON_COPY,
|
||||||
|
|
|
@ -27,7 +27,7 @@ declare_clippy_lint! {
|
||||||
/// /// Do something with the foo_bar parameter. See also
|
/// /// Do something with the foo_bar parameter. See also
|
||||||
/// /// that::other::module::foo.
|
/// /// that::other::module::foo.
|
||||||
/// // ^ `foo_bar` and `that::other::module::foo` should be ticked.
|
/// // ^ `foo_bar` and `that::other::module::foo` should be ticked.
|
||||||
/// fn doit(foo_bar) { .. }
|
/// fn doit(foo_bar: usize) {}
|
||||||
/// ```
|
/// ```
|
||||||
pub DOC_MARKDOWN,
|
pub DOC_MARKDOWN,
|
||||||
pedantic,
|
pedantic,
|
||||||
|
|
|
@ -17,6 +17,9 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # let v: Vec<usize> = vec![];
|
||||||
|
/// # fn a() {}
|
||||||
|
/// # fn b() {}
|
||||||
/// if !v.is_empty() {
|
/// if !v.is_empty() {
|
||||||
/// a()
|
/// a()
|
||||||
/// } else {
|
/// } else {
|
||||||
|
@ -27,6 +30,9 @@ declare_clippy_lint! {
|
||||||
/// Could be written:
|
/// Could be written:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # let v: Vec<usize> = vec![];
|
||||||
|
/// # fn a() {}
|
||||||
|
/// # fn b() {}
|
||||||
/// if v.is_empty() {
|
/// if v.is_empty() {
|
||||||
/// b()
|
/// b()
|
||||||
/// } else {
|
/// } else {
|
||||||
|
|
|
@ -34,7 +34,8 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// [0..].iter().zip(infinite_iter.take_while(|x| x > 5))
|
/// let infinite_iter = 0..;
|
||||||
|
/// [0..].iter().zip(infinite_iter.take_while(|x| *x > 5));
|
||||||
/// ```
|
/// ```
|
||||||
pub MAYBE_INFINITE_ITER,
|
pub MAYBE_INFINITE_ITER,
|
||||||
pedantic,
|
pedantic,
|
||||||
|
|
|
@ -110,7 +110,7 @@ macro_rules! declare_clippy_lint {
|
||||||
};
|
};
|
||||||
{ $(#[$attr:meta])* pub $name:tt, pedantic, $description:tt } => {
|
{ $(#[$attr:meta])* pub $name:tt, pedantic, $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, restriction, $description:tt } => {
|
{ $(#[$attr:meta])* pub $name:tt, restriction, $description:tt } => {
|
||||||
|
|
|
@ -91,16 +91,18 @@ declare_clippy_lint! {
|
||||||
/// types.
|
/// types.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
/// // with `y` a `Vec` or slice:
|
/// // with `y` a `Vec` or slice:
|
||||||
|
/// # let y = vec![1];
|
||||||
/// for x in y.iter() {
|
/// for x in y.iter() {
|
||||||
/// ..
|
/// // ..
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
/// can be rewritten to
|
/// can be rewritten to
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # let y = vec![1];
|
||||||
/// for x in &y {
|
/// for x in &y {
|
||||||
/// ..
|
/// // ..
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub EXPLICIT_ITER_LOOP,
|
pub EXPLICIT_ITER_LOOP,
|
||||||
|
@ -117,16 +119,18 @@ declare_clippy_lint! {
|
||||||
/// **Known problems:** None
|
/// **Known problems:** None
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
|
/// # let y = vec![1];
|
||||||
/// // with `y` a `Vec` or slice:
|
/// // with `y` a `Vec` or slice:
|
||||||
/// for x in y.into_iter() {
|
/// for x in y.into_iter() {
|
||||||
/// ..
|
/// // ..
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
/// can be rewritten to
|
/// can be rewritten to
|
||||||
/// ```ignore
|
/// ```rust
|
||||||
|
/// # let y = vec![1];
|
||||||
/// for x in y {
|
/// for x in y {
|
||||||
/// ..
|
/// // ..
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub EXPLICIT_INTO_ITER_LOOP,
|
pub EXPLICIT_INTO_ITER_LOOP,
|
||||||
|
|
|
@ -53,19 +53,25 @@ declare_clippy_lint! {
|
||||||
/// Using `match`:
|
/// Using `match`:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # fn bar(foo: &usize) {}
|
||||||
|
/// # let other_ref: usize = 1;
|
||||||
|
/// # let x: Option<&usize> = Some(&1);
|
||||||
/// match x {
|
/// match x {
|
||||||
/// Some(ref foo) => bar(foo),
|
/// Some(ref foo) => bar(foo),
|
||||||
/// _ => bar(other_ref),
|
/// _ => bar(&other_ref),
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Using `if let` with `else`:
|
/// Using `if let` with `else`:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # fn bar(foo: &usize) {}
|
||||||
|
/// # let other_ref: usize = 1;
|
||||||
|
/// # let x: Option<&usize> = Some(&1);
|
||||||
/// if let Some(ref foo) = x {
|
/// if let Some(ref foo) = x {
|
||||||
/// bar(foo);
|
/// bar(foo);
|
||||||
/// } else {
|
/// } else {
|
||||||
/// bar(other_ref);
|
/// bar(&other_ref);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub SINGLE_MATCH_ELSE,
|
pub SINGLE_MATCH_ELSE,
|
||||||
|
|
|
@ -179,7 +179,8 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// x.map(|a| a + 1).unwrap_or(0)
|
/// # let x = Some(1);
|
||||||
|
/// x.map(|a| a + 1).unwrap_or(0);
|
||||||
/// ```
|
/// ```
|
||||||
pub OPTION_MAP_UNWRAP_OR,
|
pub OPTION_MAP_UNWRAP_OR,
|
||||||
pedantic,
|
pedantic,
|
||||||
|
@ -196,7 +197,9 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// x.map(|a| a + 1).unwrap_or_else(some_function)
|
/// # let x = Some(1);
|
||||||
|
/// # fn some_function() -> usize { 1 }
|
||||||
|
/// x.map(|a| a + 1).unwrap_or_else(some_function);
|
||||||
/// ```
|
/// ```
|
||||||
pub OPTION_MAP_UNWRAP_OR_ELSE,
|
pub OPTION_MAP_UNWRAP_OR_ELSE,
|
||||||
pedantic,
|
pedantic,
|
||||||
|
@ -213,7 +216,9 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// x.map(|a| a + 1).unwrap_or_else(some_function)
|
/// # let x: Result<usize, ()> = Ok(1);
|
||||||
|
/// # fn some_function(foo: ()) -> usize { 1 }
|
||||||
|
/// x.map(|a| a + 1).unwrap_or_else(some_function);
|
||||||
/// ```
|
/// ```
|
||||||
pub RESULT_MAP_UNWRAP_OR_ELSE,
|
pub RESULT_MAP_UNWRAP_OR_ELSE,
|
||||||
pedantic,
|
pedantic,
|
||||||
|
@ -265,7 +270,8 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// iter.map(|x| x.iter()).flatten()
|
/// let vec = vec![vec![1]];
|
||||||
|
/// vec.iter().map(|x| x.iter()).flatten();
|
||||||
/// ```
|
/// ```
|
||||||
pub MAP_FLATTEN,
|
pub MAP_FLATTEN,
|
||||||
pedantic,
|
pedantic,
|
||||||
|
@ -284,7 +290,8 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// iter.filter(|x| x == 0).map(|x| x * 2)
|
/// let vec = vec![1];
|
||||||
|
/// vec.iter().filter(|x| **x == 0).map(|x| *x * 2);
|
||||||
/// ```
|
/// ```
|
||||||
pub FILTER_MAP,
|
pub FILTER_MAP,
|
||||||
pedantic,
|
pedantic,
|
||||||
|
@ -324,7 +331,7 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// (0..3).find(|x| x == 2).map(|x| x * 2);
|
/// (0..3).find(|x| *x == 2).map(|x| x * 2);
|
||||||
/// ```
|
/// ```
|
||||||
/// Can be written as
|
/// Can be written as
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
|
|
@ -16,6 +16,7 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # let mut y = 1;
|
||||||
/// let x = &mut &mut y;
|
/// let x = &mut &mut y;
|
||||||
/// ```
|
/// ```
|
||||||
pub MUT_MUT,
|
pub MUT_MUT,
|
||||||
|
|
|
@ -57,6 +57,9 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # fn condition() -> bool { false }
|
||||||
|
/// # fn update_condition() {}
|
||||||
|
/// # let x = false;
|
||||||
/// while condition() {
|
/// while condition() {
|
||||||
/// update_condition();
|
/// update_condition();
|
||||||
/// if x {
|
/// if x {
|
||||||
|
@ -71,6 +74,9 @@ declare_clippy_lint! {
|
||||||
/// Could be rewritten as
|
/// Could be rewritten as
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # fn condition() -> bool { false }
|
||||||
|
/// # fn update_condition() {}
|
||||||
|
/// # let x = false;
|
||||||
/// while condition() {
|
/// while condition() {
|
||||||
/// update_condition();
|
/// update_condition();
|
||||||
/// if x {
|
/// if x {
|
||||||
|
@ -83,22 +89,26 @@ declare_clippy_lint! {
|
||||||
/// As another example, the following code
|
/// As another example, the following code
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # fn waiting() -> bool { false }
|
||||||
/// loop {
|
/// loop {
|
||||||
/// if waiting() {
|
/// if waiting() {
|
||||||
/// continue;
|
/// continue;
|
||||||
/// } else {
|
/// } else {
|
||||||
/// // Do something useful
|
/// // Do something useful
|
||||||
/// }
|
/// }
|
||||||
|
/// # break;
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
/// Could be rewritten as
|
/// Could be rewritten as
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # fn waiting() -> bool { false }
|
||||||
/// loop {
|
/// loop {
|
||||||
/// if waiting() {
|
/// if waiting() {
|
||||||
/// continue;
|
/// continue;
|
||||||
/// }
|
/// }
|
||||||
/// // Do something useful
|
/// // Do something useful
|
||||||
|
/// # break;
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub NEEDLESS_CONTINUE,
|
pub NEEDLESS_CONTINUE,
|
||||||
|
|
|
@ -40,6 +40,9 @@ declare_clippy_lint! {
|
||||||
/// fn foo(v: Vec<i32>) {
|
/// fn foo(v: Vec<i32>) {
|
||||||
/// assert_eq!(v.len(), 42);
|
/// assert_eq!(v.len(), 42);
|
||||||
/// }
|
/// }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
/// // should be
|
/// // should be
|
||||||
/// fn foo(v: &[i32]) {
|
/// fn foo(v: &[i32]) {
|
||||||
/// assert_eq!(v.len(), 42);
|
/// assert_eq!(v.len(), 42);
|
||||||
|
|
|
@ -16,12 +16,14 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # use core::sync::atomic::{ATOMIC_ISIZE_INIT, AtomicIsize};
|
||||||
/// static FOO: AtomicIsize = ATOMIC_ISIZE_INIT;
|
/// static FOO: AtomicIsize = ATOMIC_ISIZE_INIT;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Could be written:
|
/// Could be written:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # use core::sync::atomic::AtomicIsize;
|
||||||
/// static FOO: AtomicIsize = AtomicIsize::new(0);
|
/// static FOO: AtomicIsize = AtomicIsize::new(0);
|
||||||
/// ```
|
/// ```
|
||||||
pub REPLACE_CONSTS,
|
pub REPLACE_CONSTS,
|
||||||
|
|
|
@ -67,6 +67,8 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # let y = 1;
|
||||||
|
/// # let z = 2;
|
||||||
/// let x = y;
|
/// let x = y;
|
||||||
/// let x = z; // shadows the earlier binding
|
/// let x = z; // shadows the earlier binding
|
||||||
/// ```
|
/// ```
|
||||||
|
|
|
@ -133,7 +133,8 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// let x = LinkedList::new();
|
/// # use std::collections::LinkedList;
|
||||||
|
/// let x: LinkedList<usize> = LinkedList::new();
|
||||||
/// ```
|
/// ```
|
||||||
pub LINKEDLIST,
|
pub LINKEDLIST,
|
||||||
pedantic,
|
pedantic,
|
||||||
|
@ -660,8 +661,8 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// let x = u64::MAX;
|
/// let x = std::u64::MAX;
|
||||||
/// x as f64
|
/// x as f64;
|
||||||
/// ```
|
/// ```
|
||||||
pub CAST_PRECISION_LOSS,
|
pub CAST_PRECISION_LOSS,
|
||||||
pedantic,
|
pedantic,
|
||||||
|
@ -682,7 +683,7 @@ declare_clippy_lint! {
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// let y: i8 = -1;
|
/// let y: i8 = -1;
|
||||||
/// y as u128 // will return 18446744073709551615
|
/// y as u128; // will return 18446744073709551615
|
||||||
/// ```
|
/// ```
|
||||||
pub CAST_SIGN_LOSS,
|
pub CAST_SIGN_LOSS,
|
||||||
pedantic,
|
pedantic,
|
||||||
|
@ -727,7 +728,7 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// u32::MAX as i32 // will yield a value of `-1`
|
/// std::u32::MAX as i32; // will yield a value of `-1`
|
||||||
/// ```
|
/// ```
|
||||||
pub CAST_POSSIBLE_WRAP,
|
pub CAST_POSSIBLE_WRAP,
|
||||||
pedantic,
|
pedantic,
|
||||||
|
@ -1689,7 +1690,8 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// let x : u8 = ...; (x as u32) > 300
|
/// let x: u8 = 1;
|
||||||
|
/// (x as u32) > 300;
|
||||||
/// ```
|
/// ```
|
||||||
pub INVALID_UPCAST_COMPARISONS,
|
pub INVALID_UPCAST_COMPARISONS,
|
||||||
pedantic,
|
pedantic,
|
||||||
|
|
Loading…
Reference in a new issue