Skip to content

Commit

Permalink
Auto merge of #4338 - flip1995:rollup-9cm4jbr, r=flip1995
Browse files Browse the repository at this point in the history
Rollup of 4 pull requests

Successful merges:

 - #4329 (Doctests: Enable running doc tests for pedantic lints)
 - #4330 (Doctests: Enable running doc tests for nursery lints)
 - #4331 (Doctests: Enable running doc tests for restriction lints)
 - #4332 (Split up cast.rs tests, run-rustfix for unnecessary_cast)

Failed merges:

r? @ghost

changelog: none
  • Loading branch information
bors committed Aug 5, 2019
2 parents a90b3ba + 9259eeb commit ca6a9be
Show file tree
Hide file tree
Showing 35 changed files with 261 additions and 120 deletions.
6 changes: 4 additions & 2 deletions clippy_lints/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// a + 1
/// # let a = 0;
/// a + 1;
/// ```
pub INTEGER_ARITHMETIC,
restriction,
Expand All @@ -33,7 +34,8 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// a + 1.0
/// # let a = 0.0;
/// a + 1.0;
/// ```
pub FLOAT_ARITHMETIC,
restriction,
Expand Down
14 changes: 7 additions & 7 deletions clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// // Bad
/// #[inline(always)]
///
/// fn not_quite_good_code(..) { ... }
///
/// // Good (as inner attribute)
/// #![inline(always)]
///
/// fn this_is_fine(..) { ... }
/// fn this_is_fine() { }
///
/// // Bad
/// #[inline(always)]
///
/// fn not_quite_good_code() { }
///
/// // Good (as outer attribute)
/// #[inline(always)]
/// fn this_is_fine_too(..) { ... }
/// fn this_is_fine_too() { }
/// ```
pub EMPTY_LINE_AFTER_OUTER_ATTR,
nursery,
Expand Down
2 changes: 2 additions & 0 deletions clippy_lints/src/checked_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ declare_clippy_lint! {
/// Could be written:
///
/// ```rust
/// # use std::convert::TryFrom;
/// # let foo = 1;
/// # let _ =
/// i32::try_from(foo).is_ok()
/// # ;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/copy_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```rust
/// ```rust,ignore
/// #[derive(Copy, Clone)]
/// struct Countdown(u8);
///
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ declare_clippy_lint! {
/// **Known problems:** Bounds of generic types are sometimes wrong: https://github.com/rust-lang/rust/issues/26925
///
/// **Example:**
/// ```rust
/// ```rust,ignore
/// #[derive(Copy)]
/// struct Foo;
///
/// impl Clone for Foo {
/// ..
/// // ..
/// }
/// ```
pub EXPL_IMPL_CLONE_ON_COPY,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ declare_clippy_lint! {
/// /// Do something with the foo_bar parameter. See also
/// /// that::other::module::foo.
/// // ^ `foo_bar` and `that::other::module::foo` should be ticked.
/// fn doit(foo_bar) { .. }
/// fn doit(foo_bar: usize) {}
/// ```
pub DOC_MARKDOWN,
pedantic,
Expand Down
6 changes: 6 additions & 0 deletions clippy_lints/src/else_if_without_else.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// # fn a() {}
/// # fn b() {}
/// # let x: i32 = 1;
/// if x.is_positive() {
/// a();
/// } else if x.is_negative() {
Expand All @@ -26,6 +29,9 @@ declare_clippy_lint! {
/// Could be written:
///
/// ```rust
/// # fn a() {}
/// # fn b() {}
/// # let x: i32 = 1;
/// if x.is_positive() {
/// a();
/// } else if x.is_negative() {
Expand Down
6 changes: 6 additions & 0 deletions clippy_lints/src/if_not_else.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// # let v: Vec<usize> = vec![];
/// # fn a() {}
/// # fn b() {}
/// if !v.is_empty() {
/// a()
/// } else {
Expand All @@ -27,6 +30,9 @@ declare_clippy_lint! {
/// Could be written:
///
/// ```rust
/// # let v: Vec<usize> = vec![];
/// # fn a() {}
/// # fn b() {}
/// if v.is_empty() {
/// b()
/// } else {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/indexing_slicing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ declare_clippy_lint! {
/// **Known problems:** Hopefully none.
///
/// **Example:**
/// ```rust
/// ```rust,no_run
/// // Vector
/// let x = vec![0; 5];
///
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/infinite_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```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,
pedantic,
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 @@ -110,12 +110,12 @@ macro_rules! declare_clippy_lint {
};
{ $(#[$attr:meta])* pub $name:tt, pedantic, $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, restriction, $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, cargo, $description:tt } => {
Expand All @@ -125,7 +125,7 @@ macro_rules! declare_clippy_lint {
};
{ $(#[$attr:meta])* pub $name:tt, nursery, $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, $description:tt } => {
Expand Down
18 changes: 11 additions & 7 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,18 @@ declare_clippy_lint! {
/// types.
///
/// **Example:**
/// ```ignore
/// ```rust
/// // with `y` a `Vec` or slice:
/// # let y = vec![1];
/// for x in y.iter() {
/// ..
/// // ..
/// }
/// ```
/// can be rewritten to
/// ```rust
/// # let y = vec![1];
/// for x in &y {
/// ..
/// // ..
/// }
/// ```
pub EXPLICIT_ITER_LOOP,
Expand All @@ -117,16 +119,18 @@ declare_clippy_lint! {
/// **Known problems:** None
///
/// **Example:**
/// ```ignore
/// ```rust
/// # let y = vec![1];
/// // with `y` a `Vec` or slice:
/// for x in y.into_iter() {
/// ..
/// // ..
/// }
/// ```
/// can be rewritten to
/// ```ignore
/// ```rust
/// # let y = vec![1];
/// for x in y {
/// ..
/// // ..
/// }
/// ```
pub EXPLICIT_INTO_ITER_LOOP,
Expand Down
12 changes: 10 additions & 2 deletions clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,25 @@ declare_clippy_lint! {
/// Using `match`:
///
/// ```rust
/// # fn bar(foo: &usize) {}
/// # let other_ref: usize = 1;
/// # let x: Option<&usize> = Some(&1);
/// match x {
/// Some(ref foo) => bar(foo),
/// _ => bar(other_ref),
/// _ => bar(&other_ref),
/// }
/// ```
///
/// Using `if let` with `else`:
///
/// ```rust
/// # fn bar(foo: &usize) {}
/// # let other_ref: usize = 1;
/// # let x: Option<&usize> = Some(&1);
/// if let Some(ref foo) = x {
/// bar(foo);
/// } else {
/// bar(other_ref);
/// bar(&other_ref);
/// }
/// ```
pub SINGLE_MATCH_ELSE,
Expand Down Expand Up @@ -205,6 +211,8 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// # enum Foo { A(usize), B(usize) }
/// # let x = Foo::B(1);
/// match x {
/// A => {},
/// _ => {},
Expand Down
2 changes: 2 additions & 0 deletions clippy_lints/src/mem_forget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// # use std::mem;
/// # use std::rc::Rc;
/// mem::forget(Rc::new(55))
/// ```
pub MEM_FORGET,
Expand Down
55 changes: 43 additions & 12 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,19 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
///
/// Using unwrap on an `Option`:
///
/// ```rust
/// x.unwrap()
/// let opt = Some(1);
/// opt.unwrap();
/// ```
///
/// Better:
///
/// ```rust
/// let opt = Some(1);
/// opt.expect("more helpful message");
/// ```
pub OPTION_UNWRAP_USED,
restriction,
Expand All @@ -62,8 +73,18 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// Using unwrap on an `Option`:
///
/// ```rust
/// x.unwrap()
/// let res: Result<usize, ()> = Ok(1);
/// res.unwrap();
/// ```
///
/// Better:
///
/// ```rust
/// let res: Result<usize, ()> = Ok(1);
/// res.expect("more helpful message");
/// ```
pub RESULT_UNWRAP_USED,
restriction,
Expand Down Expand Up @@ -141,9 +162,10 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// impl X {
/// pub fn as_str(self) -> &str {
/// ..
/// # struct X;
/// impl<'a> X {
/// pub fn as_str(self) -> &'a str {
/// "foo"
/// }
/// }
/// ```
Expand Down Expand Up @@ -179,7 +201,8 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```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,
pedantic,
Expand All @@ -196,7 +219,9 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```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,
pedantic,
Expand All @@ -213,7 +238,9 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```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,
pedantic,
Expand Down Expand Up @@ -265,7 +292,8 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// iter.map(|x| x.iter()).flatten()
/// let vec = vec![vec![1]];
/// vec.iter().map(|x| x.iter()).flatten();
/// ```
pub MAP_FLATTEN,
pedantic,
Expand All @@ -284,7 +312,8 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```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,
pedantic,
Expand Down Expand Up @@ -324,7 +353,7 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```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
/// ```rust
Expand Down Expand Up @@ -467,7 +496,9 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// x.clone()
/// # use std::rc::Rc;
/// let x = Rc::new(1);
/// x.clone();
/// ```
pub CLONE_ON_REF_PTR,
restriction,
Expand Down
Loading

0 comments on commit ca6a9be

Please sign in to comment.