Skip to content

Fix syntax highlighting of code fences #5110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 50 additions & 24 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ declare_clippy_lint! {
///
/// Better:
///
/// ```ignore
/// ```rust,ignore
/// let opt = Some(1);
/// opt?;
/// # Some::<()>(())
/// ```
pub OPTION_EXPECT_USED,
restriction,
Expand All @@ -143,7 +142,7 @@ declare_clippy_lint! {
///
/// Better:
///
/// ```
/// ```rust
/// let res: Result<usize, ()> = Ok(1);
/// res?;
/// # Ok::<(), ()>(())
Expand All @@ -168,11 +167,12 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```ignore
/// ```rust
/// struct X;
/// impl X {
/// fn add(&self, other: &X) -> X {
/// ..
/// // ..
/// # X
/// }
/// }
/// ```
Expand Down Expand Up @@ -200,10 +200,12 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```ignore
/// ```rust
/// # struct X;
/// impl X {
/// fn as_str(self) -> &str {
/// ..
/// fn as_str(self) -> &'static str {
/// // ..
/// # ""
/// }
/// }
/// ```
Expand Down Expand Up @@ -245,7 +247,8 @@ declare_clippy_lint! {
/// **Known problems:** The error type needs to implement `Debug`
///
/// **Example:**
/// ```ignore
/// ```rust
/// # let x = Ok::<_, ()>(());
/// x.ok().expect("why did I do this again?")
/// ```
pub OK_EXPECT,
Expand Down Expand Up @@ -318,8 +321,10 @@ declare_clippy_lint! {
/// **Known problems:** The order of the arguments is not in execution order.
///
/// **Example:**
/// ```ignore
/// opt.map_or(None, |a| a + 1)
/// ```rust
/// # let opt = Some(1);
/// opt.map_or(None, |a| Some(a + 1))
/// # ;
/// ```
pub OPTION_MAP_OR_NONE,
style,
Expand Down Expand Up @@ -707,9 +712,12 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```ignore
/// ```rust
/// # struct Foo;
/// # struct NotAFoo;
/// impl Foo {
/// fn new(..) -> NotAFoo {
/// fn new() -> NotAFoo {
/// # NotAFoo
/// }
/// }
/// ```
Expand Down Expand Up @@ -744,14 +752,20 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```rust,ignore
/// ```rust
/// # use std::ffi::CString;
/// # fn call_some_ffi_func(_: *const i8) {}
/// #
/// let c_str = CString::new("foo").unwrap().as_ptr();
/// unsafe {
/// call_some_ffi_func(c_str);
/// }
/// ```
/// Here `c_str` point to a freed address. The correct use would be:
/// ```rust,ignore
/// ```rust
/// # use std::ffi::CString;
/// # fn call_some_ffi_func(_: *const i8) {}
/// #
/// let c_str = CString::new("foo").unwrap();
/// unsafe {
/// call_some_ffi_func(c_str.as_ptr());
Expand All @@ -771,7 +785,7 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```should_panic
/// ```rust,should_panic
/// for x in (0..100).step_by(0) {
/// //..
/// }
Expand Down Expand Up @@ -953,8 +967,10 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```ignore
/// ```rust
/// # let name = "_";
/// name.chars().last() == Some('_') || name.chars().next_back() == Some('-')
/// # ;
/// ```
pub CHARS_LAST_CMP,
style,
Expand Down Expand Up @@ -1147,7 +1163,7 @@ declare_clippy_lint! {
/// **Known problems:** None
///
/// **Example:**
/// ```ignore
/// ```rust
/// unsafe { (&() as *const ()).offset(1) };
/// ```
pub ZST_OFFSET,
Expand All @@ -1165,24 +1181,30 @@ declare_clippy_lint! {
///
/// **Example:**
///
/// ```rust,ignore
/// ```rust
/// # || {
/// let metadata = std::fs::metadata("foo.txt")?;
/// let filetype = metadata.file_type();
///
/// if filetype.is_file() {
/// // read file
/// }
/// # Ok::<_, std::io::Error>(())
/// # };
/// ```
///
/// should be written as:
///
/// ```rust,ignore
/// ```rust
/// # || {
/// let metadata = std::fs::metadata("foo.txt")?;
/// let filetype = metadata.file_type();
///
/// if !filetype.is_dir() {
/// // read file
/// }
/// # Ok::<_, std::io::Error>(())
/// # };
/// ```
pub FILETYPE_IS_FILE,
restriction,
Expand All @@ -1198,12 +1220,16 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```rust,ignore
/// opt.as_ref().map(String::as_str)
/// ```rust
/// # let opt = Some("".to_string());
/// opt.as_ref().map(String::as_str)
/// # ;
/// ```
/// Can be written as
/// ```rust,ignore
/// opt.as_deref()
/// ```rust
/// # let opt = Some("".to_string());
/// opt.as_deref()
/// # ;
/// ```
pub OPTION_AS_REF_DEREF,
complexity,
Expand Down