Merge commit '70c0f90453' into clippyup
This commit is contained in:
commit
d2e2f64ef7
80 changed files with 1796 additions and 604 deletions
|
|
@ -214,6 +214,7 @@ fn run_ui_cargo(config: &mut compiletest::Config) {
|
|||
Some("main.rs") => {},
|
||||
_ => continue,
|
||||
}
|
||||
set_var("CLIPPY_CONF_DIR", case.path());
|
||||
let paths = compiletest::common::TestPaths {
|
||||
file: file_path,
|
||||
base: config.src_base.clone(),
|
||||
|
|
@ -241,9 +242,11 @@ fn run_ui_cargo(config: &mut compiletest::Config) {
|
|||
let tests = compiletest::make_tests(&config);
|
||||
|
||||
let current_dir = env::current_dir().unwrap();
|
||||
let conf_dir = var("CLIPPY_CONF_DIR").unwrap_or_default();
|
||||
let filter = env::var("TESTNAME").ok();
|
||||
let res = run_tests(&config, &filter, tests);
|
||||
env::set_current_dir(current_dir).unwrap();
|
||||
set_var("CLIPPY_CONF_DIR", conf_dir);
|
||||
|
||||
match res {
|
||||
Ok(true) => {},
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
cargo-ignore-publish = true
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "cargo_common_metadata"
|
||||
version = "0.1.0"
|
||||
publish = ["some-registry-name"]
|
||||
|
||||
[workspace]
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
// compile-flags: --crate-name=cargo_common_metadata
|
||||
#![warn(clippy::cargo_common_metadata)]
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
error: package `cargo_common_metadata` is missing `package.authors` metadata
|
||||
|
|
||||
= note: `-D clippy::cargo-common-metadata` implied by `-D warnings`
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.description` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `either package.license or package.license_file` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.repository` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.readme` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.keywords` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.categories` metadata
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "cargo_common_metadata"
|
||||
version = "0.1.0"
|
||||
publish = true
|
||||
|
||||
[workspace]
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
// compile-flags: --crate-name=cargo_common_metadata
|
||||
#![warn(clippy::cargo_common_metadata)]
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
error: package `cargo_common_metadata` is missing `package.authors` metadata
|
||||
|
|
||||
= note: `-D clippy::cargo-common-metadata` implied by `-D warnings`
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.description` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `either package.license or package.license_file` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.repository` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.readme` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.keywords` metadata
|
||||
|
||||
error: package `cargo_common_metadata` is missing `package.categories` metadata
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
cargo-ignore-publish = true
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "cargo_common_metadata"
|
||||
version = "0.1.0"
|
||||
publish = []
|
||||
|
||||
[workspace]
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
// compile-flags: --crate-name=cargo_common_metadata
|
||||
#![warn(clippy::cargo_common_metadata)]
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "cargo_common_metadata"
|
||||
version = "0.1.0"
|
||||
publish = false
|
||||
|
||||
[workspace]
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
// compile-flags: --crate-name=cargo_common_metadata
|
||||
#![warn(clippy::cargo_common_metadata)]
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1 +1 @@
|
|||
disallowed-methods = ["core::iter::traits::iterator::Iterator::sum", "regex::re_unicode::Regex::is_match"]
|
||||
disallowed-methods = ["core::iter::traits::iterator::Iterator::sum", "regex::re_unicode::Regex::is_match", "regex::re_unicode::Regex::new"]
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@ extern crate regex;
|
|||
use regex::Regex;
|
||||
|
||||
fn main() {
|
||||
let a = vec![1, 2, 3, 4];
|
||||
let re = Regex::new(r"ab.*c").unwrap();
|
||||
|
||||
re.is_match("abc");
|
||||
|
||||
let a = vec![1, 2, 3, 4];
|
||||
a.iter().sum::<i32>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,22 @@
|
|||
error: use of a disallowed method `regex::re_unicode::Regex::is_match`
|
||||
--> $DIR/conf_disallowed_method.rs:10:5
|
||||
error: use of a disallowed method `regex::re_unicode::Regex::new`
|
||||
--> $DIR/conf_disallowed_method.rs:7:14
|
||||
|
|
||||
LL | re.is_match("abc");
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
LL | let re = Regex::new(r"ab.*c").unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::disallowed-method` implied by `-D warnings`
|
||||
|
||||
error: use of a disallowed method `regex::re_unicode::Regex::is_match`
|
||||
--> $DIR/conf_disallowed_method.rs:8:5
|
||||
|
|
||||
LL | re.is_match("abc");
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: use of a disallowed method `core::iter::traits::iterator::Iterator::sum`
|
||||
--> $DIR/conf_disallowed_method.rs:12:5
|
||||
--> $DIR/conf_disallowed_method.rs:11:5
|
||||
|
|
||||
LL | a.iter().sum::<i32>();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `msrv`, `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `pass-by-value-size-limit`, `too-many-lines-threshold`, `array-size-threshold`, `vec-box-size-threshold`, `max-trait-bounds`, `max-struct-bools`, `max-fn-params-bools`, `warn-on-all-wildcard-imports`, `disallowed-methods`, `unreadable-literal-lint-fractions`, `third-party` at line 5 column 1
|
||||
error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `msrv`, `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `pass-by-value-size-limit`, `too-many-lines-threshold`, `array-size-threshold`, `vec-box-size-threshold`, `max-trait-bounds`, `max-struct-bools`, `max-fn-params-bools`, `warn-on-all-wildcard-imports`, `disallowed-methods`, `unreadable-literal-lint-fractions`, `cargo-ignore-publish`, `third-party` at line 5 column 1
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
11
src/tools/clippy/tests/ui/bytes_nth.fixed
Normal file
11
src/tools/clippy/tests/ui/bytes_nth.fixed
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// run-rustfix
|
||||
|
||||
#![allow(clippy::unnecessary_operation)]
|
||||
#![warn(clippy::bytes_nth)]
|
||||
|
||||
fn main() {
|
||||
let s = String::from("String");
|
||||
s.as_bytes().get(3);
|
||||
&s.as_bytes().get(3);
|
||||
s[..].as_bytes().get(3);
|
||||
}
|
||||
11
src/tools/clippy/tests/ui/bytes_nth.rs
Normal file
11
src/tools/clippy/tests/ui/bytes_nth.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// run-rustfix
|
||||
|
||||
#![allow(clippy::unnecessary_operation)]
|
||||
#![warn(clippy::bytes_nth)]
|
||||
|
||||
fn main() {
|
||||
let s = String::from("String");
|
||||
s.bytes().nth(3);
|
||||
&s.bytes().nth(3);
|
||||
s[..].bytes().nth(3);
|
||||
}
|
||||
22
src/tools/clippy/tests/ui/bytes_nth.stderr
Normal file
22
src/tools/clippy/tests/ui/bytes_nth.stderr
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
error: called `.byte().nth()` on a `String`
|
||||
--> $DIR/bytes_nth.rs:8:5
|
||||
|
|
||||
LL | s.bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)`
|
||||
|
|
||||
= note: `-D clippy::bytes-nth` implied by `-D warnings`
|
||||
|
||||
error: called `.byte().nth()` on a `String`
|
||||
--> $DIR/bytes_nth.rs:9:6
|
||||
|
|
||||
LL | &s.bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)`
|
||||
|
||||
error: called `.byte().nth()` on a `str`
|
||||
--> $DIR/bytes_nth.rs:10:5
|
||||
|
|
||||
LL | s[..].bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `s[..].as_bytes().get(3)`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
@ -224,6 +224,14 @@ fn negative_cases(res_opt: Result<Option<u32>, String>, res_res: Result<Result<u
|
|||
},
|
||||
_ => return,
|
||||
}
|
||||
if let Ok(val) = res_opt {
|
||||
if let Some(n) = val {
|
||||
let _ = || {
|
||||
// usage in closure
|
||||
println!("{:?}", val);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn make<T>() -> T {
|
||||
|
|
|
|||
16
src/tools/clippy/tests/ui/filter_map_identity.fixed
Normal file
16
src/tools/clippy/tests/ui/filter_map_identity.fixed
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// run-rustfix
|
||||
|
||||
#![allow(unused_imports)]
|
||||
#![warn(clippy::filter_map_identity)]
|
||||
|
||||
fn main() {
|
||||
let iterator = vec![Some(1), None, Some(2)].into_iter();
|
||||
let _ = iterator.flatten();
|
||||
|
||||
let iterator = vec![Some(1), None, Some(2)].into_iter();
|
||||
let _ = iterator.flatten();
|
||||
|
||||
use std::convert::identity;
|
||||
let iterator = vec![Some(1), None, Some(2)].into_iter();
|
||||
let _ = iterator.flatten();
|
||||
}
|
||||
16
src/tools/clippy/tests/ui/filter_map_identity.rs
Normal file
16
src/tools/clippy/tests/ui/filter_map_identity.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// run-rustfix
|
||||
|
||||
#![allow(unused_imports)]
|
||||
#![warn(clippy::filter_map_identity)]
|
||||
|
||||
fn main() {
|
||||
let iterator = vec![Some(1), None, Some(2)].into_iter();
|
||||
let _ = iterator.filter_map(|x| x);
|
||||
|
||||
let iterator = vec![Some(1), None, Some(2)].into_iter();
|
||||
let _ = iterator.filter_map(std::convert::identity);
|
||||
|
||||
use std::convert::identity;
|
||||
let iterator = vec![Some(1), None, Some(2)].into_iter();
|
||||
let _ = iterator.filter_map(identity);
|
||||
}
|
||||
22
src/tools/clippy/tests/ui/filter_map_identity.stderr
Normal file
22
src/tools/clippy/tests/ui/filter_map_identity.stderr
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
error: called `filter_map(|x| x)` on an `Iterator`
|
||||
--> $DIR/filter_map_identity.rs:8:22
|
||||
|
|
||||
LL | let _ = iterator.filter_map(|x| x);
|
||||
| ^^^^^^^^^^^^^^^^^ help: try: `flatten()`
|
||||
|
|
||||
= note: `-D clippy::filter-map-identity` implied by `-D warnings`
|
||||
|
||||
error: called `filter_map(std::convert::identity)` on an `Iterator`
|
||||
--> $DIR/filter_map_identity.rs:11:22
|
||||
|
|
||||
LL | let _ = iterator.filter_map(std::convert::identity);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()`
|
||||
|
||||
error: called `filter_map(std::convert::identity)` on an `Iterator`
|
||||
--> $DIR/filter_map_identity.rs:15:22
|
||||
|
|
||||
LL | let _ = iterator.filter_map(identity);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
error: called `flat_map(|x| x)` on an `Iterator`
|
||||
--> $DIR/unnecessary_flat_map.rs:10:22
|
||||
--> $DIR/flat_map_identity.rs:10:22
|
||||
|
|
||||
LL | let _ = iterator.flat_map(|x| x);
|
||||
| ^^^^^^^^^^^^^^^ help: try: `flatten()`
|
||||
|
|
@ -7,7 +7,7 @@ LL | let _ = iterator.flat_map(|x| x);
|
|||
= note: `-D clippy::flat-map-identity` implied by `-D warnings`
|
||||
|
||||
error: called `flat_map(std::convert::identity)` on an `Iterator`
|
||||
--> $DIR/unnecessary_flat_map.rs:13:22
|
||||
--> $DIR/flat_map_identity.rs:13:22
|
||||
|
|
||||
LL | let _ = iterator.flat_map(convert::identity);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()`
|
||||
48
src/tools/clippy/tests/ui/from_iter_instead_of_collect.fixed
Normal file
48
src/tools/clippy/tests/ui/from_iter_instead_of_collect.fixed
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// run-rustfix
|
||||
|
||||
#![warn(clippy::from_iter_instead_of_collect)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque};
|
||||
use std::iter::FromIterator;
|
||||
|
||||
fn main() {
|
||||
let iter_expr = std::iter::repeat(5).take(5);
|
||||
let _ = iter_expr.collect::<Vec<_>>();
|
||||
|
||||
let _ = vec![5, 5, 5, 5].iter().enumerate().collect::<HashMap<usize, &i8>>();
|
||||
|
||||
Vec::from_iter(vec![42u32]);
|
||||
|
||||
let a = vec![0, 1, 2];
|
||||
assert_eq!(a, (0..3).collect::<Vec<_>>());
|
||||
assert_eq!(a, (0..3).collect::<Vec<i32>>());
|
||||
|
||||
let mut b = (0..3).collect::<VecDeque<_>>();
|
||||
b.push_back(4);
|
||||
|
||||
let mut b = (0..3).collect::<VecDeque<i32>>();
|
||||
b.push_back(4);
|
||||
|
||||
{
|
||||
use std::collections;
|
||||
let mut b = (0..3).collect::<collections::VecDeque<i32>>();
|
||||
b.push_back(4);
|
||||
}
|
||||
|
||||
let values = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd')];
|
||||
let bm = values.iter().cloned().collect::<BTreeMap<_, _>>();
|
||||
let mut bar = bm.range(0..2).collect::<BTreeMap<_, _>>();
|
||||
bar.insert(&4, &'e');
|
||||
|
||||
let mut bts = (0..3).collect::<BTreeSet<_>>();
|
||||
bts.insert(2);
|
||||
{
|
||||
use std::collections;
|
||||
let _ = (0..3).collect::<collections::BTreeSet<_>>();
|
||||
let _ = (0..3).collect::<collections::BTreeSet<u32>>();
|
||||
}
|
||||
|
||||
for _i in [1, 2, 3].iter().collect::<Vec<_>>() {}
|
||||
for _i in [1, 2, 3].iter().collect::<Vec<&i32>>() {}
|
||||
}
|
||||
|
|
@ -1,13 +1,48 @@
|
|||
#![warn(clippy::from_iter_instead_of_collect)]
|
||||
// run-rustfix
|
||||
|
||||
use std::collections::HashMap;
|
||||
#![warn(clippy::from_iter_instead_of_collect)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque};
|
||||
use std::iter::FromIterator;
|
||||
|
||||
fn main() {
|
||||
let iter_expr = std::iter::repeat(5).take(5);
|
||||
Vec::from_iter(iter_expr);
|
||||
let _ = Vec::from_iter(iter_expr);
|
||||
|
||||
HashMap::<usize, &i8>::from_iter(vec![5, 5, 5, 5].iter().enumerate());
|
||||
let _ = HashMap::<usize, &i8>::from_iter(vec![5, 5, 5, 5].iter().enumerate());
|
||||
|
||||
Vec::from_iter(vec![42u32]);
|
||||
|
||||
let a = vec![0, 1, 2];
|
||||
assert_eq!(a, Vec::from_iter(0..3));
|
||||
assert_eq!(a, Vec::<i32>::from_iter(0..3));
|
||||
|
||||
let mut b = VecDeque::from_iter(0..3);
|
||||
b.push_back(4);
|
||||
|
||||
let mut b = VecDeque::<i32>::from_iter(0..3);
|
||||
b.push_back(4);
|
||||
|
||||
{
|
||||
use std::collections;
|
||||
let mut b = collections::VecDeque::<i32>::from_iter(0..3);
|
||||
b.push_back(4);
|
||||
}
|
||||
|
||||
let values = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd')];
|
||||
let bm = BTreeMap::from_iter(values.iter().cloned());
|
||||
let mut bar = BTreeMap::from_iter(bm.range(0..2));
|
||||
bar.insert(&4, &'e');
|
||||
|
||||
let mut bts = BTreeSet::from_iter(0..3);
|
||||
bts.insert(2);
|
||||
{
|
||||
use std::collections;
|
||||
let _ = collections::BTreeSet::from_iter(0..3);
|
||||
let _ = collections::BTreeSet::<u32>::from_iter(0..3);
|
||||
}
|
||||
|
||||
for _i in Vec::from_iter([1, 2, 3].iter()) {}
|
||||
for _i in Vec::<&i32>::from_iter([1, 2, 3].iter()) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,88 @@
|
|||
error: usage of `FromIterator::from_iter`
|
||||
--> $DIR/from_iter_instead_of_collect.rs:8:5
|
||||
--> $DIR/from_iter_instead_of_collect.rs:11:13
|
||||
|
|
||||
LL | Vec::from_iter(iter_expr);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `iter_expr.collect()`
|
||||
LL | let _ = Vec::from_iter(iter_expr);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `iter_expr.collect::<Vec<_>>()`
|
||||
|
|
||||
= note: `-D clippy::from-iter-instead-of-collect` implied by `-D warnings`
|
||||
|
||||
error: usage of `FromIterator::from_iter`
|
||||
--> $DIR/from_iter_instead_of_collect.rs:10:5
|
||||
--> $DIR/from_iter_instead_of_collect.rs:13:13
|
||||
|
|
||||
LL | HashMap::<usize, &i8>::from_iter(vec![5, 5, 5, 5].iter().enumerate());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `vec![5, 5, 5, 5].iter().enumerate().collect()`
|
||||
LL | let _ = HashMap::<usize, &i8>::from_iter(vec![5, 5, 5, 5].iter().enumerate());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `vec![5, 5, 5, 5].iter().enumerate().collect::<HashMap<usize, &i8>>()`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: usage of `FromIterator::from_iter`
|
||||
--> $DIR/from_iter_instead_of_collect.rs:18:19
|
||||
|
|
||||
LL | assert_eq!(a, Vec::from_iter(0..3));
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::<Vec<_>>()`
|
||||
|
||||
error: usage of `FromIterator::from_iter`
|
||||
--> $DIR/from_iter_instead_of_collect.rs:19:19
|
||||
|
|
||||
LL | assert_eq!(a, Vec::<i32>::from_iter(0..3));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::<Vec<i32>>()`
|
||||
|
||||
error: usage of `FromIterator::from_iter`
|
||||
--> $DIR/from_iter_instead_of_collect.rs:21:17
|
||||
|
|
||||
LL | let mut b = VecDeque::from_iter(0..3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::<VecDeque<_>>()`
|
||||
|
||||
error: usage of `FromIterator::from_iter`
|
||||
--> $DIR/from_iter_instead_of_collect.rs:24:17
|
||||
|
|
||||
LL | let mut b = VecDeque::<i32>::from_iter(0..3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::<VecDeque<i32>>()`
|
||||
|
||||
error: usage of `FromIterator::from_iter`
|
||||
--> $DIR/from_iter_instead_of_collect.rs:29:21
|
||||
|
|
||||
LL | let mut b = collections::VecDeque::<i32>::from_iter(0..3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::<collections::VecDeque<i32>>()`
|
||||
|
||||
error: usage of `FromIterator::from_iter`
|
||||
--> $DIR/from_iter_instead_of_collect.rs:34:14
|
||||
|
|
||||
LL | let bm = BTreeMap::from_iter(values.iter().cloned());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `values.iter().cloned().collect::<BTreeMap<_, _>>()`
|
||||
|
||||
error: usage of `FromIterator::from_iter`
|
||||
--> $DIR/from_iter_instead_of_collect.rs:35:19
|
||||
|
|
||||
LL | let mut bar = BTreeMap::from_iter(bm.range(0..2));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `bm.range(0..2).collect::<BTreeMap<_, _>>()`
|
||||
|
||||
error: usage of `FromIterator::from_iter`
|
||||
--> $DIR/from_iter_instead_of_collect.rs:38:19
|
||||
|
|
||||
LL | let mut bts = BTreeSet::from_iter(0..3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::<BTreeSet<_>>()`
|
||||
|
||||
error: usage of `FromIterator::from_iter`
|
||||
--> $DIR/from_iter_instead_of_collect.rs:42:17
|
||||
|
|
||||
LL | let _ = collections::BTreeSet::from_iter(0..3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::<collections::BTreeSet<_>>()`
|
||||
|
||||
error: usage of `FromIterator::from_iter`
|
||||
--> $DIR/from_iter_instead_of_collect.rs:43:17
|
||||
|
|
||||
LL | let _ = collections::BTreeSet::<u32>::from_iter(0..3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::<collections::BTreeSet<u32>>()`
|
||||
|
||||
error: usage of `FromIterator::from_iter`
|
||||
--> $DIR/from_iter_instead_of_collect.rs:46:15
|
||||
|
|
||||
LL | for _i in Vec::from_iter([1, 2, 3].iter()) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `[1, 2, 3].iter().collect::<Vec<_>>()`
|
||||
|
||||
error: usage of `FromIterator::from_iter`
|
||||
--> $DIR/from_iter_instead_of_collect.rs:47:15
|
||||
|
|
||||
LL | for _i in Vec::<&i32>::from_iter([1, 2, 3].iter()) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `[1, 2, 3].iter().collect::<Vec<&i32>>()`
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -16,4 +16,12 @@ fn main() {
|
|||
let _ = Box::new(());
|
||||
let _ = Droppable;
|
||||
let _ = Some(Droppable);
|
||||
|
||||
// no lint for reference
|
||||
let _ = droppable_ref();
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
fn droppable_ref() -> &'static mut Droppable {
|
||||
unimplemented!()
|
||||
}
|
||||
|
|
|
|||
76
src/tools/clippy/tests/ui/manual_flatten.rs
Normal file
76
src/tools/clippy/tests/ui/manual_flatten.rs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
#![warn(clippy::manual_flatten)]
|
||||
|
||||
fn main() {
|
||||
// Test for loop over implicitly adjusted `Iterator` with `if let` expression
|
||||
let x = vec![Some(1), Some(2), Some(3)];
|
||||
for n in x {
|
||||
if let Some(y) = n {
|
||||
println!("{}", y);
|
||||
}
|
||||
}
|
||||
|
||||
// Test for loop over implicitly implicitly adjusted `Iterator` with `if let` statement
|
||||
let y: Vec<Result<i32, i32>> = vec![];
|
||||
for n in y.clone() {
|
||||
if let Ok(n) = n {
|
||||
println!("{}", n);
|
||||
};
|
||||
}
|
||||
|
||||
// Test for loop over by reference
|
||||
for n in &y {
|
||||
if let Ok(n) = n {
|
||||
println!("{}", n);
|
||||
}
|
||||
}
|
||||
|
||||
// Test for loop over an implicit reference
|
||||
// Note: if `clippy::manual_flatten` is made autofixable, this case will
|
||||
// lead to a follow-up lint `clippy::into_iter_on_ref`
|
||||
let z = &y;
|
||||
for n in z {
|
||||
if let Ok(n) = n {
|
||||
println!("{}", n);
|
||||
}
|
||||
}
|
||||
|
||||
// Test for loop over `Iterator` with `if let` expression
|
||||
let z = vec![Some(1), Some(2), Some(3)];
|
||||
let z = z.iter();
|
||||
for n in z {
|
||||
if let Some(m) = n {
|
||||
println!("{}", m);
|
||||
}
|
||||
}
|
||||
|
||||
// Using the `None` variant should not trigger the lint
|
||||
// Note: for an autofixable suggestion, the binding in the for loop has to take the
|
||||
// name of the binding in the `if let`
|
||||
let z = vec![Some(1), Some(2), Some(3)];
|
||||
for n in z {
|
||||
if n.is_none() {
|
||||
println!("Nada.");
|
||||
}
|
||||
}
|
||||
|
||||
// Using the `Err` variant should not trigger the lint
|
||||
for n in y.clone() {
|
||||
if let Err(e) = n {
|
||||
println!("Oops: {}!", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Having an else clause should not trigger the lint
|
||||
for n in y.clone() {
|
||||
if let Ok(n) = n {
|
||||
println!("{}", n);
|
||||
} else {
|
||||
println!("Oops!");
|
||||
}
|
||||
}
|
||||
|
||||
// Using manual flatten should not trigger the lint
|
||||
for n in vec![Some(1), Some(2), Some(3)].iter().flatten() {
|
||||
println!("{}", n);
|
||||
}
|
||||
}
|
||||
108
src/tools/clippy/tests/ui/manual_flatten.stderr
Normal file
108
src/tools/clippy/tests/ui/manual_flatten.stderr
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
error: unnecessary `if let` since only the `Some` variant of the iterator element is used
|
||||
--> $DIR/manual_flatten.rs:6:5
|
||||
|
|
||||
LL | for n in x {
|
||||
| ^ - help: try: `x.into_iter().flatten()`
|
||||
| _____|
|
||||
| |
|
||||
LL | | if let Some(y) = n {
|
||||
LL | | println!("{}", y);
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= note: `-D clippy::manual-flatten` implied by `-D warnings`
|
||||
help: ...and remove the `if let` statement in the for loop
|
||||
--> $DIR/manual_flatten.rs:7:9
|
||||
|
|
||||
LL | / if let Some(y) = n {
|
||||
LL | | println!("{}", y);
|
||||
LL | | }
|
||||
| |_________^
|
||||
|
||||
error: unnecessary `if let` since only the `Ok` variant of the iterator element is used
|
||||
--> $DIR/manual_flatten.rs:14:5
|
||||
|
|
||||
LL | for n in y.clone() {
|
||||
| ^ --------- help: try: `y.clone().into_iter().flatten()`
|
||||
| _____|
|
||||
| |
|
||||
LL | | if let Ok(n) = n {
|
||||
LL | | println!("{}", n);
|
||||
LL | | };
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: ...and remove the `if let` statement in the for loop
|
||||
--> $DIR/manual_flatten.rs:15:9
|
||||
|
|
||||
LL | / if let Ok(n) = n {
|
||||
LL | | println!("{}", n);
|
||||
LL | | };
|
||||
| |_________^
|
||||
|
||||
error: unnecessary `if let` since only the `Ok` variant of the iterator element is used
|
||||
--> $DIR/manual_flatten.rs:21:5
|
||||
|
|
||||
LL | for n in &y {
|
||||
| ^ -- help: try: `y.iter().flatten()`
|
||||
| _____|
|
||||
| |
|
||||
LL | | if let Ok(n) = n {
|
||||
LL | | println!("{}", n);
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: ...and remove the `if let` statement in the for loop
|
||||
--> $DIR/manual_flatten.rs:22:9
|
||||
|
|
||||
LL | / if let Ok(n) = n {
|
||||
LL | | println!("{}", n);
|
||||
LL | | }
|
||||
| |_________^
|
||||
|
||||
error: unnecessary `if let` since only the `Ok` variant of the iterator element is used
|
||||
--> $DIR/manual_flatten.rs:31:5
|
||||
|
|
||||
LL | for n in z {
|
||||
| ^ - help: try: `z.into_iter().flatten()`
|
||||
| _____|
|
||||
| |
|
||||
LL | | if let Ok(n) = n {
|
||||
LL | | println!("{}", n);
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: ...and remove the `if let` statement in the for loop
|
||||
--> $DIR/manual_flatten.rs:32:9
|
||||
|
|
||||
LL | / if let Ok(n) = n {
|
||||
LL | | println!("{}", n);
|
||||
LL | | }
|
||||
| |_________^
|
||||
|
||||
error: unnecessary `if let` since only the `Some` variant of the iterator element is used
|
||||
--> $DIR/manual_flatten.rs:40:5
|
||||
|
|
||||
LL | for n in z {
|
||||
| ^ - help: try: `z.flatten()`
|
||||
| _____|
|
||||
| |
|
||||
LL | | if let Some(m) = n {
|
||||
LL | | println!("{}", m);
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: ...and remove the `if let` statement in the for loop
|
||||
--> $DIR/manual_flatten.rs:41:9
|
||||
|
|
||||
LL | / if let Some(m) = n {
|
||||
LL | | println!("{}", m);
|
||||
LL | | }
|
||||
| |_________^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
55
src/tools/clippy/tests/ui/semicolon_if_nothing_returned.rs
Normal file
55
src/tools/clippy/tests/ui/semicolon_if_nothing_returned.rs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#![warn(clippy::semicolon_if_nothing_returned)]
|
||||
#![feature(label_break_value)]
|
||||
|
||||
fn get_unit() {}
|
||||
|
||||
// the functions below trigger the lint
|
||||
fn main() {
|
||||
println!("Hello")
|
||||
}
|
||||
|
||||
fn hello() {
|
||||
get_unit()
|
||||
}
|
||||
|
||||
fn basic101(x: i32) {
|
||||
let y: i32;
|
||||
y = x + 1
|
||||
}
|
||||
|
||||
// this is fine
|
||||
fn print_sum(a: i32, b: i32) {
|
||||
println!("{}", a + b);
|
||||
assert_eq!(true, false);
|
||||
}
|
||||
|
||||
fn foo(x: i32) {
|
||||
let y: i32;
|
||||
if x < 1 {
|
||||
y = 4;
|
||||
} else {
|
||||
y = 5;
|
||||
}
|
||||
}
|
||||
|
||||
fn bar(x: i32) {
|
||||
let y: i32;
|
||||
match x {
|
||||
1 => y = 4,
|
||||
_ => y = 32,
|
||||
}
|
||||
}
|
||||
|
||||
fn foobar(x: i32) {
|
||||
let y: i32;
|
||||
'label: {
|
||||
y = x + 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn loop_test(x: i32) {
|
||||
let y: i32;
|
||||
for &ext in &["stdout", "stderr", "fixed"] {
|
||||
println!("{}", ext);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
error: consider adding a `;` to the last statement for consistent formatting
|
||||
--> $DIR/semicolon_if_nothing_returned.rs:8:5
|
||||
|
|
||||
LL | println!("Hello")
|
||||
| ^^^^^^^^^^^^^^^^^ help: add a `;` here: `println!("Hello");`
|
||||
|
|
||||
= note: `-D clippy::semicolon-if-nothing-returned` implied by `-D warnings`
|
||||
|
||||
error: consider adding a `;` to the last statement for consistent formatting
|
||||
--> $DIR/semicolon_if_nothing_returned.rs:12:5
|
||||
|
|
||||
LL | get_unit()
|
||||
| ^^^^^^^^^^ help: add a `;` here: `get_unit();`
|
||||
|
||||
error: consider adding a `;` to the last statement for consistent formatting
|
||||
--> $DIR/semicolon_if_nothing_returned.rs:17:5
|
||||
|
|
||||
LL | y = x + 1
|
||||
| ^^^^^^^^^ help: add a `;` here: `y = x + 1;`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
@ -7,7 +7,7 @@ fn main() {
|
|||
let one_more_f64_nan = 0.0f64 / 0.0f64;
|
||||
let zero = 0.0;
|
||||
let other_zero = 0.0;
|
||||
let other_nan = zero / other_zero; // fine - this lint doesn't propegate constants.
|
||||
let other_nan = zero / other_zero; // fine - this lint doesn't propagate constants.
|
||||
let not_nan = 2.0 / 0.0; // not an error: 2/0 = inf
|
||||
let also_not_nan = 0.0 / 2.0; // not an error: 0/2 = 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,12 @@ fn check_that_clippy_lints_has_the_same_version_as_clippy() {
|
|||
|
||||
#[test]
|
||||
fn check_that_clippy_has_the_same_major_version_as_rustc() {
|
||||
// do not run this test inside the upstream rustc repo:
|
||||
// https://github.com/rust-lang/rust-clippy/issues/6683
|
||||
if option_env!("RUSTC_TEST_SUITE").is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
let clippy_version = rustc_tools_util::get_version_info!();
|
||||
let clippy_major = clippy_version.major;
|
||||
let clippy_minor = clippy_version.minor;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue