Fix more code examples
This commit is contained in:
parent
61587c9a29
commit
262c9dc025
@ -18,13 +18,24 @@
|
|||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust,ignore
|
||||||
/// struct Foo(i32);
|
/// struct Foo(i32);
|
||||||
|
///
|
||||||
|
/// // Bad
|
||||||
/// impl From<String> for Foo {
|
/// impl From<String> for Foo {
|
||||||
/// fn from(s: String) -> Self {
|
/// fn from(s: String) -> Self {
|
||||||
/// Foo(s.parse().unwrap())
|
/// Foo(s.parse().unwrap())
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
|
///
|
||||||
|
/// // Good
|
||||||
|
/// use std::convert::TryFrom;
|
||||||
|
/// impl TryFrom<String> for Foo {
|
||||||
|
/// type Error = ();
|
||||||
|
/// fn try_from(s: String) -> Result<Self, Self::Error> {
|
||||||
|
/// s.parse()
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub FALLIBLE_IMPL_FROM,
|
pub FALLIBLE_IMPL_FROM,
|
||||||
nursery,
|
nursery,
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
/// **Example:**
|
/// **Example:**
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
///
|
|
||||||
/// let a = 3f32;
|
/// let a = 3f32;
|
||||||
/// let _ = a.powf(1.0 / 3.0);
|
/// let _ = a.powf(1.0 / 3.0);
|
||||||
/// let _ = (1.0 + a).ln();
|
/// let _ = (1.0 + a).ln();
|
||||||
@ -38,7 +37,6 @@
|
|||||||
/// is better expressed as
|
/// is better expressed as
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
///
|
|
||||||
/// let a = 3f32;
|
/// let a = 3f32;
|
||||||
/// let _ = a.cbrt();
|
/// let _ = a.cbrt();
|
||||||
/// let _ = a.ln_1p();
|
/// let _ = a.ln_1p();
|
||||||
|
@ -25,9 +25,13 @@
|
|||||||
///
|
///
|
||||||
/// **Examples:**
|
/// **Examples:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
///
|
||||||
|
/// // Bad
|
||||||
/// # let foo = "foo";
|
/// # let foo = "foo";
|
||||||
/// format!("foo");
|
|
||||||
/// format!("{}", foo);
|
/// format!("{}", foo);
|
||||||
|
///
|
||||||
|
/// // Good
|
||||||
|
/// format!("foo");
|
||||||
/// ```
|
/// ```
|
||||||
pub USELESS_FORMAT,
|
pub USELESS_FORMAT,
|
||||||
complexity,
|
complexity,
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ``` rust
|
/// ```rust
|
||||||
/// fn im_too_long() {
|
/// fn im_too_long() {
|
||||||
/// println!("");
|
/// println!("");
|
||||||
/// // ... 100 more LoC
|
/// // ... 100 more LoC
|
||||||
@ -79,10 +79,16 @@
|
|||||||
/// `some_argument.get_raw_ptr()`).
|
/// `some_argument.get_raw_ptr()`).
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust,ignore
|
||||||
|
/// // Bad
|
||||||
/// pub fn foo(x: *const u8) {
|
/// pub fn foo(x: *const u8) {
|
||||||
/// println!("{}", unsafe { *x });
|
/// println!("{}", unsafe { *x });
|
||||||
/// }
|
/// }
|
||||||
|
///
|
||||||
|
/// // Good
|
||||||
|
/// pub unsafe fn foo(x: *const u8) {
|
||||||
|
/// println!("{}", unsafe { *x });
|
||||||
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub NOT_UNSAFE_PTR_ARG_DEREF,
|
pub NOT_UNSAFE_PTR_ARG_DEREF,
|
||||||
correctness,
|
correctness,
|
||||||
|
@ -25,13 +25,6 @@
|
|||||||
/// if i != 0 {
|
/// if i != 0 {
|
||||||
/// i -= 1;
|
/// i -= 1;
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
|
||||||
/// Use instead:
|
|
||||||
/// ```rust
|
|
||||||
/// let end: u32 = 10;
|
|
||||||
/// let start: u32 = 5;
|
|
||||||
///
|
|
||||||
/// let mut i: u32 = end - start;
|
|
||||||
///
|
///
|
||||||
/// // Good
|
/// // Good
|
||||||
/// i = i.saturating_sub(1);
|
/// i = i.saturating_sub(1);
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** Checks for usage of `x >= y + 1` or `x - 1 >= y` (and `<=`) in a block
|
/// **What it does:** Checks for usage of `x >= y + 1` or `x - 1 >= y` (and `<=`) in a block
|
||||||
///
|
///
|
||||||
///
|
|
||||||
/// **Why is this bad?** Readability -- better to use `> y` instead of `>= y + 1`.
|
/// **Why is this bad?** Readability -- better to use `> y` instead of `>= y + 1`.
|
||||||
///
|
///
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
|
@ -15,10 +15,13 @@
|
|||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// fn main() {
|
/// // Bad
|
||||||
/// let x = 3 / 2;
|
/// let x = 3 / 2;
|
||||||
/// println!("{}", x);
|
/// println!("{}", x);
|
||||||
/// }
|
///
|
||||||
|
/// // Good
|
||||||
|
/// let x = 3f32 / 2f32;
|
||||||
|
/// println!("{}", x);
|
||||||
/// ```
|
/// ```
|
||||||
pub INTEGER_DIVISION,
|
pub INTEGER_DIVISION,
|
||||||
restriction,
|
restriction,
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// // Bad
|
||||||
/// fn foo() {
|
/// fn foo() {
|
||||||
/// println!("cake");
|
/// println!("cake");
|
||||||
/// }
|
/// }
|
||||||
@ -28,6 +29,21 @@
|
|||||||
/// foo(); // prints "foo"
|
/// foo(); // prints "foo"
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// // Good
|
||||||
|
/// fn foo() {
|
||||||
|
/// println!("cake");
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// fn main() {
|
||||||
|
/// fn foo() {
|
||||||
|
/// println!("foo");
|
||||||
|
/// }
|
||||||
|
/// foo(); // prints "foo"
|
||||||
|
/// foo(); // prints "foo"
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
pub ITEMS_AFTER_STATEMENTS,
|
pub ITEMS_AFTER_STATEMENTS,
|
||||||
pedantic,
|
pedantic,
|
||||||
"blocks where an item comes after a statement"
|
"blocks where an item comes after a statement"
|
||||||
|
Loading…
Reference in New Issue
Block a user