Merge commit '4f142aa105
' into clippyup
This commit is contained in:
parent
2ed404937f
commit
cd0bb7de01
284 changed files with 8555 additions and 4250 deletions
|
@ -28,6 +28,7 @@ docs! {
|
|||
"approx_constant",
|
||||
"arithmetic_side_effects",
|
||||
"as_conversions",
|
||||
"as_ptr_cast_mut",
|
||||
"as_underscore",
|
||||
"assertions_on_constants",
|
||||
"assertions_on_result_states",
|
||||
|
@ -60,6 +61,7 @@ docs! {
|
|||
"cast_enum_constructor",
|
||||
"cast_enum_truncation",
|
||||
"cast_lossless",
|
||||
"cast_nan_to_int",
|
||||
"cast_possible_truncation",
|
||||
"cast_possible_wrap",
|
||||
"cast_precision_loss",
|
||||
|
@ -257,6 +259,7 @@ docs! {
|
|||
"manual_async_fn",
|
||||
"manual_bits",
|
||||
"manual_clamp",
|
||||
"manual_filter",
|
||||
"manual_filter_map",
|
||||
"manual_find",
|
||||
"manual_find_map",
|
||||
|
@ -313,6 +316,7 @@ docs! {
|
|||
"missing_panics_doc",
|
||||
"missing_safety_doc",
|
||||
"missing_spin_loop",
|
||||
"missing_trait_methods",
|
||||
"mistyped_literal_suffixes",
|
||||
"mixed_case_hex_literals",
|
||||
"mixed_read_write_in_expression",
|
||||
|
@ -391,6 +395,7 @@ docs! {
|
|||
"panic",
|
||||
"panic_in_result_fn",
|
||||
"panicking_unwrap",
|
||||
"partial_pub_fields",
|
||||
"partialeq_ne_impl",
|
||||
"partialeq_to_none",
|
||||
"path_buf_push_overwrite",
|
||||
|
@ -553,6 +558,7 @@ docs! {
|
|||
"unseparated_literal_suffix",
|
||||
"unsound_collection_transmute",
|
||||
"unused_async",
|
||||
"unused_format_specs",
|
||||
"unused_io_amount",
|
||||
"unused_peekable",
|
||||
"unused_rounding",
|
||||
|
|
19
src/docs/as_ptr_cast_mut.txt
Normal file
19
src/docs/as_ptr_cast_mut.txt
Normal file
|
@ -0,0 +1,19 @@
|
|||
### What it does
|
||||
Checks for the result of a `&self`-taking `as_ptr` being cast to a mutable pointer
|
||||
|
||||
### Why is this bad?
|
||||
Since `as_ptr` takes a `&self`, the pointer won't have write permissions unless interior
|
||||
mutability is used, making it unlikely that having it as a mutable pointer is correct.
|
||||
|
||||
### Example
|
||||
```
|
||||
let string = String::with_capacity(1);
|
||||
let ptr = string.as_ptr() as *mut u8;
|
||||
unsafe { ptr.write(4) }; // UNDEFINED BEHAVIOUR
|
||||
```
|
||||
Use instead:
|
||||
```
|
||||
let mut string = String::with_capacity(1);
|
||||
let ptr = string.as_mut_ptr();
|
||||
unsafe { ptr.write(4) };
|
||||
```
|
|
@ -7,12 +7,6 @@ First, it's more complex, involving two calls instead of one.
|
|||
Second, `Box::default()` can be faster
|
||||
[in certain cases](https://nnethercote.github.io/perf-book/standard-library-types.html#box).
|
||||
|
||||
### Known problems
|
||||
The lint may miss some cases (e.g. Box::new(String::from(""))).
|
||||
On the other hand, it will trigger on cases where the `default`
|
||||
code comes from a macro that does something different based on
|
||||
e.g. target operating system.
|
||||
|
||||
### Example
|
||||
```
|
||||
let x: Box<String> = Box::new(Default::default());
|
||||
|
|
15
src/docs/cast_nan_to_int.txt
Normal file
15
src/docs/cast_nan_to_int.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
### What it does
|
||||
Checks for a known NaN float being cast to an integer
|
||||
|
||||
### Why is this bad?
|
||||
NaNs are cast into zero, so one could simply use this and make the
|
||||
code more readable. The lint could also hint at a programmer error.
|
||||
|
||||
### Example
|
||||
```
|
||||
let _: (0.0_f32 / 0.0) as u64;
|
||||
```
|
||||
Use instead:
|
||||
```
|
||||
let _: = 0_u64;
|
||||
```
|
21
src/docs/manual_filter.txt
Normal file
21
src/docs/manual_filter.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
### What it does
|
||||
Checks for usages of `match` which could be implemented using `filter`
|
||||
|
||||
### Why is this bad?
|
||||
Using the `filter` method is clearer and more concise.
|
||||
|
||||
### Example
|
||||
```
|
||||
match Some(0) {
|
||||
Some(x) => if x % 2 == 0 {
|
||||
Some(x)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
```
|
||||
Use instead:
|
||||
```
|
||||
Some(0).filter(|&x| x % 2 == 0);
|
||||
```
|
40
src/docs/missing_trait_methods.txt
Normal file
40
src/docs/missing_trait_methods.txt
Normal file
|
@ -0,0 +1,40 @@
|
|||
### What it does
|
||||
Checks if a provided method is used implicitly by a trait
|
||||
implementation. A usage example would be a wrapper where every method
|
||||
should perform some operation before delegating to the inner type's
|
||||
implemenation.
|
||||
|
||||
This lint should typically be enabled on a specific trait `impl` item
|
||||
rather than globally.
|
||||
|
||||
### Why is this bad?
|
||||
Indicates that a method is missing.
|
||||
|
||||
### Example
|
||||
```
|
||||
trait Trait {
|
||||
fn required();
|
||||
|
||||
fn provided() {}
|
||||
}
|
||||
|
||||
#[warn(clippy::missing_trait_methods)]
|
||||
impl Trait for Type {
|
||||
fn required() { /* ... */ }
|
||||
}
|
||||
```
|
||||
Use instead:
|
||||
```
|
||||
trait Trait {
|
||||
fn required();
|
||||
|
||||
fn provided() {}
|
||||
}
|
||||
|
||||
#[warn(clippy::missing_trait_methods)]
|
||||
impl Trait for Type {
|
||||
fn required() { /* ... */ }
|
||||
|
||||
fn provided() { /* ... */ }
|
||||
}
|
||||
```
|
27
src/docs/partial_pub_fields.txt
Normal file
27
src/docs/partial_pub_fields.txt
Normal file
|
@ -0,0 +1,27 @@
|
|||
### What it does
|
||||
Checks whether partial fields of a struct are public.
|
||||
|
||||
Either make all fields of a type public, or make none of them public
|
||||
|
||||
### Why is this bad?
|
||||
Most types should either be:
|
||||
* Abstract data types: complex objects with opaque implementation which guard
|
||||
interior invariants and expose intentionally limited API to the outside world.
|
||||
* Data: relatively simple objects which group a bunch of related attributes together.
|
||||
|
||||
### Example
|
||||
```
|
||||
pub struct Color {
|
||||
pub r: u8,
|
||||
pub g: u8,
|
||||
b: u8,
|
||||
}
|
||||
```
|
||||
Use instead:
|
||||
```
|
||||
pub struct Color {
|
||||
pub r: u8,
|
||||
pub g: u8,
|
||||
pub b: u8,
|
||||
}
|
||||
```
|
24
src/docs/unused_format_specs.txt
Normal file
24
src/docs/unused_format_specs.txt
Normal file
|
@ -0,0 +1,24 @@
|
|||
### What it does
|
||||
Detects [formatting parameters] that have no effect on the output of
|
||||
`format!()`, `println!()` or similar macros.
|
||||
|
||||
### Why is this bad?
|
||||
Shorter format specifiers are easier to read, it may also indicate that
|
||||
an expected formatting operation such as adding padding isn't happening.
|
||||
|
||||
### Example
|
||||
```
|
||||
println!("{:.}", 1.0);
|
||||
|
||||
println!("not padded: {:5}", format_args!("..."));
|
||||
```
|
||||
Use instead:
|
||||
```
|
||||
println!("{}", 1.0);
|
||||
|
||||
println!("not padded: {}", format_args!("..."));
|
||||
// OR
|
||||
println!("padded: {:5}", format!("..."));
|
||||
```
|
||||
|
||||
[formatting parameters]: https://doc.rust-lang.org/std/fmt/index.html#formatting-parameters
|
Loading…
Add table
Add a link
Reference in a new issue