Skip to content

Commit 752c02d

Browse files
authored
Merge pull request #2339 from phansch/add_some_lint_examples
Add 'positive' examples for some lints
2 parents 53b7707 + 1a16ac0 commit 752c02d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

clippy_lints/src/types.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ pub struct TypePass;
3636
/// values: Box<Vec<Foo>>,
3737
/// }
3838
/// ```
39+
///
40+
/// Better:
41+
///
42+
/// ```rust
43+
/// struct X {
44+
/// values: Vec<Foo>,
45+
/// }
46+
/// ```
3947
declare_lint! {
4048
pub BOX_VEC,
4149
Warn,
@@ -89,6 +97,12 @@ declare_lint! {
8997
/// ```rust
9098
/// fn foo(bar: &Box<T>) { ... }
9199
/// ```
100+
///
101+
/// Better:
102+
///
103+
/// ```rust
104+
/// fn foo(bar: &T) { ... }
105+
/// ```
92106
declare_lint! {
93107
pub BORROWED_BOX,
94108
Warn,
@@ -514,6 +528,12 @@ declare_lint! {
514528
/// ```rust
515529
/// fn as_u64(x: u8) -> u64 { x as u64 }
516530
/// ```
531+
///
532+
/// Using `::from` would look like this:
533+
///
534+
/// ```rust
535+
/// fn as_u64(x: u8) -> u64 { u64::from(x) }
536+
/// ```
517537
declare_lint! {
518538
pub CAST_LOSSLESS,
519539
Warn,
@@ -994,6 +1014,12 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
9941014
/// ```rust
9951015
/// 'x' as u8
9961016
/// ```
1017+
///
1018+
/// A better version, using the byte literal:
1019+
///
1020+
/// ```rust
1021+
/// b'x'
1022+
/// ```
9971023
declare_lint! {
9981024
pub CHAR_LIT_AS_U8,
9991025
Warn,

0 commit comments

Comments
 (0)