diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index 28a5f8246f77..ec4c8f5faa3f 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -45,7 +45,8 @@ declare_clippy_lint! { /// **Example:** /// ```rust /// let mut a = 5; - /// ... + /// let b = 2; + /// // ... /// a += a + b; /// ``` pub MISREFACTORED_ASSIGN_OP, diff --git a/clippy_lints/src/double_comparison.rs b/clippy_lints/src/double_comparison.rs index 0c7c81f40bf4..d48bfea73b39 100644 --- a/clippy_lints/src/double_comparison.rs +++ b/clippy_lints/src/double_comparison.rs @@ -18,13 +18,17 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust - /// x == y || x < y + /// # let x = 1; + /// # let y = 2; + /// if x == y || x < y {} /// ``` /// /// Could be written as: /// /// ```rust - /// x <= y + /// # let x = 1; + /// # let y = 2; + /// if x <= y {} /// ``` pub DOUBLE_COMPARISONS, complexity, diff --git a/clippy_lints/src/double_parens.rs b/clippy_lints/src/double_parens.rs index f39ea6a3cc5a..e55490325eca 100644 --- a/clippy_lints/src/double_parens.rs +++ b/clippy_lints/src/double_parens.rs @@ -13,9 +13,10 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust - /// ((0)) - /// foo((0)) - /// ((1, 2)) + /// # fn foo(bar: usize) {} + /// ((0)); + /// foo((0)); + /// ((1, 2)); /// ``` pub DOUBLE_PARENS, complexity, diff --git a/clippy_lints/src/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs index 60470ede5419..1346aea3ed0a 100644 --- a/clippy_lints/src/duration_subsec.rs +++ b/clippy_lints/src/duration_subsec.rs @@ -20,6 +20,7 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust + /// # use std::time::Duration; /// let dur = Duration::new(5, 0); /// let _micros = dur.subsec_nanos() / 1_000; /// let _millis = dur.subsec_nanos() / 1_000_000; diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 2db3a2bc00b7..b915d50671b3 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -42,7 +42,9 @@ declare_clippy_lint! { /// shorthand. /// /// **Example:** - /// ```rust + /// ```rust,no_run + /// # fn b() -> bool { true } + /// # fn c() -> bool { true } /// let a = b() || panic!() || c(); /// // `c()` is dead, `panic!()` is only called if `b()` returns `false` /// let x = (a, b, c, panic!()); diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index dc76bb0b2b90..a2edb4855b64 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -16,8 +16,10 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust + /// # use std::io::Write; + /// # let bar = "furchtbar"; /// // 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, complexity, diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index aed1142d9aea..751d8fd00830 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -26,8 +26,9 @@ declare_clippy_lint! { /// /// **Examples:** /// ```rust - /// format!("foo") - /// format!("{}", foo) + /// # let foo = "foo"; + /// format!("foo"); + /// format!("{}", foo); /// ``` pub USELESS_FORMAT, complexity, diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 1a163e682eff..9772a603ba03 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -23,8 +23,9 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust + /// # struct Color; /// fn foo(x: u32, y: u32, name: &str, c: Color, w: f32, h: f32, a: f32, b: f32) { - /// .. + /// // .. /// } /// ``` pub TOO_MANY_ARGUMENTS, diff --git a/clippy_lints/src/identity_op.rs b/clippy_lints/src/identity_op.rs index b3ab46781adc..1cd58a370945 100644 --- a/clippy_lints/src/identity_op.rs +++ b/clippy_lints/src/identity_op.rs @@ -17,7 +17,8 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust - /// x / 1 + 0 * 1 - 0 | 0 + /// # let x = 1; + /// x / 1 + 0 * 1 - 0 | 0; /// ``` pub IDENTITY_OP, complexity, diff --git a/clippy_lints/src/int_plus_one.rs b/clippy_lints/src/int_plus_one.rs index b59179618a6d..22ebf562d3ba 100644 --- a/clippy_lints/src/int_plus_one.rs +++ b/clippy_lints/src/int_plus_one.rs @@ -17,13 +17,17 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust - /// x >= y + 1 + /// # let x = 1; + /// # let y = 1; + /// if x >= y + 1 {} /// ``` /// - /// Could be written: + /// Could be written as: /// /// ```rust - /// x > y + /// # let x = 1; + /// # let y = 1; + /// if x > y {} /// ``` pub INT_PLUS_ONE, complexity, diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 1e9e17f599c9..39e55a9558bb 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -100,7 +100,7 @@ macro_rules! declare_clippy_lint { }; { $(#[$attr:meta])* pub $name:tt, complexity, $description:tt } => { 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 } => { @@ -130,12 +130,12 @@ macro_rules! declare_clippy_lint { }; { $(#[$attr:meta])* pub $name:tt, internal, $description:tt } => { declare_tool_lint! { - pub clippy::$name, Allow, $description, report_in_external_macro: true + $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true } }; { $(#[$attr:meta])* pub $name:tt, internal_warn, $description:tt } => { declare_tool_lint! { - pub clippy::$name, Warn, $description, report_in_external_macro: true + $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true } }; } diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 07fbc78f358b..72e28d23ebdb 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -47,7 +47,7 @@ declare_clippy_lint! { /// **Example:** /// ```rust /// fn unused_lifetime<'a>(x: u8) { - /// .. + /// // .. /// } /// ``` pub EXTRA_UNUSED_LIFETIMES, diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 02074c79b41e..3c66c74324ea 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -217,18 +217,19 @@ declare_clippy_lint! { /// **Known problems:** Sometimes the wrong binding is displayed (#383). /// /// **Example:** - /// ```rust + /// ```rust,no_run + /// # let y = Some(1); /// loop { /// let x = match y { /// Some(x) => x, /// None => break, - /// } + /// }; /// // .. do something with x /// } /// // is easier written as /// while let Some(x) = y { /// // .. do something with x - /// } + /// }; /// ``` pub WHILE_LET_LOOP, complexity, @@ -309,8 +310,11 @@ declare_clippy_lint! { /// **Known problems:** None. /// /// **Example:** - /// ```ignore - /// for i in 0..v.len() { foo(v[i]); + /// ```rust + /// # 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]); } /// ``` pub EXPLICIT_COUNTER_LOOP, diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 2e97f44b317f..22093bfbee84 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -20,20 +20,29 @@ declare_clippy_lint! { /// **Example:** /// /// ```rust - /// let x: Option<&str> = do_stuff(); + /// # fn do_stuff() -> Option { Some(String::new()) } + /// # fn log_err_msg(foo: String) -> Option { Some(foo) } + /// # fn format_msg(foo: String) -> String { String::new() } + /// let x: Option = do_stuff(); /// x.map(log_err_msg); - /// x.map(|msg| log_err_msg(format_msg(msg))) + /// # let x: Option = do_stuff(); + /// x.map(|msg| log_err_msg(format_msg(msg))); /// ``` /// /// The correct use would be: /// /// ```rust - /// let x: Option<&str> = do_stuff(); + /// # fn do_stuff() -> Option { Some(String::new()) } + /// # fn log_err_msg(foo: String) -> Option { Some(foo) } + /// # fn format_msg(foo: String) -> String { String::new() } + /// let x: Option = do_stuff(); /// if let Some(msg) = x { - /// log_err_msg(msg) + /// log_err_msg(msg); /// } + /// + /// # let x: Option = do_stuff(); /// if let Some(msg) = x { - /// log_err_msg(format_msg(msg)) + /// log_err_msg(format_msg(msg)); /// } /// ``` pub OPTION_MAP_UNIT_FN, @@ -53,21 +62,29 @@ declare_clippy_lint! { /// **Example:** /// /// ```rust - /// let x: Result<&str, &str> = do_stuff(); + /// # fn do_stuff() -> Result { Ok(String::new()) } + /// # fn log_err_msg(foo: String) -> Result { Ok(foo) } + /// # fn format_msg(foo: String) -> String { String::new() } + /// let x: Result = do_stuff(); /// x.map(log_err_msg); - /// x.map(|msg| log_err_msg(format_msg(msg))) + /// # let x: Result = do_stuff(); + /// x.map(|msg| log_err_msg(format_msg(msg))); /// ``` /// /// The correct use would be: /// /// ```rust - /// let x: Result<&str, &str> = do_stuff(); + /// # fn do_stuff() -> Result { Ok(String::new()) } + /// # fn log_err_msg(foo: String) -> Result { Ok(foo) } + /// # fn format_msg(foo: String) -> String { String::new() } + /// let x: Result = do_stuff(); /// if let Ok(msg) = x { - /// log_err_msg(msg) - /// } + /// log_err_msg(msg); + /// }; + /// # let x: Result = do_stuff(); /// if let Ok(msg) = x { - /// log_err_msg(format_msg(msg)) - /// } + /// log_err_msg(format_msg(msg)); + /// }; /// ``` pub RESULT_MAP_UNIT_FN, complexity, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 02dfb3e32aad..473f3892f22f 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -247,7 +247,8 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust - /// iter.filter(|x| x == 0).next() + /// # let vec = vec![1]; + /// vec.iter().filter(|x| **x == 0).next(); /// ``` pub FILTER_NEXT, complexity, @@ -345,7 +346,8 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust - /// iter.find(|x| x == 0).is_some() + /// # let vec = vec![1]; + /// vec.iter().find(|x| **x == 0).is_some(); /// ``` pub SEARCH_IS_SOME, complexity, @@ -363,7 +365,8 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust - /// name.chars().next() == Some('_') + /// let name = "foo"; + /// name.chars().next() == Some('_'); /// ``` pub CHARS_NEXT_CMP, complexity, @@ -434,7 +437,7 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust - /// 42u64.clone() + /// 42u64.clone(); /// ``` pub CLONE_ON_COPY, complexity, @@ -708,11 +711,13 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust + /// # fn do_stuff(x: &[i32]) {} /// let x: &[i32] = &[1, 2, 3, 4, 5]; /// do_stuff(x.as_ref()); /// ``` /// The correct use would be: /// ```rust + /// # fn do_stuff(x: &[i32]) {} /// let x: &[i32] = &[1, 2, 3, 4, 5]; /// do_stuff(x); /// ``` diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index d89f886a39b3..6d24aa008fb9 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -184,7 +184,7 @@ declare_clippy_lint! { /// **Known problems:** None. /// /// **Example:** - /// ```rust + /// ```rust,ignore /// f() && g(); // We should write `if f() { g(); }`. /// ``` pub SHORT_CIRCUIT_STATEMENT, diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index c9df436dae7e..7d6f29c521b3 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -53,7 +53,7 @@ declare_clippy_lint! { /// **Known problems:** None. /// /// **Example:** - /// ```rust + /// ```rust,ignore /// (|| 42)() /// ``` pub REDUNDANT_CLOSURE_CALL, diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index 9857e17563c1..167f00fee517 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -24,7 +24,7 @@ declare_clippy_lint! { /// shorter code. /// /// **Example:** - /// ```rust + /// ```rust,ignore /// if x { /// false /// } else { @@ -46,7 +46,7 @@ declare_clippy_lint! { /// **Known problems:** None. /// /// **Example:** - /// ```rust + /// ```rust,ignore /// if x == true {} // could be `if x { }` /// ``` pub BOOL_COMPARISON, diff --git a/clippy_lints/src/needless_borrowed_ref.rs b/clippy_lints/src/needless_borrowed_ref.rs index b6104f6cc9a5..b6598ac55b38 100644 --- a/clippy_lints/src/needless_borrowed_ref.rs +++ b/clippy_lints/src/needless_borrowed_ref.rs @@ -18,7 +18,7 @@ declare_clippy_lint! { /// /// **Known problems:** It seems that the `&ref` pattern is sometimes useful. /// For instance in the following snippet: - /// ```rust + /// ```rust,ignore /// enum Animal { /// Cat(u64), /// Dog(u64), @@ -26,8 +26,7 @@ declare_clippy_lint! { /// /// fn foo(a: &Animal, b: &Animal) { /// match (a, b) { - /// (&Animal::Cat(v), k) | (k, &Animal::Cat(v)) => (), // lifetime - /// mismatch error + /// (&Animal::Cat(v), k) | (k, &Animal::Cat(v)) => (), // lifetime mismatch error /// (&Animal::Dog(ref c), &Animal::Dog(_)) => () /// } /// } diff --git a/clippy_lints/src/needless_update.rs b/clippy_lints/src/needless_update.rs index 316395acf263..fdaa14dfb6ae 100644 --- a/clippy_lints/src/needless_update.rs +++ b/clippy_lints/src/needless_update.rs @@ -15,11 +15,17 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust + /// # struct Point { + /// # x: i32, + /// # y: i32, + /// # z: i32, + /// # } + /// # let zero_point = Point { x: 0, y: 0, z: 0 }; /// Point { /// x: 1, - /// y: 0, + /// y: 1, /// ..zero_point - /// } + /// }; /// ``` pub NEEDLESS_UPDATE, complexity, diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 8c5ddaf4140f..2fe866a1d95b 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -34,7 +34,7 @@ declare_clippy_lint! { /// **Known problems:** None. /// /// **Example:** - /// ```rust + /// ```rust,ignore /// compute_array()[0]; /// ``` pub UNNECESSARY_OPERATION, diff --git a/clippy_lints/src/overflow_check_conditional.rs b/clippy_lints/src/overflow_check_conditional.rs index c598e915a5af..f4c301958b9e 100644 --- a/clippy_lints/src/overflow_check_conditional.rs +++ b/clippy_lints/src/overflow_check_conditional.rs @@ -14,7 +14,9 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust - /// a + b < a + /// # let a = 1; + /// # let b = 2; + /// a + b < a; /// ``` pub OVERFLOW_CHECK_CONDITIONAL, complexity, diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index 1091ed0d6de9..805efa7cf20a 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -19,7 +19,7 @@ declare_clippy_lint! { /// struct 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) } /// } /// ``` diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index af2342634a11..a0391e3364e1 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -40,7 +40,8 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust - /// x.iter().zip(0..x.len()) + /// # let x = vec![1]; + /// x.iter().zip(0..x.len()); /// ``` pub RANGE_ZIP_WITH_LEN, complexity, @@ -60,7 +61,7 @@ declare_clippy_lint! { /// I.e., `let _ = (f()+1)..(f()+1)` results in `let _ = ((f()+1)..=f())`. /// /// **Example:** - /// ```rust + /// ```rust,ignore /// for x..(y+1) { .. } /// ``` pub RANGE_PLUS_ONE, @@ -78,7 +79,7 @@ declare_clippy_lint! { /// **Known problems:** None. /// /// **Example:** - /// ```rust + /// ```rust,ignore /// for x..=(y-1) { .. } /// ``` pub RANGE_MINUS_ONE, diff --git a/clippy_lints/src/reference.rs b/clippy_lints/src/reference.rs index 2ee00a2f1034..35e214faae80 100644 --- a/clippy_lints/src/reference.rs +++ b/clippy_lints/src/reference.rs @@ -15,7 +15,7 @@ declare_clippy_lint! { /// the suggested fix for `x = **&&y` is `x = *&y`, which is still incorrect. /// /// **Example:** - /// ```rust + /// ```rust,ignore /// let a = f(*&mut b); /// let c = *&d; /// ``` @@ -64,8 +64,8 @@ declare_clippy_lint! { /// **Example:** /// ```rust /// struct Point(u32, u32); - /// let point = Foo(30, 20); - /// let x = (&point).x; + /// let point = Point(30, 20); + /// let x = (&point).0; /// ``` pub REF_IN_DEREF, complexity, diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index fc5b2150d52c..11ab5b876282 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -20,12 +20,17 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust + /// let mut a = 42; + /// let mut b = 1337; + /// /// let t = b; /// b = a; /// a = t; /// ``` /// Use std::mem::swap(): /// ```rust + /// let mut a = 1; + /// let mut b = 2; /// std::mem::swap(&mut a, &mut b); /// ``` pub MANUAL_SWAP, diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 8a719c0dd041..bf4c5d65db63 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -15,13 +15,13 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust - /// pub fn foo(t: T) where T: Copy, T: Clone + /// pub fn foo(t: T) where T: Copy, T: Clone {} /// ``` /// /// Could be written as: /// /// ```rust - /// pub fn foo(t: T) where T: Copy + Clone + /// pub fn foo(t: T) where T: Copy + Clone {} /// ``` pub TYPE_REPETITION_IN_BOUNDS, complexity, diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index e2534dae09bc..a514b9c512db 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -36,8 +36,8 @@ declare_clippy_lint! { /// **Known problems:** None. /// /// **Example:** - /// ```rust - /// core::intrinsics::transmute(t) // where the result type is the same as `t`'s + /// ```rust,ignore + /// core::intrinsics::transmute(t); // where the result type is the same as `t`'s /// ``` pub USELESS_TRANSMUTE, complexity, @@ -53,7 +53,7 @@ declare_clippy_lint! { /// **Known problems:** None. /// /// **Example:** - /// ```rust + /// ```rust,ignore /// core::intrinsics::transmute(t) // where the result type is the same as /// // `*t` or `&t`'s /// ``` @@ -70,8 +70,10 @@ declare_clippy_lint! { /// **Known problems:** None. /// /// **Example:** - /// ```rust - /// let _: &T = std::mem::transmute(p); // where p: *const T + /// ```rust,ignore + /// unsafe { + /// let _: &T = std::mem::transmute(p); // where p: *const T + /// } /// /// // can be written: /// let _: &T = &*p; @@ -99,7 +101,10 @@ declare_clippy_lint! { /// /// **Example:** /// ```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: /// let _ = std::char::from_u32(x).unwrap(); @@ -127,7 +132,10 @@ declare_clippy_lint! { /// /// **Example:** /// ```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: /// let _ = std::str::from_utf8(b).unwrap(); @@ -146,7 +154,10 @@ declare_clippy_lint! { /// /// **Example:** /// ```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: /// let _: bool = x != 0; @@ -166,10 +177,12 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust - /// let _: f32 = std::mem::transmute(x); // where x: u32 + /// unsafe { + /// let _: f32 = std::mem::transmute(1_u32); // where x: u32 + /// } /// /// // should be: - /// let _: f32 = f32::from_bits(x); + /// let _: f32 = f32::from_bits(1_u32); /// ``` pub TRANSMUTE_INT_TO_FLOAT, complexity, @@ -195,7 +208,7 @@ declare_clippy_lint! { /// let _: &f32 = std::mem::transmute(&1u32); /// } /// // These can be respectively written: - /// let _ = ptr as *const f32 + /// let _ = ptr as *const f32; /// let _ = unsafe{ &*(&1u32 as *const u32 as *const f32) }; /// ``` pub TRANSMUTE_PTR_TO_PTR, diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 9b1876a1f2f1..3c8ca3fea679 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -557,7 +557,7 @@ declare_clippy_lint! { /// **Known problems:** None. /// /// **Example:** - /// ```rust + /// ```rust,ignore /// foo({ /// let a = bar(); /// baz(a); @@ -775,7 +775,7 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust - /// let _ = 2i32 as i32 + /// let _ = 2i32 as i32; /// ``` pub UNNECESSARY_CAST, complexity, @@ -1295,6 +1295,7 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust + /// # use std::rc::Rc; /// struct Foo { /// inner: Rc>>>, /// } @@ -1458,13 +1459,13 @@ declare_clippy_lint! { /// **Known problems:** None. /// /// **Example:** - /// ```rust + /// ```rust,ignore /// 'x' as u8 /// ``` /// /// A better version, using the byte literal: /// - /// ```rust + /// ```rust,ignore /// b'x' /// ``` pub CHAR_LIT_AS_U8, diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index f419338097d2..811bdce18e89 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -15,7 +15,7 @@ declare_clippy_lint! { /// **What it does:** Generates clippy code that detects the offending pattern /// /// **Example:** - /// ```rust + /// ```rust,ignore /// // ./tests/ui/my_lint.rs /// fn foo() { /// // detect the following pattern @@ -24,13 +24,14 @@ declare_clippy_lint! { /// // but ignore everything from here on /// #![clippy::author = "ignore"] /// } + /// () /// } /// ``` /// /// Running `TESTNAME=ui/my_lint cargo uitest` will produce /// a `./tests/ui/new_lint.stdout` file with the generated code: /// - /// ```rust + /// ```rust,ignore /// // ./tests/ui/new_lint.stdout /// if_chain! { /// if let ExprKind::If(ref cond, ref then, None) = item.node, diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 7f7466a1a5be..c061e4f91e8c 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -13,14 +13,14 @@ declare_clippy_lint! { /// attribute /// /// **Example:** - /// ```rust + /// ```rust,ignore /// #[clippy::dump] /// extern crate foo; /// ``` /// /// prints /// - /// ``` + /// ```text /// item `foo` /// visibility inherited from outer item /// extern crate dylib source: "/path/to/foo.so" diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 6393bf2add47..0dcac1121842 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -38,7 +38,7 @@ declare_clippy_lint! { /// `declare_lint_pass!`, `impl_lint_pass!`, and `lint_array!` macros. /// /// **Example:** - /// ```rust + /// ```rust,ignore /// declare_lint! { pub LINT_1, ... } /// declare_lint! { pub LINT_2, ... } /// declare_lint! { pub FORGOTTEN_LINT, ... } @@ -62,12 +62,12 @@ declare_clippy_lint! { /// /// **Example:** /// Bad: - /// ```rust + /// ```rust,ignore /// cx.span_lint(LINT_NAME, "message"); /// ``` /// /// Good: - /// ```rust + /// ```rust,ignore /// utils::span_lint(cx, LINT_NAME, "message"); /// ``` pub COMPILER_LINT_FUNCTIONS, @@ -85,12 +85,12 @@ declare_clippy_lint! { /// /// **Example:** /// Bad: - /// ```rust + /// ```rust,ignore /// expr.span.ctxt().outer().expn_info() /// ``` /// /// Good: - /// ```rust + /// ```rust,ignore /// expr.span.ctxt().outer_expn_info() /// ``` pub OUTER_EXPN_EXPN_INFO, diff --git a/clippy_lints/src/zero_div_zero.rs b/clippy_lints/src/zero_div_zero.rs index 094cb627dc3a..1c4c54f26267 100644 --- a/clippy_lints/src/zero_div_zero.rs +++ b/clippy_lints/src/zero_div_zero.rs @@ -15,7 +15,7 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust - /// 0.0f32 / 0.0 + /// 0.0f32 / 0.0; /// ``` pub ZERO_DIVIDED_BY_ZERO, complexity,