@@ -114,10 +114,9 @@ declare_clippy_lint! {
114
114
///
115
115
/// Better:
116
116
///
117
- /// ```ignore
117
+ /// ```rust, ignore
118
118
/// let opt = Some(1);
119
119
/// opt?;
120
- /// # Some::<()>(())
121
120
/// ```
122
121
pub OPTION_EXPECT_USED ,
123
122
restriction,
@@ -143,7 +142,7 @@ declare_clippy_lint! {
143
142
///
144
143
/// Better:
145
144
///
146
- /// ```
145
+ /// ```rust
147
146
/// let res: Result<usize, ()> = Ok(1);
148
147
/// res?;
149
148
/// # Ok::<(), ()>(())
@@ -168,11 +167,12 @@ declare_clippy_lint! {
168
167
/// **Known problems:** None.
169
168
///
170
169
/// **Example:**
171
- /// ```ignore
170
+ /// ```rust
172
171
/// struct X;
173
172
/// impl X {
174
173
/// fn add(&self, other: &X) -> X {
175
- /// ..
174
+ /// // ..
175
+ /// # X
176
176
/// }
177
177
/// }
178
178
/// ```
@@ -200,10 +200,12 @@ declare_clippy_lint! {
200
200
/// **Known problems:** None.
201
201
///
202
202
/// **Example:**
203
- /// ```ignore
203
+ /// ```rust
204
+ /// # struct X;
204
205
/// impl X {
205
- /// fn as_str(self) -> &str {
206
- /// ..
206
+ /// fn as_str(self) -> &'static str {
207
+ /// // ..
208
+ /// # ""
207
209
/// }
208
210
/// }
209
211
/// ```
@@ -245,7 +247,8 @@ declare_clippy_lint! {
245
247
/// **Known problems:** The error type needs to implement `Debug`
246
248
///
247
249
/// **Example:**
248
- /// ```ignore
250
+ /// ```rust
251
+ /// # let x = Ok::<_, ()>(());
249
252
/// x.ok().expect("why did I do this again?")
250
253
/// ```
251
254
pub OK_EXPECT ,
@@ -318,8 +321,10 @@ declare_clippy_lint! {
318
321
/// **Known problems:** The order of the arguments is not in execution order.
319
322
///
320
323
/// **Example:**
321
- /// ```ignore
322
- /// opt.map_or(None, |a| a + 1)
324
+ /// ```rust
325
+ /// # let opt = Some(1);
326
+ /// opt.map_or(None, |a| Some(a + 1))
327
+ /// # ;
323
328
/// ```
324
329
pub OPTION_MAP_OR_NONE ,
325
330
style,
@@ -707,9 +712,12 @@ declare_clippy_lint! {
707
712
/// **Known problems:** None.
708
713
///
709
714
/// **Example:**
710
- /// ```ignore
715
+ /// ```rust
716
+ /// # struct Foo;
717
+ /// # struct NotAFoo;
711
718
/// impl Foo {
712
- /// fn new(..) -> NotAFoo {
719
+ /// fn new() -> NotAFoo {
720
+ /// # NotAFoo
713
721
/// }
714
722
/// }
715
723
/// ```
@@ -744,14 +752,20 @@ declare_clippy_lint! {
744
752
/// **Known problems:** None.
745
753
///
746
754
/// **Example:**
747
- /// ```rust,ignore
755
+ /// ```rust
756
+ /// # use std::ffi::CString;
757
+ /// # fn call_some_ffi_func(_: *const i8) {}
758
+ /// #
748
759
/// let c_str = CString::new("foo").unwrap().as_ptr();
749
760
/// unsafe {
750
761
/// call_some_ffi_func(c_str);
751
762
/// }
752
763
/// ```
753
764
/// Here `c_str` point to a freed address. The correct use would be:
754
- /// ```rust,ignore
765
+ /// ```rust
766
+ /// # use std::ffi::CString;
767
+ /// # fn call_some_ffi_func(_: *const i8) {}
768
+ /// #
755
769
/// let c_str = CString::new("foo").unwrap();
756
770
/// unsafe {
757
771
/// call_some_ffi_func(c_str.as_ptr());
@@ -771,7 +785,7 @@ declare_clippy_lint! {
771
785
/// **Known problems:** None.
772
786
///
773
787
/// **Example:**
774
- /// ```should_panic
788
+ /// ```rust, should_panic
775
789
/// for x in (0..100).step_by(0) {
776
790
/// //..
777
791
/// }
@@ -953,8 +967,10 @@ declare_clippy_lint! {
953
967
/// **Known problems:** None.
954
968
///
955
969
/// **Example:**
956
- /// ```ignore
970
+ /// ```rust
971
+ /// # let name = "_";
957
972
/// name.chars().last() == Some('_') || name.chars().next_back() == Some('-')
973
+ /// # ;
958
974
/// ```
959
975
pub CHARS_LAST_CMP ,
960
976
style,
@@ -1147,7 +1163,7 @@ declare_clippy_lint! {
1147
1163
/// **Known problems:** None
1148
1164
///
1149
1165
/// **Example:**
1150
- /// ```ignore
1166
+ /// ```rust
1151
1167
/// unsafe { (&() as *const ()).offset(1) };
1152
1168
/// ```
1153
1169
pub ZST_OFFSET ,
@@ -1165,24 +1181,30 @@ declare_clippy_lint! {
1165
1181
///
1166
1182
/// **Example:**
1167
1183
///
1168
- /// ```rust,ignore
1184
+ /// ```rust
1185
+ /// # || {
1169
1186
/// let metadata = std::fs::metadata("foo.txt")?;
1170
1187
/// let filetype = metadata.file_type();
1171
1188
///
1172
1189
/// if filetype.is_file() {
1173
1190
/// // read file
1174
1191
/// }
1192
+ /// # Ok::<_, std::io::Error>(())
1193
+ /// # };
1175
1194
/// ```
1176
1195
///
1177
1196
/// should be written as:
1178
1197
///
1179
- /// ```rust,ignore
1198
+ /// ```rust
1199
+ /// # || {
1180
1200
/// let metadata = std::fs::metadata("foo.txt")?;
1181
1201
/// let filetype = metadata.file_type();
1182
1202
///
1183
1203
/// if !filetype.is_dir() {
1184
1204
/// // read file
1185
1205
/// }
1206
+ /// # Ok::<_, std::io::Error>(())
1207
+ /// # };
1186
1208
/// ```
1187
1209
pub FILETYPE_IS_FILE ,
1188
1210
restriction,
@@ -1198,12 +1220,16 @@ declare_clippy_lint! {
1198
1220
/// **Known problems:** None.
1199
1221
///
1200
1222
/// **Example:**
1201
- /// ```rust,ignore
1202
- /// opt.as_ref().map(String::as_str)
1223
+ /// ```rust
1224
+ /// # let opt = Some("".to_string());
1225
+ /// opt.as_ref().map(String::as_str)
1226
+ /// # ;
1203
1227
/// ```
1204
1228
/// Can be written as
1205
- /// ```rust,ignore
1206
- /// opt.as_deref()
1229
+ /// ```rust
1230
+ /// # let opt = Some("".to_string());
1231
+ /// opt.as_deref()
1232
+ /// # ;
1207
1233
/// ```
1208
1234
pub OPTION_AS_REF_DEREF ,
1209
1235
complexity,
0 commit comments