diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-08-09 00:03:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-09 00:03:38 +0200 |
| commit | 58c6497e4cb5ce4a22446d41514d4fe2da9e7300 (patch) | |
| tree | 4baa8ca9c40e0a6a220acbc2329a67da370358ca /src/tools/clippy/tests | |
| parent | 8789b95b673f5baec5596a210c957ad62948724d (diff) | |
| parent | 8be2688e456f5d79448564e55f35272821d6246b (diff) | |
Rollup merge of #128837 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update r? ``@Manishearth`` Updates Cargo.lock due to uitest bump
Diffstat (limited to 'src/tools/clippy/tests')
83 files changed, 2228 insertions, 683 deletions
diff --git a/src/tools/clippy/tests/check-fmt.rs b/src/tools/clippy/tests/check-fmt.rs index e106583de4a..cd3fed896c2 100644 --- a/src/tools/clippy/tests/check-fmt.rs +++ b/src/tools/clippy/tests/check-fmt.rs @@ -1,4 +1,3 @@ -#![cfg_attr(feature = "deny-warnings", deny(warnings))] #![warn(rust_2018_idioms, unused_lifetimes)] use std::path::PathBuf; diff --git a/src/tools/clippy/tests/compile-test.rs b/src/tools/clippy/tests/compile-test.rs index 4e5120406b0..c7080e5dcdc 100644 --- a/src/tools/clippy/tests/compile-test.rs +++ b/src/tools/clippy/tests/compile-test.rs @@ -1,4 +1,3 @@ -#![cfg_attr(feature = "deny-warnings", deny(warnings))] #![warn(rust_2018_idioms, unused_lifetimes)] #![allow(unused_extern_crates)] @@ -208,7 +207,8 @@ fn run_ui_toml() { ui_test::run_tests_generic( vec![config], ui_test::default_file_filter, - |config, path, _file_contents| { + |config, file_contents| { + let path = file_contents.span().file; config .program .envs @@ -260,7 +260,7 @@ fn run_ui_cargo() { path.ends_with("Cargo.toml") .then(|| ui_test::default_any_file_filter(path, config) && !ignored_32bit(path)) }, - |_config, _path, _file_contents| {}, + |_config, _file_contents| {}, status_emitter::Text::from(args.format), ) .unwrap(); diff --git a/src/tools/clippy/tests/dogfood.rs b/src/tools/clippy/tests/dogfood.rs index c8a761bf509..8d10d5e7161 100644 --- a/src/tools/clippy/tests/dogfood.rs +++ b/src/tools/clippy/tests/dogfood.rs @@ -3,7 +3,6 @@ //! //! See [Eating your own dog food](https://en.wikipedia.org/wiki/Eating_your_own_dog_food) for context -#![cfg_attr(feature = "deny-warnings", deny(warnings))] #![warn(rust_2018_idioms, unused_lifetimes)] use itertools::Itertools; diff --git a/src/tools/clippy/tests/integration.rs b/src/tools/clippy/tests/integration.rs index 77b7bb6a7bf..13cf36823c5 100644 --- a/src/tools/clippy/tests/integration.rs +++ b/src/tools/clippy/tests/integration.rs @@ -8,7 +8,6 @@ //! Clippy doesn't produce an ICE. Lint warnings are ignored by this test. #![cfg(feature = "integration")] -#![cfg_attr(feature = "deny-warnings", deny(warnings))] #![warn(rust_2018_idioms, unused_lifetimes)] use std::env; diff --git a/src/tools/clippy/tests/lint_message_convention.rs b/src/tools/clippy/tests/lint_message_convention.rs index 6ce7e44474d..7ed1f485c1c 100644 --- a/src/tools/clippy/tests/lint_message_convention.rs +++ b/src/tools/clippy/tests/lint_message_convention.rs @@ -1,4 +1,3 @@ -#![cfg_attr(feature = "deny-warnings", deny(warnings))] #![warn(rust_2018_idioms, unused_lifetimes)] use std::ffi::OsStr; diff --git a/src/tools/clippy/tests/missing-test-files.rs b/src/tools/clippy/tests/missing-test-files.rs index 141c11ddb47..a8225d037e8 100644 --- a/src/tools/clippy/tests/missing-test-files.rs +++ b/src/tools/clippy/tests/missing-test-files.rs @@ -1,4 +1,3 @@ -#![cfg_attr(feature = "deny-warnings", deny(warnings))] #![warn(rust_2018_idioms, unused_lifetimes)] #![allow(clippy::assertions_on_constants)] #![feature(path_file_prefix)] diff --git a/src/tools/clippy/tests/ui-internal/default_deprecation_reason.rs b/src/tools/clippy/tests/ui-internal/default_deprecation_reason.rs deleted file mode 100644 index c8961d5e1f0..00000000000 --- a/src/tools/clippy/tests/ui-internal/default_deprecation_reason.rs +++ /dev/null @@ -1,30 +0,0 @@ -#![deny(clippy::internal)] -#![feature(rustc_private)] - -#[macro_use] -extern crate clippy_lints; -use clippy_lints::deprecated_lints::ClippyDeprecatedLint; - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// TODO - #[clippy::version = "1.63.0"] - pub COOL_LINT_DEFAULT, - "default deprecation note" -} - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// This lint has been replaced by `cooler_lint` - #[clippy::version = "1.63.0"] - pub COOL_LINT, - "this lint has been replaced by `cooler_lint`" -} - -fn main() {} diff --git a/src/tools/clippy/tests/ui-internal/default_deprecation_reason.stderr b/src/tools/clippy/tests/ui-internal/default_deprecation_reason.stderr deleted file mode 100644 index 3b7c747c23f..00000000000 --- a/src/tools/clippy/tests/ui-internal/default_deprecation_reason.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: the lint `COOL_LINT_DEFAULT` has the default deprecation reason - --> tests/ui-internal/default_deprecation_reason.rs:8:1 - | -LL | / declare_deprecated_lint! { -LL | | /// ### What it does -LL | | /// Nothing. This lint has been deprecated. -LL | | /// -... | -LL | | "default deprecation note" -LL | | } - | |_^ - | -note: the lint level is defined here - --> tests/ui-internal/default_deprecation_reason.rs:1:9 - | -LL | #![deny(clippy::internal)] - | ^^^^^^^^^^^^^^^^ - = note: `#[deny(clippy::default_deprecation_reason)]` implied by `#[deny(clippy::internal)]` - = note: this error originates in the macro `declare_deprecated_lint` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 1 previous error - diff --git a/src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.rs b/src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.rs index 4375f324aca..858aab528a9 100644 --- a/src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.rs +++ b/src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.rs @@ -1,15 +1,19 @@ //@aux-build:../../ui/auxiliary/proc_macros.rs #![rustfmt::skip] #![feature(custom_inner_attributes)] -#![allow(unused)] -#![allow(clippy::let_and_return)] -#![allow(clippy::redundant_closure_call)] -#![allow(clippy::no_effect)] -#![allow(clippy::unnecessary_operation)] -#![allow(clippy::never_loop)] -#![allow(clippy::needless_if)] #![warn(clippy::excessive_nesting)] -#![allow(clippy::collapsible_if, clippy::blocks_in_conditions)] +#![allow( + unused, + clippy::let_and_return, + clippy::redundant_closure_call, + clippy::no_effect, + clippy::unnecessary_operation, + clippy::never_loop, + clippy::needless_if, + clippy::collapsible_if, + clippy::blocks_in_conditions, + clippy::single_match, +)] #[macro_use] extern crate proc_macros; diff --git a/src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.stderr b/src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.stderr index dafcd442055..ccdaecdd481 100644 --- a/src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.stderr +++ b/src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.stderr @@ -1,5 +1,5 @@ error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:21:25 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:25:25 | LL | let w = { 3 }; | ^^^^^ @@ -9,7 +9,7 @@ LL | let w = { 3 }; = help: to override `-D warnings` add `#[allow(clippy::excessive_nesting)]` error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:67:17 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:71:17 | LL | / impl C { LL | | pub fn c() {} @@ -19,7 +19,7 @@ LL | | } = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:81:25 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:85:25 | LL | let x = { 1 }; // not a warning, but cc is | ^^^^^ @@ -27,7 +27,7 @@ LL | let x = { 1 }; // not a warning, but cc is = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:98:17 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:102:17 | LL | / pub mod e { LL | | pub mod f {} @@ -37,7 +37,7 @@ LL | | } // not here = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:111:18 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:115:18 | LL | a_but_not({{{{{{{{0}}}}}}}}); | ^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | a_but_not({{{{{{{{0}}}}}}}}); = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:112:12 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:116:12 | LL | a.a({{{{{{{{{0}}}}}}}}}); | ^^^^^^^^^^^^^ @@ -53,7 +53,7 @@ LL | a.a({{{{{{{{{0}}}}}}}}}); = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:113:12 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:117:12 | LL | (0, {{{{{{{1}}}}}}}); | ^^^^^^^^^ @@ -61,7 +61,7 @@ LL | (0, {{{{{{{1}}}}}}}); = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:118:25 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:122:25 | LL | if true { | _________________________^ @@ -74,7 +74,7 @@ LL | | } = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:130:29 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:134:29 | LL | let z = (|| { | _____________________________^ @@ -86,7 +86,7 @@ LL | | })(); = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:149:13 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:153:13 | LL | y += {{{{{5}}}}}; | ^^^^^ @@ -94,7 +94,7 @@ LL | y += {{{{{5}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:150:20 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:154:20 | LL | let z = y + {{{{{{{{{5}}}}}}}}}; | ^^^^^^^^^^^^^ @@ -102,7 +102,7 @@ LL | let z = y + {{{{{{{{{5}}}}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:151:12 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:155:12 | LL | [0, {{{{{{{{{{0}}}}}}}}}}]; | ^^^^^^^^^^^^^^^ @@ -110,7 +110,7 @@ LL | [0, {{{{{{{{{{0}}}}}}}}}}]; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:152:25 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:156:25 | LL | let mut xx = [0; {{{{{{{{100}}}}}}}}]; | ^^^^^^^^^^^^^ @@ -118,7 +118,7 @@ LL | let mut xx = [0; {{{{{{{{100}}}}}}}}]; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:153:11 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:157:11 | LL | xx[{{{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}}}]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -126,7 +126,7 @@ LL | xx[{{{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}}}]; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:154:13 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:158:13 | LL | &mut {{{{{{{{{{y}}}}}}}}}}; | ^^^^^^^^^^^^^^^ @@ -134,7 +134,7 @@ LL | &mut {{{{{{{{{{y}}}}}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:156:17 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:160:17 | LL | for i in {{{{xx}}}} {{{{{{{{}}}}}}}} | ^^^^ @@ -142,7 +142,7 @@ LL | for i in {{{{xx}}}} {{{{{{{{}}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:156:28 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:160:28 | LL | for i in {{{{xx}}}} {{{{{{{{}}}}}}}} | ^^^^^^^^^^ @@ -150,7 +150,7 @@ LL | for i in {{{{xx}}}} {{{{{{{{}}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:158:28 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:162:28 | LL | while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}} | ^^^^^^^^^^^^^ @@ -158,7 +158,7 @@ LL | while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:158:48 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:162:48 | LL | while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}} | ^^^^^^^^ @@ -166,7 +166,7 @@ LL | while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:160:14 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:164:14 | LL | while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}} | ^^^^^^^^^^^^^^ @@ -174,7 +174,7 @@ LL | while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:160:35 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:164:35 | LL | while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}} | ^^^^^^^^^^^^ @@ -182,7 +182,7 @@ LL | while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:162:23 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:166:23 | LL | let d = D { d: {{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}} }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -190,7 +190,7 @@ LL | let d = D { d: {{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}} }; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:164:8 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:168:8 | LL | {{{{1;}}}}..{{{{{{3}}}}}}; | ^^^^ @@ -198,7 +198,7 @@ LL | {{{{1;}}}}..{{{{{{3}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:164:20 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:168:20 | LL | {{{{1;}}}}..{{{{{{3}}}}}}; | ^^^^^^^ @@ -206,7 +206,7 @@ LL | {{{{1;}}}}..{{{{{{3}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:165:8 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:169:8 | LL | {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}}; | ^^^^ @@ -214,7 +214,7 @@ LL | {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:165:21 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:169:21 | LL | {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}}; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -222,7 +222,7 @@ LL | {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:166:10 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:170:10 | LL | ..{{{{{{{5}}}}}}}; | ^^^^^^^^^ @@ -230,7 +230,7 @@ LL | ..{{{{{{{5}}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:167:11 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:171:11 | LL | ..={{{{{3}}}}}; | ^^^^^ @@ -238,7 +238,7 @@ LL | ..={{{{{3}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:168:8 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:172:8 | LL | {{{{{1;}}}}}..; | ^^^^^^ @@ -246,7 +246,7 @@ LL | {{{{{1;}}}}}..; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:170:20 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:174:20 | LL | loop { break {{{{1}}}} }; | ^^^^^ @@ -254,7 +254,7 @@ LL | loop { break {{{{1}}}} }; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:171:13 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:175:13 | LL | loop {{{{{{}}}}}} | ^^^^^^ @@ -262,7 +262,7 @@ LL | loop {{{{{{}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:173:14 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:177:14 | LL | match {{{{{{true}}}}}} { | ^^^^^^^^^^ @@ -270,7 +270,7 @@ LL | match {{{{{{true}}}}}} { = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:174:20 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:178:20 | LL | true => {{{{}}}}, | ^^ @@ -278,7 +278,7 @@ LL | true => {{{{}}}}, = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:175:21 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:179:21 | LL | false => {{{{}}}}, | ^^ @@ -286,7 +286,7 @@ LL | false => {{{{}}}}, = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:181:17 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:185:17 | LL | / { LL | | println!("warning! :)"); @@ -296,7 +296,7 @@ LL | | } = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:190:28 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:194:28 | LL | async fn c() -> u32 {{{{{{{0}}}}}}} | ^^^^^^^^^ @@ -304,7 +304,7 @@ LL | async fn c() -> u32 {{{{{{{0}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:196:8 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:200:8 | LL | {{{{b().await}}}}; | ^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr index 41d5afd3efe..320578bfabc 100644 --- a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr +++ b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr @@ -1,11 +1,15 @@ -error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a slice --> tests/ui-toml/unwrap_used/unwrap_used.rs:38:17 | LL | let _ = boxed_slice.get(1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&boxed_slice[1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::get-unwrap` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::get_unwrap)]` +help: using `[]` is clearer and more concise + | +LL | let _ = &boxed_slice[1]; + | ~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:38:17 @@ -18,11 +22,16 @@ LL | let _ = boxed_slice.get(1).unwrap(); = note: `-D clippy::unwrap-used` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` -error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a slice --> tests/ui-toml/unwrap_used/unwrap_used.rs:39:17 | LL | let _ = some_slice.get(0).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_slice[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _ = &some_slice[0]; + | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:39:17 @@ -33,11 +42,16 @@ LL | let _ = some_slice.get(0).unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a Vec --> tests/ui-toml/unwrap_used/unwrap_used.rs:40:17 | LL | let _ = some_vec.get(0).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_vec[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _ = &some_vec[0]; + | ~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:40:17 @@ -48,11 +62,16 @@ LL | let _ = some_vec.get(0).unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a VecDeque --> tests/ui-toml/unwrap_used/unwrap_used.rs:41:17 | LL | let _ = some_vecdeque.get(0).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_vecdeque[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _ = &some_vecdeque[0]; + | ~~~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:41:17 @@ -63,11 +82,16 @@ LL | let _ = some_vecdeque.get(0).unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a HashMap --> tests/ui-toml/unwrap_used/unwrap_used.rs:42:17 | LL | let _ = some_hashmap.get(&1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_hashmap[&1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _ = &some_hashmap[&1]; + | ~~~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:42:17 @@ -78,11 +102,16 @@ LL | let _ = some_hashmap.get(&1).unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a BTreeMap --> tests/ui-toml/unwrap_used/unwrap_used.rs:43:17 | LL | let _ = some_btreemap.get(&1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_btreemap[&1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _ = &some_btreemap[&1]; + | ~~~~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:43:17 @@ -93,11 +122,16 @@ LL | let _ = some_btreemap.get(&1).unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a slice --> tests/ui-toml/unwrap_used/unwrap_used.rs:47:21 | LL | let _: u8 = *boxed_slice.get(1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice[1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _: u8 = boxed_slice[1]; + | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:47:22 @@ -108,11 +142,16 @@ LL | let _: u8 = *boxed_slice.get(1).unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise +error: called `.get_mut().unwrap()` on a slice --> tests/ui-toml/unwrap_used/unwrap_used.rs:52:9 | LL | *boxed_slice.get_mut(0).unwrap() = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | boxed_slice[0] = 1; + | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:52:10 @@ -123,11 +162,16 @@ LL | *boxed_slice.get_mut(0).unwrap() = 1; = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise +error: called `.get_mut().unwrap()` on a slice --> tests/ui-toml/unwrap_used/unwrap_used.rs:53:9 | LL | *some_slice.get_mut(0).unwrap() = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_slice[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | some_slice[0] = 1; + | ~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:53:10 @@ -138,11 +182,16 @@ LL | *some_slice.get_mut(0).unwrap() = 1; = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise +error: called `.get_mut().unwrap()` on a Vec --> tests/ui-toml/unwrap_used/unwrap_used.rs:54:9 | LL | *some_vec.get_mut(0).unwrap() = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | some_vec[0] = 1; + | ~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:54:10 @@ -153,11 +202,16 @@ LL | *some_vec.get_mut(0).unwrap() = 1; = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and more concise +error: called `.get_mut().unwrap()` on a VecDeque --> tests/ui-toml/unwrap_used/unwrap_used.rs:55:9 | LL | *some_vecdeque.get_mut(0).unwrap() = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vecdeque[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | some_vecdeque[0] = 1; + | ~~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:55:10 @@ -168,11 +222,16 @@ LL | *some_vecdeque.get_mut(0).unwrap() = 1; = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a Vec --> tests/ui-toml/unwrap_used/unwrap_used.rs:67:17 | LL | let _ = some_vec.get(0..1).unwrap().to_vec(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0..1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _ = some_vec[0..1].to_vec(); + | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:67:17 @@ -183,11 +242,16 @@ LL | let _ = some_vec.get(0..1).unwrap().to_vec(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise +error: called `.get_mut().unwrap()` on a Vec --> tests/ui-toml/unwrap_used/unwrap_used.rs:68:17 | LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0..1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _ = some_vec[0..1].to_vec(); + | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:68:17 @@ -198,17 +262,27 @@ LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a slice --> tests/ui-toml/unwrap_used/unwrap_used.rs:75:13 | LL | let _ = boxed_slice.get(1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&boxed_slice[1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _ = &boxed_slice[1]; + | ~~~~~~~~~~~~~~~ -error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a slice --> tests/ui-toml/unwrap_used/unwrap_used.rs:93:17 | LL | let _ = Box::new([0]).get(1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&Box::new([0])[1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _ = &Box::new([0])[1]; + | ~~~~~~~~~~~~~~~~~ error: aborting due to 28 previous errors diff --git a/src/tools/clippy/tests/ui/assigning_clones.fixed b/src/tools/clippy/tests/ui/assigning_clones.fixed index 60f6a385fc5..b376d55a402 100644 --- a/src/tools/clippy/tests/ui/assigning_clones.fixed +++ b/src/tools/clippy/tests/ui/assigning_clones.fixed @@ -3,6 +3,7 @@ #![allow(clippy::ptr_arg)] // https://github.com/rust-lang/rust-clippy/issues/10612 #![allow(clippy::needless_late_init)] #![allow(clippy::box_collection)] +#![allow(clippy::boxed_local)] #![warn(clippy::assigning_clones)] use std::borrow::ToOwned; @@ -182,6 +183,31 @@ impl Clone for AvoidRecursiveCloneFrom { } } +// Deref handling +fn clone_into_deref_method(mut a: DerefWrapper<HasCloneFrom>, b: HasCloneFrom) { + (*a).clone_from(&b); +} + +fn clone_into_deref_with_clone_method(mut a: DerefWrapperWithClone<HasCloneFrom>, b: HasCloneFrom) { + (*a).clone_from(&b); +} + +fn clone_into_box_method(mut a: Box<HasCloneFrom>, b: HasCloneFrom) { + (*a).clone_from(&b); +} + +fn clone_into_self_deref_method(a: &mut DerefWrapperWithClone<HasCloneFrom>, b: DerefWrapperWithClone<HasCloneFrom>) { + a.clone_from(&b); +} + +fn clone_into_deref_function(mut a: DerefWrapper<HasCloneFrom>, b: HasCloneFrom) { + Clone::clone_from(&mut *a, &b); +} + +fn clone_into_box_function(mut a: Box<HasCloneFrom>, b: HasCloneFrom) { + Clone::clone_from(&mut *a, &b); +} + // ToOwned fn owned_method_mut_ref(mut_string: &mut String, ref_str: &str) { ref_str.clone_into(mut_string); @@ -328,3 +354,45 @@ mod borrowck_conflicts { path = path.components().as_path().to_owned(); } } + +struct DerefWrapper<T>(T); + +impl<T> Deref for DerefWrapper<T> { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl<T> DerefMut for DerefWrapper<T> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +struct DerefWrapperWithClone<T>(T); + +impl<T> Deref for DerefWrapperWithClone<T> { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl<T> DerefMut for DerefWrapperWithClone<T> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl<T: Clone> Clone for DerefWrapperWithClone<T> { + fn clone(&self) -> Self { + Self(self.0.clone()) + } + + fn clone_from(&mut self, source: &Self) { + *self = Self(source.0.clone()); + } +} diff --git a/src/tools/clippy/tests/ui/assigning_clones.rs b/src/tools/clippy/tests/ui/assigning_clones.rs index 6eb85be511a..11a5d4459c3 100644 --- a/src/tools/clippy/tests/ui/assigning_clones.rs +++ b/src/tools/clippy/tests/ui/assigning_clones.rs @@ -3,6 +3,7 @@ #![allow(clippy::ptr_arg)] // https://github.com/rust-lang/rust-clippy/issues/10612 #![allow(clippy::needless_late_init)] #![allow(clippy::box_collection)] +#![allow(clippy::boxed_local)] #![warn(clippy::assigning_clones)] use std::borrow::ToOwned; @@ -182,6 +183,31 @@ impl Clone for AvoidRecursiveCloneFrom { } } +// Deref handling +fn clone_into_deref_method(mut a: DerefWrapper<HasCloneFrom>, b: HasCloneFrom) { + *a = b.clone(); +} + +fn clone_into_deref_with_clone_method(mut a: DerefWrapperWithClone<HasCloneFrom>, b: HasCloneFrom) { + *a = b.clone(); +} + +fn clone_into_box_method(mut a: Box<HasCloneFrom>, b: HasCloneFrom) { + *a = b.clone(); +} + +fn clone_into_self_deref_method(a: &mut DerefWrapperWithClone<HasCloneFrom>, b: DerefWrapperWithClone<HasCloneFrom>) { + *a = b.clone(); +} + +fn clone_into_deref_function(mut a: DerefWrapper<HasCloneFrom>, b: HasCloneFrom) { + *a = Clone::clone(&b); +} + +fn clone_into_box_function(mut a: Box<HasCloneFrom>, b: HasCloneFrom) { + *a = Clone::clone(&b); +} + // ToOwned fn owned_method_mut_ref(mut_string: &mut String, ref_str: &str) { *mut_string = ref_str.to_owned(); @@ -328,3 +354,45 @@ mod borrowck_conflicts { path = path.components().as_path().to_owned(); } } + +struct DerefWrapper<T>(T); + +impl<T> Deref for DerefWrapper<T> { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl<T> DerefMut for DerefWrapper<T> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +struct DerefWrapperWithClone<T>(T); + +impl<T> Deref for DerefWrapperWithClone<T> { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl<T> DerefMut for DerefWrapperWithClone<T> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl<T: Clone> Clone for DerefWrapperWithClone<T> { + fn clone(&self) -> Self { + Self(self.0.clone()) + } + + fn clone_from(&mut self, source: &Self) { + *self = Self(source.0.clone()); + } +} diff --git a/src/tools/clippy/tests/ui/assigning_clones.stderr b/src/tools/clippy/tests/ui/assigning_clones.stderr index a68516376ab..19724a6d4ec 100644 --- a/src/tools/clippy/tests/ui/assigning_clones.stderr +++ b/src/tools/clippy/tests/ui/assigning_clones.stderr @@ -1,5 +1,5 @@ error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:24:5 + --> tests/ui/assigning_clones.rs:25:5 | LL | *mut_thing = value_thing.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `mut_thing.clone_from(&value_thing)` @@ -8,142 +8,178 @@ LL | *mut_thing = value_thing.clone(); = help: to override `-D warnings` add `#[allow(clippy::assigning_clones)]` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:28:5 + --> tests/ui/assigning_clones.rs:29:5 | LL | *mut_thing = ref_thing.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `mut_thing.clone_from(ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:32:5 + --> tests/ui/assigning_clones.rs:33:5 | LL | mut_thing = ref_thing.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `mut_thing.clone_from(ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:36:5 + --> tests/ui/assigning_clones.rs:37:5 | LL | *mut_thing = Clone::clone(ref_thing); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(mut_thing, ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:40:5 + --> tests/ui/assigning_clones.rs:41:5 | LL | mut_thing = Clone::clone(ref_thing); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(&mut mut_thing, ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:44:5 + --> tests/ui/assigning_clones.rs:45:5 | LL | *mut_thing = Clone::clone(ref_thing); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(mut_thing, ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:48:5 + --> tests/ui/assigning_clones.rs:49:5 | LL | *mut_thing = HasCloneFrom::clone(ref_thing); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(mut_thing, ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:52:5 + --> tests/ui/assigning_clones.rs:53:5 | LL | *mut_thing = <HasCloneFrom as Clone>::clone(ref_thing); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(mut_thing, ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:57:5 + --> tests/ui/assigning_clones.rs:58:5 | LL | *(mut_thing + &mut HasCloneFrom) = ref_thing.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `(mut_thing + &mut HasCloneFrom).clone_from(ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:62:5 + --> tests/ui/assigning_clones.rs:63:5 | LL | *mut_thing = (ref_thing + ref_thing).clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `mut_thing.clone_from(ref_thing + ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:67:5 + --> tests/ui/assigning_clones.rs:68:5 | LL | s = format!("{} {}", "hello", "world").clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `s.clone_from(&format!("{} {}", "hello", "world"))` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:72:5 + --> tests/ui/assigning_clones.rs:73:5 | LL | s = Clone::clone(&format!("{} {}", "hello", "world")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(&mut s, &format!("{} {}", "hello", "world"))` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:78:9 + --> tests/ui/assigning_clones.rs:79:9 | LL | a = b.clone(); | ^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:149:5 + --> tests/ui/assigning_clones.rs:150:5 | LL | a = b.clone(); | ^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:156:5 + --> tests/ui/assigning_clones.rs:157:5 | LL | a = b.clone(); | ^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:157:5 + --> tests/ui/assigning_clones.rs:158:5 | LL | a = c.to_owned(); | ^^^^^^^^^^^^^^^^ help: use `clone_into()`: `c.clone_into(&mut a)` +error: assigning the result of `Clone::clone()` may be inefficient + --> tests/ui/assigning_clones.rs:188:5 + | +LL | *a = b.clone(); + | ^^^^^^^^^^^^^^ help: use `clone_from()`: `(*a).clone_from(&b)` + +error: assigning the result of `Clone::clone()` may be inefficient + --> tests/ui/assigning_clones.rs:192:5 + | +LL | *a = b.clone(); + | ^^^^^^^^^^^^^^ help: use `clone_from()`: `(*a).clone_from(&b)` + +error: assigning the result of `Clone::clone()` may be inefficient + --> tests/ui/assigning_clones.rs:196:5 + | +LL | *a = b.clone(); + | ^^^^^^^^^^^^^^ help: use `clone_from()`: `(*a).clone_from(&b)` + +error: assigning the result of `Clone::clone()` may be inefficient + --> tests/ui/assigning_clones.rs:200:5 + | +LL | *a = b.clone(); + | ^^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)` + +error: assigning the result of `Clone::clone()` may be inefficient + --> tests/ui/assigning_clones.rs:204:5 + | +LL | *a = Clone::clone(&b); + | ^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(&mut *a, &b)` + +error: assigning the result of `Clone::clone()` may be inefficient + --> tests/ui/assigning_clones.rs:208:5 + | +LL | *a = Clone::clone(&b); + | ^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(&mut *a, &b)` + error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:187:5 + --> tests/ui/assigning_clones.rs:213:5 | LL | *mut_string = ref_str.to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(mut_string)` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:191:5 + --> tests/ui/assigning_clones.rs:217:5 | LL | mut_string = ref_str.to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut mut_string)` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:212:5 + --> tests/ui/assigning_clones.rs:238:5 | LL | **mut_box_string = ref_str.to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut (*mut_box_string))` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:216:5 + --> tests/ui/assigning_clones.rs:242:5 | LL | **mut_box_string = ref_str.to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut (*mut_box_string))` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:220:5 + --> tests/ui/assigning_clones.rs:246:5 | LL | *mut_thing = ToOwned::to_owned(ref_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ToOwned::clone_into(ref_str, mut_thing)` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:224:5 + --> tests/ui/assigning_clones.rs:250:5 | LL | mut_thing = ToOwned::to_owned(ref_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ToOwned::clone_into(ref_str, &mut mut_thing)` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:229:5 + --> tests/ui/assigning_clones.rs:255:5 | LL | s = format!("{} {}", "hello", "world").to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `format!("{} {}", "hello", "world").clone_into(&mut s)` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:234:5 + --> tests/ui/assigning_clones.rs:260:5 | LL | s = ToOwned::to_owned(&format!("{} {}", "hello", "world")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ToOwned::clone_into(&format!("{} {}", "hello", "world"), &mut s)` -error: aborting due to 24 previous errors +error: aborting due to 30 previous errors diff --git a/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.stderr b/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.stderr index b15857c325a..2adaecc96d6 100644 --- a/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.stderr +++ b/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.stderr @@ -9,7 +9,7 @@ note: the lint level is defined here | LL | #![deny(clippy::bind_instead_of_map)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: try +help: use `map` instead | LL | let _ = Some("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); | ~~~ ~ ~~~~~~~ @@ -20,7 +20,7 @@ error: using `Result.and_then(|x| Ok(y))`, which is more succinctly expressed as LL | let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Ok(0) } else { Ok(s.len()) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -help: try +help: use `map` instead | LL | let _ = Ok::<_, ()>("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); | ~~~ ~ ~~~~~~~ @@ -31,7 +31,7 @@ error: using `Result.or_else(|x| Err(y))`, which is more succinctly expressed as LL | let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Err(s.len() + 20) } else { Err(s.len()) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -help: try +help: use `map_err` instead | LL | let _ = Err::<(), _>("42").map_err(|s| if s.len() < 42 { s.len() + 20 } else { s.len() }); | ~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~ @@ -48,7 +48,7 @@ LL | | } LL | | }); | |______^ | -help: try +help: use `map` instead | LL ~ Some("42").map(|s| { LL | if { @@ -82,7 +82,7 @@ error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed LL | let _ = Some("").and_then(|s| if s.len() == 20 { Some(m!()) } else { Some(Some(20)) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -help: try +help: use `map` instead | LL | let _ = Some("").map(|s| if s.len() == 20 { m!() } else { Some(20) }); | ~~~ ~~~~ ~~~~~~~~ diff --git a/src/tools/clippy/tests/ui/crashes/ice-3717.stderr b/src/tools/clippy/tests/ui/crashes/ice-3717.stderr index 01627ff5b94..4b4618ee1bb 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-3717.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-3717.stderr @@ -9,14 +9,13 @@ note: the lint level is defined here | LL | #![deny(clippy::implicit_hasher)] | ^^^^^^^^^^^^^^^^^^^^^^^ -help: consider adding a type parameter +help: add a type parameter for `BuildHasher` | -LL | pub fn ice_3717<S: ::std::hash::BuildHasher + Default>(_: &HashSet<usize, S>) { - | +++++++++++++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~ -help: ...and use generic constructor +LL ~ pub fn ice_3717<S: ::std::hash::BuildHasher + Default>(_: &HashSet<usize, S>) { +LL | +LL | let _ = [0u8; 0]; +LL ~ let _: HashSet<usize> = HashSet::default(); | -LL | let _: HashSet<usize> = HashSet::default(); - | ~~~~~~~~~~~~~~~~~~ error: aborting due to 1 previous error diff --git a/src/tools/clippy/tests/ui/crashes/ice-6254.rs b/src/tools/clippy/tests/ui/crashes/ice-6254.rs index 8af60890390..aaca32ab2d9 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-6254.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-6254.rs @@ -2,7 +2,8 @@ // panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', // compiler/rustc_mir_build/src/thir/pattern/_match.rs:2030:5 -#[allow(clippy::derive_partial_eq_without_eq)] +#![allow(clippy::derive_partial_eq_without_eq, clippy::single_match)] + #[derive(PartialEq)] struct Foo(i32); const FOO_REF_REF: &&Foo = &&Foo(42); diff --git a/src/tools/clippy/tests/ui/create_dir.stderr b/src/tools/clippy/tests/ui/create_dir.stderr index 9c6e640ca78..ab51705bb55 100644 --- a/src/tools/clippy/tests/ui/create_dir.stderr +++ b/src/tools/clippy/tests/ui/create_dir.stderr @@ -2,16 +2,25 @@ error: calling `std::fs::create_dir` where there may be a better way --> tests/ui/create_dir.rs:10:5 | LL | std::fs::create_dir("foo"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `std::fs::create_dir_all` instead: `create_dir_all("foo")` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::create-dir` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::create_dir)]` +help: consider calling `std::fs::create_dir_all` instead + | +LL | create_dir_all("foo"); + | ~~~~~~~~~~~~~~~~~~~~~ error: calling `std::fs::create_dir` where there may be a better way --> tests/ui/create_dir.rs:11:5 | LL | std::fs::create_dir("bar").unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `std::fs::create_dir_all` instead: `create_dir_all("bar")` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider calling `std::fs::create_dir_all` instead + | +LL | create_dir_all("bar").unwrap(); + | ~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 2 previous errors diff --git a/src/tools/clippy/tests/ui/dbg_macro/dbg_macro.stderr b/src/tools/clippy/tests/ui/dbg_macro/dbg_macro.stderr index 7d3c3f7c918..b3d74b9ff61 100644 --- a/src/tools/clippy/tests/ui/dbg_macro/dbg_macro.stderr +++ b/src/tools/clippy/tests/ui/dbg_macro/dbg_macro.stderr @@ -81,7 +81,7 @@ error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:48:5 | LL | dbg!(); - | ^^^^^^^ + | ^^^^^^ | help: remove the invocation before committing it to a version control system | @@ -136,7 +136,7 @@ error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:43:13 | LL | dbg!(); - | ^^^^^^^ + | ^^^^^^ ... LL | expand_to_dbg!(); | ---------------- in this macro invocation diff --git a/src/tools/clippy/tests/ui/dbg_macro/dbg_macro_unfixable.stderr b/src/tools/clippy/tests/ui/dbg_macro/dbg_macro_unfixable.stderr index 16e51f4742e..b8e91906b93 100644 --- a/src/tools/clippy/tests/ui/dbg_macro/dbg_macro_unfixable.stderr +++ b/src/tools/clippy/tests/ui/dbg_macro/dbg_macro_unfixable.stderr @@ -2,7 +2,7 @@ error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/auxiliary/submodule.rs:2:5 | LL | dbg!(); - | ^^^^^^^ + | ^^^^^^ | = note: `-D clippy::dbg-macro` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::dbg_macro)]` diff --git a/src/tools/clippy/tests/ui/deprecated.rs b/src/tools/clippy/tests/ui/deprecated.rs index d3c34fb3716..5617db90a47 100644 --- a/src/tools/clippy/tests/ui/deprecated.rs +++ b/src/tools/clippy/tests/ui/deprecated.rs @@ -2,23 +2,18 @@ // Use that command to update this file and do not edit by hand. // Manual edits will be overwritten. -#![warn(clippy::should_assert_eq)] -#![warn(clippy::extend_from_slice)] -#![warn(clippy::range_step_by_zero)] -#![warn(clippy::unstable_as_slice)] -#![warn(clippy::unstable_as_mut_slice)] -#![warn(clippy::misaligned_transmute)] -#![warn(clippy::assign_ops)] -#![warn(clippy::if_let_redundant_pattern_matching)] -#![warn(clippy::unsafe_vector_initialization)] -#![warn(clippy::unused_collect)] -#![warn(clippy::replace_consts)] -#![warn(clippy::regex_macro)] -#![warn(clippy::find_map)] -#![warn(clippy::filter_map)] -#![warn(clippy::pub_enum_variant_names)] -#![warn(clippy::wrong_pub_self_convention)] -#![warn(clippy::maybe_misused_cfg)] -#![warn(clippy::mismatched_target_os)] +#![warn(clippy::should_assert_eq)] //~ ERROR: lint `clippy::should_assert_eq` +#![warn(clippy::extend_from_slice)] //~ ERROR: lint `clippy::extend_from_slice` +#![warn(clippy::range_step_by_zero)] //~ ERROR: lint `clippy::range_step_by_zero` +#![warn(clippy::unstable_as_slice)] //~ ERROR: lint `clippy::unstable_as_slice` +#![warn(clippy::unstable_as_mut_slice)] //~ ERROR: lint `clippy::unstable_as_mut_slice` +#![warn(clippy::misaligned_transmute)] //~ ERROR: lint `clippy::misaligned_transmute` +#![warn(clippy::assign_ops)] //~ ERROR: lint `clippy::assign_ops` +#![warn(clippy::unsafe_vector_initialization)] //~ ERROR: lint `clippy::unsafe_vector_initialization` +#![warn(clippy::unused_collect)] //~ ERROR: lint `clippy::unused_collect` +#![warn(clippy::replace_consts)] //~ ERROR: lint `clippy::replace_consts` +#![warn(clippy::regex_macro)] //~ ERROR: lint `clippy::regex_macro` +#![warn(clippy::pub_enum_variant_names)] //~ ERROR: lint `clippy::pub_enum_variant_names` +#![warn(clippy::wrong_pub_self_convention)] //~ ERROR: lint `clippy::wrong_pub_self_convention` fn main() {} diff --git a/src/tools/clippy/tests/ui/deprecated.stderr b/src/tools/clippy/tests/ui/deprecated.stderr index 49b90c70c06..b3e1646c804 100644 --- a/src/tools/clippy/tests/ui/deprecated.stderr +++ b/src/tools/clippy/tests/ui/deprecated.stderr @@ -1,4 +1,4 @@ -error: lint `clippy::should_assert_eq` has been removed: `assert!()` will be more flexible with RFC 2011 +error: lint `clippy::should_assert_eq` has been removed: `assert!(a == b)` can now print the values the same way `assert_eq!(a, b) can --> tests/ui/deprecated.rs:5:9 | LL | #![warn(clippy::should_assert_eq)] @@ -7,107 +7,77 @@ LL | #![warn(clippy::should_assert_eq)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(renamed_and_removed_lints)]` -error: lint `clippy::extend_from_slice` has been removed: `.extend_from_slice(_)` is a faster way to extend a Vec by a slice +error: lint `clippy::extend_from_slice` has been removed: `Vec::extend_from_slice` is no longer faster than `Vec::extend` due to specialization --> tests/ui/deprecated.rs:6:9 | LL | #![warn(clippy::extend_from_slice)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::range_step_by_zero` has been removed: `iterator.step_by(0)` panics nowadays +error: lint `clippy::range_step_by_zero` has been removed: `Iterator::step_by(0)` now panics and is no longer an infinite iterator --> tests/ui/deprecated.rs:7:9 | LL | #![warn(clippy::range_step_by_zero)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7 +error: lint `clippy::unstable_as_slice` has been removed: `Vec::as_slice` is now stable --> tests/ui/deprecated.rs:8:9 | LL | #![warn(clippy::unstable_as_slice)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::unstable_as_mut_slice` has been removed: `Vec::as_mut_slice` has been stabilized in 1.7 +error: lint `clippy::unstable_as_mut_slice` has been removed: `Vec::as_mut_slice` is now stable --> tests/ui/deprecated.rs:9:9 | LL | #![warn(clippy::unstable_as_mut_slice)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::misaligned_transmute` has been removed: this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr +error: lint `clippy::misaligned_transmute` has been removed: split into `clippy::cast_ptr_alignment` and `clippy::transmute_ptr_to_ptr` --> tests/ui/deprecated.rs:10:9 | LL | #![warn(clippy::misaligned_transmute)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::assign_ops` has been removed: using compound assignment operators (e.g., `+=`) is harmless +error: lint `clippy::assign_ops` has been removed: compound operators are harmless and linting on them is not in scope for clippy --> tests/ui/deprecated.rs:11:9 | LL | #![warn(clippy::assign_ops)] | ^^^^^^^^^^^^^^^^^^ -error: lint `clippy::if_let_redundant_pattern_matching` has been removed: this lint has been changed to redundant_pattern_matching +error: lint `clippy::unsafe_vector_initialization` has been removed: the suggested alternative could be substantially slower --> tests/ui/deprecated.rs:12:9 | -LL | #![warn(clippy::if_let_redundant_pattern_matching)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: lint `clippy::unsafe_vector_initialization` has been removed: the replacement suggested by this lint had substantially different behavior - --> tests/ui/deprecated.rs:13:9 - | LL | #![warn(clippy::unsafe_vector_initialization)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::unused_collect` has been removed: `collect` has been marked as #[must_use] in rustc and that covers all cases of this lint - --> tests/ui/deprecated.rs:14:9 +error: lint `clippy::unused_collect` has been removed: `Iterator::collect` is now marked as `#[must_use]` + --> tests/ui/deprecated.rs:13:9 | LL | #![warn(clippy::unused_collect)] | ^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::replace_consts` has been removed: associated-constants `MIN`/`MAX` of integers are preferred to `{min,max}_value()` and module constants - --> tests/ui/deprecated.rs:15:9 +error: lint `clippy::replace_consts` has been removed: `min_value` and `max_value` are now deprecated + --> tests/ui/deprecated.rs:14:9 | LL | #![warn(clippy::replace_consts)] | ^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::regex_macro` has been removed: the regex! macro has been removed from the regex crate in 2018 - --> tests/ui/deprecated.rs:16:9 +error: lint `clippy::regex_macro` has been removed: the `regex!` macro was removed from the regex crate in 2018 + --> tests/ui/deprecated.rs:15:9 | LL | #![warn(clippy::regex_macro)] | ^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::find_map` has been removed: this lint has been replaced by `manual_find_map`, a more specific lint - --> tests/ui/deprecated.rs:17:9 - | -LL | #![warn(clippy::find_map)] - | ^^^^^^^^^^^^^^^^ - -error: lint `clippy::filter_map` has been removed: this lint has been replaced by `manual_filter_map`, a more specific lint - --> tests/ui/deprecated.rs:18:9 - | -LL | #![warn(clippy::filter_map)] - | ^^^^^^^^^^^^^^^^^^ - -error: lint `clippy::pub_enum_variant_names` has been removed: set the `avoid-breaking-exported-api` config option to `false` to enable the `enum_variant_names` lint for public items - --> tests/ui/deprecated.rs:19:9 +error: lint `clippy::pub_enum_variant_names` has been removed: `clippy::enum_variant_names` now covers this case via the `avoid-breaking-exported-api` config + --> tests/ui/deprecated.rs:16:9 | LL | #![warn(clippy::pub_enum_variant_names)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::wrong_pub_self_convention` has been removed: set the `avoid-breaking-exported-api` config option to `false` to enable the `wrong_self_convention` lint for public items - --> tests/ui/deprecated.rs:20:9 +error: lint `clippy::wrong_pub_self_convention` has been removed: `clippy::wrong_self_convention` now covers this case via the `avoid-breaking-exported-api` config + --> tests/ui/deprecated.rs:17:9 | LL | #![warn(clippy::wrong_pub_self_convention)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::maybe_misused_cfg` has been removed: this lint has been replaced by `unexpected_cfgs` - --> tests/ui/deprecated.rs:21:9 - | -LL | #![warn(clippy::maybe_misused_cfg)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: lint `clippy::mismatched_target_os` has been removed: this lint has been replaced by `unexpected_cfgs` - --> tests/ui/deprecated.rs:22:9 - | -LL | #![warn(clippy::mismatched_target_os)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 18 previous errors +error: aborting due to 13 previous errors diff --git a/src/tools/clippy/tests/ui/deprecated_old.rs b/src/tools/clippy/tests/ui/deprecated_old.rs deleted file mode 100644 index 356ad5f060b..00000000000 --- a/src/tools/clippy/tests/ui/deprecated_old.rs +++ /dev/null @@ -1,9 +0,0 @@ -#[warn(unstable_as_slice)] -//~^ ERROR: lint `unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized -//~| NOTE: `-D renamed-and-removed-lints` implied by `-D warnings` -#[warn(unstable_as_mut_slice)] -//~^ ERROR: lint `unstable_as_mut_slice` has been removed: `Vec::as_mut_slice` has been st -#[warn(misaligned_transmute)] -//~^ ERROR: lint `misaligned_transmute` has been removed: this lint has been split into ca - -fn main() {} diff --git a/src/tools/clippy/tests/ui/deprecated_old.stderr b/src/tools/clippy/tests/ui/deprecated_old.stderr deleted file mode 100644 index 685bca64df5..00000000000 --- a/src/tools/clippy/tests/ui/deprecated_old.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error: lint `unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7 - --> tests/ui/deprecated_old.rs:1:8 - | -LL | #[warn(unstable_as_slice)] - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D renamed-and-removed-lints` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(renamed_and_removed_lints)]` - -error: lint `unstable_as_mut_slice` has been removed: `Vec::as_mut_slice` has been stabilized in 1.7 - --> tests/ui/deprecated_old.rs:4:8 - | -LL | #[warn(unstable_as_mut_slice)] - | ^^^^^^^^^^^^^^^^^^^^^ - -error: lint `misaligned_transmute` has been removed: this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr - --> tests/ui/deprecated_old.rs:6:8 - | -LL | #[warn(misaligned_transmute)] - | ^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/src/tools/clippy/tests/ui/deref_by_slicing.fixed b/src/tools/clippy/tests/ui/deref_by_slicing.fixed index a3c2e845666..87b33b1f881 100644 --- a/src/tools/clippy/tests/ui/deref_by_slicing.fixed +++ b/src/tools/clippy/tests/ui/deref_by_slicing.fixed @@ -25,4 +25,8 @@ fn main() { let bytes: &[u8] = &[]; let _ = (&*bytes).read_to_end(&mut vec![]).unwrap(); // Err, re-borrows slice + + // issue 12751 + let a = &mut [1, 2, 3][..]; + let _ = &*a; } diff --git a/src/tools/clippy/tests/ui/deref_by_slicing.rs b/src/tools/clippy/tests/ui/deref_by_slicing.rs index 5b4a73712ee..8d8882a1781 100644 --- a/src/tools/clippy/tests/ui/deref_by_slicing.rs +++ b/src/tools/clippy/tests/ui/deref_by_slicing.rs @@ -25,4 +25,8 @@ fn main() { let bytes: &[u8] = &[]; let _ = (&bytes[..]).read_to_end(&mut vec![]).unwrap(); // Err, re-borrows slice + + // issue 12751 + let a = &mut [1, 2, 3][..]; + let _ = &a[..]; } diff --git a/src/tools/clippy/tests/ui/deref_by_slicing.stderr b/src/tools/clippy/tests/ui/deref_by_slicing.stderr index 17b00610899..ceb9ab6db73 100644 --- a/src/tools/clippy/tests/ui/deref_by_slicing.stderr +++ b/src/tools/clippy/tests/ui/deref_by_slicing.stderr @@ -55,5 +55,11 @@ error: slicing when dereferencing would work LL | let _ = (&bytes[..]).read_to_end(&mut vec![]).unwrap(); // Err, re-borrows slice | ^^^^^^^^^^^^ help: reborrow the original value instead: `(&*bytes)` -error: aborting due to 9 previous errors +error: slicing when dereferencing would work + --> tests/ui/deref_by_slicing.rs:31:13 + | +LL | let _ = &a[..]; + | ^^^^^^ help: reborrow the original value instead: `&*a` + +error: aborting due to 10 previous errors diff --git a/src/tools/clippy/tests/ui/doc/footnote_issue_13183.rs b/src/tools/clippy/tests/ui/doc/footnote_issue_13183.rs new file mode 100644 index 00000000000..a18b4c3ac53 --- /dev/null +++ b/src/tools/clippy/tests/ui/doc/footnote_issue_13183.rs @@ -0,0 +1,10 @@ +// This is a regression test for <https://github.com/rust-lang/rust-clippy/issues/13183>. +// It should not warn on missing backticks on footnote references. + +#![warn(clippy::doc_markdown)] +// Should not warn! +//! Here's a footnote[^example_footnote_identifier] +//! +//! [^example_footnote_identifier]: This is merely an example. + +fn main() {} diff --git a/src/tools/clippy/tests/ui/empty_drop.stderr b/src/tools/clippy/tests/ui/empty_drop.stderr index 4223ddaf3fb..d4d020fec30 100644 --- a/src/tools/clippy/tests/ui/empty_drop.stderr +++ b/src/tools/clippy/tests/ui/empty_drop.stderr @@ -4,10 +4,11 @@ error: empty drop implementation LL | / impl Drop for Foo { LL | | fn drop(&mut self) {} LL | | } - | |_^ help: try removing this impl + | |_^ | = note: `-D clippy::empty-drop` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::empty_drop)]` + = help: try removing this impl error: empty drop implementation --> tests/ui/empty_drop.rs:23:1 @@ -17,7 +18,9 @@ LL | | fn drop(&mut self) { LL | | {} LL | | } LL | | } - | |_^ help: try removing this impl + | |_^ + | + = help: try removing this impl error: aborting due to 2 previous errors diff --git a/src/tools/clippy/tests/ui/eta.fixed b/src/tools/clippy/tests/ui/eta.fixed index 7126f279945..ca422ee29c1 100644 --- a/src/tools/clippy/tests/ui/eta.fixed +++ b/src/tools/clippy/tests/ui/eta.fixed @@ -2,6 +2,7 @@ #![allow(unused)] #![allow( clippy::needless_borrow, + clippy::needless_option_as_deref, clippy::needless_pass_by_value, clippy::no_effect, clippy::option_map_unit_fn, @@ -482,3 +483,19 @@ mod issue_12853 { x(); } } + +mod issue_13073 { + fn get_default() -> Option<&'static str> { + Some("foo") + } + + pub fn foo() { + // shouldn't lint + let bind: Option<String> = None; + let _field = bind.as_deref().or_else(|| get_default()).unwrap(); + let bind: Option<&'static str> = None; + let _field = bind.as_deref().or_else(|| get_default()).unwrap(); + // should lint + let _field = bind.or_else(get_default).unwrap(); + } +} diff --git a/src/tools/clippy/tests/ui/eta.rs b/src/tools/clippy/tests/ui/eta.rs index 0787abf5f3e..c0db91c03ef 100644 --- a/src/tools/clippy/tests/ui/eta.rs +++ b/src/tools/clippy/tests/ui/eta.rs @@ -2,6 +2,7 @@ #![allow(unused)] #![allow( clippy::needless_borrow, + clippy::needless_option_as_deref, clippy::needless_pass_by_value, clippy::no_effect, clippy::option_map_unit_fn, @@ -482,3 +483,19 @@ mod issue_12853 { x(); } } + +mod issue_13073 { + fn get_default() -> Option<&'static str> { + Some("foo") + } + + pub fn foo() { + // shouldn't lint + let bind: Option<String> = None; + let _field = bind.as_deref().or_else(|| get_default()).unwrap(); + let bind: Option<&'static str> = None; + let _field = bind.as_deref().or_else(|| get_default()).unwrap(); + // should lint + let _field = bind.or_else(|| get_default()).unwrap(); + } +} diff --git a/src/tools/clippy/tests/ui/eta.stderr b/src/tools/clippy/tests/ui/eta.stderr index c757601042f..5540261fc57 100644 --- a/src/tools/clippy/tests/ui/eta.stderr +++ b/src/tools/clippy/tests/ui/eta.stderr @@ -1,5 +1,5 @@ error: redundant closure - --> tests/ui/eta.rs:29:27 + --> tests/ui/eta.rs:30:27 | LL | let a = Some(1u8).map(|a| foo(a)); | ^^^^^^^^^^ help: replace the closure with the function itself: `foo` @@ -8,31 +8,31 @@ LL | let a = Some(1u8).map(|a| foo(a)); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure)]` error: redundant closure - --> tests/ui/eta.rs:33:40 + --> tests/ui/eta.rs:34:40 | LL | let _: Option<Vec<u8>> = true.then(|| vec![]); // special case vec! | ^^^^^^^^^ help: replace the closure with `Vec::new`: `std::vec::Vec::new` error: redundant closure - --> tests/ui/eta.rs:34:35 + --> tests/ui/eta.rs:35:35 | LL | let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted? | ^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo2` error: redundant closure - --> tests/ui/eta.rs:35:26 + --> tests/ui/eta.rs:36:26 | LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted | ^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `below` error: redundant closure - --> tests/ui/eta.rs:42:27 + --> tests/ui/eta.rs:43:27 | LL | let e = Some(1u8).map(|a| generic(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `generic` error: redundant closure - --> tests/ui/eta.rs:94:51 + --> tests/ui/eta.rs:95:51 | LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); | ^^^^^^^^^^^ help: replace the closure with the method itself: `TestStruct::foo` @@ -41,166 +41,172 @@ LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_for_method_calls)]` error: redundant closure - --> tests/ui/eta.rs:95:51 + --> tests/ui/eta.rs:96:51 | LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo()); | ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `TestTrait::trait_foo` error: redundant closure - --> tests/ui/eta.rs:97:42 + --> tests/ui/eta.rs:98:42 | LL | let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear()); | ^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::vec::Vec::clear` error: redundant closure - --> tests/ui/eta.rs:101:29 + --> tests/ui/eta.rs:102:29 | LL | let e = Some("str").map(|s| s.to_string()); | ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::string::ToString::to_string` error: redundant closure - --> tests/ui/eta.rs:102:27 + --> tests/ui/eta.rs:103:27 | LL | let e = Some('a').map(|s| s.to_uppercase()); | ^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_uppercase` error: redundant closure - --> tests/ui/eta.rs:104:65 + --> tests/ui/eta.rs:105:65 | LL | let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_ascii_uppercase` error: redundant closure - --> tests/ui/eta.rs:167:22 + --> tests/ui/eta.rs:168:22 | LL | requires_fn_once(|| x()); | ^^^^^^ help: replace the closure with the function itself: `x` error: redundant closure - --> tests/ui/eta.rs:174:27 + --> tests/ui/eta.rs:175:27 | LL | let a = Some(1u8).map(|a| foo_ptr(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo_ptr` error: redundant closure - --> tests/ui/eta.rs:179:27 + --> tests/ui/eta.rs:180:27 | LL | let a = Some(1u8).map(|a| closure(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `closure` error: redundant closure - --> tests/ui/eta.rs:211:28 + --> tests/ui/eta.rs:212:28 | LL | x.into_iter().for_each(|x| add_to_res(x)); | ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut add_to_res` error: redundant closure - --> tests/ui/eta.rs:212:28 + --> tests/ui/eta.rs:213:28 | LL | y.into_iter().for_each(|x| add_to_res(x)); | ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut add_to_res` error: redundant closure - --> tests/ui/eta.rs:213:28 + --> tests/ui/eta.rs:214:28 | LL | z.into_iter().for_each(|x| add_to_res(x)); | ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `add_to_res` error: redundant closure - --> tests/ui/eta.rs:220:21 + --> tests/ui/eta.rs:221:21 | LL | Some(1).map(|n| closure(n)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut closure` error: redundant closure - --> tests/ui/eta.rs:224:21 + --> tests/ui/eta.rs:225:21 | LL | Some(1).map(|n| in_loop(n)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `in_loop` error: redundant closure - --> tests/ui/eta.rs:317:18 + --> tests/ui/eta.rs:318:18 | LL | takes_fn_mut(|| f()); | ^^^^^^ help: replace the closure with the function itself: `&mut f` error: redundant closure - --> tests/ui/eta.rs:320:19 + --> tests/ui/eta.rs:321:19 | LL | takes_fn_once(|| f()); | ^^^^^^ help: replace the closure with the function itself: `&mut f` error: redundant closure - --> tests/ui/eta.rs:324:26 + --> tests/ui/eta.rs:325:26 | LL | move || takes_fn_mut(|| f_used_once()) | ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut f_used_once` error: redundant closure - --> tests/ui/eta.rs:336:19 + --> tests/ui/eta.rs:337:19 | LL | array_opt.map(|a| a.as_slice()); | ^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8; 3]>::as_slice` error: redundant closure - --> tests/ui/eta.rs:339:19 + --> tests/ui/eta.rs:340:19 | LL | slice_opt.map(|s| s.len()); | ^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8]>::len` error: redundant closure - --> tests/ui/eta.rs:342:17 + --> tests/ui/eta.rs:343:17 | LL | ptr_opt.map(|p| p.is_null()); | ^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<*const usize>::is_null` error: redundant closure - --> tests/ui/eta.rs:346:17 + --> tests/ui/eta.rs:347:17 | LL | dyn_opt.map(|d| d.method_on_dyn()); | ^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<dyn TestTrait>::method_on_dyn` error: redundant closure - --> tests/ui/eta.rs:406:19 + --> tests/ui/eta.rs:407:19 | LL | let _ = f(&0, |x, y| f2(x, y)); | ^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `f2` error: redundant closure - --> tests/ui/eta.rs:434:22 + --> tests/ui/eta.rs:435:22 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `Test::method` error: redundant closure - --> tests/ui/eta.rs:438:22 + --> tests/ui/eta.rs:439:22 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `super::Outer::method` error: redundant closure - --> tests/ui/eta.rs:451:18 + --> tests/ui/eta.rs:452:18 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `test_mod::Test::method` error: redundant closure - --> tests/ui/eta.rs:458:30 + --> tests/ui/eta.rs:459:30 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `crate::issue_10854::d::Test::method` error: redundant closure - --> tests/ui/eta.rs:477:38 + --> tests/ui/eta.rs:478:38 | LL | let x = Box::new(|| None.map(|x| f(x))); | ^^^^^^^^ help: replace the closure with the function itself: `&f` error: redundant closure - --> tests/ui/eta.rs:481:38 + --> tests/ui/eta.rs:482:38 | LL | let x = Box::new(|| None.map(|x| f(x))); | ^^^^^^^^ help: replace the closure with the function itself: `f` -error: aborting due to 33 previous errors +error: redundant closure + --> tests/ui/eta.rs:499:35 + | +LL | let _field = bind.or_else(|| get_default()).unwrap(); + | ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `get_default` + +error: aborting due to 34 previous errors diff --git a/src/tools/clippy/tests/ui/excessive_precision.stderr b/src/tools/clippy/tests/ui/excessive_precision.stderr index 6d8e166a649..81e4fb6765d 100644 --- a/src/tools/clippy/tests/ui/excessive_precision.stderr +++ b/src/tools/clippy/tests/ui/excessive_precision.stderr @@ -2,100 +2,179 @@ error: float has excessive precision --> tests/ui/excessive_precision.rs:20:26 | LL | const BAD32_1: f32 = 0.123_456_789_f32; - | ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79_f32` + | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::excessive-precision` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::excessive_precision)]` +help: consider changing the type or truncating it to + | +LL | const BAD32_1: f32 = 0.123_456_79_f32; + | ~~~~~~~~~~~~~~~~ error: float has excessive precision --> tests/ui/excessive_precision.rs:21:26 | LL | const BAD32_2: f32 = 0.123_456_789; - | ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79` + | ^^^^^^^^^^^^^ + | +help: consider changing the type or truncating it to + | +LL | const BAD32_2: f32 = 0.123_456_79; + | ~~~~~~~~~~~~ error: float has excessive precision --> tests/ui/excessive_precision.rs:22:26 | LL | const BAD32_3: f32 = 0.100_000_000_000_1; - | ^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.1` + | ^^^^^^^^^^^^^^^^^^^ + | +help: consider changing the type or truncating it to + | +LL | const BAD32_3: f32 = 0.1; + | ~~~ error: float has excessive precision --> tests/ui/excessive_precision.rs:23:29 | LL | const BAD32_EDGE: f32 = 1.000_000_9; - | ^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.000_001` + | ^^^^^^^^^^^ + | +help: consider changing the type or truncating it to + | +LL | const BAD32_EDGE: f32 = 1.000_001; + | ~~~~~~~~~ error: float has excessive precision --> tests/ui/excessive_precision.rs:27:26 | LL | const BAD64_3: f64 = 0.100_000_000_000_000_000_1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.1` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider changing the type or truncating it to + | +LL | const BAD64_3: f64 = 0.1; + | ~~~ error: float has excessive precision --> tests/ui/excessive_precision.rs:30:22 | LL | println!("{:?}", 8.888_888_888_888_888_888_888); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `8.888_888_888_888_89` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider changing the type or truncating it to + | +LL | println!("{:?}", 8.888_888_888_888_89); + | ~~~~~~~~~~~~~~~~~~~~ error: float has excessive precision --> tests/ui/excessive_precision.rs:41:22 | LL | let bad32: f32 = 1.123_456_789; - | ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8` + | ^^^^^^^^^^^^^ + | +help: consider changing the type or truncating it to + | +LL | let bad32: f32 = 1.123_456_8; + | ~~~~~~~~~~~ error: float has excessive precision --> tests/ui/excessive_precision.rs:42:26 | LL | let bad32_suf: f32 = 1.123_456_789_f32; - | ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8_f32` + | ^^^^^^^^^^^^^^^^^ + | +help: consider changing the type or truncating it to + | +LL | let bad32_suf: f32 = 1.123_456_8_f32; + | ~~~~~~~~~~~~~~~ error: float has excessive precision --> tests/ui/excessive_precision.rs:43:21 | LL | let bad32_inf = 1.123_456_789_f32; - | ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8_f32` + | ^^^^^^^^^^^^^^^^^ + | +help: consider changing the type or truncating it to + | +LL | let bad32_inf = 1.123_456_8_f32; + | ~~~~~~~~~~~~~~~ error: float has excessive precision --> tests/ui/excessive_precision.rs:53:36 | LL | let bad_vec32: Vec<f32> = vec![0.123_456_789]; - | ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79` + | ^^^^^^^^^^^^^ + | +help: consider changing the type or truncating it to + | +LL | let bad_vec32: Vec<f32> = vec![0.123_456_79]; + | ~~~~~~~~~~~~ error: float has excessive precision --> tests/ui/excessive_precision.rs:54:36 | LL | let bad_vec64: Vec<f64> = vec![0.123_456_789_123_456_789]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_123_456_78` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider changing the type or truncating it to + | +LL | let bad_vec64: Vec<f64> = vec![0.123_456_789_123_456_78]; + | ~~~~~~~~~~~~~~~~~~~~~~~~ error: float has excessive precision --> tests/ui/excessive_precision.rs:58:24 | LL | let bad_e32: f32 = 1.123_456_788_888e-10; - | ^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8e-10` + | ^^^^^^^^^^^^^^^^^^^^^ + | +help: consider changing the type or truncating it to + | +LL | let bad_e32: f32 = 1.123_456_8e-10; + | ~~~~~~~~~~~~~~~ error: float has excessive precision --> tests/ui/excessive_precision.rs:61:27 | LL | let bad_bige32: f32 = 1.123_456_788_888E-10; - | ^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8E-10` + | ^^^^^^^^^^^^^^^^^^^^^ + | +help: consider changing the type or truncating it to + | +LL | let bad_bige32: f32 = 1.123_456_8E-10; + | ~~~~~~~~~~~~~~~ error: float has excessive precision --> tests/ui/excessive_precision.rs:70:13 | LL | let _ = 2.225_073_858_507_201_1e-308_f64; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `2.225_073_858_507_201e-308_f64` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider changing the type or truncating it to + | +LL | let _ = 2.225_073_858_507_201e-308_f64; + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: float has excessive precision --> tests/ui/excessive_precision.rs:73:13 | LL | let _ = 1.000_000_000_000_001e-324_f64; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0_f64` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider changing the type or truncating it to + | +LL | let _ = 0_f64; + | ~~~~~ error: float has excessive precision --> tests/ui/excessive_precision.rs:83:20 | LL | const _: f64 = 3.0000000000000000e+00; - | ^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `3.0` + | ^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider changing the type or truncating it to + | +LL | const _: f64 = 3.0; + | ~~~ error: aborting due to 16 previous errors diff --git a/src/tools/clippy/tests/ui/explicit_counter_loop.rs b/src/tools/clippy/tests/ui/explicit_counter_loop.rs index c25e79a3617..28b477b6921 100644 --- a/src/tools/clippy/tests/ui/explicit_counter_loop.rs +++ b/src/tools/clippy/tests/ui/explicit_counter_loop.rs @@ -278,3 +278,16 @@ mod issue_10058 { } } } + +mod issue_13123 { + pub fn test() { + let mut vec = vec![1, 2, 3, 4]; + let mut _index = 0; + 'label: for v in vec { + _index += 1; + if v == 1 { + break 'label; + } + } + } +} diff --git a/src/tools/clippy/tests/ui/explicit_counter_loop.stderr b/src/tools/clippy/tests/ui/explicit_counter_loop.stderr index e28f8783f9c..1b2d1f8570a 100644 --- a/src/tools/clippy/tests/ui/explicit_counter_loop.stderr +++ b/src/tools/clippy/tests/ui/explicit_counter_loop.stderr @@ -57,5 +57,11 @@ LL | for _item in slice { | = note: `idx_u32` is of type `u32`, making it ineligible for `Iterator::enumerate` -error: aborting due to 9 previous errors +error: the variable `_index` is used as a loop counter + --> tests/ui/explicit_counter_loop.rs:286:9 + | +LL | 'label: for v in vec { + | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `'label: for (_index, v) in vec.into_iter().enumerate()` + +error: aborting due to 10 previous errors diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.stderr b/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.stderr index e5bb8d13269..a05b7138bc9 100644 --- a/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.stderr +++ b/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.stderr @@ -2,106 +2,190 @@ error: casting function pointer `foo` to `i8` --> tests/ui/fn_to_numeric_cast_any.rs:23:13 | LL | let _ = foo as i8; - | ^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i8` + | ^^^^^^^^^ | = note: `-D clippy::fn-to-numeric-cast-any` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast_any)]` +help: did you mean to invoke the function? + | +LL | let _ = foo() as i8; + | ~~~~~~~~~~~ error: casting function pointer `foo` to `i16` --> tests/ui/fn_to_numeric_cast_any.rs:26:13 | LL | let _ = foo as i16; - | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i16` + | ^^^^^^^^^^ + | +help: did you mean to invoke the function? + | +LL | let _ = foo() as i16; + | ~~~~~~~~~~~~ error: casting function pointer `foo` to `i32` --> tests/ui/fn_to_numeric_cast_any.rs:28:13 | LL | let _ = foo as i32; - | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i32` + | ^^^^^^^^^^ + | +help: did you mean to invoke the function? + | +LL | let _ = foo() as i32; + | ~~~~~~~~~~~~ error: casting function pointer `foo` to `i64` --> tests/ui/fn_to_numeric_cast_any.rs:30:13 | LL | let _ = foo as i64; - | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i64` + | ^^^^^^^^^^ + | +help: did you mean to invoke the function? + | +LL | let _ = foo() as i64; + | ~~~~~~~~~~~~ error: casting function pointer `foo` to `i128` --> tests/ui/fn_to_numeric_cast_any.rs:32:13 | LL | let _ = foo as i128; - | ^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i128` + | ^^^^^^^^^^^ + | +help: did you mean to invoke the function? + | +LL | let _ = foo() as i128; + | ~~~~~~~~~~~~~ error: casting function pointer `foo` to `isize` --> tests/ui/fn_to_numeric_cast_any.rs:34:13 | LL | let _ = foo as isize; - | ^^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as isize` + | ^^^^^^^^^^^^ + | +help: did you mean to invoke the function? + | +LL | let _ = foo() as isize; + | ~~~~~~~~~~~~~~ error: casting function pointer `foo` to `u8` --> tests/ui/fn_to_numeric_cast_any.rs:37:13 | LL | let _ = foo as u8; - | ^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u8` + | ^^^^^^^^^ + | +help: did you mean to invoke the function? + | +LL | let _ = foo() as u8; + | ~~~~~~~~~~~ error: casting function pointer `foo` to `u16` --> tests/ui/fn_to_numeric_cast_any.rs:39:13 | LL | let _ = foo as u16; - | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u16` + | ^^^^^^^^^^ + | +help: did you mean to invoke the function? + | +LL | let _ = foo() as u16; + | ~~~~~~~~~~~~ error: casting function pointer `foo` to `u32` --> tests/ui/fn_to_numeric_cast_any.rs:41:13 | LL | let _ = foo as u32; - | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u32` + | ^^^^^^^^^^ + | +help: did you mean to invoke the function? + | +LL | let _ = foo() as u32; + | ~~~~~~~~~~~~ error: casting function pointer `foo` to `u64` --> tests/ui/fn_to_numeric_cast_any.rs:43:13 | LL | let _ = foo as u64; - | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u64` + | ^^^^^^^^^^ + | +help: did you mean to invoke the function? + | +LL | let _ = foo() as u64; + | ~~~~~~~~~~~~ error: casting function pointer `foo` to `u128` --> tests/ui/fn_to_numeric_cast_any.rs:45:13 | LL | let _ = foo as u128; - | ^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u128` + | ^^^^^^^^^^^ + | +help: did you mean to invoke the function? + | +LL | let _ = foo() as u128; + | ~~~~~~~~~~~~~ error: casting function pointer `foo` to `usize` --> tests/ui/fn_to_numeric_cast_any.rs:47:13 | LL | let _ = foo as usize; - | ^^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as usize` + | ^^^^^^^^^^^^ + | +help: did you mean to invoke the function? + | +LL | let _ = foo() as usize; + | ~~~~~~~~~~~~~~ error: casting function pointer `Struct::static_method` to `usize` --> tests/ui/fn_to_numeric_cast_any.rs:52:13 | LL | let _ = Struct::static_method as usize; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `Struct::static_method() as usize` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: did you mean to invoke the function? + | +LL | let _ = Struct::static_method() as usize; + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting function pointer `f` to `usize` --> tests/ui/fn_to_numeric_cast_any.rs:57:5 | LL | f as usize - | ^^^^^^^^^^ help: did you mean to invoke the function?: `f() as usize` + | ^^^^^^^^^^ + | +help: did you mean to invoke the function? + | +LL | f() as usize + | error: casting function pointer `T::static_method` to `usize` --> tests/ui/fn_to_numeric_cast_any.rs:62:5 | LL | T::static_method as usize - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `T::static_method() as usize` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: did you mean to invoke the function? + | +LL | T::static_method() as usize + | error: casting function pointer `(clos as fn(u32) -> u32)` to `usize` --> tests/ui/fn_to_numeric_cast_any.rs:69:13 | LL | let _ = (clos as fn(u32) -> u32) as usize; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `(clos as fn(u32) -> u32)() as usize` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: did you mean to invoke the function? + | +LL | let _ = (clos as fn(u32) -> u32)() as usize; + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting function pointer `foo` to `*const ()` --> tests/ui/fn_to_numeric_cast_any.rs:74:13 | LL | let _ = foo as *const (); - | ^^^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as *const ()` + | ^^^^^^^^^^^^^^^^ + | +help: did you mean to invoke the function? + | +LL | let _ = foo() as *const (); + | ~~~~~~~~~~~~~~~~~~ error: aborting due to 17 previous errors diff --git a/src/tools/clippy/tests/ui/for_kv_map.fixed b/src/tools/clippy/tests/ui/for_kv_map.fixed index a2112d7b730..1733b29128f 100644 --- a/src/tools/clippy/tests/ui/for_kv_map.fixed +++ b/src/tools/clippy/tests/ui/for_kv_map.fixed @@ -40,6 +40,16 @@ fn main() { let _k = k; } + let m: HashMap<u64, u64> = HashMap::new(); + let rm = &m; + 'label: for k in rm.keys() { + //~^ ERROR: you seem to want to iterate on a map's keys + let _k = k; + if *k == 0u64 { + break 'label; + } + } + // The following should not produce warnings. let m: HashMap<u64, u64> = HashMap::new(); diff --git a/src/tools/clippy/tests/ui/for_kv_map.rs b/src/tools/clippy/tests/ui/for_kv_map.rs index 1b7959b8f92..de465a7c8e6 100644 --- a/src/tools/clippy/tests/ui/for_kv_map.rs +++ b/src/tools/clippy/tests/ui/for_kv_map.rs @@ -40,6 +40,16 @@ fn main() { let _k = k; } + let m: HashMap<u64, u64> = HashMap::new(); + let rm = &m; + 'label: for (k, _value) in rm { + //~^ ERROR: you seem to want to iterate on a map's keys + let _k = k; + if *k == 0u64 { + break 'label; + } + } + // The following should not produce warnings. let m: HashMap<u64, u64> = HashMap::new(); diff --git a/src/tools/clippy/tests/ui/for_kv_map.stderr b/src/tools/clippy/tests/ui/for_kv_map.stderr index f4ce473d095..adcc3ab8fdb 100644 --- a/src/tools/clippy/tests/ui/for_kv_map.stderr +++ b/src/tools/clippy/tests/ui/for_kv_map.stderr @@ -55,5 +55,16 @@ help: use the corresponding method LL | for k in rm.keys() { | ~ ~~~~~~~~~ -error: aborting due to 5 previous errors +error: you seem to want to iterate on a map's keys + --> tests/ui/for_kv_map.rs:45:32 + | +LL | 'label: for (k, _value) in rm { + | ^^ + | +help: use the corresponding method + | +LL | 'label: for k in rm.keys() { + | ~ ~~~~~~~~~ + +error: aborting due to 6 previous errors diff --git a/src/tools/clippy/tests/ui/get_unwrap.stderr b/src/tools/clippy/tests/ui/get_unwrap.stderr index a08b6657dcc..0f8b279da1e 100644 --- a/src/tools/clippy/tests/ui/get_unwrap.stderr +++ b/src/tools/clippy/tests/ui/get_unwrap.stderr @@ -1,14 +1,18 @@ -error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a slice --> tests/ui/get_unwrap.rs:37:17 | LL | let _ = boxed_slice.get(1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&boxed_slice[1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here --> tests/ui/get_unwrap.rs:9:9 | LL | #![deny(clippy::get_unwrap)] | ^^^^^^^^^^^^^^^^^^ +help: using `[]` is clearer and more concise + | +LL | let _ = &boxed_slice[1]; + | ~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:37:17 @@ -21,11 +25,16 @@ LL | let _ = boxed_slice.get(1).unwrap(); = note: `-D clippy::unwrap-used` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` -error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a slice --> tests/ui/get_unwrap.rs:38:17 | LL | let _ = some_slice.get(0).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_slice[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _ = &some_slice[0]; + | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:38:17 @@ -36,11 +45,16 @@ LL | let _ = some_slice.get(0).unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a Vec --> tests/ui/get_unwrap.rs:39:17 | LL | let _ = some_vec.get(0).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_vec[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _ = &some_vec[0]; + | ~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:39:17 @@ -51,11 +65,16 @@ LL | let _ = some_vec.get(0).unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a VecDeque --> tests/ui/get_unwrap.rs:40:17 | LL | let _ = some_vecdeque.get(0).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_vecdeque[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _ = &some_vecdeque[0]; + | ~~~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:40:17 @@ -66,11 +85,16 @@ LL | let _ = some_vecdeque.get(0).unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a HashMap --> tests/ui/get_unwrap.rs:41:17 | LL | let _ = some_hashmap.get(&1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_hashmap[&1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _ = &some_hashmap[&1]; + | ~~~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:41:17 @@ -81,11 +105,16 @@ LL | let _ = some_hashmap.get(&1).unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a BTreeMap --> tests/ui/get_unwrap.rs:42:17 | LL | let _ = some_btreemap.get(&1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_btreemap[&1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _ = &some_btreemap[&1]; + | ~~~~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:42:17 @@ -96,11 +125,16 @@ LL | let _ = some_btreemap.get(&1).unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a slice --> tests/ui/get_unwrap.rs:46:21 | LL | let _: u8 = *boxed_slice.get(1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice[1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _: u8 = boxed_slice[1]; + | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:46:22 @@ -111,11 +145,16 @@ LL | let _: u8 = *boxed_slice.get(1).unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise +error: called `.get_mut().unwrap()` on a slice --> tests/ui/get_unwrap.rs:51:9 | LL | *boxed_slice.get_mut(0).unwrap() = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | boxed_slice[0] = 1; + | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:51:10 @@ -126,11 +165,16 @@ LL | *boxed_slice.get_mut(0).unwrap() = 1; = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise +error: called `.get_mut().unwrap()` on a slice --> tests/ui/get_unwrap.rs:52:9 | LL | *some_slice.get_mut(0).unwrap() = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_slice[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | some_slice[0] = 1; + | ~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:52:10 @@ -141,11 +185,16 @@ LL | *some_slice.get_mut(0).unwrap() = 1; = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise +error: called `.get_mut().unwrap()` on a Vec --> tests/ui/get_unwrap.rs:53:9 | LL | *some_vec.get_mut(0).unwrap() = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | some_vec[0] = 1; + | ~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:53:10 @@ -156,11 +205,16 @@ LL | *some_vec.get_mut(0).unwrap() = 1; = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and more concise +error: called `.get_mut().unwrap()` on a VecDeque --> tests/ui/get_unwrap.rs:54:9 | LL | *some_vecdeque.get_mut(0).unwrap() = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vecdeque[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | some_vecdeque[0] = 1; + | ~~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:54:10 @@ -171,11 +225,16 @@ LL | *some_vecdeque.get_mut(0).unwrap() = 1; = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a Vec --> tests/ui/get_unwrap.rs:66:17 | LL | let _ = some_vec.get(0..1).unwrap().to_vec(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0..1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _ = some_vec[0..1].to_vec(); + | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:66:17 @@ -186,11 +245,16 @@ LL | let _ = some_vec.get(0..1).unwrap().to_vec(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise +error: called `.get_mut().unwrap()` on a Vec --> tests/ui/get_unwrap.rs:67:17 | LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0..1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _ = some_vec[0..1].to_vec(); + | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:67:17 @@ -201,29 +265,49 @@ LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message -error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a slice --> tests/ui/get_unwrap.rs:77:24 | LL | let _x: &i32 = f.get(1 + 2).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^ help: try: `&f[1 + 2]` + | ^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _x: &i32 = &f[1 + 2]; + | ~~~~~~~~~ -error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a slice --> tests/ui/get_unwrap.rs:80:18 | LL | let _x = f.get(1 + 2).unwrap().to_string(); - | ^^^^^^^^^^^^^^^^^^^^^ help: try: `f[1 + 2]` + | ^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _x = f[1 + 2].to_string(); + | ~~~~~~~~ -error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise +error: called `.get().unwrap()` on a slice --> tests/ui/get_unwrap.rs:83:18 | LL | let _x = f.get(1 + 2).unwrap().abs(); - | ^^^^^^^^^^^^^^^^^^^^^ help: try: `f[1 + 2]` + | ^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let _x = f[1 + 2].abs(); + | ~~~~~~~~ -error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise +error: called `.get_mut().unwrap()` on a slice --> tests/ui/get_unwrap.rs:100:33 | LL | let b = rest.get_mut(linidx(j, k) - linidx(i, k) - 1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut rest[linidx(j, k) - linidx(i, k) - 1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: using `[]` is clearer and more concise + | +LL | let b = &mut rest[linidx(j, k) - linidx(i, k) - 1]; + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 30 previous errors diff --git a/src/tools/clippy/tests/ui/if_let_mutex.rs b/src/tools/clippy/tests/ui/if_let_mutex.rs index cb6915e0eba..bb0eadfca1c 100644 --- a/src/tools/clippy/tests/ui/if_let_mutex.rs +++ b/src/tools/clippy/tests/ui/if_let_mutex.rs @@ -1,4 +1,5 @@ #![warn(clippy::if_let_mutex)] +#![allow(clippy::redundant_pattern_matching)] use std::ops::Deref; use std::sync::Mutex; @@ -50,4 +51,12 @@ fn mutex_ref(mutex: &Mutex<i32>) { }; } +fn multiple_mutexes(m1: &Mutex<()>, m2: &Mutex<()>) { + if let Ok(_) = m1.lock() { + m2.lock(); + } else { + m1.lock(); + } +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/if_let_mutex.stderr b/src/tools/clippy/tests/ui/if_let_mutex.stderr index 6e0115c23af..45df4ac4d67 100644 --- a/src/tools/clippy/tests/ui/if_let_mutex.stderr +++ b/src/tools/clippy/tests/ui/if_let_mutex.stderr @@ -1,5 +1,5 @@ error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock - --> tests/ui/if_let_mutex.rs:10:5 + --> tests/ui/if_let_mutex.rs:11:5 | LL | if let Err(locked) = m.lock() { | ^ - this Mutex will remain locked for the entire `if let`-block... @@ -19,7 +19,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::if_let_mutex)]` error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock - --> tests/ui/if_let_mutex.rs:23:5 + --> tests/ui/if_let_mutex.rs:24:5 | LL | if let Some(locked) = m.lock().unwrap().deref() { | ^ - this Mutex will remain locked for the entire `if let`-block... @@ -37,7 +37,7 @@ LL | | }; = help: move the lock call outside of the `if let ...` expression error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock - --> tests/ui/if_let_mutex.rs:45:5 + --> tests/ui/if_let_mutex.rs:46:5 | LL | if let Ok(i) = mutex.lock() { | ^ ----- this Mutex will remain locked for the entire `if let`-block... @@ -53,5 +53,21 @@ LL | | }; | = help: move the lock call outside of the `if let ...` expression -error: aborting due to 3 previous errors +error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock + --> tests/ui/if_let_mutex.rs:55:5 + | +LL | if let Ok(_) = m1.lock() { + | ^ -- this Mutex will remain locked for the entire `if let`-block... + | _____| + | | +LL | | m2.lock(); +LL | | } else { +LL | | m1.lock(); + | | -- ... and is tried to lock again here, which will always deadlock. +LL | | } + | |_____^ + | + = help: move the lock call outside of the `if let ...` expression + +error: aborting due to 4 previous errors diff --git a/src/tools/clippy/tests/ui/if_then_some_else_none.fixed b/src/tools/clippy/tests/ui/if_then_some_else_none.fixed new file mode 100644 index 00000000000..ad13372a68b --- /dev/null +++ b/src/tools/clippy/tests/ui/if_then_some_else_none.fixed @@ -0,0 +1,119 @@ +#![warn(clippy::if_then_some_else_none)] +#![allow(clippy::redundant_pattern_matching, clippy::unnecessary_lazy_evaluations)] + +fn main() { + // Should issue an error. + let _ = foo().then(|| { println!("true!"); "foo" }); + + // Should issue an error when macros are used. + let _ = matches!(true, true).then(|| { println!("true!"); matches!(true, false) }); + + // Should issue an error. Binary expression `o < 32` should be parenthesized. + let x = Some(5); + let _ = x.and_then(|o| (o < 32).then_some(o)); + //~^ ERROR: this could be simplified with `bool::then_some` + + // Should issue an error. Unary expression `!x` should be parenthesized. + let x = true; + let _ = (!x).then_some(0); + //~^ ERROR: this could be simplified with `bool::then_some` + + // Should not issue an error since the `else` block has a statement besides `None`. + let _ = if foo() { + println!("true!"); + Some("foo") + } else { + eprintln!("false..."); + None + }; + + // Should not issue an error since there are more than 2 blocks in the if-else chain. + let _ = if foo() { + println!("foo true!"); + Some("foo") + } else if bar() { + println!("bar true!"); + Some("bar") + } else { + None + }; + + let _ = if foo() { + println!("foo true!"); + Some("foo") + } else { + bar().then(|| { + println!("bar true!"); + "bar" + }) + }; + + // Should not issue an error since the `then` block has `None`, not `Some`. + let _ = if foo() { None } else { Some("foo is false") }; + + // Should not issue an error since the `else` block doesn't use `None` directly. + let _ = if foo() { Some("foo is true") } else { into_none() }; + + // Should not issue an error since the `then` block doesn't use `Some` directly. + let _ = if foo() { into_some("foo") } else { None }; +} + +#[clippy::msrv = "1.49"] +fn _msrv_1_49() { + // `bool::then` was stabilized in 1.50. Do not lint this + let _ = if foo() { + println!("true!"); + Some(149) + } else { + None + }; +} + +#[clippy::msrv = "1.50"] +fn _msrv_1_50() { + let _ = foo().then(|| { println!("true!"); 150 }); +} + +fn foo() -> bool { + unimplemented!() +} + +fn bar() -> bool { + unimplemented!() +} + +fn into_some<T>(v: T) -> Option<T> { + Some(v) +} + +fn into_none<T>() -> Option<T> { + None +} + +// Should not warn +fn f(b: bool, v: Option<()>) -> Option<()> { + if b { + v?; // This is a potential early return, is not equivalent with `bool::then` + + Some(()) + } else { + None + } +} + +fn issue11394(b: bool, v: Result<(), ()>) -> Result<(), ()> { + let x = if b { + #[allow(clippy::let_unit_value)] + let _ = v?; + Some(()) + } else { + None + }; + + Ok(()) +} + +const fn issue12103(x: u32) -> Option<u32> { + // Should not issue an error in `const` context + if x > 42 { Some(150) } else { None } +} diff --git a/src/tools/clippy/tests/ui/if_then_some_else_none.rs b/src/tools/clippy/tests/ui/if_then_some_else_none.rs index ccde154bd56..73edbb7da2a 100644 --- a/src/tools/clippy/tests/ui/if_then_some_else_none.rs +++ b/src/tools/clippy/tests/ui/if_then_some_else_none.rs @@ -1,5 +1,5 @@ #![warn(clippy::if_then_some_else_none)] -#![allow(clippy::redundant_pattern_matching)] +#![allow(clippy::redundant_pattern_matching, clippy::unnecessary_lazy_evaluations)] fn main() { // Should issue an error. diff --git a/src/tools/clippy/tests/ui/if_then_some_else_none.stderr b/src/tools/clippy/tests/ui/if_then_some_else_none.stderr index e0a95aebdc1..aed01e026cb 100644 --- a/src/tools/clippy/tests/ui/if_then_some_else_none.stderr +++ b/src/tools/clippy/tests/ui/if_then_some_else_none.stderr @@ -9,9 +9,8 @@ LL | | Some("foo") LL | | } else { LL | | None LL | | }; - | |_____^ + | |_____^ help: try: `foo().then(|| { println!("true!"); "foo" })` | - = help: consider using `bool::then` like: `foo().then(|| { /* snippet */ "foo" })` = note: `-D clippy::if-then-some-else-none` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::if_then_some_else_none)]` @@ -26,25 +25,19 @@ LL | | Some(matches!(true, false)) LL | | } else { LL | | None LL | | }; - | |_____^ - | - = help: consider using `bool::then` like: `matches!(true, true).then(|| { /* snippet */ matches!(true, false) })` + | |_____^ help: try: `matches!(true, true).then(|| { println!("true!"); matches!(true, false) })` error: this could be simplified with `bool::then_some` --> tests/ui/if_then_some_else_none.rs:25:28 | LL | let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using `bool::then_some` like: `(o < 32).then_some(o)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(o < 32).then_some(o)` error: this could be simplified with `bool::then_some` --> tests/ui/if_then_some_else_none.rs:30:13 | LL | let _ = if !x { Some(0) } else { None }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using `bool::then_some` like: `(!x).then_some(0)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(!x).then_some(0)` error: this could be simplified with `bool::then` --> tests/ui/if_then_some_else_none.rs:86:13 @@ -57,9 +50,7 @@ LL | | Some(150) LL | | } else { LL | | None LL | | }; - | |_____^ - | - = help: consider using `bool::then` like: `foo().then(|| { /* snippet */ 150 })` + | |_____^ help: try: `foo().then(|| { println!("true!"); 150 })` error: aborting due to 5 previous errors diff --git a/src/tools/clippy/tests/ui/implicit_hasher.fixed b/src/tools/clippy/tests/ui/implicit_hasher.fixed new file mode 100644 index 00000000000..2d6dc0274cf --- /dev/null +++ b/src/tools/clippy/tests/ui/implicit_hasher.fixed @@ -0,0 +1,102 @@ +//@aux-build:proc_macros.rs +#![deny(clippy::implicit_hasher)] + +#[macro_use] +extern crate proc_macros; + +use std::cmp::Eq; +use std::collections::{HashMap, HashSet}; +use std::hash::{BuildHasher, Hash}; + +pub trait Foo<T>: Sized { + fn make() -> (Self, Self); +} + +impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<i8> for HashMap<K, V, S> { + fn make() -> (Self, Self) { + // OK, don't suggest to modify these + let _: HashMap<i32, i32> = HashMap::new(); + let _: HashSet<i32> = HashSet::new(); + + (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) + } +} +impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<i8> for (HashMap<K, V, S>,) { + fn make() -> (Self, Self) { + ((HashMap::default(),), (HashMap::with_capacity_and_hasher(10, Default::default()),)) + } +} +impl<S: ::std::hash::BuildHasher + Default> Foo<i16> for HashMap<String, String, S> { + fn make() -> (Self, Self) { + (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) + } +} + +impl<K: Hash + Eq, V, S: BuildHasher + Default> Foo<i32> for HashMap<K, V, S> { + fn make() -> (Self, Self) { + (HashMap::default(), HashMap::with_capacity_and_hasher(10, S::default())) + } +} +impl<S: BuildHasher + Default> Foo<i64> for HashMap<String, String, S> { + fn make() -> (Self, Self) { + (HashMap::default(), HashMap::with_capacity_and_hasher(10, S::default())) + } +} + +impl<T: Hash + Eq, S: ::std::hash::BuildHasher + Default> Foo<i8> for HashSet<T, S> { + fn make() -> (Self, Self) { + (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) + } +} +impl<S: ::std::hash::BuildHasher + Default> Foo<i16> for HashSet<String, S> { + fn make() -> (Self, Self) { + (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) + } +} + +impl<T: Hash + Eq, S: BuildHasher + Default> Foo<i32> for HashSet<T, S> { + fn make() -> (Self, Self) { + (HashSet::default(), HashSet::with_capacity_and_hasher(10, S::default())) + } +} +impl<S: BuildHasher + Default> Foo<i64> for HashSet<String, S> { + fn make() -> (Self, Self) { + (HashSet::default(), HashSet::with_capacity_and_hasher(10, S::default())) + } +} + +pub fn map<S: ::std::hash::BuildHasher>(map: &mut HashMap<i32, i32, S>) {} + +pub fn set<S: ::std::hash::BuildHasher>(set: &mut HashSet<i32, S>) {} + +#[inline_macros] +pub mod gen { + use super::*; + inline! { + impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<u8> for HashMap<K, V, S> { + fn make() -> (Self, Self) { + (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) + } + } + + pub fn bar(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {} + } +} + +// When the macro is in a different file, the suggestion spans can't be combined properly +// and should not cause an ICE +// See #2707 +#[macro_use] +#[path = "auxiliary/test_macro.rs"] +pub mod test_macro; +__implicit_hasher_test_macro!(impl<K, V> for HashMap<K, V> where V: test_macro::A); + +// #4260 +external! { + pub fn f(input: &HashMap<u32, u32>) {} +} + +// #7712 +pub async fn election_vote<S: ::std::hash::BuildHasher>(_data: HashMap<i32, i32, S>) {} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/implicit_hasher.rs b/src/tools/clippy/tests/ui/implicit_hasher.rs index f7cd541741b..0a334357bd1 100644 --- a/src/tools/clippy/tests/ui/implicit_hasher.rs +++ b/src/tools/clippy/tests/ui/implicit_hasher.rs @@ -1,11 +1,8 @@ //@aux-build:proc_macros.rs -//@no-rustfix #![deny(clippy::implicit_hasher)] -#![allow(unused)] #[macro_use] extern crate proc_macros; -use proc_macros::external; use std::cmp::Eq; use std::collections::{HashMap, HashSet}; @@ -68,9 +65,11 @@ impl<S: BuildHasher + Default> Foo<i64> for HashSet<String, S> { } } -pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {} +pub fn map(map: &mut HashMap<i32, i32>) {} -#[proc_macros::inline_macros] +pub fn set(set: &mut HashSet<i32>) {} + +#[inline_macros] pub mod gen { use super::*; inline! { diff --git a/src/tools/clippy/tests/ui/implicit_hasher.stderr b/src/tools/clippy/tests/ui/implicit_hasher.stderr index a3df8edf389..48c6ebc209c 100644 --- a/src/tools/clippy/tests/ui/implicit_hasher.stderr +++ b/src/tools/clippy/tests/ui/implicit_hasher.stderr @@ -1,40 +1,121 @@ -error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` - --> tests/ui/implicit_hasher.rs:14:1 +error: impl for `HashMap` should be generalized over different hashers + --> tests/ui/implicit_hasher.rs:15:35 + | +LL | impl<K: Hash + Eq, V> Foo<i8> for HashMap<K, V> { + | ^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> tests/ui/implicit_hasher.rs:2:9 + | +LL | #![deny(clippy::implicit_hasher)] + | ^^^^^^^^^^^^^^^^^^^^^^^ +help: add a type parameter for `BuildHasher` + | +LL ~ impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<i8> for HashMap<K, V, S> { +LL | fn make() -> (Self, Self) { +... +LL | +LL ~ (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) + | + +error: impl for `HashMap` should be generalized over different hashers + --> tests/ui/implicit_hasher.rs:24:36 + | +LL | impl<K: Hash + Eq, V> Foo<i8> for (HashMap<K, V>,) { + | ^^^^^^^^^^^^^ + | +help: add a type parameter for `BuildHasher` + | +LL ~ impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<i8> for (HashMap<K, V, S>,) { +LL | fn make() -> (Self, Self) { +LL ~ ((HashMap::default(),), (HashMap::with_capacity_and_hasher(10, Default::default()),)) + | + +error: impl for `HashMap` should be generalized over different hashers + --> tests/ui/implicit_hasher.rs:29:19 + | +LL | impl Foo<i16> for HashMap<String, String> { + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +help: add a type parameter for `BuildHasher` + | +LL ~ impl<S: ::std::hash::BuildHasher + Default> Foo<i16> for HashMap<String, String, S> { +LL | fn make() -> (Self, Self) { +LL ~ (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) + | + +error: impl for `HashSet` should be generalized over different hashers + --> tests/ui/implicit_hasher.rs:46:32 + | +LL | impl<T: Hash + Eq> Foo<i8> for HashSet<T> { + | ^^^^^^^^^^ + | +help: add a type parameter for `BuildHasher` + | +LL ~ impl<T: Hash + Eq, S: ::std::hash::BuildHasher + Default> Foo<i8> for HashSet<T, S> { +LL | fn make() -> (Self, Self) { +LL ~ (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) | -LL | pub trait Foo<T>: Sized { - | ^^^^^^^^^^^^^^^^^^^^^^^ -error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` - --> tests/ui/implicit_hasher.rs:71:1 +error: impl for `HashSet` should be generalized over different hashers + --> tests/ui/implicit_hasher.rs:51:19 + | +LL | impl Foo<i16> for HashSet<String> { + | ^^^^^^^^^^^^^^^ + | +help: add a type parameter for `BuildHasher` + | +LL ~ impl<S: ::std::hash::BuildHasher + Default> Foo<i16> for HashSet<String, S> { +LL | fn make() -> (Self, Self) { +LL ~ (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) | -LL | pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` - --> tests/ui/implicit_hasher.rs:74:1 +error: parameter of type `HashMap` should be generalized over different hashers + --> tests/ui/implicit_hasher.rs:68:22 + | +LL | pub fn map(map: &mut HashMap<i32, i32>) {} + | ^^^^^^^^^^^^^^^^^ | -LL | pub mod gen { - | ^^^^^^^^^^^ +help: add a type parameter for `BuildHasher` + | +LL | pub fn map<S: ::std::hash::BuildHasher>(map: &mut HashMap<i32, i32, S>) {} + | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~ -error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` - --> tests/ui/implicit_hasher.rs:92:1 +error: parameter of type `HashSet` should be generalized over different hashers + --> tests/ui/implicit_hasher.rs:70:22 + | +LL | pub fn set(set: &mut HashSet<i32>) {} + | ^^^^^^^^^^^^ | -LL | pub mod test_macro; - | ^^^^^^^^^^^^^^^^^^^ +help: add a type parameter for `BuildHasher` + | +LL | pub fn set<S: ::std::hash::BuildHasher>(set: &mut HashSet<i32, S>) {} + | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~ -error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` - --> tests/ui/implicit_hasher.rs:96:1 +error: impl for `HashMap` should be generalized over different hashers + --> tests/ui/implicit_hasher.rs:76:43 + | +LL | impl<K: Hash + Eq, V> Foo<u8> for HashMap<K, V> { + | ^^^^^^^^^^^^^ | -LL | external! { - | ^^^^^^^^^ + = note: this error originates in the macro `__inline_mac_mod_gen` (in Nightly builds, run with -Z macro-backtrace for more info) +help: add a type parameter for `BuildHasher` + | +LL ~ impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<u8> for HashMap<K, V, S> { +LL | fn make() -> (Self, Self) { +LL ~ (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) | - = note: this error originates in the macro `external` (in Nightly builds, run with -Z macro-backtrace for more info) -error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` - --> tests/ui/implicit_hasher.rs:101:1 +error: parameter of type `HashMap` should be generalized over different hashers + --> tests/ui/implicit_hasher.rs:100:35 | LL | pub async fn election_vote(_data: HashMap<i32, i32>) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ + | +help: add a type parameter for `BuildHasher` + | +LL | pub async fn election_vote<S: ::std::hash::BuildHasher>(_data: HashMap<i32, i32, S>) {} + | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~ -error: aborting due to 6 previous errors +error: aborting due to 9 previous errors diff --git a/src/tools/clippy/tests/ui/implicit_return.stderr b/src/tools/clippy/tests/ui/implicit_return.stderr index f06d4e983c5..3b06f26f5a0 100644 --- a/src/tools/clippy/tests/ui/implicit_return.stderr +++ b/src/tools/clippy/tests/ui/implicit_return.stderr @@ -2,88 +2,157 @@ error: missing `return` statement --> tests/ui/implicit_return.rs:15:5 | LL | true - | ^^^^ help: add `return` as shown: `return true` + | ^^^^ | = note: `-D clippy::implicit-return` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::implicit_return)]` +help: add `return` as shown + | +LL | return true + | error: missing `return` statement --> tests/ui/implicit_return.rs:19:15 | LL | if true { true } else { false } - | ^^^^ help: add `return` as shown: `return true` + | ^^^^ + | +help: add `return` as shown + | +LL | if true { return true } else { false } + | ~~~~~~~~~~~ error: missing `return` statement --> tests/ui/implicit_return.rs:19:29 | LL | if true { true } else { false } - | ^^^^^ help: add `return` as shown: `return false` + | ^^^^^ + | +help: add `return` as shown + | +LL | if true { true } else { return false } + | ~~~~~~~~~~~~ error: missing `return` statement --> tests/ui/implicit_return.rs:25:17 | LL | true => false, - | ^^^^^ help: add `return` as shown: `return false` + | ^^^^^ + | +help: add `return` as shown + | +LL | true => return false, + | ~~~~~~~~~~~~ error: missing `return` statement --> tests/ui/implicit_return.rs:26:20 | LL | false => { true }, - | ^^^^ help: add `return` as shown: `return true` + | ^^^^ + | +help: add `return` as shown + | +LL | false => { return true }, + | ~~~~~~~~~~~ error: missing `return` statement --> tests/ui/implicit_return.rs:39:9 | LL | break true; - | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` + | ^^^^^^^^^^ + | +help: change `break` to `return` as shown + | +LL | return true; + | ~~~~~~~~~~~ error: missing `return` statement --> tests/ui/implicit_return.rs:46:13 | LL | break true; - | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` + | ^^^^^^^^^^ + | +help: change `break` to `return` as shown + | +LL | return true; + | ~~~~~~~~~~~ error: missing `return` statement --> tests/ui/implicit_return.rs:54:13 | LL | break true; - | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` + | ^^^^^^^^^^ + | +help: change `break` to `return` as shown + | +LL | return true; + | ~~~~~~~~~~~ error: missing `return` statement --> tests/ui/implicit_return.rs:72:18 | LL | let _ = || { true }; - | ^^^^ help: add `return` as shown: `return true` + | ^^^^ + | +help: add `return` as shown + | +LL | let _ = || { return true }; + | ~~~~~~~~~~~ error: missing `return` statement --> tests/ui/implicit_return.rs:73:16 | LL | let _ = || true; - | ^^^^ help: add `return` as shown: `return true` + | ^^^^ + | +help: add `return` as shown + | +LL | let _ = || return true; + | ~~~~~~~~~~~ error: missing `return` statement --> tests/ui/implicit_return.rs:81:5 | LL | format!("test {}", "test") - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: add `return` as shown + | +LL | return format!("test {}", "test") + | error: missing `return` statement --> tests/ui/implicit_return.rs:90:5 | LL | m!(true, false) - | ^^^^^^^^^^^^^^^ help: add `return` as shown: `return m!(true, false)` + | ^^^^^^^^^^^^^^^ + | +help: add `return` as shown + | +LL | return m!(true, false) + | error: missing `return` statement --> tests/ui/implicit_return.rs:96:13 | LL | break true; - | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` + | ^^^^^^^^^^ + | +help: change `break` to `return` as shown + | +LL | return true; + | ~~~~~~~~~~~ error: missing `return` statement --> tests/ui/implicit_return.rs:101:17 | LL | break 'outer false; - | ^^^^^^^^^^^^^^^^^^ help: change `break` to `return` as shown: `return false` + | ^^^^^^^^^^^^^^^^^^ + | +help: change `break` to `return` as shown + | +LL | return false; + | ~~~~~~~~~~~~ error: missing `return` statement --> tests/ui/implicit_return.rs:116:5 @@ -104,7 +173,12 @@ error: missing `return` statement --> tests/ui/implicit_return.rs:130:5 | LL | true - | ^^^^ help: add `return` as shown: `return true` + | ^^^^ + | +help: add `return` as shown + | +LL | return true + | error: aborting due to 16 previous errors diff --git a/src/tools/clippy/tests/ui/lossy_float_literal.stderr b/src/tools/clippy/tests/ui/lossy_float_literal.stderr index b5a07418734..3026854e317 100644 --- a/src/tools/clippy/tests/ui/lossy_float_literal.stderr +++ b/src/tools/clippy/tests/ui/lossy_float_literal.stderr @@ -2,70 +2,124 @@ error: literal cannot be represented as the underlying type without loss of prec --> tests/ui/lossy_float_literal.rs:14:18 | LL | let _: f32 = 16_777_217.0; - | ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_216.0` + | ^^^^^^^^^^^^ | = note: `-D clippy::lossy-float-literal` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::lossy_float_literal)]` +help: consider changing the type or replacing it with + | +LL | let _: f32 = 16_777_216.0; + | ~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:15:18 | LL | let _: f32 = 16_777_219.0; - | ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` + | ^^^^^^^^^^^^ + | +help: consider changing the type or replacing it with + | +LL | let _: f32 = 16_777_220.0; + | ~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:16:18 | LL | let _: f32 = 16_777_219.; - | ^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` + | ^^^^^^^^^^^ + | +help: consider changing the type or replacing it with + | +LL | let _: f32 = 16_777_220.0; + | ~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:17:18 | LL | let _: f32 = 16_777_219.000; - | ^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` + | ^^^^^^^^^^^^^^ + | +help: consider changing the type or replacing it with + | +LL | let _: f32 = 16_777_220.0; + | ~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:18:13 | LL | let _ = 16_777_219f32; - | ^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220_f32` + | ^^^^^^^^^^^^^ + | +help: consider changing the type or replacing it with + | +LL | let _ = 16_777_220_f32; + | ~~~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:19:19 | LL | let _: f32 = -16_777_219.0; - | ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` + | ^^^^^^^^^^^^ + | +help: consider changing the type or replacing it with + | +LL | let _: f32 = -16_777_220.0; + | ~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:21:18 | LL | let _: f64 = 9_007_199_254_740_993.0; - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider changing the type or replacing it with + | +LL | let _: f64 = 9_007_199_254_740_992.0; + | ~~~~~~~~~~~~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:22:18 | LL | let _: f64 = 9_007_199_254_740_993.; - | ^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` + | ^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider changing the type or replacing it with + | +LL | let _: f64 = 9_007_199_254_740_992.0; + | ~~~~~~~~~~~~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:23:18 | LL | let _: f64 = 9_007_199_254_740_993.00; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider changing the type or replacing it with + | +LL | let _: f64 = 9_007_199_254_740_992.0; + | ~~~~~~~~~~~~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:24:13 | LL | let _ = 9_007_199_254_740_993f64; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992_f64` + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider changing the type or replacing it with + | +LL | let _ = 9_007_199_254_740_992_f64; + | ~~~~~~~~~~~~~~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:25:19 | LL | let _: f64 = -9_007_199_254_740_993.0; - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider changing the type or replacing it with + | +LL | let _: f64 = -9_007_199_254_740_992.0; + | ~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 11 previous errors diff --git a/src/tools/clippy/tests/ui/missing_trait_methods.rs b/src/tools/clippy/tests/ui/missing_trait_methods.rs index 1b09b717ff7..55b904bde59 100644 --- a/src/tools/clippy/tests/ui/missing_trait_methods.rs +++ b/src/tools/clippy/tests/ui/missing_trait_methods.rs @@ -49,4 +49,12 @@ impl B for Complete { } } +trait MissingMultiple { + fn one() {} + fn two() {} + fn three() {} +} + +impl MissingMultiple for Partial {} + fn main() {} diff --git a/src/tools/clippy/tests/ui/missing_trait_methods.stderr b/src/tools/clippy/tests/ui/missing_trait_methods.stderr index f5d5d4418b2..9c4968b022d 100644 --- a/src/tools/clippy/tests/ui/missing_trait_methods.stderr +++ b/src/tools/clippy/tests/ui/missing_trait_methods.stderr @@ -24,5 +24,41 @@ help: implement the method LL | fn b<'a, T: AsRef<[u8]>>(a: &'a T) -> &'a [u8] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors +error: missing trait method provided by default: `one` + --> tests/ui/missing_trait_methods.rs:58:1 + | +LL | impl MissingMultiple for Partial {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: implement the method + --> tests/ui/missing_trait_methods.rs:53:5 + | +LL | fn one() {} + | ^^^^^^^^ + +error: missing trait method provided by default: `two` + --> tests/ui/missing_trait_methods.rs:58:1 + | +LL | impl MissingMultiple for Partial {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: implement the method + --> tests/ui/missing_trait_methods.rs:54:5 + | +LL | fn two() {} + | ^^^^^^^^ + +error: missing trait method provided by default: `three` + --> tests/ui/missing_trait_methods.rs:58:1 + | +LL | impl MissingMultiple for Partial {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: implement the method + --> tests/ui/missing_trait_methods.rs:55:5 + | +LL | fn three() {} + | ^^^^^^^^^^ + +error: aborting due to 5 previous errors diff --git a/src/tools/clippy/tests/ui/needless_borrows_for_generic_args.fixed b/src/tools/clippy/tests/ui/needless_borrows_for_generic_args.fixed index 5478372cbe0..c1dc8b5e8d0 100644 --- a/src/tools/clippy/tests/ui/needless_borrows_for_generic_args.fixed +++ b/src/tools/clippy/tests/ui/needless_borrows_for_generic_args.fixed @@ -333,4 +333,12 @@ fn main() { f(&y); // Don't lint f("".to_owned()); // Lint } + { + fn takes_writer<T: std::io::Write>(_: T) {} + + fn issue_12856(mut buffer: &mut Vec<u8>) { + takes_writer(&mut buffer); // Don't lint, would make buffer unavailable later + buffer.extend(b"\n"); + } + } } diff --git a/src/tools/clippy/tests/ui/needless_borrows_for_generic_args.rs b/src/tools/clippy/tests/ui/needless_borrows_for_generic_args.rs index 2643815d939..c7f66824d58 100644 --- a/src/tools/clippy/tests/ui/needless_borrows_for_generic_args.rs +++ b/src/tools/clippy/tests/ui/needless_borrows_for_generic_args.rs @@ -333,4 +333,12 @@ fn main() { f(&y); // Don't lint f(&"".to_owned()); // Lint } + { + fn takes_writer<T: std::io::Write>(_: T) {} + + fn issue_12856(mut buffer: &mut Vec<u8>) { + takes_writer(&mut buffer); // Don't lint, would make buffer unavailable later + buffer.extend(b"\n"); + } + } } diff --git a/src/tools/clippy/tests/ui/needless_pub_self.stderr b/src/tools/clippy/tests/ui/needless_pub_self.stderr index 0bff2e4b8b7..1fdd8416565 100644 --- a/src/tools/clippy/tests/ui/needless_pub_self.stderr +++ b/src/tools/clippy/tests/ui/needless_pub_self.stderr @@ -2,22 +2,27 @@ error: unnecessary `pub(self)` --> tests/ui/needless_pub_self.rs:13:1 | LL | pub(self) fn a() {} - | ^^^^^^^^^ help: remove it + | ^^^^^^^^^ | = note: `-D clippy::needless-pub-self` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_pub_self)]` + = help: remove it error: unnecessary `pub(in self)` --> tests/ui/needless_pub_self.rs:14:1 | LL | pub(in self) fn b() {} - | ^^^^^^^^^^^^ help: remove it + | ^^^^^^^^^^^^ + | + = help: remove it error: unnecessary `pub(self)` --> tests/ui/needless_pub_self.rs:20:5 | LL | pub(self) fn f() {} - | ^^^^^^^^^ help: remove it + | ^^^^^^^^^ + | + = help: remove it error: aborting due to 3 previous errors diff --git a/src/tools/clippy/tests/ui/nonminimal_bool.rs b/src/tools/clippy/tests/ui/nonminimal_bool.rs index d117e8bf9c7..52b0155a762 100644 --- a/src/tools/clippy/tests/ui/nonminimal_bool.rs +++ b/src/tools/clippy/tests/ui/nonminimal_bool.rs @@ -177,3 +177,9 @@ fn issue_12371(x: usize) -> bool { // Should not warn! !x != 0 } + +// Not linted because it is slow to do so +// https://github.com/rust-lang/rust-clippy/issues/13206 +fn many_ops(a: bool, b: bool, c: bool, d: bool, e: bool, f: bool) -> bool { + (a && c && f) || (!a && b && !d) || (!b && !c && !e) || (d && e && !f) +} diff --git a/src/tools/clippy/tests/ui/patterns.fixed b/src/tools/clippy/tests/ui/patterns.fixed index 332cba97155..feaec33ac15 100644 --- a/src/tools/clippy/tests/ui/patterns.fixed +++ b/src/tools/clippy/tests/ui/patterns.fixed @@ -1,7 +1,7 @@ //@aux-build:proc_macros.rs #![warn(clippy::all)] #![allow(unused)] -#![allow(clippy::uninlined_format_args)] +#![allow(clippy::uninlined_format_args, clippy::single_match)] #[macro_use] extern crate proc_macros; diff --git a/src/tools/clippy/tests/ui/patterns.rs b/src/tools/clippy/tests/ui/patterns.rs index 45d907688e3..53812c7deec 100644 --- a/src/tools/clippy/tests/ui/patterns.rs +++ b/src/tools/clippy/tests/ui/patterns.rs @@ -1,7 +1,7 @@ //@aux-build:proc_macros.rs #![warn(clippy::all)] #![allow(unused)] -#![allow(clippy::uninlined_format_args)] +#![allow(clippy::uninlined_format_args, clippy::single_match)] #[macro_use] extern crate proc_macros; diff --git a/src/tools/clippy/tests/ui/rename.fixed b/src/tools/clippy/tests/ui/rename.fixed index d70c9f8d06c..b810fd8224f 100644 --- a/src/tools/clippy/tests/ui/rename.fixed +++ b/src/tools/clippy/tests/ui/rename.fixed @@ -13,7 +13,10 @@ #![allow(clippy::disallowed_methods)] #![allow(clippy::disallowed_types)] #![allow(clippy::mixed_read_write_in_expression)] +#![allow(clippy::manual_find_map)] +#![allow(clippy::manual_filter_map)] #![allow(clippy::useless_conversion)] +#![allow(clippy::redundant_pattern_matching)] #![allow(clippy::match_result_ok)] #![allow(clippy::non_canonical_clone_impl)] #![allow(clippy::non_canonical_partial_ord_impl)] @@ -47,6 +50,7 @@ #![allow(invalid_value)] #![allow(invalid_from_utf8_unchecked)] #![allow(let_underscore_drop)] +#![allow(unexpected_cfgs)] #![allow(enum_intrinsics_non_enums)] #![allow(non_fmt_panics)] #![allow(named_arguments_used_positionally)] @@ -55,65 +59,72 @@ #![allow(unknown_lints)] #![allow(unused_labels)] #![allow(ambiguous_wide_pointer_comparisons)] -#![warn(clippy::almost_complete_range)] -#![warn(clippy::disallowed_names)] -#![warn(clippy::blocks_in_conditions)] -#![warn(clippy::blocks_in_conditions)] -#![warn(clippy::blocks_in_conditions)] -#![warn(clippy::box_collection)] -#![warn(clippy::redundant_static_lifetimes)] -#![warn(clippy::cognitive_complexity)] -#![warn(clippy::derived_hash_with_manual_eq)] -#![warn(clippy::disallowed_methods)] -#![warn(clippy::disallowed_types)] -#![warn(clippy::mixed_read_write_in_expression)] -#![warn(clippy::useless_conversion)] -#![warn(clippy::match_result_ok)] -#![warn(clippy::non_canonical_clone_impl)] -#![warn(clippy::non_canonical_partial_ord_impl)] -#![warn(clippy::arithmetic_side_effects)] -#![warn(clippy::overly_complex_bool_expr)] -#![warn(clippy::new_without_default)] -#![warn(clippy::bind_instead_of_map)] -#![warn(clippy::expect_used)] -#![warn(clippy::map_unwrap_or)] -#![warn(clippy::map_unwrap_or)] -#![warn(clippy::unwrap_used)] -#![warn(clippy::panicking_overflow_checks)] -#![warn(clippy::needless_borrow)] -#![warn(clippy::expect_used)] -#![warn(clippy::map_unwrap_or)] -#![warn(clippy::unwrap_used)] -#![warn(clippy::single_char_add_str)] -#![warn(clippy::module_name_repetitions)] -#![warn(clippy::missing_const_for_thread_local)] -#![warn(clippy::recursive_format_impl)] -#![warn(clippy::unwrap_or_default)] -#![warn(clippy::invisible_characters)] -#![warn(invalid_reference_casting)] -#![warn(suspicious_double_ref_op)] -#![warn(invalid_nan_comparisons)] -#![warn(drop_bounds)] -#![warn(dropping_copy_types)] -#![warn(dropping_references)] -#![warn(useless_ptr_null_checks)] -#![warn(for_loops_over_fallibles)] -#![warn(for_loops_over_fallibles)] -#![warn(for_loops_over_fallibles)] -#![warn(forgetting_copy_types)] -#![warn(forgetting_references)] -#![warn(array_into_iter)] -#![warn(invalid_atomic_ordering)] -#![warn(invalid_value)] -#![warn(invalid_from_utf8_unchecked)] -#![warn(let_underscore_drop)] -#![warn(enum_intrinsics_non_enums)] -#![warn(non_fmt_panics)] -#![warn(named_arguments_used_positionally)] -#![warn(temporary_cstring_as_ptr)] -#![warn(undropped_manually_drops)] -#![warn(unknown_lints)] -#![warn(unused_labels)] -#![warn(ambiguous_wide_pointer_comparisons)] +#![allow(clippy::reversed_empty_ranges)] +#![warn(clippy::almost_complete_range)] //~ ERROR: lint `clippy::almost_complete_letter_range` +#![warn(clippy::disallowed_names)] //~ ERROR: lint `clippy::blacklisted_name` +#![warn(clippy::blocks_in_conditions)] //~ ERROR: lint `clippy::block_in_if_condition_expr` +#![warn(clippy::blocks_in_conditions)] //~ ERROR: lint `clippy::block_in_if_condition_stmt` +#![warn(clippy::blocks_in_conditions)] //~ ERROR: lint `clippy::blocks_in_if_conditions` +#![warn(clippy::box_collection)] //~ ERROR: lint `clippy::box_vec` +#![warn(clippy::redundant_static_lifetimes)] //~ ERROR: lint `clippy::const_static_lifetime` +#![warn(clippy::cognitive_complexity)] //~ ERROR: lint `clippy::cyclomatic_complexity` +#![warn(clippy::derived_hash_with_manual_eq)] //~ ERROR: lint `clippy::derive_hash_xor_eq` +#![warn(clippy::disallowed_methods)] //~ ERROR: lint `clippy::disallowed_method` +#![warn(clippy::disallowed_types)] //~ ERROR: lint `clippy::disallowed_type` +#![warn(clippy::mixed_read_write_in_expression)] //~ ERROR: lint `clippy::eval_order_dependence` +#![warn(clippy::manual_find_map)] //~ ERROR: lint `clippy::find_map` +#![warn(clippy::manual_filter_map)] //~ ERROR: lint `clippy::filter_map` +#![warn(clippy::useless_conversion)] //~ ERROR: lint `clippy::identity_conversion` +#![warn(clippy::redundant_pattern_matching)] //~ ERROR: lint `clippy::if_let_redundant_pattern_matching` +#![warn(clippy::match_result_ok)] //~ ERROR: lint `clippy::if_let_some_result` +#![warn(clippy::non_canonical_clone_impl)] //~ ERROR: lint `clippy::incorrect_clone_impl_on_copy_type` +#![warn(clippy::non_canonical_partial_ord_impl)] //~ ERROR: lint `clippy::incorrect_partial_ord_impl_on_ord_type` +#![warn(clippy::arithmetic_side_effects)] //~ ERROR: lint `clippy::integer_arithmetic` +#![warn(clippy::overly_complex_bool_expr)] //~ ERROR: lint `clippy::logic_bug` +#![warn(clippy::new_without_default)] //~ ERROR: lint `clippy::new_without_default_derive` +#![warn(clippy::bind_instead_of_map)] //~ ERROR: lint `clippy::option_and_then_some` +#![warn(clippy::expect_used)] //~ ERROR: lint `clippy::option_expect_used` +#![warn(clippy::map_unwrap_or)] //~ ERROR: lint `clippy::option_map_unwrap_or` +#![warn(clippy::map_unwrap_or)] //~ ERROR: lint `clippy::option_map_unwrap_or_else` +#![warn(clippy::unwrap_used)] //~ ERROR: lint `clippy::option_unwrap_used` +#![warn(clippy::panicking_overflow_checks)] //~ ERROR: lint `clippy::overflow_check_conditional` +#![warn(clippy::needless_borrow)] //~ ERROR: lint `clippy::ref_in_deref` +#![warn(clippy::expect_used)] //~ ERROR: lint `clippy::result_expect_used` +#![warn(clippy::map_unwrap_or)] //~ ERROR: lint `clippy::result_map_unwrap_or_else` +#![warn(clippy::unwrap_used)] //~ ERROR: lint `clippy::result_unwrap_used` +#![warn(clippy::single_char_add_str)] //~ ERROR: lint `clippy::single_char_push_str` +#![warn(clippy::module_name_repetitions)] //~ ERROR: lint `clippy::stutter` +#![warn(clippy::missing_const_for_thread_local)] //~ ERROR: lint `clippy::thread_local_initializer_can_be_made_const` +#![warn(clippy::recursive_format_impl)] //~ ERROR: lint `clippy::to_string_in_display` +#![warn(clippy::unwrap_or_default)] //~ ERROR: lint `clippy::unwrap_or_else_default` +#![warn(clippy::invisible_characters)] //~ ERROR: lint `clippy::zero_width_space` +#![warn(invalid_reference_casting)] //~ ERROR: lint `clippy::cast_ref_to_mut` +#![warn(suspicious_double_ref_op)] //~ ERROR: lint `clippy::clone_double_ref` +#![warn(invalid_nan_comparisons)] //~ ERROR: lint `clippy::cmp_nan` +#![warn(drop_bounds)] //~ ERROR: lint `clippy::drop_bounds` +#![warn(dropping_copy_types)] //~ ERROR: lint `clippy::drop_copy` +#![warn(dropping_references)] //~ ERROR: lint `clippy::drop_ref` +#![warn(useless_ptr_null_checks)] //~ ERROR: lint `clippy::fn_null_check` +#![warn(for_loops_over_fallibles)] //~ ERROR: lint `clippy::for_loop_over_option` +#![warn(for_loops_over_fallibles)] //~ ERROR: lint `clippy::for_loop_over_result` +#![warn(for_loops_over_fallibles)] //~ ERROR: lint `clippy::for_loops_over_fallibles` +#![warn(forgetting_copy_types)] //~ ERROR: lint `clippy::forget_copy` +#![warn(forgetting_references)] //~ ERROR: lint `clippy::forget_ref` +#![warn(array_into_iter)] //~ ERROR: lint `clippy::into_iter_on_array` +#![warn(invalid_atomic_ordering)] //~ ERROR: lint `clippy::invalid_atomic_ordering` +#![warn(invalid_value)] //~ ERROR: lint `clippy::invalid_ref` +#![warn(invalid_from_utf8_unchecked)] //~ ERROR: lint `clippy::invalid_utf8_in_unchecked` +#![warn(let_underscore_drop)] //~ ERROR: lint `clippy::let_underscore_drop` +#![warn(unexpected_cfgs)] //~ ERROR: lint `clippy::maybe_misused_cfg` +#![warn(enum_intrinsics_non_enums)] //~ ERROR: lint `clippy::mem_discriminant_non_enum` +#![warn(unexpected_cfgs)] //~ ERROR: lint `clippy::mismatched_target_os` +#![warn(non_fmt_panics)] //~ ERROR: lint `clippy::panic_params` +#![warn(named_arguments_used_positionally)] //~ ERROR: lint `clippy::positional_named_format_parameters` +#![warn(temporary_cstring_as_ptr)] //~ ERROR: lint `clippy::temporary_cstring_as_ptr` +#![warn(undropped_manually_drops)] //~ ERROR: lint `clippy::undropped_manually_drops` +#![warn(unknown_lints)] //~ ERROR: lint `clippy::unknown_clippy_lints` +#![warn(unused_labels)] //~ ERROR: lint `clippy::unused_label` +#![warn(ambiguous_wide_pointer_comparisons)] //~ ERROR: lint `clippy::vtable_address_comparisons` +#![warn(clippy::reversed_empty_ranges)] //~ ERROR: lint `clippy::reverse_range_loop` fn main() {} diff --git a/src/tools/clippy/tests/ui/rename.rs b/src/tools/clippy/tests/ui/rename.rs index 8d0ac3c8f95..e03df1658ee 100644 --- a/src/tools/clippy/tests/ui/rename.rs +++ b/src/tools/clippy/tests/ui/rename.rs @@ -13,7 +13,10 @@ #![allow(clippy::disallowed_methods)] #![allow(clippy::disallowed_types)] #![allow(clippy::mixed_read_write_in_expression)] +#![allow(clippy::manual_find_map)] +#![allow(clippy::manual_filter_map)] #![allow(clippy::useless_conversion)] +#![allow(clippy::redundant_pattern_matching)] #![allow(clippy::match_result_ok)] #![allow(clippy::non_canonical_clone_impl)] #![allow(clippy::non_canonical_partial_ord_impl)] @@ -47,6 +50,7 @@ #![allow(invalid_value)] #![allow(invalid_from_utf8_unchecked)] #![allow(let_underscore_drop)] +#![allow(unexpected_cfgs)] #![allow(enum_intrinsics_non_enums)] #![allow(non_fmt_panics)] #![allow(named_arguments_used_positionally)] @@ -55,65 +59,72 @@ #![allow(unknown_lints)] #![allow(unused_labels)] #![allow(ambiguous_wide_pointer_comparisons)] -#![warn(clippy::almost_complete_letter_range)] -#![warn(clippy::blacklisted_name)] -#![warn(clippy::block_in_if_condition_expr)] -#![warn(clippy::block_in_if_condition_stmt)] -#![warn(clippy::blocks_in_if_conditions)] -#![warn(clippy::box_vec)] -#![warn(clippy::const_static_lifetime)] -#![warn(clippy::cyclomatic_complexity)] -#![warn(clippy::derive_hash_xor_eq)] -#![warn(clippy::disallowed_method)] -#![warn(clippy::disallowed_type)] -#![warn(clippy::eval_order_dependence)] -#![warn(clippy::identity_conversion)] -#![warn(clippy::if_let_some_result)] -#![warn(clippy::incorrect_clone_impl_on_copy_type)] -#![warn(clippy::incorrect_partial_ord_impl_on_ord_type)] -#![warn(clippy::integer_arithmetic)] -#![warn(clippy::logic_bug)] -#![warn(clippy::new_without_default_derive)] -#![warn(clippy::option_and_then_some)] -#![warn(clippy::option_expect_used)] -#![warn(clippy::option_map_unwrap_or)] -#![warn(clippy::option_map_unwrap_or_else)] -#![warn(clippy::option_unwrap_used)] -#![warn(clippy::overflow_check_conditional)] -#![warn(clippy::ref_in_deref)] -#![warn(clippy::result_expect_used)] -#![warn(clippy::result_map_unwrap_or_else)] -#![warn(clippy::result_unwrap_used)] -#![warn(clippy::single_char_push_str)] -#![warn(clippy::stutter)] -#![warn(clippy::thread_local_initializer_can_be_made_const)] -#![warn(clippy::to_string_in_display)] -#![warn(clippy::unwrap_or_else_default)] -#![warn(clippy::zero_width_space)] -#![warn(clippy::cast_ref_to_mut)] -#![warn(clippy::clone_double_ref)] -#![warn(clippy::cmp_nan)] -#![warn(clippy::drop_bounds)] -#![warn(clippy::drop_copy)] -#![warn(clippy::drop_ref)] -#![warn(clippy::fn_null_check)] -#![warn(clippy::for_loop_over_option)] -#![warn(clippy::for_loop_over_result)] -#![warn(clippy::for_loops_over_fallibles)] -#![warn(clippy::forget_copy)] -#![warn(clippy::forget_ref)] -#![warn(clippy::into_iter_on_array)] -#![warn(clippy::invalid_atomic_ordering)] -#![warn(clippy::invalid_ref)] -#![warn(clippy::invalid_utf8_in_unchecked)] -#![warn(clippy::let_underscore_drop)] -#![warn(clippy::mem_discriminant_non_enum)] -#![warn(clippy::panic_params)] -#![warn(clippy::positional_named_format_parameters)] -#![warn(clippy::temporary_cstring_as_ptr)] -#![warn(clippy::undropped_manually_drops)] -#![warn(clippy::unknown_clippy_lints)] -#![warn(clippy::unused_label)] -#![warn(clippy::vtable_address_comparisons)] +#![allow(clippy::reversed_empty_ranges)] +#![warn(clippy::almost_complete_letter_range)] //~ ERROR: lint `clippy::almost_complete_letter_range` +#![warn(clippy::blacklisted_name)] //~ ERROR: lint `clippy::blacklisted_name` +#![warn(clippy::block_in_if_condition_expr)] //~ ERROR: lint `clippy::block_in_if_condition_expr` +#![warn(clippy::block_in_if_condition_stmt)] //~ ERROR: lint `clippy::block_in_if_condition_stmt` +#![warn(clippy::blocks_in_if_conditions)] //~ ERROR: lint `clippy::blocks_in_if_conditions` +#![warn(clippy::box_vec)] //~ ERROR: lint `clippy::box_vec` +#![warn(clippy::const_static_lifetime)] //~ ERROR: lint `clippy::const_static_lifetime` +#![warn(clippy::cyclomatic_complexity)] //~ ERROR: lint `clippy::cyclomatic_complexity` +#![warn(clippy::derive_hash_xor_eq)] //~ ERROR: lint `clippy::derive_hash_xor_eq` +#![warn(clippy::disallowed_method)] //~ ERROR: lint `clippy::disallowed_method` +#![warn(clippy::disallowed_type)] //~ ERROR: lint `clippy::disallowed_type` +#![warn(clippy::eval_order_dependence)] //~ ERROR: lint `clippy::eval_order_dependence` +#![warn(clippy::find_map)] //~ ERROR: lint `clippy::find_map` +#![warn(clippy::filter_map)] //~ ERROR: lint `clippy::filter_map` +#![warn(clippy::identity_conversion)] //~ ERROR: lint `clippy::identity_conversion` +#![warn(clippy::if_let_redundant_pattern_matching)] //~ ERROR: lint `clippy::if_let_redundant_pattern_matching` +#![warn(clippy::if_let_some_result)] //~ ERROR: lint `clippy::if_let_some_result` +#![warn(clippy::incorrect_clone_impl_on_copy_type)] //~ ERROR: lint `clippy::incorrect_clone_impl_on_copy_type` +#![warn(clippy::incorrect_partial_ord_impl_on_ord_type)] //~ ERROR: lint `clippy::incorrect_partial_ord_impl_on_ord_type` +#![warn(clippy::integer_arithmetic)] //~ ERROR: lint `clippy::integer_arithmetic` +#![warn(clippy::logic_bug)] //~ ERROR: lint `clippy::logic_bug` +#![warn(clippy::new_without_default_derive)] //~ ERROR: lint `clippy::new_without_default_derive` +#![warn(clippy::option_and_then_some)] //~ ERROR: lint `clippy::option_and_then_some` +#![warn(clippy::option_expect_used)] //~ ERROR: lint `clippy::option_expect_used` +#![warn(clippy::option_map_unwrap_or)] //~ ERROR: lint `clippy::option_map_unwrap_or` +#![warn(clippy::option_map_unwrap_or_else)] //~ ERROR: lint `clippy::option_map_unwrap_or_else` +#![warn(clippy::option_unwrap_used)] //~ ERROR: lint `clippy::option_unwrap_used` +#![warn(clippy::overflow_check_conditional)] //~ ERROR: lint `clippy::overflow_check_conditional` +#![warn(clippy::ref_in_deref)] //~ ERROR: lint `clippy::ref_in_deref` +#![warn(clippy::result_expect_used)] //~ ERROR: lint `clippy::result_expect_used` +#![warn(clippy::result_map_unwrap_or_else)] //~ ERROR: lint `clippy::result_map_unwrap_or_else` +#![warn(clippy::result_unwrap_used)] //~ ERROR: lint `clippy::result_unwrap_used` +#![warn(clippy::single_char_push_str)] //~ ERROR: lint `clippy::single_char_push_str` +#![warn(clippy::stutter)] //~ ERROR: lint `clippy::stutter` +#![warn(clippy::thread_local_initializer_can_be_made_const)] //~ ERROR: lint `clippy::thread_local_initializer_can_be_made_const` +#![warn(clippy::to_string_in_display)] //~ ERROR: lint `clippy::to_string_in_display` +#![warn(clippy::unwrap_or_else_default)] //~ ERROR: lint `clippy::unwrap_or_else_default` +#![warn(clippy::zero_width_space)] //~ ERROR: lint `clippy::zero_width_space` +#![warn(clippy::cast_ref_to_mut)] //~ ERROR: lint `clippy::cast_ref_to_mut` +#![warn(clippy::clone_double_ref)] //~ ERROR: lint `clippy::clone_double_ref` +#![warn(clippy::cmp_nan)] //~ ERROR: lint `clippy::cmp_nan` +#![warn(clippy::drop_bounds)] //~ ERROR: lint `clippy::drop_bounds` +#![warn(clippy::drop_copy)] //~ ERROR: lint `clippy::drop_copy` +#![warn(clippy::drop_ref)] //~ ERROR: lint `clippy::drop_ref` +#![warn(clippy::fn_null_check)] //~ ERROR: lint `clippy::fn_null_check` +#![warn(clippy::for_loop_over_option)] //~ ERROR: lint `clippy::for_loop_over_option` +#![warn(clippy::for_loop_over_result)] //~ ERROR: lint `clippy::for_loop_over_result` +#![warn(clippy::for_loops_over_fallibles)] //~ ERROR: lint `clippy::for_loops_over_fallibles` +#![warn(clippy::forget_copy)] //~ ERROR: lint `clippy::forget_copy` +#![warn(clippy::forget_ref)] //~ ERROR: lint `clippy::forget_ref` +#![warn(clippy::into_iter_on_array)] //~ ERROR: lint `clippy::into_iter_on_array` +#![warn(clippy::invalid_atomic_ordering)] //~ ERROR: lint `clippy::invalid_atomic_ordering` +#![warn(clippy::invalid_ref)] //~ ERROR: lint `clippy::invalid_ref` +#![warn(clippy::invalid_utf8_in_unchecked)] //~ ERROR: lint `clippy::invalid_utf8_in_unchecked` +#![warn(clippy::let_underscore_drop)] //~ ERROR: lint `clippy::let_underscore_drop` +#![warn(clippy::maybe_misused_cfg)] //~ ERROR: lint `clippy::maybe_misused_cfg` +#![warn(clippy::mem_discriminant_non_enum)] //~ ERROR: lint `clippy::mem_discriminant_non_enum` +#![warn(clippy::mismatched_target_os)] //~ ERROR: lint `clippy::mismatched_target_os` +#![warn(clippy::panic_params)] //~ ERROR: lint `clippy::panic_params` +#![warn(clippy::positional_named_format_parameters)] //~ ERROR: lint `clippy::positional_named_format_parameters` +#![warn(clippy::temporary_cstring_as_ptr)] //~ ERROR: lint `clippy::temporary_cstring_as_ptr` +#![warn(clippy::undropped_manually_drops)] //~ ERROR: lint `clippy::undropped_manually_drops` +#![warn(clippy::unknown_clippy_lints)] //~ ERROR: lint `clippy::unknown_clippy_lints` +#![warn(clippy::unused_label)] //~ ERROR: lint `clippy::unused_label` +#![warn(clippy::vtable_address_comparisons)] //~ ERROR: lint `clippy::vtable_address_comparisons` +#![warn(clippy::reverse_range_loop)] //~ ERROR: lint `clippy::reverse_range_loop` fn main() {} diff --git a/src/tools/clippy/tests/ui/rename.stderr b/src/tools/clippy/tests/ui/rename.stderr index d6637324a03..46d9f0fac59 100644 --- a/src/tools/clippy/tests/ui/rename.stderr +++ b/src/tools/clippy/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> tests/ui/rename.rs:58:9 + --> tests/ui/rename.rs:63:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -8,358 +8,394 @@ LL | #![warn(clippy::almost_complete_letter_range)] = help: to override `-D warnings` add `#[allow(renamed_and_removed_lints)]` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> tests/ui/rename.rs:59:9 + --> tests/ui/rename.rs:64:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_conditions` - --> tests/ui/rename.rs:60:9 + --> tests/ui/rename.rs:65:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_conditions` - --> tests/ui/rename.rs:61:9 + --> tests/ui/rename.rs:66:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_conditions` error: lint `clippy::blocks_in_if_conditions` has been renamed to `clippy::blocks_in_conditions` - --> tests/ui/rename.rs:62:9 + --> tests/ui/rename.rs:67:9 | LL | #![warn(clippy::blocks_in_if_conditions)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> tests/ui/rename.rs:63:9 + --> tests/ui/rename.rs:68:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> tests/ui/rename.rs:64:9 + --> tests/ui/rename.rs:69:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> tests/ui/rename.rs:65:9 + --> tests/ui/rename.rs:70:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> tests/ui/rename.rs:66:9 + --> tests/ui/rename.rs:71:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> tests/ui/rename.rs:67:9 + --> tests/ui/rename.rs:72:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> tests/ui/rename.rs:68:9 + --> tests/ui/rename.rs:73:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> tests/ui/rename.rs:69:9 + --> tests/ui/rename.rs:74:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` +error: lint `clippy::find_map` has been renamed to `clippy::manual_find_map` + --> tests/ui/rename.rs:75:9 + | +LL | #![warn(clippy::find_map)] + | ^^^^^^^^^^^^^^^^ help: use the new name: `clippy::manual_find_map` + +error: lint `clippy::filter_map` has been renamed to `clippy::manual_filter_map` + --> tests/ui/rename.rs:76:9 + | +LL | #![warn(clippy::filter_map)] + | ^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::manual_filter_map` + error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> tests/ui/rename.rs:70:9 + --> tests/ui/rename.rs:77:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` +error: lint `clippy::if_let_redundant_pattern_matching` has been renamed to `clippy::redundant_pattern_matching` + --> tests/ui/rename.rs:78:9 + | +LL | #![warn(clippy::if_let_redundant_pattern_matching)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_pattern_matching` + error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> tests/ui/rename.rs:71:9 + --> tests/ui/rename.rs:79:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::incorrect_clone_impl_on_copy_type` has been renamed to `clippy::non_canonical_clone_impl` - --> tests/ui/rename.rs:72:9 + --> tests/ui/rename.rs:80:9 | LL | #![warn(clippy::incorrect_clone_impl_on_copy_type)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::non_canonical_clone_impl` error: lint `clippy::incorrect_partial_ord_impl_on_ord_type` has been renamed to `clippy::non_canonical_partial_ord_impl` - --> tests/ui/rename.rs:73:9 + --> tests/ui/rename.rs:81:9 | LL | #![warn(clippy::incorrect_partial_ord_impl_on_ord_type)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::non_canonical_partial_ord_impl` error: lint `clippy::integer_arithmetic` has been renamed to `clippy::arithmetic_side_effects` - --> tests/ui/rename.rs:74:9 + --> tests/ui/rename.rs:82:9 | LL | #![warn(clippy::integer_arithmetic)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::arithmetic_side_effects` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> tests/ui/rename.rs:75:9 + --> tests/ui/rename.rs:83:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> tests/ui/rename.rs:76:9 + --> tests/ui/rename.rs:84:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> tests/ui/rename.rs:77:9 + --> tests/ui/rename.rs:85:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> tests/ui/rename.rs:78:9 + --> tests/ui/rename.rs:86:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> tests/ui/rename.rs:79:9 + --> tests/ui/rename.rs:87:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> tests/ui/rename.rs:80:9 + --> tests/ui/rename.rs:88:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> tests/ui/rename.rs:81:9 + --> tests/ui/rename.rs:89:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::overflow_check_conditional` has been renamed to `clippy::panicking_overflow_checks` - --> tests/ui/rename.rs:82:9 + --> tests/ui/rename.rs:90:9 | LL | #![warn(clippy::overflow_check_conditional)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::panicking_overflow_checks` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> tests/ui/rename.rs:83:9 + --> tests/ui/rename.rs:91:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> tests/ui/rename.rs:84:9 + --> tests/ui/rename.rs:92:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> tests/ui/rename.rs:85:9 + --> tests/ui/rename.rs:93:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> tests/ui/rename.rs:86:9 + --> tests/ui/rename.rs:94:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> tests/ui/rename.rs:87:9 + --> tests/ui/rename.rs:95:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> tests/ui/rename.rs:88:9 + --> tests/ui/rename.rs:96:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::thread_local_initializer_can_be_made_const` has been renamed to `clippy::missing_const_for_thread_local` - --> tests/ui/rename.rs:89:9 + --> tests/ui/rename.rs:97:9 | LL | #![warn(clippy::thread_local_initializer_can_be_made_const)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::missing_const_for_thread_local` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> tests/ui/rename.rs:90:9 + --> tests/ui/rename.rs:98:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::unwrap_or_else_default` has been renamed to `clippy::unwrap_or_default` - --> tests/ui/rename.rs:91:9 + --> tests/ui/rename.rs:99:9 | LL | #![warn(clippy::unwrap_or_else_default)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_or_default` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> tests/ui/rename.rs:92:9 + --> tests/ui/rename.rs:100:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` error: lint `clippy::cast_ref_to_mut` has been renamed to `invalid_reference_casting` - --> tests/ui/rename.rs:93:9 + --> tests/ui/rename.rs:101:9 | LL | #![warn(clippy::cast_ref_to_mut)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_reference_casting` error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op` - --> tests/ui/rename.rs:94:9 + --> tests/ui/rename.rs:102:9 | LL | #![warn(clippy::clone_double_ref)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op` error: lint `clippy::cmp_nan` has been renamed to `invalid_nan_comparisons` - --> tests/ui/rename.rs:95:9 + --> tests/ui/rename.rs:103:9 | LL | #![warn(clippy::cmp_nan)] | ^^^^^^^^^^^^^^^ help: use the new name: `invalid_nan_comparisons` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> tests/ui/rename.rs:96:9 + --> tests/ui/rename.rs:104:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` error: lint `clippy::drop_copy` has been renamed to `dropping_copy_types` - --> tests/ui/rename.rs:97:9 + --> tests/ui/rename.rs:105:9 | LL | #![warn(clippy::drop_copy)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `dropping_copy_types` error: lint `clippy::drop_ref` has been renamed to `dropping_references` - --> tests/ui/rename.rs:98:9 + --> tests/ui/rename.rs:106:9 | LL | #![warn(clippy::drop_ref)] | ^^^^^^^^^^^^^^^^ help: use the new name: `dropping_references` error: lint `clippy::fn_null_check` has been renamed to `useless_ptr_null_checks` - --> tests/ui/rename.rs:99:9 + --> tests/ui/rename.rs:107:9 | LL | #![warn(clippy::fn_null_check)] | ^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `useless_ptr_null_checks` error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> tests/ui/rename.rs:100:9 + --> tests/ui/rename.rs:108:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> tests/ui/rename.rs:101:9 + --> tests/ui/rename.rs:109:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> tests/ui/rename.rs:102:9 + --> tests/ui/rename.rs:110:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::forget_copy` has been renamed to `forgetting_copy_types` - --> tests/ui/rename.rs:103:9 + --> tests/ui/rename.rs:111:9 | LL | #![warn(clippy::forget_copy)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_copy_types` error: lint `clippy::forget_ref` has been renamed to `forgetting_references` - --> tests/ui/rename.rs:104:9 + --> tests/ui/rename.rs:112:9 | LL | #![warn(clippy::forget_ref)] | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> tests/ui/rename.rs:105:9 + --> tests/ui/rename.rs:113:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> tests/ui/rename.rs:106:9 + --> tests/ui/rename.rs:114:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> tests/ui/rename.rs:107:9 + --> tests/ui/rename.rs:115:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::invalid_utf8_in_unchecked` has been renamed to `invalid_from_utf8_unchecked` - --> tests/ui/rename.rs:108:9 + --> tests/ui/rename.rs:116:9 | LL | #![warn(clippy::invalid_utf8_in_unchecked)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_from_utf8_unchecked` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> tests/ui/rename.rs:109:9 + --> tests/ui/rename.rs:117:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` +error: lint `clippy::maybe_misused_cfg` has been renamed to `unexpected_cfgs` + --> tests/ui/rename.rs:118:9 + | +LL | #![warn(clippy::maybe_misused_cfg)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unexpected_cfgs` + error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> tests/ui/rename.rs:110:9 + --> tests/ui/rename.rs:119:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` +error: lint `clippy::mismatched_target_os` has been renamed to `unexpected_cfgs` + --> tests/ui/rename.rs:120:9 + | +LL | #![warn(clippy::mismatched_target_os)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unexpected_cfgs` + error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> tests/ui/rename.rs:111:9 + --> tests/ui/rename.rs:121:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> tests/ui/rename.rs:112:9 + --> tests/ui/rename.rs:122:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> tests/ui/rename.rs:113:9 + --> tests/ui/rename.rs:123:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::undropped_manually_drops` has been renamed to `undropped_manually_drops` - --> tests/ui/rename.rs:114:9 + --> tests/ui/rename.rs:124:9 | LL | #![warn(clippy::undropped_manually_drops)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `undropped_manually_drops` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> tests/ui/rename.rs:115:9 + --> tests/ui/rename.rs:125:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> tests/ui/rename.rs:116:9 + --> tests/ui/rename.rs:126:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` error: lint `clippy::vtable_address_comparisons` has been renamed to `ambiguous_wide_pointer_comparisons` - --> tests/ui/rename.rs:117:9 + --> tests/ui/rename.rs:127:9 | LL | #![warn(clippy::vtable_address_comparisons)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `ambiguous_wide_pointer_comparisons` -error: aborting due to 60 previous errors +error: lint `clippy::reverse_range_loop` has been renamed to `clippy::reversed_empty_ranges` + --> tests/ui/rename.rs:128:9 + | +LL | #![warn(clippy::reverse_range_loop)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::reversed_empty_ranges` + +error: aborting due to 66 previous errors diff --git a/src/tools/clippy/tests/ui/set_contains_or_insert.rs b/src/tools/clippy/tests/ui/set_contains_or_insert.rs index 8465007402a..d3a3e1c878b 100644 --- a/src/tools/clippy/tests/ui/set_contains_or_insert.rs +++ b/src/tools/clippy/tests/ui/set_contains_or_insert.rs @@ -3,17 +3,78 @@ #![allow(clippy::needless_borrow)] #![warn(clippy::set_contains_or_insert)] -use std::collections::HashSet; +use std::collections::{BTreeSet, HashSet}; -fn main() { - should_warn_cases(); +fn should_warn_hashset() { + let mut set = HashSet::new(); + let value = 5; + + if !set.contains(&value) { + set.insert(value); + println!("Just a comment"); + } + + if set.contains(&value) { + set.insert(value); + println!("Just a comment"); + } + + if !set.contains(&value) { + set.insert(value); + } - should_not_warn_cases(); + if !!set.contains(&value) { + set.insert(value); + println!("Just a comment"); + } + + if (&set).contains(&value) { + set.insert(value); + } + + let borrow_value = &6; + if !set.contains(borrow_value) { + set.insert(*borrow_value); + } + + let borrow_set = &mut set; + if !borrow_set.contains(&value) { + borrow_set.insert(value); + } } -fn should_warn_cases() { +fn should_not_warn_hashset() { let mut set = HashSet::new(); let value = 5; + let another_value = 6; + + if !set.contains(&value) { + set.insert(another_value); + } + + if !set.contains(&value) { + println!("Just a comment"); + } + + if simply_true() { + set.insert(value); + } + + if !set.contains(&value) { + set.replace(value); //it is not insert + println!("Just a comment"); + } + + if set.contains(&value) { + println!("value is already in set"); + } else { + set.insert(value); + } +} + +fn should_warn_btreeset() { + let mut set = BTreeSet::new(); + let value = 5; if !set.contains(&value) { set.insert(value); @@ -49,8 +110,8 @@ fn should_warn_cases() { } } -fn should_not_warn_cases() { - let mut set = HashSet::new(); +fn should_not_warn_btreeset() { + let mut set = BTreeSet::new(); let value = 5; let another_value = 6; @@ -81,3 +142,11 @@ fn should_not_warn_cases() { fn simply_true() -> bool { true } + +// This is placed last in order to be able to add new tests without changing line numbers +fn main() { + should_warn_hashset(); + should_warn_btreeset(); + should_not_warn_hashset(); + should_not_warn_btreeset(); +} diff --git a/src/tools/clippy/tests/ui/set_contains_or_insert.stderr b/src/tools/clippy/tests/ui/set_contains_or_insert.stderr index 507e20964fc..14ad6300544 100644 --- a/src/tools/clippy/tests/ui/set_contains_or_insert.stderr +++ b/src/tools/clippy/tests/ui/set_contains_or_insert.stderr @@ -1,5 +1,5 @@ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:18:13 + --> tests/ui/set_contains_or_insert.rs:12:13 | LL | if !set.contains(&value) { | ^^^^^^^^^^^^^^^^ @@ -10,7 +10,7 @@ LL | set.insert(value); = help: to override `-D warnings` add `#[allow(clippy::set_contains_or_insert)]` error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:23:12 + --> tests/ui/set_contains_or_insert.rs:17:12 | LL | if set.contains(&value) { | ^^^^^^^^^^^^^^^^ @@ -18,7 +18,7 @@ LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:28:13 + --> tests/ui/set_contains_or_insert.rs:22:13 | LL | if !set.contains(&value) { | ^^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:32:14 + --> tests/ui/set_contains_or_insert.rs:26:14 | LL | if !!set.contains(&value) { | ^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:37:15 + --> tests/ui/set_contains_or_insert.rs:31:15 | LL | if (&set).contains(&value) { | ^^^^^^^^^^^^^^^^ @@ -42,7 +42,7 @@ LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:42:13 + --> tests/ui/set_contains_or_insert.rs:36:13 | LL | if !set.contains(borrow_value) { | ^^^^^^^^^^^^^^^^^^^^^^ @@ -50,12 +50,68 @@ LL | set.insert(*borrow_value); | ^^^^^^^^^^^^^^^^^^^^^ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:47:20 + --> tests/ui/set_contains_or_insert.rs:41:20 | LL | if !borrow_set.contains(&value) { | ^^^^^^^^^^^^^^^^ LL | borrow_set.insert(value); | ^^^^^^^^^^^^^ -error: aborting due to 7 previous errors +error: usage of `BTreeSet::insert` after `BTreeSet::contains` + --> tests/ui/set_contains_or_insert.rs:79:13 + | +LL | if !set.contains(&value) { + | ^^^^^^^^^^^^^^^^ +LL | set.insert(value); + | ^^^^^^^^^^^^^ + +error: usage of `BTreeSet::insert` after `BTreeSet::contains` + --> tests/ui/set_contains_or_insert.rs:84:12 + | +LL | if set.contains(&value) { + | ^^^^^^^^^^^^^^^^ +LL | set.insert(value); + | ^^^^^^^^^^^^^ + +error: usage of `BTreeSet::insert` after `BTreeSet::contains` + --> tests/ui/set_contains_or_insert.rs:89:13 + | +LL | if !set.contains(&value) { + | ^^^^^^^^^^^^^^^^ +LL | set.insert(value); + | ^^^^^^^^^^^^^ + +error: usage of `BTreeSet::insert` after `BTreeSet::contains` + --> tests/ui/set_contains_or_insert.rs:93:14 + | +LL | if !!set.contains(&value) { + | ^^^^^^^^^^^^^^^^ +LL | set.insert(value); + | ^^^^^^^^^^^^^ + +error: usage of `BTreeSet::insert` after `BTreeSet::contains` + --> tests/ui/set_contains_or_insert.rs:98:15 + | +LL | if (&set).contains(&value) { + | ^^^^^^^^^^^^^^^^ +LL | set.insert(value); + | ^^^^^^^^^^^^^ + +error: usage of `BTreeSet::insert` after `BTreeSet::contains` + --> tests/ui/set_contains_or_insert.rs:103:13 + | +LL | if !set.contains(borrow_value) { + | ^^^^^^^^^^^^^^^^^^^^^^ +LL | set.insert(*borrow_value); + | ^^^^^^^^^^^^^^^^^^^^^ + +error: usage of `BTreeSet::insert` after `BTreeSet::contains` + --> tests/ui/set_contains_or_insert.rs:108:20 + | +LL | if !borrow_set.contains(&value) { + | ^^^^^^^^^^^^^^^^ +LL | borrow_set.insert(value); + | ^^^^^^^^^^^^^ + +error: aborting due to 14 previous errors diff --git a/src/tools/clippy/tests/ui/single_match.fixed b/src/tools/clippy/tests/ui/single_match.fixed index acd70416d8b..5249c440889 100644 --- a/src/tools/clippy/tests/ui/single_match.fixed +++ b/src/tools/clippy/tests/ui/single_match.fixed @@ -253,3 +253,46 @@ mod issue8634 { } } } + +fn issue11365() { + enum Foo { + A, + B, + C, + } + use Foo::{A, B, C}; + + match Some(A) { + Some(A | B | C) => println!(), + None => {}, + } + + match Some(A) { + Some(A | B) => println!(), + Some { 0: C } | None => {}, + } + + match [A, A] { + [A, _] => println!(), + [_, A | B | C] => {}, + } + + match Ok::<_, u32>(Some(A)) { + Ok(Some(A)) => println!(), + Err(_) | Ok(None | Some(B | C)) => {}, + } + + if let Ok(Some(A)) = Ok::<_, u32>(Some(A)) { println!() } + + match &Some(A) { + Some(A | B | C) => println!(), + None => {}, + } + + match &Some(A) { + &Some(A | B | C) => println!(), + None => {}, + } + + if let Some(A | B) = &Some(A) { println!() } +} diff --git a/src/tools/clippy/tests/ui/single_match.rs b/src/tools/clippy/tests/ui/single_match.rs index bde78199810..882098a56e7 100644 --- a/src/tools/clippy/tests/ui/single_match.rs +++ b/src/tools/clippy/tests/ui/single_match.rs @@ -311,3 +311,52 @@ mod issue8634 { } } } + +fn issue11365() { + enum Foo { + A, + B, + C, + } + use Foo::{A, B, C}; + + match Some(A) { + Some(A | B | C) => println!(), + None => {}, + } + + match Some(A) { + Some(A | B) => println!(), + Some { 0: C } | None => {}, + } + + match [A, A] { + [A, _] => println!(), + [_, A | B | C] => {}, + } + + match Ok::<_, u32>(Some(A)) { + Ok(Some(A)) => println!(), + Err(_) | Ok(None | Some(B | C)) => {}, + } + + match Ok::<_, u32>(Some(A)) { + Ok(Some(A)) => println!(), + Err(_) | Ok(None | Some(_)) => {}, + } + + match &Some(A) { + Some(A | B | C) => println!(), + None => {}, + } + + match &Some(A) { + &Some(A | B | C) => println!(), + None => {}, + } + + match &Some(A) { + Some(A | B) => println!(), + None | Some(_) => {}, + } +} diff --git a/src/tools/clippy/tests/ui/single_match.stderr b/src/tools/clippy/tests/ui/single_match.stderr index a249c120ee4..ceb2a193bf7 100644 --- a/src/tools/clippy/tests/ui/single_match.stderr +++ b/src/tools/clippy/tests/ui/single_match.stderr @@ -198,5 +198,23 @@ LL + } LL + } | -error: aborting due to 18 previous errors +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match.rs:343:5 + | +LL | / match Ok::<_, u32>(Some(A)) { +LL | | Ok(Some(A)) => println!(), +LL | | Err(_) | Ok(None | Some(_)) => {}, +LL | | } + | |_____^ help: try: `if let Ok(Some(A)) = Ok::<_, u32>(Some(A)) { println!() }` + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match.rs:358:5 + | +LL | / match &Some(A) { +LL | | Some(A | B) => println!(), +LL | | None | Some(_) => {}, +LL | | } + | |_____^ help: try: `if let Some(A | B) = &Some(A) { println!() }` + +error: aborting due to 20 previous errors diff --git a/src/tools/clippy/tests/ui/std_instead_of_core.fixed b/src/tools/clippy/tests/ui/std_instead_of_core.fixed index 6ede7bfcd9f..227b98c683e 100644 --- a/src/tools/clippy/tests/ui/std_instead_of_core.fixed +++ b/src/tools/clippy/tests/ui/std_instead_of_core.fixed @@ -75,8 +75,17 @@ mod std_in_proc_macro_derive { struct B {} } -fn main() { - std_instead_of_core(); - std_instead_of_alloc(); - alloc_instead_of_core(); +// Some intrinsics are usable on stable but live in an unstable module, but should still suggest +// replacing std -> core +fn intrinsic(a: *mut u8, b: *mut u8) { + unsafe { + core::intrinsics::copy(a, b, 1); + //~^ std_instead_of_core + } } + +#[clippy::msrv = "1.76"] +fn msrv_1_76(_: std::net::IpAddr) {} + +#[clippy::msrv = "1.77"] +fn msrv_1_77(_: core::net::IpAddr) {} diff --git a/src/tools/clippy/tests/ui/std_instead_of_core.rs b/src/tools/clippy/tests/ui/std_instead_of_core.rs index e22b4f61f3e..01bb78dd3bf 100644 --- a/src/tools/clippy/tests/ui/std_instead_of_core.rs +++ b/src/tools/clippy/tests/ui/std_instead_of_core.rs @@ -75,8 +75,17 @@ mod std_in_proc_macro_derive { struct B {} } -fn main() { - std_instead_of_core(); - std_instead_of_alloc(); - alloc_instead_of_core(); +// Some intrinsics are usable on stable but live in an unstable module, but should still suggest +// replacing std -> core +fn intrinsic(a: *mut u8, b: *mut u8) { + unsafe { + std::intrinsics::copy(a, b, 1); + //~^ std_instead_of_core + } } + +#[clippy::msrv = "1.76"] +fn msrv_1_76(_: std::net::IpAddr) {} + +#[clippy::msrv = "1.77"] +fn msrv_1_77(_: std::net::IpAddr) {} diff --git a/src/tools/clippy/tests/ui/std_instead_of_core.stderr b/src/tools/clippy/tests/ui/std_instead_of_core.stderr index 22cb9db7050..45d60d235ce 100644 --- a/src/tools/clippy/tests/ui/std_instead_of_core.stderr +++ b/src/tools/clippy/tests/ui/std_instead_of_core.stderr @@ -85,5 +85,17 @@ LL | use alloc::slice::from_ref; = note: `-D clippy::alloc-instead-of-core` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::alloc_instead_of_core)]` -error: aborting due to 13 previous errors +error: used import from `std` instead of `core` + --> tests/ui/std_instead_of_core.rs:82:9 + | +LL | std::intrinsics::copy(a, b, 1); + | ^^^ help: consider importing the item from `core`: `core` + +error: used import from `std` instead of `core` + --> tests/ui/std_instead_of_core.rs:91:17 + | +LL | fn msrv_1_77(_: std::net::IpAddr) {} + | ^^^ help: consider importing the item from `core`: `core` + +error: aborting due to 15 previous errors diff --git a/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.stderr b/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.stderr index 4faf0237c17..43b03676b1d 100644 --- a/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.stderr +++ b/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.stderr @@ -2,51 +2,84 @@ error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:19:13 | LL | let _ = 2 ^ 5; - | ^^^^^ help: did you mean to write: `2.pow(5)` + | ^^^^^ | = note: `-D clippy::suspicious-xor-used-as-pow` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::suspicious_xor_used_as_pow)]` +help: did you mean to write + | +LL | let _ = 2.pow(5); + | ~~~~~~~~ error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:22:13 | LL | let _ = 2i32 ^ 9i32; - | ^^^^^^^^^^^ help: did you mean to write: `2i32.pow(9i32)` + | ^^^^^^^^^^^ + | +help: did you mean to write + | +LL | let _ = 2i32.pow(9i32); + | ~~~~~~~~~~~~~~ error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:24:13 | LL | let _ = 2i32 ^ 2i32; - | ^^^^^^^^^^^ help: did you mean to write: `2i32.pow(2i32)` + | ^^^^^^^^^^^ + | +help: did you mean to write + | +LL | let _ = 2i32.pow(2i32); + | ~~~~~~~~~~~~~~ error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:26:13 | LL | let _ = 50i32 ^ 3i32; - | ^^^^^^^^^^^^ help: did you mean to write: `50i32.pow(3i32)` + | ^^^^^^^^^^^^ + | +help: did you mean to write + | +LL | let _ = 50i32.pow(3i32); + | ~~~~~~~~~~~~~~~ error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:28:13 | LL | let _ = 5i32 ^ 8i32; - | ^^^^^^^^^^^ help: did you mean to write: `5i32.pow(8i32)` + | ^^^^^^^^^^^ + | +help: did you mean to write + | +LL | let _ = 5i32.pow(8i32); + | ~~~~~~~~~~~~~~ error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:30:13 | LL | let _ = 2i32 ^ 32i32; - | ^^^^^^^^^^^^ help: did you mean to write: `2i32.pow(32i32)` + | ^^^^^^^^^^^^ + | +help: did you mean to write + | +LL | let _ = 2i32.pow(32i32); + | ~~~~~~~~~~~~~~~ error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:13:9 | LL | 1 ^ 2 // should warn even if inside macro - | ^^^^^ help: did you mean to write: `1.pow(2)` + | ^^^^^ ... LL | macro_test_inside!(); | -------------------- in this macro invocation | = note: this error originates in the macro `macro_test_inside` (in Nightly builds, run with -Z macro-backtrace for more info) +help: did you mean to write + | +LL | 1.pow(2) // should warn even if inside macro + | ~~~~~~~~ error: aborting due to 7 previous errors diff --git a/src/tools/clippy/tests/ui/try_err.fixed b/src/tools/clippy/tests/ui/try_err.fixed index aae4f8ac47f..f149bfb7774 100644 --- a/src/tools/clippy/tests/ui/try_err.fixed +++ b/src/tools/clippy/tests/ui/try_err.fixed @@ -1,5 +1,5 @@ //@aux-build:proc_macros.rs - +#![feature(try_blocks)] #![deny(clippy::try_err)] #![allow( clippy::unnecessary_wraps, @@ -152,3 +152,11 @@ pub fn try_return(x: bool) -> Result<i32, i32> { } Ok(0) } + +// Test that the lint is suppressed in try block. +pub fn try_block() -> Result<(), i32> { + let _: Result<_, i32> = try { + Err(1)?; + }; + Ok(()) +} diff --git a/src/tools/clippy/tests/ui/try_err.rs b/src/tools/clippy/tests/ui/try_err.rs index 927eccf2d54..841ec6b5d5c 100644 --- a/src/tools/clippy/tests/ui/try_err.rs +++ b/src/tools/clippy/tests/ui/try_err.rs @@ -1,5 +1,5 @@ //@aux-build:proc_macros.rs - +#![feature(try_blocks)] #![deny(clippy::try_err)] #![allow( clippy::unnecessary_wraps, @@ -152,3 +152,11 @@ pub fn try_return(x: bool) -> Result<i32, i32> { } Ok(0) } + +// Test that the lint is suppressed in try block. +pub fn try_block() -> Result<(), i32> { + let _: Result<_, i32> = try { + Err(1)?; + }; + Ok(()) +} diff --git a/src/tools/clippy/tests/ui/uninit_vec.rs b/src/tools/clippy/tests/ui/uninit_vec.rs index 58729a97d57..0cc77a8775d 100644 --- a/src/tools/clippy/tests/ui/uninit_vec.rs +++ b/src/tools/clippy/tests/ui/uninit_vec.rs @@ -1,7 +1,7 @@ #![warn(clippy::uninit_vec)] -use std::mem::MaybeUninit; use std::cell::UnsafeCell; +use std::mem::MaybeUninit; #[derive(Default)] struct MyVec { diff --git a/src/tools/clippy/tests/ui/unneeded_field_pattern.rs b/src/tools/clippy/tests/ui/unneeded_field_pattern.rs index 0dc21f4ce94..1d42f81711b 100644 --- a/src/tools/clippy/tests/ui/unneeded_field_pattern.rs +++ b/src/tools/clippy/tests/ui/unneeded_field_pattern.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs #![warn(clippy::unneeded_field_pattern)] -#![allow(dead_code, unused)] +#![allow(dead_code, unused, clippy::single_match)] #[macro_use] extern crate proc_macros; diff --git a/src/tools/clippy/tests/ui/unused_result_ok.fixed b/src/tools/clippy/tests/ui/unused_result_ok.fixed new file mode 100644 index 00000000000..e78fde5c9e3 --- /dev/null +++ b/src/tools/clippy/tests/ui/unused_result_ok.fixed @@ -0,0 +1,40 @@ +//@aux-build:proc_macros.rs +#![warn(clippy::unused_result_ok)] +#![allow(dead_code)] + +#[macro_use] +extern crate proc_macros; + +fn bad_style(x: &str) { + let _ = x.parse::<u32>(); +} + +fn good_style(x: &str) -> Option<u32> { + x.parse::<u32>().ok() +} + +#[rustfmt::skip] +fn strange_parse(x: &str) { + let _ = x . parse::<i32>(); +} + +macro_rules! v { + () => { + Ok::<(), ()>(()) + }; +} + +macro_rules! w { + () => { + let _ = Ok::<(), ()>(()); + }; +} + +fn main() { + let _ = v!(); + w!(); + + external! { + Ok::<(),()>(()).ok(); + }; +} diff --git a/src/tools/clippy/tests/ui/unused_result_ok.rs b/src/tools/clippy/tests/ui/unused_result_ok.rs new file mode 100644 index 00000000000..117d64c4cec --- /dev/null +++ b/src/tools/clippy/tests/ui/unused_result_ok.rs @@ -0,0 +1,40 @@ +//@aux-build:proc_macros.rs +#![warn(clippy::unused_result_ok)] +#![allow(dead_code)] + +#[macro_use] +extern crate proc_macros; + +fn bad_style(x: &str) { + x.parse::<u32>().ok(); +} + +fn good_style(x: &str) -> Option<u32> { + x.parse::<u32>().ok() +} + +#[rustfmt::skip] +fn strange_parse(x: &str) { + x . parse::<i32>() . ok (); +} + +macro_rules! v { + () => { + Ok::<(), ()>(()) + }; +} + +macro_rules! w { + () => { + Ok::<(), ()>(()).ok(); + }; +} + +fn main() { + v!().ok(); + w!(); + + external! { + Ok::<(),()>(()).ok(); + }; +} diff --git a/src/tools/clippy/tests/ui/unused_result_ok.stderr b/src/tools/clippy/tests/ui/unused_result_ok.stderr new file mode 100644 index 00000000000..241e0c71261 --- /dev/null +++ b/src/tools/clippy/tests/ui/unused_result_ok.stderr @@ -0,0 +1,52 @@ +error: ignoring a result with `.ok()` is misleading + --> tests/ui/unused_result_ok.rs:9:5 + | +LL | x.parse::<u32>().ok(); + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::unused-result-ok` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unused_result_ok)]` +help: consider using `let _ =` and removing the call to `.ok()` instead + | +LL | let _ = x.parse::<u32>(); + | ~~~~~~~~~~~~~~~~~~~~~~~~ + +error: ignoring a result with `.ok()` is misleading + --> tests/ui/unused_result_ok.rs:18:5 + | +LL | x . parse::<i32>() . ok (); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `let _ =` and removing the call to `.ok()` instead + | +LL | let _ = x . parse::<i32>(); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: ignoring a result with `.ok()` is misleading + --> tests/ui/unused_result_ok.rs:34:5 + | +LL | v!().ok(); + | ^^^^^^^^^ + | +help: consider using `let _ =` and removing the call to `.ok()` instead + | +LL | let _ = v!(); + | ~~~~~~~~~~~~ + +error: ignoring a result with `.ok()` is misleading + --> tests/ui/unused_result_ok.rs:29:9 + | +LL | Ok::<(), ()>(()).ok(); + | ^^^^^^^^^^^^^^^^^^^^^ +... +LL | w!(); + | ---- in this macro invocation + | + = note: this error originates in the macro `w` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider using `let _ =` and removing the call to `.ok()` instead + | +LL | let _ = Ok::<(), ()>(()); + | ~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 4 previous errors + diff --git a/src/tools/clippy/tests/ui/unwrap_expect_used.rs b/src/tools/clippy/tests/ui/unwrap_expect_used.rs index 96368a07053..a56bd0a8d07 100644 --- a/src/tools/clippy/tests/ui/unwrap_expect_used.rs +++ b/src/tools/clippy/tests/ui/unwrap_expect_used.rs @@ -31,7 +31,7 @@ fn main() { // Don't trigger on unwrap_err on an option Some(3).unwrap_err(); - Some(3).expect_err("Hellow none!"); + Some(3).expect_err("Hello none!"); // Issue #11245: The `Err` variant can never be constructed so do not lint this. let x: Result<(), !> = Ok(()); diff --git a/src/tools/clippy/tests/ui/while_let_on_iterator.fixed b/src/tools/clippy/tests/ui/while_let_on_iterator.fixed index 59b5c858d04..b8087c6e000 100644 --- a/src/tools/clippy/tests/ui/while_let_on_iterator.fixed +++ b/src/tools/clippy/tests/ui/while_let_on_iterator.fixed @@ -456,6 +456,15 @@ fn fn_once_closure() { }); } +fn issue13123() { + let mut it = 0..20; + 'label: for n in it { + if n % 25 == 0 { + break 'label; + } + } +} + fn main() { let mut it = 0..20; for _ in it { diff --git a/src/tools/clippy/tests/ui/while_let_on_iterator.rs b/src/tools/clippy/tests/ui/while_let_on_iterator.rs index 559513d5694..8e02f59b512 100644 --- a/src/tools/clippy/tests/ui/while_let_on_iterator.rs +++ b/src/tools/clippy/tests/ui/while_let_on_iterator.rs @@ -456,6 +456,15 @@ fn fn_once_closure() { }); } +fn issue13123() { + let mut it = 0..20; + 'label: while let Some(n) = it.next() { + if n % 25 == 0 { + break 'label; + } + } +} + fn main() { let mut it = 0..20; while let Some(..) = it.next() { diff --git a/src/tools/clippy/tests/ui/while_let_on_iterator.stderr b/src/tools/clippy/tests/ui/while_let_on_iterator.stderr index 8ff1f23644b..d96b26acf34 100644 --- a/src/tools/clippy/tests/ui/while_let_on_iterator.stderr +++ b/src/tools/clippy/tests/ui/while_let_on_iterator.stderr @@ -160,8 +160,14 @@ LL | while let Some(x) = it.next() { error: this loop could be written as a `for` loop --> tests/ui/while_let_on_iterator.rs:461:5 | +LL | 'label: while let Some(n) = it.next() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'label: for n in it` + +error: this loop could be written as a `for` loop + --> tests/ui/while_let_on_iterator.rs:470:5 + | LL | while let Some(..) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in it` -error: aborting due to 27 previous errors +error: aborting due to 28 previous errors diff --git a/src/tools/clippy/tests/versioncheck.rs b/src/tools/clippy/tests/versioncheck.rs index eba5405e67e..68328333937 100644 --- a/src/tools/clippy/tests/versioncheck.rs +++ b/src/tools/clippy/tests/versioncheck.rs @@ -1,4 +1,3 @@ -#![cfg_attr(feature = "deny-warnings", deny(warnings))] #![warn(rust_2018_idioms, unused_lifetimes)] #![allow(clippy::single_match_else)] diff --git a/src/tools/clippy/tests/workspace_test/path_dep/Cargo.toml b/src/tools/clippy/tests/workspace_test/path_dep/Cargo.toml index 85a91cd2dec..98b4fb7aa50 100644 --- a/src/tools/clippy/tests/workspace_test/path_dep/Cargo.toml +++ b/src/tools/clippy/tests/workspace_test/path_dep/Cargo.toml @@ -1,3 +1,6 @@ [package] name = "path_dep" version = "0.1.0" + +[features] +primary_package_test = [] |
