@@ -40,8 +40,19 @@ declare_clippy_lint! {
40
40
/// **Known problems:** None.
41
41
///
42
42
/// **Example:**
43
+ ///
44
+ /// Using unwrap on an `Option`:
45
+ ///
43
46
/// ```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");
45
56
/// ```
46
57
pub OPTION_UNWRAP_USED ,
47
58
restriction,
@@ -62,8 +73,18 @@ declare_clippy_lint! {
62
73
/// **Known problems:** None.
63
74
///
64
75
/// **Example:**
76
+ /// Using unwrap on an `Option`:
77
+ ///
65
78
/// ```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");
67
88
/// ```
68
89
pub RESULT_UNWRAP_USED ,
69
90
restriction,
@@ -141,9 +162,10 @@ declare_clippy_lint! {
141
162
///
142
163
/// **Example:**
143
164
/// ```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"
147
169
/// }
148
170
/// }
149
171
/// ```
@@ -179,7 +201,8 @@ declare_clippy_lint! {
179
201
///
180
202
/// **Example:**
181
203
/// ```rust
182
- /// x.map(|a| a + 1).unwrap_or(0)
204
+ /// # let x = Some(1);
205
+ /// x.map(|a| a + 1).unwrap_or(0);
183
206
/// ```
184
207
pub OPTION_MAP_UNWRAP_OR ,
185
208
pedantic,
@@ -196,7 +219,9 @@ declare_clippy_lint! {
196
219
///
197
220
/// **Example:**
198
221
/// ```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);
200
225
/// ```
201
226
pub OPTION_MAP_UNWRAP_OR_ELSE ,
202
227
pedantic,
@@ -213,7 +238,9 @@ declare_clippy_lint! {
213
238
///
214
239
/// **Example:**
215
240
/// ```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);
217
244
/// ```
218
245
pub RESULT_MAP_UNWRAP_OR_ELSE ,
219
246
pedantic,
@@ -265,7 +292,8 @@ declare_clippy_lint! {
265
292
///
266
293
/// **Example:**
267
294
/// ```rust
268
- /// iter.map(|x| x.iter()).flatten()
295
+ /// let vec = vec![vec![1]];
296
+ /// vec.iter().map(|x| x.iter()).flatten();
269
297
/// ```
270
298
pub MAP_FLATTEN ,
271
299
pedantic,
@@ -284,7 +312,8 @@ declare_clippy_lint! {
284
312
///
285
313
/// **Example:**
286
314
/// ```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);
288
317
/// ```
289
318
pub FILTER_MAP ,
290
319
pedantic,
@@ -324,7 +353,7 @@ declare_clippy_lint! {
324
353
///
325
354
/// **Example:**
326
355
/// ```rust
327
- /// (0..3).find(|x| x == 2).map(|x| x * 2);
356
+ /// (0..3).find(|x| * x == 2).map(|x| x * 2);
328
357
/// ```
329
358
/// Can be written as
330
359
/// ```rust
@@ -467,7 +496,9 @@ declare_clippy_lint! {
467
496
///
468
497
/// **Example:**
469
498
/// ```rust
470
- /// x.clone()
499
+ /// # use std::rc::Rc;
500
+ /// let x = Rc::new(1);
501
+ /// x.clone();
471
502
/// ```
472
503
pub CLONE_ON_REF_PTR ,
473
504
restriction,
0 commit comments