From 1a16ac058dda3bcb20c57d9f1daf1d22b6a992a4 Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Mon, 8 Jan 2018 10:17:05 +0100 Subject: [PATCH] Add 'positive' examples for some lints This allows to see at a quick glance what the improved code could look like for these lints. --- clippy_lints/src/types.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index c146d306a5a..bf4e85f689f 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -36,6 +36,14 @@ pub struct TypePass; /// values: Box>, /// } /// ``` +/// +/// Better: +/// +/// ```rust +/// struct X { +/// values: Vec, +/// } +/// ``` declare_lint! { pub BOX_VEC, Warn, @@ -89,6 +97,12 @@ declare_lint! { /// ```rust /// fn foo(bar: &Box) { ... } /// ``` +/// +/// Better: +/// +/// ```rust +/// fn foo(bar: &T) { ... } +/// ``` declare_lint! { pub BORROWED_BOX, Warn, @@ -514,6 +528,12 @@ declare_lint! { /// ```rust /// fn as_u64(x: u8) -> u64 { x as u64 } /// ``` +/// +/// Using `::from` would look like this: +/// +/// ```rust +/// fn as_u64(x: u8) -> u64 { u64::from(x) } +/// ``` declare_lint! { pub CAST_LOSSLESS, Warn, @@ -994,6 +1014,12 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor { /// ```rust /// 'x' as u8 /// ``` +/// +/// A better version, using the byte literal: +/// +/// ```rust +/// b'x' +/// ``` declare_lint! { pub CHAR_LIT_AS_U8, Warn,