Make docs more consistent

This commit is contained in:
Serial
2022-05-28 09:22:59 -04:00
parent 5920fa3516
commit cfd0f5592b
29 changed files with 110 additions and 69 deletions

View File

@@ -28,7 +28,7 @@ declare_clippy_lint! {
/// let x = 3.14; /// let x = 3.14;
/// let y = 1_f64 / x; /// let y = 1_f64 / x;
/// ``` /// ```
/// Use predefined constants instead: /// Use instead:
/// ```rust /// ```rust
/// let x = std::f32::consts::PI; /// let x = std::f32::consts::PI;
/// let y = std::f64::consts::FRAC_1_PI; /// let y = std::f64::consts::FRAC_1_PI;

View File

@@ -29,7 +29,7 @@ declare_clippy_lint! {
/// f(a as u16); /// f(a as u16);
/// ``` /// ```
/// ///
/// Usually better represents the semantics you expect: /// Use instead:
/// ```rust,ignore /// ```rust,ignore
/// f(a.try_into()?); /// f(a.try_into()?);
/// ``` /// ```

View File

@@ -27,10 +27,16 @@ declare_clippy_lint! {
/// let mut a = 5; /// let mut a = 5;
/// let b = 0; /// let b = 0;
/// // ... /// // ...
/// // Bad
/// a = a + b;
/// ///
/// // Good /// a = a + b;
/// ```
///
/// Use instead:
/// ```rust
/// let mut a = 5;
/// let b = 0;
/// // ...
///
/// a += b; /// a += b;
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]

View File

@@ -89,13 +89,14 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```ignore /// ```ignore
/// // Bad
/// #[deny(dead_code)] /// #[deny(dead_code)]
/// extern crate foo; /// extern crate foo;
/// #[forbid(dead_code)] /// #[forbid(dead_code)]
/// use foo::bar; /// use foo::bar;
/// ```
/// ///
/// // Ok /// Use instead:
/// ```rust,ignore
/// #[allow(unused_imports)] /// #[allow(unused_imports)]
/// use foo::baz; /// use foo::baz;
/// #[allow(unused_imports)] /// #[allow(unused_imports)]
@@ -146,15 +147,19 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// #[allow(dead_code)]
///
/// fn not_quite_good_code() { }
/// ```
///
/// Use instead:
/// ```rust
/// // Good (as inner attribute) /// // Good (as inner attribute)
/// #![allow(dead_code)] /// #![allow(dead_code)]
/// ///
/// fn this_is_fine() { } /// fn this_is_fine() { }
/// ///
/// // Bad /// // or
/// #[allow(dead_code)]
///
/// fn not_quite_good_code() { }
/// ///
/// // Good (as outer attribute) /// // Good (as outer attribute)
/// #[allow(dead_code)] /// #[allow(dead_code)]
@@ -175,12 +180,11 @@ declare_clippy_lint! {
/// These lints should only be enabled on a lint-by-lint basis and with careful consideration. /// These lints should only be enabled on a lint-by-lint basis and with careful consideration.
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust /// ```rust
/// #![deny(clippy::restriction)] /// #![deny(clippy::restriction)]
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust /// ```rust
/// #![deny(clippy::as_conversions)] /// #![deny(clippy::as_conversions)]
/// ``` /// ```
@@ -205,13 +209,12 @@ declare_clippy_lint! {
/// [#3123](https://github.com/rust-lang/rust-clippy/pull/3123#issuecomment-422321765) /// [#3123](https://github.com/rust-lang/rust-clippy/pull/3123#issuecomment-422321765)
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust /// ```rust
/// #[cfg_attr(rustfmt, rustfmt_skip)] /// #[cfg_attr(rustfmt, rustfmt_skip)]
/// fn main() { } /// fn main() { }
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust /// ```rust
/// #[rustfmt::skip] /// #[rustfmt::skip]
/// fn main() { } /// fn main() { }
@@ -231,19 +234,19 @@ declare_clippy_lint! {
/// by the conditional compilation engine. /// by the conditional compilation engine.
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust /// ```rust
/// #[cfg(linux)] /// #[cfg(linux)]
/// fn conditional() { } /// fn conditional() { }
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust /// ```rust
/// #[cfg(target_os = "linux")] /// #[cfg(target_os = "linux")]
/// fn conditional() { } /// fn conditional() { }
/// ``` /// ```
/// ///
/// Or: /// or
///
/// ```rust /// ```rust
/// #[cfg(unix)] /// #[cfg(unix)]
/// fn conditional() { } /// fn conditional() { }
@@ -266,14 +269,13 @@ declare_clippy_lint! {
/// ensure that others understand the reasoning /// ensure that others understand the reasoning
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust /// ```rust
/// #![feature(lint_reasons)] /// #![feature(lint_reasons)]
/// ///
/// #![allow(clippy::some_lint)] /// #![allow(clippy::some_lint)]
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust /// ```rust
/// #![feature(lint_reasons)] /// #![feature(lint_reasons)]
/// ///

View File

@@ -29,7 +29,7 @@ declare_clippy_lint! {
/// if true { /* ... */ } /// if true { /* ... */ }
/// ``` /// ```
/// ///
/// // or /// or
/// ///
/// ```rust /// ```rust
/// # fn somefunc() -> bool { true }; /// # fn somefunc() -> bool { true };

View File

@@ -27,8 +27,14 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```ignore /// ```ignore
/// if a && true // should be: if a /// if a && true {}
/// if !(a == b) // should be: if a != b /// if !(a == b) {}
/// ```
///
/// Use instead:
/// ```rust,ignore
/// if a {}
/// if a != b {}
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub NONMINIMAL_BOOL, pub NONMINIMAL_BOOL,
@@ -48,10 +54,15 @@ declare_clippy_lint! {
/// Ignores short circuiting behavior. /// Ignores short circuiting behavior.
/// ///
/// ### Example /// ### Example
/// ```ignore /// ```rust,ignore
/// // The `b` is unnecessary, the expression is equivalent to `if a`.
/// if a && b || a { ... } /// if a && b || a { ... }
/// ``` /// ```
/// The `b` is unnecessary, the expression is equivalent to `if a`. ///
/// Use instead:
/// ```rust,ignore
/// if a {}
/// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub LOGIC_BUG, pub LOGIC_BUG,
correctness, correctness,

View File

@@ -28,7 +28,13 @@ declare_clippy_lint! {
/// ### Example /// ### Example
/// ```rust /// ```rust
/// # let vec = vec![1_u8]; /// # let vec = vec![1_u8];
/// &vec.iter().filter(|x| **x == 0u8).count(); // use bytecount::count instead /// let count = vec.iter().filter(|x| **x == 0u8).count();
/// ```
///
/// Use instead:
/// ```rust,ignore
/// # let vec = vec![1_u8];
/// let count = bytecount::count(&vec, 0u8);
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub NAIVE_BYTECOUNT, pub NAIVE_BYTECOUNT,

View File

@@ -25,7 +25,7 @@ declare_clippy_lint! {
/// complexity. /// complexity.
/// ///
/// ### Example /// ### Example
/// No. You'll see it when you get the warning. /// You'll see it when you get the warning.
#[clippy::version = "1.35.0"] #[clippy::version = "1.35.0"]
pub COGNITIVE_COMPLEXITY, pub COGNITIVE_COMPLEXITY,
nursery, nursery,

View File

@@ -41,7 +41,7 @@ declare_clippy_lint! {
/// ///
/// ``` /// ```
/// ///
/// Should be written: /// Use instead:
/// ///
/// ```rust,ignore /// ```rust,ignore
/// if x && y { /// if x && y {

View File

@@ -34,7 +34,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// ///
/// Could be written: /// Use instead:
/// ///
/// ```rust,ignore /// ```rust,ignore
/// use std::cmp::Ordering; /// use std::cmp::Ordering;

View File

@@ -141,7 +141,7 @@ declare_clippy_lint! {
/// }; /// };
/// ``` /// ```
/// ///
/// Could be written as: /// Use instead:
/// ```ignore /// ```ignore
/// println!("Hello World"); /// println!("Hello World");
/// let foo = if … { /// let foo = if … {

View File

@@ -21,7 +21,7 @@ declare_clippy_lint! {
/// bar: bool /// bar: bool
/// } /// }
/// ///
/// impl std::default::Default for Foo { /// impl Default for Foo {
/// fn default() -> Self { /// fn default() -> Self {
/// Self { /// Self {
/// bar: false /// bar: false

View File

@@ -24,7 +24,7 @@ declare_clippy_lint! {
/// if x == y || x < y {} /// if x == y || x < y {}
/// ``` /// ```
/// ///
/// Could be written as: /// Use instead:
/// ///
/// ```rust /// ```rust
/// # let x = 1; /// # let x = 1;

View File

@@ -22,15 +22,17 @@ declare_clippy_lint! {
/// ### Example /// ### Example
/// ```rust /// ```rust
/// # use std::time::Duration; /// # use std::time::Duration;
/// let dur = Duration::new(5, 0); /// # let duration = Duration::new(5, 0);
/// let micros = duration.subsec_nanos() / 1_000;
/// let millis = duration.subsec_nanos() / 1_000_000;
/// ```
/// ///
/// // Bad /// Use instead:
/// let _micros = dur.subsec_nanos() / 1_000; /// ```rust
/// let _millis = dur.subsec_nanos() / 1_000_000; /// # use std::time::Duration;
/// /// # let duration = Duration::new(5, 0);
/// // Good /// let micros = duration.subsec_micros();
/// let _micros = dur.subsec_micros(); /// let millis = duration.subsec_millis();
/// let _millis = dur.subsec_millis();
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub DURATION_SUBSEC, pub DURATION_SUBSEC,

View File

@@ -26,7 +26,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// ///
/// Could be written: /// Use instead:
/// ///
/// ```rust /// ```rust
/// # fn a() {} /// # fn a() {}

View File

@@ -23,12 +23,11 @@ declare_clippy_lint! {
/// ///
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust /// ```rust
/// enum Test {} /// enum Test {}
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust /// ```rust
/// #![feature(never_type)] /// #![feature(never_type)]
/// ///

View File

@@ -46,7 +46,7 @@ declare_clippy_lint! {
/// map.insert(k, v); /// map.insert(k, v);
/// } /// }
/// ``` /// ```
/// can both be rewritten as: /// Use instead:
/// ```rust /// ```rust
/// # use std::collections::HashMap; /// # use std::collections::HashMap;
/// # let mut map = HashMap::new(); /// # let mut map = HashMap::new();

View File

@@ -32,7 +32,7 @@ declare_clippy_lint! {
/// BattenbergCake, /// BattenbergCake,
/// } /// }
/// ``` /// ```
/// Could be written as: /// Use instead:
/// ```rust /// ```rust
/// enum Cake { /// enum Cake {
/// BlackForest, /// BlackForest,

View File

@@ -26,7 +26,7 @@ declare_clippy_lint! {
/// do_thing(); /// do_thing();
/// } /// }
/// ``` /// ```
/// Should be written /// Use instead:
/// ```rust,ignore /// ```rust,ignore
/// if x == Some(2) { /// if x == Some(2) {
/// do_thing(); /// do_thing();

View File

@@ -31,12 +31,14 @@ declare_clippy_lint! {
/// ### Example /// ### Example
/// ```rust /// ```rust
/// # fn foo(bar: usize) {} /// # fn foo(bar: usize) {}
/// // Bad
/// let x = Box::new(1); /// let x = Box::new(1);
/// foo(*x); /// foo(*x);
/// println!("{}", *x); /// println!("{}", *x);
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// # fn foo(bar: usize) {}
/// let x = 1; /// let x = 1;
/// foo(x); /// foo(x);
/// println!("{}", x); /// println!("{}", x);

View File

@@ -18,7 +18,6 @@ declare_clippy_lint! {
/// readability and API. /// readability and API.
/// ///
/// ### Example /// ### Example
/// Bad:
/// ```rust /// ```rust
/// struct S { /// struct S {
/// is_pending: bool, /// is_pending: bool,
@@ -27,7 +26,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// ///
/// Good: /// Use instead:
/// ```rust /// ```rust
/// enum S { /// enum S {
/// Pending, /// Pending,

View File

@@ -21,8 +21,16 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// # use std::io::Write; /// # use std::io::Write;
/// # let bar = "furchtbar"; /// # let bar = "furchtbar";
/// // this would be clearer as `eprintln!("foo: {:?}", bar);`
/// writeln!(&mut std::io::stderr(), "foo: {:?}", bar).unwrap(); /// writeln!(&mut std::io::stderr(), "foo: {:?}", bar).unwrap();
/// writeln!(&mut std::io::stdout(), "foo: {:?}", bar).unwrap();
/// ```
///
/// Use instead:
/// ```rust
/// # use std::io::Write;
/// # let bar = "furchtbar";
/// eprintln!("foo: {:?}", bar);
/// println!("foo: {:?}", bar);
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]
pub EXPLICIT_WRITE, pub EXPLICIT_WRITE,

View File

@@ -20,7 +20,6 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// 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())
@@ -28,8 +27,8 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// ///
/// Use instead:
/// ```rust /// ```rust
/// // Good
/// struct Foo(i32); /// struct Foo(i32);
/// ///
/// impl TryFrom<String> for Foo { /// impl TryFrom<String> for Foo {

View File

@@ -19,11 +19,12 @@ declare_clippy_lint! {
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// // Bad
/// let v: f32 = 0.123_456_789_9; /// let v: f32 = 0.123_456_789_9;
/// println!("{}", v); // 0.123_456_789 /// println!("{}", v); // 0.123_456_789
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// let v: f64 = 0.123_456_789_9; /// let v: f64 = 0.123_456_789_9;
/// println!("{}", v); // 0.123_456_789_9 /// println!("{}", v); // 0.123_456_789_9
/// ``` /// ```

View File

@@ -35,8 +35,7 @@ declare_clippy_lint! {
/// let _ = a.exp() - 1.0; /// let _ = a.exp() - 1.0;
/// ``` /// ```
/// ///
/// is better expressed as /// Use instead:
///
/// ```rust /// ```rust
/// let a = 3f32; /// let a = 3f32;
/// let _ = a.cbrt(); /// let _ = a.cbrt();

View File

@@ -25,12 +25,13 @@ declare_clippy_lint! {
/// ///
/// ### Examples /// ### Examples
/// ```rust /// ```rust
///
/// // Bad
/// let foo = "foo"; /// let foo = "foo";
/// format!("{}", foo); /// format!("{}", foo);
/// ```
/// ///
/// // Good /// Use instead:
/// ```rust
/// let foo = "foo";
/// foo.to_owned(); /// foo.to_owned();
/// ``` /// ```
#[clippy::version = "pre 1.29.0"] #[clippy::version = "pre 1.29.0"]

View File

@@ -36,12 +36,18 @@ declare_clippy_lint! {
/// This is either a typo in the binary operator or confusing. /// This is either a typo in the binary operator or confusing.
/// ///
/// ### Example /// ### Example
/// ```rust,ignore /// ```rust
/// if foo <- 30 { // this should be `foo < -30` but looks like a different operator /// # let foo = true;
/// } /// # let bar = false;
/// // &&! looks like a different operator
/// if foo &&! bar {}
/// ```
/// ///
/// if foo &&! bar { // this should be `foo && !bar` but looks like a different operator /// Use instead:
/// } /// ```rust
/// # let foo = true;
/// # let bar = false;
/// if foo && !bar {}
/// ``` /// ```
#[clippy::version = "1.40.0"] #[clippy::version = "1.40.0"]
pub SUSPICIOUS_UNARY_OP_FORMATTING, pub SUSPICIOUS_UNARY_OP_FORMATTING,

View File

@@ -192,7 +192,7 @@ declare_clippy_lint! {
/// } /// }
/// ``` /// ```
/// ///
/// // or /// or
/// ///
/// ```rust /// ```rust
/// # let res: Result<i32, std::io::Error> = Ok(1); /// # let res: Result<i32, std::io::Error> = Ok(1);

View File

@@ -203,7 +203,7 @@ declare_clippy_lint! {
/// opt.expect("more helpful message"); /// opt.expect("more helpful message");
/// ``` /// ```
/// ///
/// // or /// or
/// ///
/// ```rust /// ```rust
/// # let res: Result<usize, ()> = Ok(1); /// # let res: Result<usize, ()> = Ok(1);
@@ -245,7 +245,7 @@ declare_clippy_lint! {
/// opt?; /// opt?;
/// ``` /// ```
/// ///
/// // or /// or
/// ///
/// ```rust /// ```rust
/// # let res: Result<usize, ()> = Ok(1); /// # let res: Result<usize, ()> = Ok(1);
@@ -440,7 +440,7 @@ declare_clippy_lint! {
/// x.map_or(0, |a| a + 1); /// x.map_or(0, |a| a + 1);
/// ``` /// ```
/// ///
/// // or /// or
/// ///
/// ```rust /// ```rust
/// # let x: Result<usize, ()> = Ok(1); /// # let x: Result<usize, ()> = Ok(1);