1
Fork 0

Doctests: Fix all complexity lint docs

cc #4319
This commit is contained in:
Philipp Hansch 2019-08-02 08:13:54 +02:00
parent 18a7dce4da
commit abfa8a952c
No known key found for this signature in database
GPG key ID: 82AA61CAA11397E6
33 changed files with 155 additions and 83 deletions

View file

@ -45,7 +45,8 @@ declare_clippy_lint! {
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// let mut a = 5; /// let mut a = 5;
/// ... /// let b = 2;
/// // ...
/// a += a + b; /// a += a + b;
/// ``` /// ```
pub MISREFACTORED_ASSIGN_OP, pub MISREFACTORED_ASSIGN_OP,

View file

@ -18,13 +18,17 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// x == y || x < y /// # let x = 1;
/// # let y = 2;
/// if x == y || x < y {}
/// ``` /// ```
/// ///
/// Could be written as: /// Could be written as:
/// ///
/// ```rust /// ```rust
/// x <= y /// # let x = 1;
/// # let y = 2;
/// if x <= y {}
/// ``` /// ```
pub DOUBLE_COMPARISONS, pub DOUBLE_COMPARISONS,
complexity, complexity,

View file

@ -13,9 +13,10 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// ((0)) /// # fn foo(bar: usize) {}
/// foo((0)) /// ((0));
/// ((1, 2)) /// foo((0));
/// ((1, 2));
/// ``` /// ```
pub DOUBLE_PARENS, pub DOUBLE_PARENS,
complexity, complexity,

View file

@ -20,6 +20,7 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// # use std::time::Duration;
/// let dur = Duration::new(5, 0); /// let dur = Duration::new(5, 0);
/// let _micros = dur.subsec_nanos() / 1_000; /// let _micros = dur.subsec_nanos() / 1_000;
/// let _millis = dur.subsec_nanos() / 1_000_000; /// let _millis = dur.subsec_nanos() / 1_000_000;

View file

@ -42,7 +42,9 @@ declare_clippy_lint! {
/// shorthand. /// shorthand.
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,no_run
/// # fn b() -> bool { true }
/// # fn c() -> bool { true }
/// let a = b() || panic!() || c(); /// let a = b() || panic!() || c();
/// // `c()` is dead, `panic!()` is only called if `b()` returns `false` /// // `c()` is dead, `panic!()` is only called if `b()` returns `false`
/// let x = (a, b, c, panic!()); /// let x = (a, b, c, panic!());

View file

@ -16,8 +16,10 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// # use std::io::Write;
/// # let bar = "furchtbar";
/// // this would be clearer as `eprintln!("foo: {:?}", bar);` /// // this would be clearer as `eprintln!("foo: {:?}", bar);`
/// writeln!(&mut io::stderr(), "foo: {:?}", bar).unwrap(); /// writeln!(&mut std::io::stderr(), "foo: {:?}", bar).unwrap();
/// ``` /// ```
pub EXPLICIT_WRITE, pub EXPLICIT_WRITE,
complexity, complexity,

View file

@ -26,8 +26,9 @@ declare_clippy_lint! {
/// ///
/// **Examples:** /// **Examples:**
/// ```rust /// ```rust
/// format!("foo") /// # let foo = "foo";
/// format!("{}", foo) /// format!("foo");
/// format!("{}", foo);
/// ``` /// ```
pub USELESS_FORMAT, pub USELESS_FORMAT,
complexity, complexity,

View file

@ -23,8 +23,9 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// # struct Color;
/// fn foo(x: u32, y: u32, name: &str, c: Color, w: f32, h: f32, a: f32, b: f32) { /// fn foo(x: u32, y: u32, name: &str, c: Color, w: f32, h: f32, a: f32, b: f32) {
/// .. /// // ..
/// } /// }
/// ``` /// ```
pub TOO_MANY_ARGUMENTS, pub TOO_MANY_ARGUMENTS,

View file

@ -17,7 +17,8 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// x / 1 + 0 * 1 - 0 | 0 /// # let x = 1;
/// x / 1 + 0 * 1 - 0 | 0;
/// ``` /// ```
pub IDENTITY_OP, pub IDENTITY_OP,
complexity, complexity,

View file

@ -17,13 +17,17 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// x >= y + 1 /// # let x = 1;
/// # let y = 1;
/// if x >= y + 1 {}
/// ``` /// ```
/// ///
/// Could be written: /// Could be written as:
/// ///
/// ```rust /// ```rust
/// x > y /// # let x = 1;
/// # let y = 1;
/// if x > y {}
/// ``` /// ```
pub INT_PLUS_ONE, pub INT_PLUS_ONE,
complexity, complexity,

View file

@ -100,7 +100,7 @@ macro_rules! declare_clippy_lint {
}; };
{ $(#[$attr:meta])* pub $name:tt, complexity, $description:tt } => { { $(#[$attr:meta])* pub $name:tt, complexity, $description:tt } => {
declare_tool_lint! { declare_tool_lint! {
pub clippy::$name, Warn, $description, report_in_external_macro: true $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
} }
}; };
{ $(#[$attr:meta])* pub $name:tt, perf, $description:tt } => { { $(#[$attr:meta])* pub $name:tt, perf, $description:tt } => {

View file

@ -47,7 +47,7 @@ declare_clippy_lint! {
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// fn unused_lifetime<'a>(x: u8) { /// fn unused_lifetime<'a>(x: u8) {
/// .. /// // ..
/// } /// }
/// ``` /// ```
pub EXTRA_UNUSED_LIFETIMES, pub EXTRA_UNUSED_LIFETIMES,

View file

@ -217,18 +217,19 @@ declare_clippy_lint! {
/// **Known problems:** Sometimes the wrong binding is displayed (#383). /// **Known problems:** Sometimes the wrong binding is displayed (#383).
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,no_run
/// # let y = Some(1);
/// loop { /// loop {
/// let x = match y { /// let x = match y {
/// Some(x) => x, /// Some(x) => x,
/// None => break, /// None => break,
/// } /// };
/// // .. do something with x /// // .. do something with x
/// } /// }
/// // is easier written as /// // is easier written as
/// while let Some(x) = y { /// while let Some(x) = y {
/// // .. do something with x /// // .. do something with x
/// } /// };
/// ``` /// ```
pub WHILE_LET_LOOP, pub WHILE_LET_LOOP,
complexity, complexity,
@ -309,8 +310,11 @@ declare_clippy_lint! {
/// **Known problems:** None. /// **Known problems:** None.
/// ///
/// **Example:** /// **Example:**
/// ```ignore /// ```rust
/// for i in 0..v.len() { foo(v[i]); /// # let v = vec![1];
/// # fn foo(bar: usize) {}
/// # fn bar(bar: usize, baz: usize) {}
/// for i in 0..v.len() { foo(v[i]); }
/// for i in 0..v.len() { bar(i, v[i]); } /// for i in 0..v.len() { bar(i, v[i]); }
/// ``` /// ```
pub EXPLICIT_COUNTER_LOOP, pub EXPLICIT_COUNTER_LOOP,

View file

@ -20,20 +20,29 @@ declare_clippy_lint! {
/// **Example:** /// **Example:**
/// ///
/// ```rust /// ```rust
/// let x: Option<&str> = do_stuff(); /// # fn do_stuff() -> Option<String> { Some(String::new()) }
/// # fn log_err_msg(foo: String) -> Option<String> { Some(foo) }
/// # fn format_msg(foo: String) -> String { String::new() }
/// let x: Option<String> = do_stuff();
/// x.map(log_err_msg); /// x.map(log_err_msg);
/// x.map(|msg| log_err_msg(format_msg(msg))) /// # let x: Option<String> = do_stuff();
/// x.map(|msg| log_err_msg(format_msg(msg)));
/// ``` /// ```
/// ///
/// The correct use would be: /// The correct use would be:
/// ///
/// ```rust /// ```rust
/// let x: Option<&str> = do_stuff(); /// # fn do_stuff() -> Option<String> { Some(String::new()) }
/// # fn log_err_msg(foo: String) -> Option<String> { Some(foo) }
/// # fn format_msg(foo: String) -> String { String::new() }
/// let x: Option<String> = do_stuff();
/// if let Some(msg) = x { /// if let Some(msg) = x {
/// log_err_msg(msg) /// log_err_msg(msg);
/// } /// }
///
/// # let x: Option<String> = do_stuff();
/// if let Some(msg) = x { /// if let Some(msg) = x {
/// log_err_msg(format_msg(msg)) /// log_err_msg(format_msg(msg));
/// } /// }
/// ``` /// ```
pub OPTION_MAP_UNIT_FN, pub OPTION_MAP_UNIT_FN,
@ -53,21 +62,29 @@ declare_clippy_lint! {
/// **Example:** /// **Example:**
/// ///
/// ```rust /// ```rust
/// let x: Result<&str, &str> = do_stuff(); /// # fn do_stuff() -> Result<String, String> { Ok(String::new()) }
/// # fn log_err_msg(foo: String) -> Result<String, String> { Ok(foo) }
/// # fn format_msg(foo: String) -> String { String::new() }
/// let x: Result<String, String> = do_stuff();
/// x.map(log_err_msg); /// x.map(log_err_msg);
/// x.map(|msg| log_err_msg(format_msg(msg))) /// # let x: Result<String, String> = do_stuff();
/// x.map(|msg| log_err_msg(format_msg(msg)));
/// ``` /// ```
/// ///
/// The correct use would be: /// The correct use would be:
/// ///
/// ```rust /// ```rust
/// let x: Result<&str, &str> = do_stuff(); /// # fn do_stuff() -> Result<String, String> { Ok(String::new()) }
/// # fn log_err_msg(foo: String) -> Result<String, String> { Ok(foo) }
/// # fn format_msg(foo: String) -> String { String::new() }
/// let x: Result<String, String> = do_stuff();
/// if let Ok(msg) = x { /// if let Ok(msg) = x {
/// log_err_msg(msg) /// log_err_msg(msg);
/// } /// };
/// # let x: Result<String, String> = do_stuff();
/// if let Ok(msg) = x { /// if let Ok(msg) = x {
/// log_err_msg(format_msg(msg)) /// log_err_msg(format_msg(msg));
/// } /// };
/// ``` /// ```
pub RESULT_MAP_UNIT_FN, pub RESULT_MAP_UNIT_FN,
complexity, complexity,

View file

@ -247,7 +247,8 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// iter.filter(|x| x == 0).next() /// # let vec = vec![1];
/// vec.iter().filter(|x| **x == 0).next();
/// ``` /// ```
pub FILTER_NEXT, pub FILTER_NEXT,
complexity, complexity,
@ -345,7 +346,8 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// iter.find(|x| x == 0).is_some() /// # let vec = vec![1];
/// vec.iter().find(|x| **x == 0).is_some();
/// ``` /// ```
pub SEARCH_IS_SOME, pub SEARCH_IS_SOME,
complexity, complexity,
@ -363,7 +365,8 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// name.chars().next() == Some('_') /// let name = "foo";
/// name.chars().next() == Some('_');
/// ``` /// ```
pub CHARS_NEXT_CMP, pub CHARS_NEXT_CMP,
complexity, complexity,
@ -434,7 +437,7 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// 42u64.clone() /// 42u64.clone();
/// ``` /// ```
pub CLONE_ON_COPY, pub CLONE_ON_COPY,
complexity, complexity,
@ -708,11 +711,13 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// # fn do_stuff(x: &[i32]) {}
/// let x: &[i32] = &[1, 2, 3, 4, 5]; /// let x: &[i32] = &[1, 2, 3, 4, 5];
/// do_stuff(x.as_ref()); /// do_stuff(x.as_ref());
/// ``` /// ```
/// The correct use would be: /// The correct use would be:
/// ```rust /// ```rust
/// # fn do_stuff(x: &[i32]) {}
/// let x: &[i32] = &[1, 2, 3, 4, 5]; /// let x: &[i32] = &[1, 2, 3, 4, 5];
/// do_stuff(x); /// do_stuff(x);
/// ``` /// ```

View file

@ -184,7 +184,7 @@ declare_clippy_lint! {
/// **Known problems:** None. /// **Known problems:** None.
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,ignore
/// f() && g(); // We should write `if f() { g(); }`. /// f() && g(); // We should write `if f() { g(); }`.
/// ``` /// ```
pub SHORT_CIRCUIT_STATEMENT, pub SHORT_CIRCUIT_STATEMENT,

View file

@ -53,7 +53,7 @@ declare_clippy_lint! {
/// **Known problems:** None. /// **Known problems:** None.
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,ignore
/// (|| 42)() /// (|| 42)()
/// ``` /// ```
pub REDUNDANT_CLOSURE_CALL, pub REDUNDANT_CLOSURE_CALL,

View file

@ -24,7 +24,7 @@ declare_clippy_lint! {
/// shorter code. /// shorter code.
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,ignore
/// if x { /// if x {
/// false /// false
/// } else { /// } else {
@ -46,7 +46,7 @@ declare_clippy_lint! {
/// **Known problems:** None. /// **Known problems:** None.
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,ignore
/// if x == true {} // could be `if x { }` /// if x == true {} // could be `if x { }`
/// ``` /// ```
pub BOOL_COMPARISON, pub BOOL_COMPARISON,

View file

@ -18,7 +18,7 @@ declare_clippy_lint! {
/// ///
/// **Known problems:** It seems that the `&ref` pattern is sometimes useful. /// **Known problems:** It seems that the `&ref` pattern is sometimes useful.
/// For instance in the following snippet: /// For instance in the following snippet:
/// ```rust /// ```rust,ignore
/// enum Animal { /// enum Animal {
/// Cat(u64), /// Cat(u64),
/// Dog(u64), /// Dog(u64),
@ -26,8 +26,7 @@ declare_clippy_lint! {
/// ///
/// fn foo(a: &Animal, b: &Animal) { /// fn foo(a: &Animal, b: &Animal) {
/// match (a, b) { /// match (a, b) {
/// (&Animal::Cat(v), k) | (k, &Animal::Cat(v)) => (), // lifetime /// (&Animal::Cat(v), k) | (k, &Animal::Cat(v)) => (), // lifetime mismatch error
/// mismatch error
/// (&Animal::Dog(ref c), &Animal::Dog(_)) => () /// (&Animal::Dog(ref c), &Animal::Dog(_)) => ()
/// } /// }
/// } /// }

View file

@ -15,11 +15,17 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// # struct Point {
/// # x: i32,
/// # y: i32,
/// # z: i32,
/// # }
/// # let zero_point = Point { x: 0, y: 0, z: 0 };
/// Point { /// Point {
/// x: 1, /// x: 1,
/// y: 0, /// y: 1,
/// ..zero_point /// ..zero_point
/// } /// };
/// ``` /// ```
pub NEEDLESS_UPDATE, pub NEEDLESS_UPDATE,
complexity, complexity,

View file

@ -34,7 +34,7 @@ declare_clippy_lint! {
/// **Known problems:** None. /// **Known problems:** None.
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,ignore
/// compute_array()[0]; /// compute_array()[0];
/// ``` /// ```
pub UNNECESSARY_OPERATION, pub UNNECESSARY_OPERATION,

View file

@ -14,7 +14,9 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// a + b < a /// # let a = 1;
/// # let b = 2;
/// a + b < a;
/// ``` /// ```
pub OVERFLOW_CHECK_CONDITIONAL, pub OVERFLOW_CHECK_CONDITIONAL,
complexity, complexity,

View file

@ -19,7 +19,7 @@ declare_clippy_lint! {
/// struct Foo; /// struct Foo;
/// ///
/// impl PartialEq for Foo { /// impl PartialEq for Foo {
/// fn eq(&self, other: &Foo) -> bool { ... } /// fn eq(&self, other: &Foo) -> bool { true }
/// fn ne(&self, other: &Foo) -> bool { !(self == other) } /// fn ne(&self, other: &Foo) -> bool { !(self == other) }
/// } /// }
/// ``` /// ```

View file

@ -40,7 +40,8 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// x.iter().zip(0..x.len()) /// # let x = vec![1];
/// x.iter().zip(0..x.len());
/// ``` /// ```
pub RANGE_ZIP_WITH_LEN, pub RANGE_ZIP_WITH_LEN,
complexity, complexity,
@ -60,7 +61,7 @@ declare_clippy_lint! {
/// I.e., `let _ = (f()+1)..(f()+1)` results in `let _ = ((f()+1)..=f())`. /// I.e., `let _ = (f()+1)..(f()+1)` results in `let _ = ((f()+1)..=f())`.
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,ignore
/// for x..(y+1) { .. } /// for x..(y+1) { .. }
/// ``` /// ```
pub RANGE_PLUS_ONE, pub RANGE_PLUS_ONE,
@ -78,7 +79,7 @@ declare_clippy_lint! {
/// **Known problems:** None. /// **Known problems:** None.
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,ignore
/// for x..=(y-1) { .. } /// for x..=(y-1) { .. }
/// ``` /// ```
pub RANGE_MINUS_ONE, pub RANGE_MINUS_ONE,

View file

@ -15,7 +15,7 @@ declare_clippy_lint! {
/// the suggested fix for `x = **&&y` is `x = *&y`, which is still incorrect. /// the suggested fix for `x = **&&y` is `x = *&y`, which is still incorrect.
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,ignore
/// let a = f(*&mut b); /// let a = f(*&mut b);
/// let c = *&d; /// let c = *&d;
/// ``` /// ```
@ -64,8 +64,8 @@ declare_clippy_lint! {
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// struct Point(u32, u32); /// struct Point(u32, u32);
/// let point = Foo(30, 20); /// let point = Point(30, 20);
/// let x = (&point).x; /// let x = (&point).0;
/// ``` /// ```
pub REF_IN_DEREF, pub REF_IN_DEREF,
complexity, complexity,

View file

@ -20,12 +20,17 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// let mut a = 42;
/// let mut b = 1337;
///
/// let t = b; /// let t = b;
/// b = a; /// b = a;
/// a = t; /// a = t;
/// ``` /// ```
/// Use std::mem::swap(): /// Use std::mem::swap():
/// ```rust /// ```rust
/// let mut a = 1;
/// let mut b = 2;
/// std::mem::swap(&mut a, &mut b); /// std::mem::swap(&mut a, &mut b);
/// ``` /// ```
pub MANUAL_SWAP, pub MANUAL_SWAP,

View file

@ -15,13 +15,13 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// pub fn foo<T>(t: T) where T: Copy, T: Clone /// pub fn foo<T>(t: T) where T: Copy, T: Clone {}
/// ``` /// ```
/// ///
/// Could be written as: /// Could be written as:
/// ///
/// ```rust /// ```rust
/// pub fn foo<T>(t: T) where T: Copy + Clone /// pub fn foo<T>(t: T) where T: Copy + Clone {}
/// ``` /// ```
pub TYPE_REPETITION_IN_BOUNDS, pub TYPE_REPETITION_IN_BOUNDS,
complexity, complexity,

View file

@ -36,8 +36,8 @@ declare_clippy_lint! {
/// **Known problems:** None. /// **Known problems:** None.
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,ignore
/// core::intrinsics::transmute(t) // where the result type is the same as `t`'s /// core::intrinsics::transmute(t); // where the result type is the same as `t`'s
/// ``` /// ```
pub USELESS_TRANSMUTE, pub USELESS_TRANSMUTE,
complexity, complexity,
@ -53,7 +53,7 @@ declare_clippy_lint! {
/// **Known problems:** None. /// **Known problems:** None.
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,ignore
/// core::intrinsics::transmute(t) // where the result type is the same as /// core::intrinsics::transmute(t) // where the result type is the same as
/// // `*t` or `&t`'s /// // `*t` or `&t`'s
/// ``` /// ```
@ -70,8 +70,10 @@ declare_clippy_lint! {
/// **Known problems:** None. /// **Known problems:** None.
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,ignore
/// let _: &T = std::mem::transmute(p); // where p: *const T /// unsafe {
/// let _: &T = std::mem::transmute(p); // where p: *const T
/// }
/// ///
/// // can be written: /// // can be written:
/// let _: &T = &*p; /// let _: &T = &*p;
@ -99,7 +101,10 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// let _: char = std::mem::transmute(x); // where x: u32 /// let x = 1_u32;
/// unsafe {
/// let _: char = std::mem::transmute(x); // where x: u32
/// }
/// ///
/// // should be: /// // should be:
/// let _ = std::char::from_u32(x).unwrap(); /// let _ = std::char::from_u32(x).unwrap();
@ -127,7 +132,10 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// let _: &str = std::mem::transmute(b); // where b: &[u8] /// let b: &[u8] = &[1_u8, 2_u8];
/// unsafe {
/// let _: &str = std::mem::transmute(b); // where b: &[u8]
/// }
/// ///
/// // should be: /// // should be:
/// let _ = std::str::from_utf8(b).unwrap(); /// let _ = std::str::from_utf8(b).unwrap();
@ -146,7 +154,10 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// let _: bool = std::mem::transmute(x); // where x: u8 /// let x = 1_u8;
/// unsafe {
/// let _: bool = std::mem::transmute(x); // where x: u8
/// }
/// ///
/// // should be: /// // should be:
/// let _: bool = x != 0; /// let _: bool = x != 0;
@ -166,10 +177,12 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// let _: f32 = std::mem::transmute(x); // where x: u32 /// unsafe {
/// let _: f32 = std::mem::transmute(1_u32); // where x: u32
/// }
/// ///
/// // should be: /// // should be:
/// let _: f32 = f32::from_bits(x); /// let _: f32 = f32::from_bits(1_u32);
/// ``` /// ```
pub TRANSMUTE_INT_TO_FLOAT, pub TRANSMUTE_INT_TO_FLOAT,
complexity, complexity,
@ -195,7 +208,7 @@ declare_clippy_lint! {
/// let _: &f32 = std::mem::transmute(&1u32); /// let _: &f32 = std::mem::transmute(&1u32);
/// } /// }
/// // These can be respectively written: /// // These can be respectively written:
/// let _ = ptr as *const f32 /// let _ = ptr as *const f32;
/// let _ = unsafe{ &*(&1u32 as *const u32 as *const f32) }; /// let _ = unsafe{ &*(&1u32 as *const u32 as *const f32) };
/// ``` /// ```
pub TRANSMUTE_PTR_TO_PTR, pub TRANSMUTE_PTR_TO_PTR,

View file

@ -557,7 +557,7 @@ declare_clippy_lint! {
/// **Known problems:** None. /// **Known problems:** None.
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,ignore
/// foo({ /// foo({
/// let a = bar(); /// let a = bar();
/// baz(a); /// baz(a);
@ -775,7 +775,7 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// let _ = 2i32 as i32 /// let _ = 2i32 as i32;
/// ``` /// ```
pub UNNECESSARY_CAST, pub UNNECESSARY_CAST,
complexity, complexity,
@ -1295,6 +1295,7 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// # use std::rc::Rc;
/// struct Foo { /// struct Foo {
/// inner: Rc<Vec<Vec<Box<(u32, u32, u32, u32)>>>>, /// inner: Rc<Vec<Vec<Box<(u32, u32, u32, u32)>>>>,
/// } /// }
@ -1458,13 +1459,13 @@ declare_clippy_lint! {
/// **Known problems:** None. /// **Known problems:** None.
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,ignore
/// 'x' as u8 /// 'x' as u8
/// ``` /// ```
/// ///
/// A better version, using the byte literal: /// A better version, using the byte literal:
/// ///
/// ```rust /// ```rust,ignore
/// b'x' /// b'x'
/// ``` /// ```
pub CHAR_LIT_AS_U8, pub CHAR_LIT_AS_U8,

View file

@ -15,7 +15,7 @@ declare_clippy_lint! {
/// **What it does:** Generates clippy code that detects the offending pattern /// **What it does:** Generates clippy code that detects the offending pattern
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,ignore
/// // ./tests/ui/my_lint.rs /// // ./tests/ui/my_lint.rs
/// fn foo() { /// fn foo() {
/// // detect the following pattern /// // detect the following pattern
@ -24,13 +24,14 @@ declare_clippy_lint! {
/// // but ignore everything from here on /// // but ignore everything from here on
/// #![clippy::author = "ignore"] /// #![clippy::author = "ignore"]
/// } /// }
/// ()
/// } /// }
/// ``` /// ```
/// ///
/// Running `TESTNAME=ui/my_lint cargo uitest` will produce /// Running `TESTNAME=ui/my_lint cargo uitest` will produce
/// a `./tests/ui/new_lint.stdout` file with the generated code: /// a `./tests/ui/new_lint.stdout` file with the generated code:
/// ///
/// ```rust /// ```rust,ignore
/// // ./tests/ui/new_lint.stdout /// // ./tests/ui/new_lint.stdout
/// if_chain! { /// if_chain! {
/// if let ExprKind::If(ref cond, ref then, None) = item.node, /// if let ExprKind::If(ref cond, ref then, None) = item.node,

View file

@ -13,14 +13,14 @@ declare_clippy_lint! {
/// attribute /// attribute
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,ignore
/// #[clippy::dump] /// #[clippy::dump]
/// extern crate foo; /// extern crate foo;
/// ``` /// ```
/// ///
/// prints /// prints
/// ///
/// ``` /// ```text
/// item `foo` /// item `foo`
/// visibility inherited from outer item /// visibility inherited from outer item
/// extern crate dylib source: "/path/to/foo.so" /// extern crate dylib source: "/path/to/foo.so"

View file

@ -38,7 +38,7 @@ declare_clippy_lint! {
/// `declare_lint_pass!`, `impl_lint_pass!`, and `lint_array!` macros. /// `declare_lint_pass!`, `impl_lint_pass!`, and `lint_array!` macros.
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust,ignore
/// declare_lint! { pub LINT_1, ... } /// declare_lint! { pub LINT_1, ... }
/// declare_lint! { pub LINT_2, ... } /// declare_lint! { pub LINT_2, ... }
/// declare_lint! { pub FORGOTTEN_LINT, ... } /// declare_lint! { pub FORGOTTEN_LINT, ... }
@ -62,12 +62,12 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// Bad: /// Bad:
/// ```rust /// ```rust,ignore
/// cx.span_lint(LINT_NAME, "message"); /// cx.span_lint(LINT_NAME, "message");
/// ``` /// ```
/// ///
/// Good: /// Good:
/// ```rust /// ```rust,ignore
/// utils::span_lint(cx, LINT_NAME, "message"); /// utils::span_lint(cx, LINT_NAME, "message");
/// ``` /// ```
pub COMPILER_LINT_FUNCTIONS, pub COMPILER_LINT_FUNCTIONS,
@ -85,12 +85,12 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// Bad: /// Bad:
/// ```rust /// ```rust,ignore
/// expr.span.ctxt().outer().expn_info() /// expr.span.ctxt().outer().expn_info()
/// ``` /// ```
/// ///
/// Good: /// Good:
/// ```rust /// ```rust,ignore
/// expr.span.ctxt().outer_expn_info() /// expr.span.ctxt().outer_expn_info()
/// ``` /// ```
pub OUTER_EXPN_EXPN_INFO, pub OUTER_EXPN_EXPN_INFO,

View file

@ -15,7 +15,7 @@ declare_clippy_lint! {
/// ///
/// **Example:** /// **Example:**
/// ```rust /// ```rust
/// 0.0f32 / 0.0 /// 0.0f32 / 0.0;
/// ``` /// ```
pub ZERO_DIVIDED_BY_ZERO, pub ZERO_DIVIDED_BY_ZERO,
complexity, complexity,