diff options
| author | David Koloski <dkoloski@google.com> | 2022-09-21 13:02:37 -0400 |
|---|---|---|
| committer | David Koloski <dkoloski@google.com> | 2022-09-21 13:13:27 -0400 |
| commit | 4d015293d1cb7ebdd0972e620c3e0f1763ad2ec8 (patch) | |
| tree | e7ff35c233cbd27cdba9e66a233797c5ab2f0cd7 /src | |
| parent | 0dc24ca37640f748d0deac392cb784dd6359b96c (diff) | |
| download | rust-4d015293d1cb7ebdd0972e620c3e0f1763ad2ec8.tar.gz rust-4d015293d1cb7ebdd0972e620c3e0f1763ad2ec8.zip | |
Merge commit '7248d06384c6a90de58c04c1f46be88821278d8b' into sync-from-clippy
Diffstat (limited to 'src')
| -rw-r--r-- | src/docs.rs | 2 | ||||
| -rw-r--r-- | src/docs/iter_kv_map.txt | 22 | ||||
| -rw-r--r-- | src/docs/positional_named_format_parameters.txt | 15 | ||||
| -rw-r--r-- | src/docs/print_literal.txt | 4 | ||||
| -rw-r--r-- | src/docs/print_stderr.txt | 8 | ||||
| -rw-r--r-- | src/docs/print_stdout.txt | 8 | ||||
| -rw-r--r-- | src/docs/write_literal.txt | 4 |
7 files changed, 25 insertions, 38 deletions
diff --git a/src/docs.rs b/src/docs.rs index f3a5048e7fa..6c89b4dde37 100644 --- a/src/docs.rs +++ b/src/docs.rs @@ -221,6 +221,7 @@ docs! { "items_after_statements", "iter_cloned_collect", "iter_count", + "iter_kv_map", "iter_next_loop", "iter_next_slice", "iter_not_returning_iterator", @@ -391,7 +392,6 @@ docs! { "partialeq_to_none", "path_buf_push_overwrite", "pattern_type_mismatch", - "positional_named_format_parameters", "possible_missing_comma", "precedence", "print_in_format_impl", diff --git a/src/docs/iter_kv_map.txt b/src/docs/iter_kv_map.txt new file mode 100644 index 00000000000..a063c8195ef --- /dev/null +++ b/src/docs/iter_kv_map.txt @@ -0,0 +1,22 @@ +### What it does + +Checks for iterating a map (`HashMap` or `BTreeMap`) and +ignoring either the keys or values. + +### Why is this bad? + +Readability. There are `keys` and `values` methods that +can be used to express that we only need the keys or the values. + +### Example + +``` +let map: HashMap<u32, u32> = HashMap::new(); +let values = map.iter().map(|(_, value)| value).collect::<Vec<_>>(); +``` + +Use instead: +``` +let map: HashMap<u32, u32> = HashMap::new(); +let values = map.values().collect::<Vec<_>>(); +``` \ No newline at end of file diff --git a/src/docs/positional_named_format_parameters.txt b/src/docs/positional_named_format_parameters.txt deleted file mode 100644 index e391d240667..00000000000 --- a/src/docs/positional_named_format_parameters.txt +++ /dev/null @@ -1,15 +0,0 @@ -### What it does -This lint warns when a named parameter in a format string is used as a positional one. - -### Why is this bad? -It may be confused for an assignment and obfuscates which parameter is being used. - -### Example -``` -println!("{}", x = 10); -``` - -Use instead: -``` -println!("{x}", x = 10); -``` \ No newline at end of file diff --git a/src/docs/print_literal.txt b/src/docs/print_literal.txt index 160073414f9..a6252a68780 100644 --- a/src/docs/print_literal.txt +++ b/src/docs/print_literal.txt @@ -6,10 +6,6 @@ Using literals as `println!` args is inefficient (c.f., https://github.com/matthiaskrgr/rust-str-bench) and unnecessary (i.e., just put the literal in the format string) -### Known problems -Will also warn with macro calls as arguments that expand to literals --- e.g., `println!("{}", env!("FOO"))`. - ### Example ``` println!("{}", "foo"); diff --git a/src/docs/print_stderr.txt b/src/docs/print_stderr.txt index fc14511cd6a..9c6edeeef12 100644 --- a/src/docs/print_stderr.txt +++ b/src/docs/print_stderr.txt @@ -7,13 +7,7 @@ People often print on *stderr* while debugging an application and might forget to remove those prints afterward. ### Known problems -* Only catches `eprint!` and `eprintln!` calls. -* The lint level is unaffected by crate attributes. The level can still - be set for functions, modules and other items. To change the level for - the entire crate, please use command line flags. More information and a - configuration example can be found in [clippy#6610]. - -[clippy#6610]: https://github.com/rust-lang/rust-clippy/issues/6610#issuecomment-977120558 +Only catches `eprint!` and `eprintln!` calls. ### Example ``` diff --git a/src/docs/print_stdout.txt b/src/docs/print_stdout.txt index 6c9a4b98e1e..d2cbd811d1b 100644 --- a/src/docs/print_stdout.txt +++ b/src/docs/print_stdout.txt @@ -7,13 +7,7 @@ People often print on *stdout* while debugging an application and might forget to remove those prints afterward. ### Known problems -* Only catches `print!` and `println!` calls. -* The lint level is unaffected by crate attributes. The level can still - be set for functions, modules and other items. To change the level for - the entire crate, please use command line flags. More information and a - configuration example can be found in [clippy#6610]. - -[clippy#6610]: https://github.com/rust-lang/rust-clippy/issues/6610#issuecomment-977120558 +Only catches `print!` and `println!` calls. ### Example ``` diff --git a/src/docs/write_literal.txt b/src/docs/write_literal.txt index 9c41a48f9f7..a7a884d0871 100644 --- a/src/docs/write_literal.txt +++ b/src/docs/write_literal.txt @@ -6,10 +6,6 @@ Using literals as `writeln!` args is inefficient (c.f., https://github.com/matthiaskrgr/rust-str-bench) and unnecessary (i.e., just put the literal in the format string) -### Known problems -Will also warn with macro calls as arguments that expand to literals --- e.g., `writeln!(buf, "{}", env!("FOO"))`. - ### Example ``` writeln!(buf, "{}", "foo"); |
