Merge pull request #2339 from phansch/add_some_lint_examples

Add 'positive' examples for some lints
This commit is contained in:
Manish Goregaokar 2018-01-08 15:09:33 +05:30 committed by GitHub
commit 752c02d35d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,6 +36,14 @@ pub struct TypePass;
/// values: Box<Vec<Foo>>, /// values: Box<Vec<Foo>>,
/// } /// }
/// ``` /// ```
///
/// Better:
///
/// ```rust
/// struct X {
/// values: Vec<Foo>,
/// }
/// ```
declare_lint! { declare_lint! {
pub BOX_VEC, pub BOX_VEC,
Warn, Warn,
@ -89,6 +97,12 @@ declare_lint! {
/// ```rust /// ```rust
/// fn foo(bar: &Box<T>) { ... } /// fn foo(bar: &Box<T>) { ... }
/// ``` /// ```
///
/// Better:
///
/// ```rust
/// fn foo(bar: &T) { ... }
/// ```
declare_lint! { declare_lint! {
pub BORROWED_BOX, pub BORROWED_BOX,
Warn, Warn,
@ -514,6 +528,12 @@ declare_lint! {
/// ```rust /// ```rust
/// fn as_u64(x: u8) -> u64 { x as u64 } /// 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! { declare_lint! {
pub CAST_LOSSLESS, pub CAST_LOSSLESS,
Warn, Warn,
@ -994,6 +1014,12 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
/// ```rust /// ```rust
/// 'x' as u8 /// 'x' as u8
/// ``` /// ```
///
/// A better version, using the byte literal:
///
/// ```rust
/// b'x'
/// ```
declare_lint! { declare_lint! {
pub CHAR_LIT_AS_U8, pub CHAR_LIT_AS_U8,
Warn, Warn,