Fix some code examples in doc

This commit is contained in:
ThibsG 2020-05-27 16:24:53 +02:00
parent bee0608fad
commit 61587c9a29
9 changed files with 78 additions and 7 deletions

View file

@ -24,7 +24,11 @@ declare_clippy_lint! {
/// let mut a = 5;
/// let b = 0;
/// // ...
/// // Bad
/// a = a + b;
///
/// // Good
/// a += b;
/// ```
pub ASSIGN_OP_PATTERN,
style,

View file

@ -13,10 +13,24 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// // Bad
/// fn simple_double_parens() -> i32 {
/// ((0))
/// }
///
/// // Good
/// fn simple_no_parens() -> i32 {
/// 0
/// }
///
/// // or
///
/// # fn foo(bar: usize) {}
/// ((0));
/// // Bad
/// foo((0));
/// ((1, 2));
///
/// // Good
/// foo(0);
/// ```
pub DOUBLE_PARENS,
complexity,

View file

@ -27,6 +27,10 @@ declare_clippy_lint! {
/// ```rust
/// fn foo<T: Drop>() {}
/// ```
/// Could be written as:
/// ```rust
/// fn foo() {}
/// ```
pub DROP_BOUNDS,
correctness,
"Bounds of the form `T: Drop` are useless"

View file

@ -22,8 +22,14 @@ declare_clippy_lint! {
/// ```rust
/// # use std::time::Duration;
/// let dur = Duration::new(5, 0);
///
/// // Bad
/// let _micros = dur.subsec_nanos() / 1_000;
/// let _millis = dur.subsec_nanos() / 1_000_000;
///
/// // Good
/// let _micros = dur.subsec_micros();
/// let _millis = dur.subsec_millis();
/// ```
pub DURATION_SUBSEC,
complexity,

View file

@ -25,31 +25,47 @@ declare_clippy_lint! {
/// BattenbergCake,
/// }
/// ```
/// Could be written as:
/// ```rust
/// enum Cake {
/// BlackForest,
/// Hummingbird,
/// Battenberg,
/// }
/// ```
pub ENUM_VARIANT_NAMES,
style,
"enums where all variants share a prefix/postfix"
}
declare_clippy_lint! {
/// **What it does:** Detects enumeration variants that are prefixed or suffixed
/// by the same characters.
/// **What it does:** Detects public enumeration variants that are
/// prefixed or suffixed by the same characters.
///
/// **Why is this bad?** Enumeration variant names should specify their variant,
/// **Why is this bad?** Public enumeration variant names should specify their variant,
/// not repeat the enumeration name.
///
/// **Known problems:** None.
///
/// **Example:**
/// ```rust
/// enum Cake {
/// pub enum Cake {
/// BlackForestCake,
/// HummingbirdCake,
/// BattenbergCake,
/// }
/// ```
/// Could be written as:
/// ```rust
/// pub enum Cake {
/// BlackForest,
/// Hummingbird,
/// Battenberg,
/// }
/// ```
pub PUB_ENUM_VARIANT_NAMES,
pedantic,
"enums where all variants share a prefix/postfix"
"public enums where all variants share a prefix/postfix"
}
declare_clippy_lint! {
@ -66,6 +82,12 @@ declare_clippy_lint! {
/// struct BlackForestCake;
/// }
/// ```
/// Could be written as:
/// ```rust
/// mod cake {
/// struct BlackForest;
/// }
/// ```
pub MODULE_NAME_REPETITIONS,
pedantic,
"type names prefixed/postfixed with their containing module's name"

View file

@ -39,7 +39,11 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```ignore
/// // Bad
/// &x == y
///
/// // Good
/// x == *y
/// ```
pub OP_REF,
style,

View file

@ -28,9 +28,16 @@ declare_clippy_lint! {
/// **Example:**
/// ```rust
/// # fn foo(bar: usize) {}
///
/// // Bad
/// let x = Box::new(1);
/// foo(*x);
/// println!("{}", *x);
///
/// // Good
/// let x = 1;
/// foo(x);
/// println!("{}", x);
/// ```
pub BOXED_LOCAL,
perf,

View file

@ -26,7 +26,11 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust,ignore
/// // Bad
/// xs.map(|x| foo(x))
///
/// // Good
/// foo(xs)
/// ```
/// where `foo(_)` is a plain function that takes the exact argument type of
/// `x`.

View file

@ -21,11 +21,17 @@ declare_clippy_lint! {
/// **Example:**
/// ```rust
/// let mut x = 0;
///
/// // Bad
/// let a = {
/// x = 1;
/// 1
/// } + x;
/// // Unclear whether a is 1 or 2.
///
/// // Good
/// x = 1;
/// let a = 1 + x;
/// ```
pub EVAL_ORDER_DEPENDENCE,
complexity,