Skip to content

Commit 8e9089e

Browse files
committed
Auto merge of rust-lang#5110 - Aloso:patch-1, r=flip1995
Fix syntax highlighting of code fences The documentation for RESULT_EXPECT_USED includes this code: let res: Result<usize, ()> = Ok(1); res?; # Ok::<(), ()>(()) Because the code fence didn't start with `rust`, the code wasn't highlighted and the line starting with `#` was displayed on the website. This is now fixed. EDIT: I noticed that highlighting for some other lints is broken as well. It only works if the code fence looks like this: ````markdown ```rust // .. ``` ```` However, many code blocks were ignored. I un-ignored most code blocks and made them compile by adding hidden code with `#`. While doing so, I found two mistakes: ```rust opt.map_or(None, |a| a + 1) // instead of opt.map_or(None, |a| Some(a + 1)) ``` and ```rust fn as_str(self) -> &str // instead of fn as_str(self) -> &'static str ``` changelog: none
2 parents bbef531 + 1f600f3 commit 8e9089e

File tree

1 file changed

+50
-24
lines changed
  • clippy_lints/src/methods

1 file changed

+50
-24
lines changed

clippy_lints/src/methods/mod.rs

+50-24
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,9 @@ declare_clippy_lint! {
114114
///
115115
/// Better:
116116
///
117-
/// ```ignore
117+
/// ```rust,ignore
118118
/// let opt = Some(1);
119119
/// opt?;
120-
/// # Some::<()>(())
121120
/// ```
122121
pub OPTION_EXPECT_USED,
123122
restriction,
@@ -143,7 +142,7 @@ declare_clippy_lint! {
143142
///
144143
/// Better:
145144
///
146-
/// ```
145+
/// ```rust
147146
/// let res: Result<usize, ()> = Ok(1);
148147
/// res?;
149148
/// # Ok::<(), ()>(())
@@ -168,11 +167,12 @@ declare_clippy_lint! {
168167
/// **Known problems:** None.
169168
///
170169
/// **Example:**
171-
/// ```ignore
170+
/// ```rust
172171
/// struct X;
173172
/// impl X {
174173
/// fn add(&self, other: &X) -> X {
175-
/// ..
174+
/// // ..
175+
/// # X
176176
/// }
177177
/// }
178178
/// ```
@@ -200,10 +200,12 @@ declare_clippy_lint! {
200200
/// **Known problems:** None.
201201
///
202202
/// **Example:**
203-
/// ```ignore
203+
/// ```rust
204+
/// # struct X;
204205
/// impl X {
205-
/// fn as_str(self) -> &str {
206-
/// ..
206+
/// fn as_str(self) -> &'static str {
207+
/// // ..
208+
/// # ""
207209
/// }
208210
/// }
209211
/// ```
@@ -245,7 +247,8 @@ declare_clippy_lint! {
245247
/// **Known problems:** The error type needs to implement `Debug`
246248
///
247249
/// **Example:**
248-
/// ```ignore
250+
/// ```rust
251+
/// # let x = Ok::<_, ()>(());
249252
/// x.ok().expect("why did I do this again?")
250253
/// ```
251254
pub OK_EXPECT,
@@ -318,8 +321,10 @@ declare_clippy_lint! {
318321
/// **Known problems:** The order of the arguments is not in execution order.
319322
///
320323
/// **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+
/// # ;
323328
/// ```
324329
pub OPTION_MAP_OR_NONE,
325330
style,
@@ -707,9 +712,12 @@ declare_clippy_lint! {
707712
/// **Known problems:** None.
708713
///
709714
/// **Example:**
710-
/// ```ignore
715+
/// ```rust
716+
/// # struct Foo;
717+
/// # struct NotAFoo;
711718
/// impl Foo {
712-
/// fn new(..) -> NotAFoo {
719+
/// fn new() -> NotAFoo {
720+
/// # NotAFoo
713721
/// }
714722
/// }
715723
/// ```
@@ -744,14 +752,20 @@ declare_clippy_lint! {
744752
/// **Known problems:** None.
745753
///
746754
/// **Example:**
747-
/// ```rust,ignore
755+
/// ```rust
756+
/// # use std::ffi::CString;
757+
/// # fn call_some_ffi_func(_: *const i8) {}
758+
/// #
748759
/// let c_str = CString::new("foo").unwrap().as_ptr();
749760
/// unsafe {
750761
/// call_some_ffi_func(c_str);
751762
/// }
752763
/// ```
753764
/// 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+
/// #
755769
/// let c_str = CString::new("foo").unwrap();
756770
/// unsafe {
757771
/// call_some_ffi_func(c_str.as_ptr());
@@ -771,7 +785,7 @@ declare_clippy_lint! {
771785
/// **Known problems:** None.
772786
///
773787
/// **Example:**
774-
/// ```should_panic
788+
/// ```rust,should_panic
775789
/// for x in (0..100).step_by(0) {
776790
/// //..
777791
/// }
@@ -953,8 +967,10 @@ declare_clippy_lint! {
953967
/// **Known problems:** None.
954968
///
955969
/// **Example:**
956-
/// ```ignore
970+
/// ```rust
971+
/// # let name = "_";
957972
/// name.chars().last() == Some('_') || name.chars().next_back() == Some('-')
973+
/// # ;
958974
/// ```
959975
pub CHARS_LAST_CMP,
960976
style,
@@ -1147,7 +1163,7 @@ declare_clippy_lint! {
11471163
/// **Known problems:** None
11481164
///
11491165
/// **Example:**
1150-
/// ```ignore
1166+
/// ```rust
11511167
/// unsafe { (&() as *const ()).offset(1) };
11521168
/// ```
11531169
pub ZST_OFFSET,
@@ -1165,24 +1181,30 @@ declare_clippy_lint! {
11651181
///
11661182
/// **Example:**
11671183
///
1168-
/// ```rust,ignore
1184+
/// ```rust
1185+
/// # || {
11691186
/// let metadata = std::fs::metadata("foo.txt")?;
11701187
/// let filetype = metadata.file_type();
11711188
///
11721189
/// if filetype.is_file() {
11731190
/// // read file
11741191
/// }
1192+
/// # Ok::<_, std::io::Error>(())
1193+
/// # };
11751194
/// ```
11761195
///
11771196
/// should be written as:
11781197
///
1179-
/// ```rust,ignore
1198+
/// ```rust
1199+
/// # || {
11801200
/// let metadata = std::fs::metadata("foo.txt")?;
11811201
/// let filetype = metadata.file_type();
11821202
///
11831203
/// if !filetype.is_dir() {
11841204
/// // read file
11851205
/// }
1206+
/// # Ok::<_, std::io::Error>(())
1207+
/// # };
11861208
/// ```
11871209
pub FILETYPE_IS_FILE,
11881210
restriction,
@@ -1198,12 +1220,16 @@ declare_clippy_lint! {
11981220
/// **Known problems:** None.
11991221
///
12001222
/// **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+
/// # ;
12031227
/// ```
12041228
/// Can be written as
1205-
/// ```rust,ignore
1206-
/// opt.as_deref()
1229+
/// ```rust
1230+
/// # let opt = Some("".to_string());
1231+
/// opt.as_deref()
1232+
/// # ;
12071233
/// ```
12081234
pub OPTION_AS_REF_DEREF,
12091235
complexity,

0 commit comments

Comments
 (0)