Skip to content

Commit 713ad96

Browse files
authored
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
2 parents 20021bb + 1dc9a50 commit 713ad96

16 files changed

+73
-27
lines changed

clippy_lints/src/checked_conversions.rs

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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/if_not_else.rs

Lines changed: 6 additions & 0 deletions
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/infinite_iter.rs

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ 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 } => {

clippy_lints/src/loops.rs

Lines changed: 11 additions & 7 deletions
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

Lines changed: 8 additions & 2 deletions
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,

clippy_lints/src/methods/mod.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ declare_clippy_lint! {
179179
///
180180
/// **Example:**
181181
/// ```rust
182-
/// x.map(|a| a + 1).unwrap_or(0)
182+
/// # let x = Some(1);
183+
/// x.map(|a| a + 1).unwrap_or(0);
183184
/// ```
184185
pub OPTION_MAP_UNWRAP_OR,
185186
pedantic,
@@ -196,7 +197,9 @@ declare_clippy_lint! {
196197
///
197198
/// **Example:**
198199
/// ```rust
199-
/// x.map(|a| a + 1).unwrap_or_else(some_function)
200+
/// # let x = Some(1);
201+
/// # fn some_function() -> usize { 1 }
202+
/// x.map(|a| a + 1).unwrap_or_else(some_function);
200203
/// ```
201204
pub OPTION_MAP_UNWRAP_OR_ELSE,
202205
pedantic,
@@ -213,7 +216,9 @@ declare_clippy_lint! {
213216
///
214217
/// **Example:**
215218
/// ```rust
216-
/// x.map(|a| a + 1).unwrap_or_else(some_function)
219+
/// # let x: Result<usize, ()> = Ok(1);
220+
/// # fn some_function(foo: ()) -> usize { 1 }
221+
/// x.map(|a| a + 1).unwrap_or_else(some_function);
217222
/// ```
218223
pub RESULT_MAP_UNWRAP_OR_ELSE,
219224
pedantic,
@@ -265,7 +270,8 @@ declare_clippy_lint! {
265270
///
266271
/// **Example:**
267272
/// ```rust
268-
/// iter.map(|x| x.iter()).flatten()
273+
/// let vec = vec![vec![1]];
274+
/// vec.iter().map(|x| x.iter()).flatten();
269275
/// ```
270276
pub MAP_FLATTEN,
271277
pedantic,
@@ -284,7 +290,8 @@ declare_clippy_lint! {
284290
///
285291
/// **Example:**
286292
/// ```rust
287-
/// iter.filter(|x| x == 0).map(|x| x * 2)
293+
/// let vec = vec![1];
294+
/// vec.iter().filter(|x| **x == 0).map(|x| *x * 2);
288295
/// ```
289296
pub FILTER_MAP,
290297
pedantic,
@@ -324,7 +331,7 @@ declare_clippy_lint! {
324331
///
325332
/// **Example:**
326333
/// ```rust
327-
/// (0..3).find(|x| x == 2).map(|x| x * 2);
334+
/// (0..3).find(|x| *x == 2).map(|x| x * 2);
328335
/// ```
329336
/// Can be written as
330337
/// ```rust

0 commit comments

Comments
 (0)