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