Skip to content

Commit ca6a9be

Browse files
committed
Auto merge of #4338 - flip1995:rollup-9cm4jbr, r=flip1995
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
2 parents a90b3ba + 9259eeb commit ca6a9be

35 files changed

+261
-120
lines changed

clippy_lints/src/arithmetic.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ declare_clippy_lint! {
1616
///
1717
/// **Example:**
1818
/// ```rust
19-
/// a + 1
19+
/// # let a = 0;
20+
/// a + 1;
2021
/// ```
2122
pub INTEGER_ARITHMETIC,
2223
restriction,
@@ -33,7 +34,8 @@ declare_clippy_lint! {
3334
///
3435
/// **Example:**
3536
/// ```rust
36-
/// a + 1.0
37+
/// # let a = 0.0;
38+
/// a + 1.0;
3739
/// ```
3840
pub FLOAT_ARITHMETIC,
3941
restriction,

clippy_lints/src/attrs.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,19 @@ declare_clippy_lint! {
113113
///
114114
/// **Example:**
115115
/// ```rust
116-
/// // Bad
117-
/// #[inline(always)]
118-
///
119-
/// fn not_quite_good_code(..) { ... }
120-
///
121116
/// // Good (as inner attribute)
122117
/// #![inline(always)]
123118
///
124-
/// fn this_is_fine(..) { ... }
119+
/// fn this_is_fine() { }
120+
///
121+
/// // Bad
122+
/// #[inline(always)]
123+
///
124+
/// fn not_quite_good_code() { }
125125
///
126126
/// // Good (as outer attribute)
127127
/// #[inline(always)]
128-
/// fn this_is_fine_too(..) { ... }
128+
/// fn this_is_fine_too() { }
129129
/// ```
130130
pub EMPTY_LINE_AFTER_OUTER_ATTR,
131131
nursery,

clippy_lints/src/checked_conversions.rs

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ declare_clippy_lint! {
2727
/// Could be written:
2828
///
2929
/// ```rust
30+
/// # use std::convert::TryFrom;
31+
/// # let foo = 1;
3032
/// # let _ =
3133
/// i32::try_from(foo).is_ok()
3234
/// # ;

clippy_lints/src/copy_iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ declare_clippy_lint! {
1313
/// **Known problems:** None.
1414
///
1515
/// **Example:**
16-
/// ```rust
16+
/// ```rust,ignore
1717
/// #[derive(Copy, Clone)]
1818
/// struct Countdown(u8);
1919
///

clippy_lints/src/derive.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ declare_clippy_lint! {
4949
/// **Known problems:** Bounds of generic types are sometimes wrong: https://github.com/rust-lang/rust/issues/26925
5050
///
5151
/// **Example:**
52-
/// ```rust
52+
/// ```rust,ignore
5353
/// #[derive(Copy)]
5454
/// struct Foo;
5555
///
5656
/// impl Clone for Foo {
57-
/// ..
57+
/// // ..
5858
/// }
5959
/// ```
6060
pub EXPL_IMPL_CLONE_ON_COPY,

clippy_lints/src/doc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ declare_clippy_lint! {
2727
/// /// Do something with the foo_bar parameter. See also
2828
/// /// that::other::module::foo.
2929
/// // ^ `foo_bar` and `that::other::module::foo` should be ticked.
30-
/// fn doit(foo_bar) { .. }
30+
/// fn doit(foo_bar: usize) {}
3131
/// ```
3232
pub DOC_MARKDOWN,
3333
pedantic,

clippy_lints/src/else_if_without_else.rs

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ declare_clippy_lint! {
1616
///
1717
/// **Example:**
1818
/// ```rust
19+
/// # fn a() {}
20+
/// # fn b() {}
21+
/// # let x: i32 = 1;
1922
/// if x.is_positive() {
2023
/// a();
2124
/// } else if x.is_negative() {
@@ -26,6 +29,9 @@ declare_clippy_lint! {
2629
/// Could be written:
2730
///
2831
/// ```rust
32+
/// # fn a() {}
33+
/// # fn b() {}
34+
/// # let x: i32 = 1;
2935
/// if x.is_positive() {
3036
/// a();
3137
/// } else if x.is_negative() {

clippy_lints/src/if_not_else.rs

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ declare_clippy_lint! {
1717
///
1818
/// **Example:**
1919
/// ```rust
20+
/// # let v: Vec<usize> = vec![];
21+
/// # fn a() {}
22+
/// # fn b() {}
2023
/// if !v.is_empty() {
2124
/// a()
2225
/// } else {
@@ -27,6 +30,9 @@ declare_clippy_lint! {
2730
/// Could be written:
2831
///
2932
/// ```rust
33+
/// # let v: Vec<usize> = vec![];
34+
/// # fn a() {}
35+
/// # fn b() {}
3036
/// if v.is_empty() {
3137
/// b()
3238
/// } else {

clippy_lints/src/indexing_slicing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ declare_clippy_lint! {
4747
/// **Known problems:** Hopefully none.
4848
///
4949
/// **Example:**
50-
/// ```rust
50+
/// ```rust,no_run
5151
/// // Vector
5252
/// let x = vec![0; 5];
5353
///

clippy_lints/src/infinite_iter.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ declare_clippy_lint! {
3434
///
3535
/// **Example:**
3636
/// ```rust
37-
/// [0..].iter().zip(infinite_iter.take_while(|x| x > 5))
37+
/// let infinite_iter = 0..;
38+
/// [0..].iter().zip(infinite_iter.take_while(|x| *x > 5));
3839
/// ```
3940
pub MAYBE_INFINITE_ITER,
4041
pedantic,

clippy_lints/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ macro_rules! declare_clippy_lint {
110110
};
111111
{ $(#[$attr:meta])* pub $name:tt, pedantic, $description:tt } => {
112112
declare_tool_lint! {
113-
pub clippy::$name, Allow, $description, report_in_external_macro: true
113+
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
114114
}
115115
};
116116
{ $(#[$attr:meta])* pub $name:tt, restriction, $description:tt } => {
117117
declare_tool_lint! {
118-
pub clippy::$name, Allow, $description, report_in_external_macro: true
118+
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
119119
}
120120
};
121121
{ $(#[$attr:meta])* pub $name:tt, cargo, $description:tt } => {
@@ -125,7 +125,7 @@ macro_rules! declare_clippy_lint {
125125
};
126126
{ $(#[$attr:meta])* pub $name:tt, nursery, $description:tt } => {
127127
declare_tool_lint! {
128-
pub clippy::$name, Allow, $description, report_in_external_macro: true
128+
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
129129
}
130130
};
131131
{ $(#[$attr:meta])* pub $name:tt, internal, $description:tt } => {

clippy_lints/src/loops.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,18 @@ declare_clippy_lint! {
9191
/// types.
9292
///
9393
/// **Example:**
94-
/// ```ignore
94+
/// ```rust
9595
/// // with `y` a `Vec` or slice:
96+
/// # let y = vec![1];
9697
/// for x in y.iter() {
97-
/// ..
98+
/// // ..
9899
/// }
99100
/// ```
100101
/// can be rewritten to
101102
/// ```rust
103+
/// # let y = vec![1];
102104
/// for x in &y {
103-
/// ..
105+
/// // ..
104106
/// }
105107
/// ```
106108
pub EXPLICIT_ITER_LOOP,
@@ -117,16 +119,18 @@ declare_clippy_lint! {
117119
/// **Known problems:** None
118120
///
119121
/// **Example:**
120-
/// ```ignore
122+
/// ```rust
123+
/// # let y = vec![1];
121124
/// // with `y` a `Vec` or slice:
122125
/// for x in y.into_iter() {
123-
/// ..
126+
/// // ..
124127
/// }
125128
/// ```
126129
/// can be rewritten to
127-
/// ```ignore
130+
/// ```rust
131+
/// # let y = vec![1];
128132
/// for x in y {
129-
/// ..
133+
/// // ..
130134
/// }
131135
/// ```
132136
pub EXPLICIT_INTO_ITER_LOOP,

clippy_lints/src/matches.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,25 @@ declare_clippy_lint! {
5353
/// Using `match`:
5454
///
5555
/// ```rust
56+
/// # fn bar(foo: &usize) {}
57+
/// # let other_ref: usize = 1;
58+
/// # let x: Option<&usize> = Some(&1);
5659
/// match x {
5760
/// Some(ref foo) => bar(foo),
58-
/// _ => bar(other_ref),
61+
/// _ => bar(&other_ref),
5962
/// }
6063
/// ```
6164
///
6265
/// Using `if let` with `else`:
6366
///
6467
/// ```rust
68+
/// # fn bar(foo: &usize) {}
69+
/// # let other_ref: usize = 1;
70+
/// # let x: Option<&usize> = Some(&1);
6571
/// if let Some(ref foo) = x {
6672
/// bar(foo);
6773
/// } else {
68-
/// bar(other_ref);
74+
/// bar(&other_ref);
6975
/// }
7076
/// ```
7177
pub SINGLE_MATCH_ELSE,
@@ -205,6 +211,8 @@ declare_clippy_lint! {
205211
///
206212
/// **Example:**
207213
/// ```rust
214+
/// # enum Foo { A(usize), B(usize) }
215+
/// # let x = Foo::B(1);
208216
/// match x {
209217
/// A => {},
210218
/// _ => {},

clippy_lints/src/mem_forget.rs

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ declare_clippy_lint! {
1414
///
1515
/// **Example:**
1616
/// ```rust
17+
/// # use std::mem;
18+
/// # use std::rc::Rc;
1719
/// mem::forget(Rc::new(55))
1820
/// ```
1921
pub MEM_FORGET,

clippy_lints/src/methods/mod.rs

+43-12
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,19 @@ declare_clippy_lint! {
4040
/// **Known problems:** None.
4141
///
4242
/// **Example:**
43+
///
44+
/// Using unwrap on an `Option`:
45+
///
4346
/// ```rust
44-
/// x.unwrap()
47+
/// let opt = Some(1);
48+
/// opt.unwrap();
49+
/// ```
50+
///
51+
/// Better:
52+
///
53+
/// ```rust
54+
/// let opt = Some(1);
55+
/// opt.expect("more helpful message");
4556
/// ```
4657
pub OPTION_UNWRAP_USED,
4758
restriction,
@@ -62,8 +73,18 @@ declare_clippy_lint! {
6273
/// **Known problems:** None.
6374
///
6475
/// **Example:**
76+
/// Using unwrap on an `Option`:
77+
///
6578
/// ```rust
66-
/// x.unwrap()
79+
/// let res: Result<usize, ()> = Ok(1);
80+
/// res.unwrap();
81+
/// ```
82+
///
83+
/// Better:
84+
///
85+
/// ```rust
86+
/// let res: Result<usize, ()> = Ok(1);
87+
/// res.expect("more helpful message");
6788
/// ```
6889
pub RESULT_UNWRAP_USED,
6990
restriction,
@@ -141,9 +162,10 @@ declare_clippy_lint! {
141162
///
142163
/// **Example:**
143164
/// ```rust
144-
/// impl X {
145-
/// pub fn as_str(self) -> &str {
146-
/// ..
165+
/// # struct X;
166+
/// impl<'a> X {
167+
/// pub fn as_str(self) -> &'a str {
168+
/// "foo"
147169
/// }
148170
/// }
149171
/// ```
@@ -179,7 +201,8 @@ declare_clippy_lint! {
179201
///
180202
/// **Example:**
181203
/// ```rust
182-
/// x.map(|a| a + 1).unwrap_or(0)
204+
/// # let x = Some(1);
205+
/// x.map(|a| a + 1).unwrap_or(0);
183206
/// ```
184207
pub OPTION_MAP_UNWRAP_OR,
185208
pedantic,
@@ -196,7 +219,9 @@ declare_clippy_lint! {
196219
///
197220
/// **Example:**
198221
/// ```rust
199-
/// x.map(|a| a + 1).unwrap_or_else(some_function)
222+
/// # let x = Some(1);
223+
/// # fn some_function() -> usize { 1 }
224+
/// x.map(|a| a + 1).unwrap_or_else(some_function);
200225
/// ```
201226
pub OPTION_MAP_UNWRAP_OR_ELSE,
202227
pedantic,
@@ -213,7 +238,9 @@ declare_clippy_lint! {
213238
///
214239
/// **Example:**
215240
/// ```rust
216-
/// x.map(|a| a + 1).unwrap_or_else(some_function)
241+
/// # let x: Result<usize, ()> = Ok(1);
242+
/// # fn some_function(foo: ()) -> usize { 1 }
243+
/// x.map(|a| a + 1).unwrap_or_else(some_function);
217244
/// ```
218245
pub RESULT_MAP_UNWRAP_OR_ELSE,
219246
pedantic,
@@ -265,7 +292,8 @@ declare_clippy_lint! {
265292
///
266293
/// **Example:**
267294
/// ```rust
268-
/// iter.map(|x| x.iter()).flatten()
295+
/// let vec = vec![vec![1]];
296+
/// vec.iter().map(|x| x.iter()).flatten();
269297
/// ```
270298
pub MAP_FLATTEN,
271299
pedantic,
@@ -284,7 +312,8 @@ declare_clippy_lint! {
284312
///
285313
/// **Example:**
286314
/// ```rust
287-
/// iter.filter(|x| x == 0).map(|x| x * 2)
315+
/// let vec = vec![1];
316+
/// vec.iter().filter(|x| **x == 0).map(|x| *x * 2);
288317
/// ```
289318
pub FILTER_MAP,
290319
pedantic,
@@ -324,7 +353,7 @@ declare_clippy_lint! {
324353
///
325354
/// **Example:**
326355
/// ```rust
327-
/// (0..3).find(|x| x == 2).map(|x| x * 2);
356+
/// (0..3).find(|x| *x == 2).map(|x| x * 2);
328357
/// ```
329358
/// Can be written as
330359
/// ```rust
@@ -467,7 +496,9 @@ declare_clippy_lint! {
467496
///
468497
/// **Example:**
469498
/// ```rust
470-
/// x.clone()
499+
/// # use std::rc::Rc;
500+
/// let x = Rc::new(1);
501+
/// x.clone();
471502
/// ```
472503
pub CLONE_ON_REF_PTR,
473504
restriction,

0 commit comments

Comments
 (0)