From 4534b131cf18d5ff64381fea6170f93b9af0b0fe Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Wed, 21 Feb 2024 03:22:35 -0500 Subject: [PATCH 1/4] Fix `empty_line_after_outer_attr` when a comment follows the attribute. --- clippy_lints/src/attrs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 755f4ad3c892..0d1f85f49d7e 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -864,7 +864,7 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::It let lines = snippet.split('\n').collect::>(); let lines = without_block_comments(lines); - if lines.iter().filter(|l| l.trim().is_empty()).count() > 2 { + if lines.iter().skip(1).filter(|l| l.trim().is_empty()).count() > 1 { let (lint_msg, lint_type) = match attr.kind { AttrKind::DocComment(..) => ( "found an empty line after a doc comment. \ From 7dbe12ad2b8b9b7cd87a13c061aedcb355fbb880 Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Wed, 21 Feb 2024 03:23:34 -0500 Subject: [PATCH 2/4] Fix `large_include_file` test to not depend on the size of the size of the test itself. --- tests/ui-toml/large_include_file/large_include_file.rs | 8 ++++---- tests/ui-toml/large_include_file/small.txt | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 tests/ui-toml/large_include_file/small.txt diff --git a/tests/ui-toml/large_include_file/large_include_file.rs b/tests/ui-toml/large_include_file/large_include_file.rs index f3dbb6ad1cf5..1c69654ea725 100644 --- a/tests/ui-toml/large_include_file/large_include_file.rs +++ b/tests/ui-toml/large_include_file/large_include_file.rs @@ -1,16 +1,16 @@ #![warn(clippy::large_include_file)] // Good -const GOOD_INCLUDE_BYTES: &[u8; 581] = include_bytes!("large_include_file.rs"); -const GOOD_INCLUDE_STR: &str = include_str!("large_include_file.rs"); +const GOOD_INCLUDE_BYTES: &[u8] = include_bytes!("small.txt"); +const GOOD_INCLUDE_STR: &str = include_str!("small.txt"); #[allow(clippy::large_include_file)] -const ALLOWED_TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt"); +const ALLOWED_TOO_BIG_INCLUDE_BYTES: &[u8] = include_bytes!("too_big.txt"); #[allow(clippy::large_include_file)] const ALLOWED_TOO_BIG_INCLUDE_STR: &str = include_str!("too_big.txt"); // Bad -const TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt"); +const TOO_BIG_INCLUDE_BYTES: &[u8] = include_bytes!("too_big.txt"); const TOO_BIG_INCLUDE_STR: &str = include_str!("too_big.txt"); fn main() {} diff --git a/tests/ui-toml/large_include_file/small.txt b/tests/ui-toml/large_include_file/small.txt new file mode 100644 index 000000000000..6f7b5d003790 --- /dev/null +++ b/tests/ui-toml/large_include_file/small.txt @@ -0,0 +1 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Maecenas accumsan lacus vel facilisis volutpat. Etiam dignissim diam quis enim lobortis scelerisque fermentum dui faucibus. Tellus id interdum velit laoreet id donec ultrices. Est ultricies integer quis auctor elit sed vulputate. Erat velit scelerisque in dictum non consectetur a erat nam. Sed blandit libero volutpat sed. Tortor condimentum lacinia quis vel eros. Enim ut tellus elementum sagittis vitae et leo duis. Congue mauris rhoncus aenean vel elit scelerisque. From 345fc07a90cfb767d0e9c3cc6a6e9dd48a5a7b48 Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Wed, 21 Feb 2024 03:24:06 -0500 Subject: [PATCH 3/4] Remove problematic error annotations. --- tests/ui/crashes/ice-6255.rs | 1 - tests/ui/declare_interior_mutable_const/others.rs | 4 ++-- tests/ui/declare_interior_mutable_const/traits.rs | 2 +- tests/ui/iter_filter_is_ok.rs | 12 ------------ tests/ui/iter_filter_is_some.rs | 10 ---------- tests/ui/struct_fields.rs | 4 ---- tests/ui/unconditional_recursion.rs | 1 - 7 files changed, 3 insertions(+), 31 deletions(-) diff --git a/tests/ui/crashes/ice-6255.rs b/tests/ui/crashes/ice-6255.rs index b6555ac5c407..b1f990752c19 100644 --- a/tests/ui/crashes/ice-6255.rs +++ b/tests/ui/crashes/ice-6255.rs @@ -12,4 +12,3 @@ fn main() { } define_other_core!(); -//~^ ERROR: macro-expanded `extern crate` items cannot shadow names passed with `--extern` diff --git a/tests/ui/declare_interior_mutable_const/others.rs b/tests/ui/declare_interior_mutable_const/others.rs index 1cec2980652c..f0ff1946513b 100644 --- a/tests/ui/declare_interior_mutable_const/others.rs +++ b/tests/ui/declare_interior_mutable_const/others.rs @@ -16,7 +16,7 @@ macro_rules! declare_const { const $name: $ty = $e; }; } -declare_const!(_ONCE: Once = Once::new()); //~ ERROR: interior mutable +declare_const!(_ONCE: Once = Once::new()); // const ATOMIC_REF: &AtomicUsize = &AtomicUsize::new(7); // This will simply trigger E0492. @@ -49,7 +49,7 @@ mod issue_8493 { }; } - issue_8493!(); //~ ERROR: interior mutable + issue_8493!(); } fn main() {} diff --git a/tests/ui/declare_interior_mutable_const/traits.rs b/tests/ui/declare_interior_mutable_const/traits.rs index a6ccdd270798..d91da14cb999 100644 --- a/tests/ui/declare_interior_mutable_const/traits.rs +++ b/tests/ui/declare_interior_mutable_const/traits.rs @@ -15,7 +15,7 @@ trait ConcreteTypes { const ATOMIC: AtomicUsize; //~ ERROR: interior mutable const INTEGER: u64; const STRING: String; - declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); //~ ERROR: interior mutable + declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); } impl ConcreteTypes for u64 { diff --git a/tests/ui/iter_filter_is_ok.rs b/tests/ui/iter_filter_is_ok.rs index 89b083b84f32..b023bd50cc46 100644 --- a/tests/ui/iter_filter_is_ok.rs +++ b/tests/ui/iter_filter_is_ok.rs @@ -9,51 +9,39 @@ fn main() { { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(Result::is_ok); - //~^ HELP: consider using `flatten` instead let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|a| a.is_ok()); - //~^ HELP: consider using `flatten` instead #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().filter(|o| { o.is_ok() }); - //~^ HELP: consider using `flatten` instead } { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|&a| a.is_ok()); - //~^ HELP: consider using `flatten` instead let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|&a| a.is_ok()); - //~^ HELP: consider using `flatten` instead #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().filter(|&o| { o.is_ok() }); - //~^ HELP: consider using `flatten` instead } { let _ = vec![Ok(1), Err(2), Ok(3)] .into_iter() .filter(std::result::Result::is_ok); - //~^ HELP: consider using `flatten` instead let _ = vec![Ok(1), Err(2), Ok(3)] .into_iter() .filter(|a| std::result::Result::is_ok(a)); - //~^ HELP: consider using `flatten` instead #[rustfmt::skip] let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|a| { std::result::Result::is_ok(a) }); - //~^ HELP: consider using `flatten` instead } { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|ref a| a.is_ok()); - //~^ HELP: consider using `flatten` instead let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|ref a| a.is_ok()); - //~^ HELP: consider using `flatten` instead #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().filter(|ref o| { o.is_ok() }); - //~^ HELP: consider using `flatten` instead } } diff --git a/tests/ui/iter_filter_is_some.rs b/tests/ui/iter_filter_is_some.rs index c74775a82ba0..35ae092d45af 100644 --- a/tests/ui/iter_filter_is_some.rs +++ b/tests/ui/iter_filter_is_some.rs @@ -12,45 +12,35 @@ use std::collections::HashMap; fn main() { { let _ = vec![Some(1), None, Some(3)].into_iter().filter(Option::is_some); - //~^ HELP: consider using `flatten` instead let _ = vec![Some(1), None, Some(3)].into_iter().filter(|a| a.is_some()); - //~^ HELP: consider using `flatten` instead #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().filter(|o| { o.is_some() }); - //~^ HELP: consider using `flatten` instead } { let _ = vec![Some(1), None, Some(3)] .into_iter() .filter(std::option::Option::is_some); - //~^ HELP: consider using `flatten` instead let _ = vec![Some(1), None, Some(3)] .into_iter() .filter(|a| std::option::Option::is_some(a)); - //~^ HELP: consider using `flatten` instead #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().filter(|a| { std::option::Option::is_some(a) }); - //~^ HELP: consider using `flatten` instead } { let _ = vec![Some(1), None, Some(3)].into_iter().filter(|&a| a.is_some()); - //~^ HELP: consider using `flatten` instead #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().filter(|&o| { o.is_some() }); - //~^ HELP: consider using `flatten` instead } { let _ = vec![Some(1), None, Some(3)].into_iter().filter(|ref a| a.is_some()); - //~^ HELP: consider using `flatten` instead #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().filter(|ref o| { o.is_some() }); - //~^ HELP: consider using `flatten` instead } } diff --git a/tests/ui/struct_fields.rs b/tests/ui/struct_fields.rs index 7c9e9d8ed269..30f3caa783dc 100644 --- a/tests/ui/struct_fields.rs +++ b/tests/ui/struct_fields.rs @@ -231,7 +231,6 @@ mod macro_tests { }; } mk_struct!(); - //~^ ERROR: all fields have the same prefix: `some` macro_rules! mk_struct2 { () => { @@ -243,7 +242,6 @@ mod macro_tests { }; } mk_struct2!(); - //~^ ERROR: field name starts with the struct's name macro_rules! mk_struct_with_names { ($struct_name:ident, $field:ident) => { @@ -256,7 +254,6 @@ mod macro_tests { } // expands to `struct Foo { foo: i32, ... }` mk_struct_with_names!(Foo, foo); - //~^ ERROR: field name starts with the struct's name // expands to a struct with all fields starting with `other` but should not // be linted because some fields come from the macro definition and the other from the input @@ -296,7 +293,6 @@ mod macro_tests { }; } mk_struct_full_def!(PrefixData, some_data, some_meta, some_other); - //~^ ERROR: all fields have the same prefix: `some` } // should not lint on external code diff --git a/tests/ui/unconditional_recursion.rs b/tests/ui/unconditional_recursion.rs index 6ad3bde51cde..47fe62812086 100644 --- a/tests/ui/unconditional_recursion.rs +++ b/tests/ui/unconditional_recursion.rs @@ -156,7 +156,6 @@ macro_rules! impl_partial_eq { struct S5; impl_partial_eq!(S5); -//~^ ERROR: function cannot return without recursing struct S6 { field: String, From ada5754045447dffb68fc741cad1e1c04d165700 Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Wed, 21 Feb 2024 04:04:19 -0500 Subject: [PATCH 4/4] Add error annotations to all test files --- .../ui-toml/absolute_paths/absolute_paths.rs | 22 +- .../uninlined_format_args.fixed | 7 +- .../uninlined_format_args.rs | 7 +- .../uninlined_format_args.stderr | 6 +- .../arithmetic_side_effects_allowed.rs | 18 +- .../array_size_threshold.rs | 4 +- .../array_size_threshold.stderr | 2 +- .../await_holding_invalid_type.rs | 5 +- .../await_holding_invalid_type.stderr | 2 +- .../conf_deprecated_key.rs | 1 + .../conf_deprecated_key.stderr | 2 +- tests/ui-toml/dbg_macro/dbg_macro.rs | 16 +- tests/ui-toml/dbg_macro/dbg_macro.stderr | 20 +- .../disallowed_macros/disallowed_macros.rs | 31 +-- .../disallowed_macros.stderr | 10 +- .../disallowed_names.rs | 4 +- .../disallowed_names.rs | 2 +- .../doc_markdown.fixed | 1 + .../doc_valid_idents_append/doc_markdown.rs | 1 + .../doc_markdown.stderr | 2 +- .../doc_markdown.fixed | 3 + .../doc_valid_idents_replace/doc_markdown.rs | 3 + .../doc_markdown.stderr | 6 +- .../excessive_nesting/excessive_nesting.rs | 55 ++-- .../excessive_nesting.stderr | 72 +++--- tests/ui-toml/expect_used/expect_used.rs | 4 +- .../ui-toml/fn_params_excessive_bools/test.rs | 2 +- tests/ui-toml/functions_maxlines/test.rs | 4 + tests/ui-toml/functions_maxlines/test.stderr | 8 +- tests/ui-toml/ifs_same_cond/ifs_same_cond.rs | 1 + .../ifs_same_cond/ifs_same_cond.stderr | 2 +- .../ui-toml/large_futures/large_futures.fixed | 2 +- tests/ui-toml/large_futures/large_futures.rs | 2 +- .../large_include_file/large_include_file.rs | 2 + .../large_include_file.stderr | 8 +- .../lint_decimal_readability/test.fixed | 3 +- .../ui-toml/lint_decimal_readability/test.rs | 3 +- .../lint_decimal_readability/test.stderr | 2 +- .../min_ident_chars/min_ident_chars.rs | 14 +- .../min_ident_chars/min_ident_chars.stderr | 2 +- .../min_rust_version/min_rust_version.fixed | 2 +- .../min_rust_version/min_rust_version.rs | 2 +- .../conf_missing_enforced_import_rename.fixed | 10 +- .../conf_missing_enforced_import_rename.rs | 10 +- ...conf_missing_enforced_import_rename.stderr | 10 +- .../module_inception/module_inception.rs | 2 + .../module_inception/module_inception.stderr | 4 +- .../modulo_arithmetic/modulo_arithmetic.rs | 8 +- .../conf_nonstandard_macro_braces.fixed | 13 +- .../conf_nonstandard_macro_braces.rs | 13 +- .../conf_nonstandard_macro_braces.stderr | 10 +- tests/ui-toml/print_macro/print_macro.rs | 4 +- .../pub_crate_missing_doc.rs | 8 +- .../pub_crate_missing_doc.stderr | 12 +- ...ub_underscore_fields.all_pub_fields.stderr | 10 +- .../pub_underscore_fields.rs | 12 +- tests/ui-toml/semicolon_block/both.fixed | 7 +- tests/ui-toml/semicolon_block/both.rs | 7 +- tests/ui-toml/semicolon_block/both.stderr | 4 +- .../semicolon_inside_block.fixed | 1 + .../semicolon_block/semicolon_inside_block.rs | 1 + .../semicolon_inside_block.stderr | 2 +- .../semicolon_outside_block.fixed | 6 +- .../semicolon_outside_block.rs | 6 +- .../strict_non_send_fields_in_send_ty/test.rs | 6 +- .../test.stderr | 16 +- tests/ui-toml/struct_excessive_bools/test.rs | 1 + .../struct_excessive_bools/test.stderr | 2 +- tests/ui-toml/suppress_lint_in_const/test.rs | 12 +- .../conf_french_disallowed_name.rs | 11 +- .../conf_disallowed_methods.rs | 25 +- .../conf_disallowed_methods.stderr | 16 +- .../conf_disallowed_types.rs | 32 ++- .../conf_disallowed_types.stderr | 38 +-- tests/ui-toml/toml_trivially_copy/test.rs | 2 + .../undocumented_unsafe_blocks.default.stderr | 66 ++--- ...undocumented_unsafe_blocks.disabled.stderr | 86 +++---- .../undocumented_unsafe_blocks.rs | 69 +++-- tests/ui-toml/unwrap_used/unwrap_used.fixed | 30 ++- tests/ui-toml/unwrap_used/unwrap_used.rs | 30 ++- tests/ui-toml/unwrap_used/unwrap_used.stderr | 52 ++-- .../upper_case_acronyms.fixed | 26 +- .../upper_case_acronyms.rs | 26 +- .../upper_case_acronyms.stderr | 28 +-- tests/ui-toml/vec_box_sized/test.fixed | 6 +- tests/ui-toml/vec_box_sized/test.rs | 6 +- tests/ui/allow_attributes.fixed | 4 +- tests/ui/allow_attributes.rs | 4 +- tests/ui/allow_attributes_without_reason.rs | 7 +- .../ui/allow_attributes_without_reason.stderr | 6 +- tests/ui/almost_complete_range.fixed | 54 ++-- tests/ui/almost_complete_range.rs | 54 ++-- tests/ui/arithmetic_side_effects.rs | 238 +++++++++--------- tests/ui/as_conversions.rs | 4 +- tests/ui/as_underscore.fixed | 4 +- tests/ui/as_underscore.rs | 4 +- tests/ui/assertions_on_result_states.fixed | 13 +- tests/ui/assertions_on_result_states.rs | 13 +- tests/ui/assertions_on_result_states.stderr | 8 +- tests/ui/assign_ops.fixed | 22 +- tests/ui/assign_ops.rs | 22 +- tests/ui/async_yields_async.fixed | 10 +- tests/ui/async_yields_async.rs | 10 +- tests/ui/async_yields_async.stderr | 14 +- tests/ui/bind_instead_of_map.fixed | 6 +- tests/ui/bind_instead_of_map.rs | 6 +- tests/ui/bind_instead_of_map_multipart.fixed | 5 + tests/ui/bind_instead_of_map_multipart.rs | 5 + tests/ui/bind_instead_of_map_multipart.stderr | 8 +- tests/ui/blocks_in_conditions.fixed | 2 +- tests/ui/blocks_in_conditions.rs | 2 +- tests/ui/bool_assert_comparison.fixed | 48 ++-- tests/ui/bool_assert_comparison.rs | 48 ++-- tests/ui/bool_assert_comparison.stderr | 48 ++-- tests/ui/bool_comparison.fixed | 36 ++- tests/ui/bool_comparison.rs | 36 ++- tests/ui/bool_comparison.stderr | 50 ++-- tests/ui/bool_to_int_with_if.fixed | 10 +- tests/ui/bool_to_int_with_if.rs | 10 +- tests/ui/bool_to_int_with_if.stderr | 18 +- tests/ui/borrow_as_ptr.fixed | 4 +- tests/ui/borrow_as_ptr.rs | 4 +- tests/ui/borrow_as_ptr_no_std.fixed | 4 +- tests/ui/borrow_as_ptr_no_std.rs | 4 +- tests/ui/borrow_deref_ref.fixed | 5 +- tests/ui/borrow_deref_ref.rs | 5 +- tests/ui/borrow_deref_ref.stderr | 2 +- tests/ui/box_default.fixed | 23 +- tests/ui/box_default.rs | 23 +- tests/ui/box_default.stderr | 30 +-- tests/ui/builtin_type_shadow.rs | 1 + tests/ui/builtin_type_shadow.stderr | 4 +- tests/ui/bytes_count_to_len.fixed | 7 +- tests/ui/bytes_count_to_len.rs | 7 +- tests/ui/bytes_count_to_len.stderr | 6 +- tests/ui/bytes_nth.fixed | 6 +- tests/ui/bytes_nth.rs | 6 +- ...sensitive_file_extension_comparisons.fixed | 6 + ...se_sensitive_file_extension_comparisons.rs | 6 + ...ensitive_file_extension_comparisons.stderr | 10 +- tests/ui/cast_abs_to_unsigned.fixed | 35 +-- tests/ui/cast_abs_to_unsigned.rs | 35 +-- tests/ui/cast_abs_to_unsigned.stderr | 2 +- tests/ui/cast_lossless_bool.fixed | 30 +-- tests/ui/cast_lossless_bool.rs | 30 +-- tests/ui/cast_lossless_float.fixed | 22 +- tests/ui/cast_lossless_float.rs | 22 +- tests/ui/cast_lossless_integer.fixed | 42 ++-- tests/ui/cast_lossless_integer.rs | 42 ++-- tests/ui/cast_raw_slice_pointer_cast.fixed | 7 + tests/ui/cast_raw_slice_pointer_cast.rs | 7 + tests/ui/cast_raw_slice_pointer_cast.stderr | 12 +- tests/ui/cast_size.64bit.stderr | 16 +- tests/ui/cast_size.rs | 32 +-- tests/ui/cfg_attr_rustfmt.fixed | 6 +- tests/ui/cfg_attr_rustfmt.rs | 6 +- tests/ui/char_lit_as_u8_suggestions.fixed | 8 +- tests/ui/char_lit_as_u8_suggestions.rs | 8 +- tests/ui/checked_conversions.fixed | 18 +- tests/ui/checked_conversions.rs | 18 +- tests/ui/checked_conversions.stderr | 32 +-- .../ui/checked_unwrap/simple_conditionals.rs | 2 +- tests/ui/clear_with_drain.fixed | 42 ++-- tests/ui/clear_with_drain.rs | 42 ++-- tests/ui/clone_on_copy.fixed | 17 +- tests/ui/clone_on_copy.rs | 17 +- tests/ui/clone_on_copy.stderr | 2 +- tests/ui/cloned_instead_of_copied.fixed | 12 +- tests/ui/cloned_instead_of_copied.rs | 12 +- tests/ui/cloned_instead_of_copied.stderr | 8 +- .../ui/cmp_owned/asymmetric_partial_eq.fixed | 12 +- tests/ui/cmp_owned/asymmetric_partial_eq.rs | 12 +- tests/ui/cmp_owned/comparison_flip.fixed | 2 + tests/ui/cmp_owned/comparison_flip.rs | 2 + tests/ui/cmp_owned/comparison_flip.stderr | 4 +- tests/ui/cmp_owned/with_suggestion.fixed | 12 +- tests/ui/cmp_owned/with_suggestion.rs | 12 +- tests/ui/collapsible_else_if.fixed | 8 + tests/ui/collapsible_else_if.rs | 8 + tests/ui/collapsible_else_if.stderr | 16 +- tests/ui/collapsible_if.fixed | 9 + tests/ui/collapsible_if.rs | 9 + tests/ui/collapsible_if.stderr | 18 +- tests/ui/collapsible_match2.rs | 1 + tests/ui/collapsible_match2.stderr | 12 +- tests/ui/collapsible_str_replace.fixed | 14 ++ tests/ui/collapsible_str_replace.rs | 14 ++ tests/ui/collapsible_str_replace.stderr | 26 +- tests/ui/comparison_to_empty.fixed | 17 +- tests/ui/comparison_to_empty.rs | 17 +- tests/ui/crashes/ice-10148.rs | 2 +- tests/ui/crashes/ice-11422.fixed | 1 + tests/ui/crashes/ice-11422.rs | 1 + tests/ui/crashes/ice-11803.rs | 2 + tests/ui/crashes/ice-11803.stderr | 4 +- tests/ui/crate_in_macro_def.fixed | 1 + tests/ui/crate_in_macro_def.rs | 1 + tests/ui/create_dir.fixed | 4 +- tests/ui/create_dir.rs | 4 +- tests/ui/decimal_literal_representation.fixed | 13 + tests/ui/decimal_literal_representation.rs | 13 + .../ui/decimal_literal_representation.stderr | 14 +- .../declare_interior_mutable_const/others.rs | 3 +- .../declare_interior_mutable_const/traits.rs | 2 +- .../ui/default_constructed_unit_structs.fixed | 7 +- tests/ui/default_constructed_unit_structs.rs | 7 +- .../default_constructed_unit_structs.stderr | 8 +- tests/ui/default_instead_of_iter_empty.fixed | 3 + tests/ui/default_instead_of_iter_empty.rs | 3 + tests/ui/default_instead_of_iter_empty.stderr | 4 +- ...default_instead_of_iter_empty_no_std.fixed | 2 + .../default_instead_of_iter_empty_no_std.rs | 2 + ...efault_instead_of_iter_empty_no_std.stderr | 2 +- tests/ui/default_numeric_fallback_f64.fixed | 38 +-- tests/ui/default_numeric_fallback_f64.rs | 38 +-- tests/ui/default_numeric_fallback_f64.stderr | 38 +-- tests/ui/default_numeric_fallback_i32.fixed | 44 ++-- tests/ui/default_numeric_fallback_i32.rs | 44 ++-- tests/ui/default_numeric_fallback_i32.stderr | 48 ++-- tests/ui/default_trait_access.fixed | 10 +- tests/ui/default_trait_access.rs | 10 +- tests/ui/default_trait_access.stderr | 10 +- tests/ui/deref_addrof.fixed | 20 +- tests/ui/deref_addrof.rs | 20 +- tests/ui/deref_by_slicing.fixed | 15 +- tests/ui/deref_by_slicing.rs | 15 +- tests/ui/deref_by_slicing.stderr | 10 +- tests/ui/derivable_impls.fixed | 8 + tests/ui/derivable_impls.rs | 8 + tests/ui/derivable_impls.stderr | 16 +- tests/ui/derive_partial_eq_without_eq.fixed | 22 +- tests/ui/derive_partial_eq_without_eq.rs | 22 +- tests/ui/doc/doc-fixable.fixed | 33 +++ tests/ui/doc/doc-fixable.rs | 33 +++ tests/ui/doc/doc-fixable.stderr | 62 ++--- tests/ui/doc_unsafe.rs | 7 +- tests/ui/doc_unsafe.stderr | 12 +- tests/ui/double_comparison.fixed | 8 + tests/ui/double_comparison.rs | 8 + tests/ui/double_comparison.stderr | 16 +- tests/ui/drain_collect.fixed | 20 +- tests/ui/drain_collect.rs | 20 +- tests/ui/duration_subsec.fixed | 8 +- tests/ui/duration_subsec.rs | 8 +- tests/ui/duration_subsec.stderr | 8 +- tests/ui/eager_transmute.fixed | 17 ++ tests/ui/eager_transmute.rs | 17 ++ tests/ui/eager_transmute.stderr | 32 +-- tests/ui/empty_drop.fixed | 2 + tests/ui/empty_drop.rs | 2 + tests/ui/empty_drop.stderr | 4 +- tests/ui/empty_line_after_doc_comments.rs | 3 + tests/ui/empty_line_after_doc_comments.stderr | 8 +- tests/ui/empty_line_after_outer_attribute.rs | 6 + .../empty_line_after_outer_attribute.stderr | 12 +- tests/ui/empty_loop.rs | 6 +- tests/ui/empty_structs_with_brackets.fixed | 3 + tests/ui/empty_structs_with_brackets.rs | 3 + tests/ui/empty_structs_with_brackets.stderr | 4 +- tests/ui/endian_bytes.rs | 142 ++++++----- tests/ui/endian_bytes.stderr | 50 ++-- tests/ui/entry.fixed | 10 + tests/ui/entry.rs | 10 + tests/ui/entry.stderr | 20 +- tests/ui/entry_btree.fixed | 1 + tests/ui/entry_btree.rs | 1 + tests/ui/entry_btree.stderr | 2 +- tests/ui/entry_with_else.fixed | 7 + tests/ui/entry_with_else.rs | 7 + tests/ui/entry_with_else.stderr | 14 +- tests/ui/enum_glob_use.fixed | 6 +- tests/ui/enum_glob_use.rs | 6 +- tests/ui/eq_op_macros.rs | 8 +- tests/ui/equatable_if_let.fixed | 23 +- tests/ui/equatable_if_let.rs | 23 +- tests/ui/equatable_if_let.stderr | 16 +- tests/ui/err_expect.fixed | 4 +- tests/ui/err_expect.rs | 4 +- tests/ui/eta.fixed | 48 ++-- tests/ui/eta.rs | 48 ++-- tests/ui/eta.stderr | 60 ++--- tests/ui/excessive_precision.fixed | 22 +- tests/ui/excessive_precision.rs | 22 +- tests/ui/excessive_precision.stderr | 24 +- tests/ui/exhaustive_items.fixed | 3 + tests/ui/exhaustive_items.rs | 3 + tests/ui/exhaustive_items.stderr | 6 +- tests/ui/expect_fun_call.fixed | 17 +- tests/ui/expect_fun_call.rs | 17 +- tests/ui/expect_fun_call.stderr | 28 +-- tests/ui/explicit_auto_deref.fixed | 87 ++++--- tests/ui/explicit_auto_deref.rs | 87 ++++--- tests/ui/explicit_auto_deref.stderr | 82 +++--- tests/ui/explicit_deref_methods.fixed | 20 +- tests/ui/explicit_deref_methods.rs | 20 +- tests/ui/explicit_deref_methods.stderr | 16 +- tests/ui/explicit_into_iter_loop.fixed | 12 +- tests/ui/explicit_into_iter_loop.rs | 12 +- tests/ui/explicit_iter_loop.fixed | 36 +-- tests/ui/explicit_iter_loop.rs | 36 +-- tests/ui/explicit_write.fixed | 13 + tests/ui/explicit_write.rs | 13 + tests/ui/explicit_write.stderr | 24 +- tests/ui/extend_with_drain.fixed | 8 +- tests/ui/extend_with_drain.rs | 8 +- tests/ui/extra_unused_lifetimes.rs | 9 +- tests/ui/extra_unused_lifetimes.stderr | 6 +- tests/ui/extra_unused_type_parameters.fixed | 8 + tests/ui/extra_unused_type_parameters.rs | 8 + tests/ui/extra_unused_type_parameters.stderr | 16 +- tests/ui/field_reassign_with_default.rs | 22 +- tests/ui/filter_map_bool_then.fixed | 10 + tests/ui/filter_map_bool_then.rs | 10 + tests/ui/filter_map_bool_then.stderr | 18 +- tests/ui/filter_map_identity.fixed | 6 +- tests/ui/filter_map_identity.rs | 6 +- tests/ui/filter_map_identity.stderr | 4 +- tests/ui/filter_map_next_fixable.fixed | 2 + tests/ui/filter_map_next_fixable.rs | 2 + tests/ui/filter_map_next_fixable.stderr | 2 +- tests/ui/flat_map_identity.fixed | 5 +- tests/ui/flat_map_identity.rs | 5 +- tests/ui/flat_map_identity.stderr | 2 +- tests/ui/flat_map_option.fixed | 4 +- tests/ui/flat_map_option.rs | 4 +- tests/ui/floating_point_abs.fixed | 16 +- tests/ui/floating_point_abs.rs | 16 +- tests/ui/floating_point_exp.fixed | 10 +- tests/ui/floating_point_exp.rs | 10 +- tests/ui/floating_point_hypot.fixed | 5 +- tests/ui/floating_point_hypot.rs | 5 +- tests/ui/floating_point_hypot.stderr | 2 +- tests/ui/floating_point_log.fixed | 57 ++--- tests/ui/floating_point_log.rs | 57 ++--- tests/ui/floating_point_log.stderr | 26 +- tests/ui/floating_point_logbase.fixed | 10 +- tests/ui/floating_point_logbase.rs | 10 +- tests/ui/floating_point_mul_add.fixed | 24 +- tests/ui/floating_point_mul_add.rs | 24 +- tests/ui/floating_point_mul_add.stderr | 6 +- tests/ui/floating_point_powf.fixed | 62 ++--- tests/ui/floating_point_powf.rs | 62 ++--- tests/ui/floating_point_powi.fixed | 28 +-- tests/ui/floating_point_powi.rs | 28 +-- tests/ui/floating_point_rad.fixed | 10 +- tests/ui/floating_point_rad.rs | 10 +- tests/ui/floating_point_rad.stderr | 14 +- tests/ui/fn_to_numeric_cast.rs | 48 ++-- tests/ui/format.fixed | 29 ++- tests/ui/format.rs | 29 ++- tests/ui/format.stderr | 24 +- tests/ui/format_args.fixed | 31 ++- tests/ui/format_args.rs | 31 ++- tests/ui/format_args.stderr | 48 ++-- tests/ui/four_forward_slashes.fixed | 5 + tests/ui/four_forward_slashes.rs | 5 + tests/ui/four_forward_slashes.stderr | 10 +- .../ui/four_forward_slashes_first_line.fixed | 1 + tests/ui/four_forward_slashes_first_line.rs | 1 + .../ui/four_forward_slashes_first_line.stderr | 2 +- tests/ui/from_iter_instead_of_collect.fixed | 15 ++ tests/ui/from_iter_instead_of_collect.rs | 15 ++ tests/ui/from_iter_instead_of_collect.stderr | 28 +-- tests/ui/from_over_into.fixed | 7 + tests/ui/from_over_into.rs | 7 + tests/ui/from_over_into.stderr | 14 +- tests/ui/get_last_with_len.fixed | 11 +- tests/ui/get_last_with_len.rs | 11 +- tests/ui/get_unwrap.fixed | 33 ++- tests/ui/get_unwrap.rs | 33 ++- tests/ui/get_unwrap.stderr | 56 ++--- tests/ui/identity_op.fixed | 1 + tests/ui/identity_op.rs | 1 + tests/ui/identity_op.stderr | 24 +- tests/ui/if_same_then_else.rs | 1 + tests/ui/if_same_then_else.stderr | 4 +- tests/ui/implicit_clone.fixed | 22 +- tests/ui/implicit_clone.rs | 22 +- tests/ui/implicit_return.fixed | 29 ++- tests/ui/implicit_return.rs | 29 ++- tests/ui/implicit_return.stderr | 26 +- tests/ui/implicit_saturating_add.fixed | 24 ++ tests/ui/implicit_saturating_add.rs | 24 ++ tests/ui/implicit_saturating_add.stderr | 48 ++-- tests/ui/implicit_saturating_sub.fixed | 23 ++ tests/ui/implicit_saturating_sub.rs | 23 ++ tests/ui/implicit_saturating_sub.stderr | 46 ++-- tests/ui/implied_bounds_in_impls.fixed | 21 +- tests/ui/implied_bounds_in_impls.rs | 21 +- tests/ui/implied_bounds_in_impls.stderr | 38 +-- tests/ui/inconsistent_digit_grouping.fixed | 15 +- tests/ui/inconsistent_digit_grouping.rs | 15 +- tests/ui/inconsistent_digit_grouping.stderr | 10 +- .../ui/inconsistent_struct_constructor.fixed | 3 +- tests/ui/inconsistent_struct_constructor.rs | 3 +- .../ui/inconsistent_struct_constructor.stderr | 2 +- tests/ui/indexing_slicing_index.rs | 10 +- tests/ui/inefficient_to_string.fixed | 12 +- tests/ui/inefficient_to_string.rs | 12 +- tests/ui/infallible_destructuring_match.fixed | 4 + tests/ui/infallible_destructuring_match.rs | 4 + .../ui/infallible_destructuring_match.stderr | 8 +- tests/ui/infinite_loops.rs | 2 + tests/ui/infinite_loops.stderr | 24 +- tests/ui/inline_fn_without_body.fixed | 3 + tests/ui/inline_fn_without_body.rs | 6 +- tests/ui/inline_fn_without_body.stderr | 24 +- tests/ui/int_plus_one.fixed | 8 +- tests/ui/int_plus_one.rs | 8 +- tests/ui/into_iter_without_iter.rs | 1 + tests/ui/into_iter_without_iter.stderr | 2 +- tests/ui/invalid_null_ptr_usage.fixed | 25 ++ tests/ui/invalid_null_ptr_usage.rs | 25 ++ tests/ui/invalid_null_ptr_usage.stderr | 48 ++-- tests/ui/is_digit_ascii_radix.fixed | 6 +- tests/ui/is_digit_ascii_radix.rs | 6 +- tests/ui/issue_2356.fixed | 1 + tests/ui/issue_2356.rs | 1 + tests/ui/issue_2356.stderr | 2 +- tests/ui/items_after_statement.rs | 1 + tests/ui/items_after_statement.stderr | 2 +- .../items_after_test_module/root_module.fixed | 1 + .../ui/items_after_test_module/root_module.rs | 1 + .../root_module.stderr | 2 +- tests/ui/iter_cloned_collect.fixed | 5 + tests/ui/iter_cloned_collect.rs | 5 + tests/ui/iter_cloned_collect.stderr | 8 +- tests/ui/iter_count.fixed | 50 ++-- tests/ui/iter_count.rs | 50 ++-- tests/ui/iter_filter_is_ok.fixed | 24 +- tests/ui/iter_filter_is_ok.rs | 12 + tests/ui/iter_filter_is_some.fixed | 20 +- tests/ui/iter_filter_is_some.rs | 10 + tests/ui/iter_kv_map.fixed | 28 +++ tests/ui/iter_kv_map.rs | 28 +++ tests/ui/iter_kv_map.stderr | 74 +++--- tests/ui/iter_next_slice.fixed | 8 +- tests/ui/iter_next_slice.rs | 8 +- tests/ui/iter_nth.rs | 10 +- tests/ui/iter_nth.stderr | 8 +- tests/ui/iter_nth_zero.fixed | 6 +- tests/ui/iter_nth_zero.rs | 6 +- tests/ui/iter_on_empty_collections.fixed | 6 + tests/ui/iter_on_empty_collections.rs | 6 + tests/ui/iter_on_empty_collections.stderr | 10 +- tests/ui/iter_on_single_items.fixed | 6 + tests/ui/iter_on_single_items.rs | 6 + tests/ui/iter_on_single_items.stderr | 10 +- tests/ui/iter_over_hash_type.rs | 13 + tests/ui/iter_over_hash_type.stderr | 26 +- tests/ui/iter_overeager_cloned.fixed | 19 ++ tests/ui/iter_overeager_cloned.rs | 19 ++ tests/ui/iter_overeager_cloned.stderr | 36 +-- tests/ui/iter_skip_next.fixed | 10 +- tests/ui/iter_skip_next.rs | 10 +- tests/ui/iter_skip_next.stderr | 10 +- tests/ui/iter_skip_zero.fixed | 8 +- tests/ui/iter_skip_zero.rs | 8 +- tests/ui/iter_with_drain.fixed | 7 +- tests/ui/iter_with_drain.rs | 7 +- tests/ui/iter_with_drain.stderr | 10 +- tests/ui/iter_without_into_iter.rs | 2 + tests/ui/iter_without_into_iter.stderr | 8 +- tests/ui/large_const_arrays.fixed | 9 + tests/ui/large_const_arrays.rs | 9 + tests/ui/large_const_arrays.stderr | 16 +- tests/ui/large_digit_groups.fixed | 10 +- tests/ui/large_digit_groups.rs | 10 +- tests/ui/large_enum_variant.64bit.stderr | 44 ++-- tests/ui/large_enum_variant.rs | 16 ++ tests/ui/large_futures.fixed | 1 + tests/ui/large_futures.rs | 1 + tests/ui/large_futures.stderr | 2 +- tests/ui/large_types_passed_by_value.rs | 9 +- tests/ui/large_types_passed_by_value.stderr | 12 +- tests/ui/len_zero.fixed | 32 ++- tests/ui/len_zero.rs | 32 ++- tests/ui/len_zero.stderr | 46 ++-- tests/ui/len_zero_ranges.fixed | 4 +- tests/ui/len_zero_ranges.rs | 4 +- tests/ui/let_underscore_untyped.rs | 10 +- tests/ui/let_unit.fixed | 4 +- tests/ui/let_unit.rs | 4 +- tests/ui/let_unit.stderr | 4 +- tests/ui/let_with_type_underscore.rs | 10 +- tests/ui/lines_filter_map_ok.fixed | 6 + tests/ui/lines_filter_map_ok.rs | 6 + tests/ui/lines_filter_map_ok.stderr | 20 +- tests/ui/lossy_float_literal.fixed | 22 +- tests/ui/lossy_float_literal.rs | 22 +- tests/ui/macro_use_imports.fixed | 8 +- tests/ui/macro_use_imports.rs | 8 +- tests/ui/manual_assert.edition2018.fixed | 9 + tests/ui/manual_assert.edition2018.stderr | 18 +- tests/ui/manual_assert.edition2021.fixed | 9 + tests/ui/manual_assert.edition2021.stderr | 18 +- tests/ui/manual_assert.rs | 9 + tests/ui/manual_async_fn.fixed | 13 + tests/ui/manual_async_fn.rs | 13 + tests/ui/manual_async_fn.stderr | 26 +- tests/ui/manual_bits.fixed | 63 ++--- tests/ui/manual_bits.rs | 63 ++--- tests/ui/manual_bits.stderr | 4 +- tests/ui/manual_c_str_literals.fixed | 21 +- tests/ui/manual_c_str_literals.rs | 21 +- tests/ui/manual_c_str_literals.stderr | 18 +- tests/ui/manual_filter.fixed | 15 ++ tests/ui/manual_filter.rs | 15 ++ tests/ui/manual_filter.stderr | 30 +-- tests/ui/manual_filter_map.fixed | 29 +++ tests/ui/manual_filter_map.rs | 29 +++ tests/ui/manual_filter_map.stderr | 72 +++--- tests/ui/manual_find_fixable.fixed | 12 + tests/ui/manual_find_fixable.rs | 12 + tests/ui/manual_find_fixable.stderr | 24 +- tests/ui/manual_find_map.fixed | 30 +++ tests/ui/manual_find_map.rs | 30 +++ tests/ui/manual_find_map.stderr | 74 +++--- tests/ui/manual_float_methods.rs | 8 +- tests/ui/manual_float_methods.stderr | 10 +- tests/ui/manual_hash_one.fixed | 8 +- tests/ui/manual_hash_one.rs | 8 +- tests/ui/manual_instant_elapsed.fixed | 2 + tests/ui/manual_instant_elapsed.rs | 2 + tests/ui/manual_instant_elapsed.stderr | 2 +- tests/ui/manual_is_ascii_check.fixed | 39 +-- tests/ui/manual_is_ascii_check.rs | 39 +-- tests/ui/manual_is_ascii_check.stderr | 30 +-- tests/ui/manual_is_variant_and.fixed | 8 + tests/ui/manual_is_variant_and.rs | 8 + tests/ui/manual_is_variant_and.stderr | 16 +- tests/ui/manual_let_else.rs | 1 + tests/ui/manual_let_else.stderr | 18 +- tests/ui/manual_let_else_question_mark.fixed | 9 +- tests/ui/manual_let_else_question_mark.rs | 9 +- tests/ui/manual_let_else_question_mark.stderr | 8 +- tests/ui/manual_main_separator_str.fixed | 4 + tests/ui/manual_main_separator_str.rs | 4 + tests/ui/manual_main_separator_str.stderr | 6 +- tests/ui/manual_map_option.fixed | 21 ++ tests/ui/manual_map_option.rs | 21 ++ tests/ui/manual_map_option.stderr | 42 ++-- tests/ui/manual_map_option_2.fixed | 5 + tests/ui/manual_map_option_2.rs | 5 + tests/ui/manual_map_option_2.stderr | 10 +- tests/ui/manual_next_back.fixed | 4 +- tests/ui/manual_next_back.rs | 4 +- tests/ui/manual_non_exhaustive_enum.rs | 1 + tests/ui/manual_non_exhaustive_enum.stderr | 4 +- tests/ui/manual_non_exhaustive_struct.rs | 1 + tests/ui/manual_non_exhaustive_struct.stderr | 12 +- tests/ui/manual_ok_or.fixed | 7 +- tests/ui/manual_ok_or.rs | 7 +- tests/ui/manual_ok_or.stderr | 4 +- tests/ui/manual_range_patterns.fixed | 26 +- tests/ui/manual_range_patterns.rs | 26 +- tests/ui/manual_range_patterns.stderr | 36 +-- tests/ui/manual_rem_euclid.fixed | 20 +- tests/ui/manual_rem_euclid.rs | 20 +- tests/ui/manual_retain.fixed | 40 +++ tests/ui/manual_retain.rs | 40 +++ tests/ui/manual_retain.stderr | 74 +++--- tests/ui/manual_saturating_arithmetic.fixed | 29 +++ tests/ui/manual_saturating_arithmetic.rs | 29 +++ tests/ui/manual_saturating_arithmetic.stderr | 46 ++-- tests/ui/manual_slice_size_calculation.fixed | 11 + tests/ui/manual_slice_size_calculation.rs | 11 + tests/ui/manual_slice_size_calculation.stderr | 14 +- tests/ui/manual_split_once.fixed | 29 ++- tests/ui/manual_split_once.rs | 29 ++- tests/ui/manual_split_once.stderr | 46 ++-- tests/ui/manual_str_repeat.fixed | 10 + tests/ui/manual_str_repeat.rs | 10 + tests/ui/manual_str_repeat.stderr | 18 +- tests/ui/manual_string_new.fixed | 16 +- tests/ui/manual_string_new.rs | 16 +- tests/ui/manual_string_new.stderr | 2 +- tests/ui/manual_try_fold.rs | 4 + tests/ui/manual_try_fold.stderr | 6 +- tests/ui/manual_unwrap_or.fixed | 14 ++ tests/ui/manual_unwrap_or.rs | 14 ++ tests/ui/manual_unwrap_or.stderr | 28 +-- tests/ui/manual_while_let_some.fixed | 7 + tests/ui/manual_while_let_some.rs | 7 + tests/ui/manual_while_let_some.stderr | 12 +- tests/ui/map_clone.fixed | 9 +- tests/ui/map_clone.rs | 9 +- tests/ui/map_clone.stderr | 28 +-- tests/ui/map_collect_result_unit.fixed | 2 + tests/ui/map_collect_result_unit.rs | 2 + tests/ui/map_collect_result_unit.stderr | 2 +- tests/ui/map_flatten_fixable.fixed | 9 + tests/ui/map_flatten_fixable.rs | 9 + tests/ui/map_flatten_fixable.stderr | 16 +- tests/ui/map_identity.fixed | 18 +- tests/ui/map_identity.rs | 18 +- tests/ui/map_identity.stderr | 20 +- tests/ui/map_unwrap_or.rs | 18 +- tests/ui/map_unwrap_or.stderr | 30 +-- tests/ui/map_unwrap_or_fixable.fixed | 2 + tests/ui/map_unwrap_or_fixable.rs | 2 + tests/ui/map_unwrap_or_fixable.stderr | 4 +- tests/ui/match_as_ref.fixed | 3 + tests/ui/match_as_ref.rs | 3 + tests/ui/match_as_ref.stderr | 6 +- tests/ui/match_expr_like_matches_macro.fixed | 14 ++ tests/ui/match_expr_like_matches_macro.rs | 14 ++ tests/ui/match_expr_like_matches_macro.stderr | 28 +-- tests/ui/match_ref_pats.fixed | 5 + tests/ui/match_ref_pats.rs | 5 + tests/ui/match_ref_pats.stderr | 10 +- tests/ui/match_result_ok.fixed | 3 + tests/ui/match_result_ok.rs | 3 + tests/ui/match_result_ok.stderr | 4 +- tests/ui/match_same_arms2.rs | 3 +- tests/ui/match_same_arms2.stderr | 18 +- tests/ui/match_single_binding.fixed | 24 ++ tests/ui/match_single_binding.rs | 24 ++ tests/ui/match_single_binding.stderr | 48 ++-- tests/ui/match_single_binding2.fixed | 4 + tests/ui/match_single_binding2.rs | 4 + tests/ui/match_single_binding2.stderr | 8 +- tests/ui/match_str_case_mismatch.fixed | 14 +- tests/ui/match_str_case_mismatch.rs | 14 +- .../match_wildcard_for_single_variants.fixed | 20 +- .../ui/match_wildcard_for_single_variants.rs | 20 +- tests/ui/mem_replace.fixed | 24 ++ tests/ui/mem_replace.rs | 24 ++ tests/ui/mem_replace.stderr | 46 ++-- tests/ui/mem_replace_macro.rs | 1 + tests/ui/mem_replace_no_std.fixed | 7 + tests/ui/mem_replace_no_std.rs | 7 + tests/ui/mem_replace_no_std.stderr | 12 +- tests/ui/methods.rs | 2 + tests/ui/methods.stderr | 4 +- tests/ui/methods_fixable.fixed | 2 +- tests/ui/methods_fixable.rs | 2 +- tests/ui/min_ident_chars.rs | 52 ++-- tests/ui/min_ident_chars.stderr | 64 ++--- tests/ui/mismatched_target_os_non_unix.fixed | 8 +- tests/ui/mismatched_target_os_non_unix.rs | 8 +- tests/ui/mismatched_target_os_unix.fixed | 33 +-- tests/ui/mismatched_target_os_unix.rs | 33 +-- .../missing_asserts_for_indexing_unfixable.rs | 6 +- tests/ui/missing_doc.rs | 21 +- tests/ui/missing_doc.stderr | 23 +- tests/ui/missing_doc_impl.rs | 11 +- tests/ui/missing_doc_impl.stderr | 14 +- tests/ui/missing_panics_doc.rs | 12 + tests/ui/missing_panics_doc.stderr | 48 ++-- tests/ui/missing_spin_loop.fixed | 8 +- tests/ui/missing_spin_loop.rs | 8 +- tests/ui/missing_spin_loop.stderr | 6 +- tests/ui/missing_spin_loop_no_std.fixed | 2 +- tests/ui/missing_spin_loop_no_std.rs | 2 +- tests/ui/mistyped_literal_suffix.fixed | 29 ++- tests/ui/mistyped_literal_suffix.rs | 29 ++- tests/ui/mistyped_literal_suffix.stderr | 28 +-- tests/ui/multiple_unsafe_ops_per_block.rs | 8 + tests/ui/multiple_unsafe_ops_per_block.stderr | 58 ++--- tests/ui/must_use_candidates.fixed | 5 + tests/ui/must_use_candidates.rs | 5 + tests/ui/must_use_candidates.stderr | 10 +- tests/ui/must_use_unit.fixed | 6 +- tests/ui/must_use_unit.rs | 6 +- tests/ui/mut_mut.rs | 12 +- tests/ui/mut_mut.stderr | 18 +- tests/ui/mut_mutex_lock.fixed | 2 +- tests/ui/mut_mutex_lock.rs | 2 +- tests/ui/needless_arbitrary_self_type.fixed | 6 + tests/ui/needless_arbitrary_self_type.rs | 6 + tests/ui/needless_arbitrary_self_type.stderr | 12 +- ...edless_arbitrary_self_type_unfixable.fixed | 1 + .../needless_arbitrary_self_type_unfixable.rs | 1 + tests/ui/needless_bitwise_bool.fixed | 1 + tests/ui/needless_bitwise_bool.rs | 1 + tests/ui/needless_bitwise_bool.stderr | 2 +- tests/ui/needless_bool/fixable.fixed | 25 +- tests/ui/needless_bool/fixable.rs | 25 +- tests/ui/needless_bool/fixable.stderr | 42 ++-- tests/ui/needless_bool/simple.rs | 4 + tests/ui/needless_bool/simple.stderr | 8 +- tests/ui/needless_bool_assign.fixed | 4 + tests/ui/needless_bool_assign.rs | 4 + tests/ui/needless_bool_assign.stderr | 10 +- tests/ui/needless_borrow.fixed | 54 ++-- tests/ui/needless_borrow.rs | 54 ++-- tests/ui/needless_borrow.stderr | 54 ++-- tests/ui/needless_borrowed_ref.fixed | 21 +- tests/ui/needless_borrowed_ref.rs | 21 +- tests/ui/needless_borrowed_ref.stderr | 32 +-- .../needless_borrows_for_generic_args.fixed | 16 +- tests/ui/needless_borrows_for_generic_args.rs | 16 +- .../needless_borrows_for_generic_args.stderr | 22 +- tests/ui/needless_collect.fixed | 21 +- tests/ui/needless_collect.rs | 21 +- tests/ui/needless_collect.stderr | 36 +-- tests/ui/needless_else.fixed | 1 + tests/ui/needless_else.rs | 1 + tests/ui/needless_else.stderr | 2 +- tests/ui/needless_for_each_fixable.fixed | 8 + tests/ui/needless_for_each_fixable.rs | 8 + tests/ui/needless_for_each_fixable.stderr | 16 +- tests/ui/needless_if.fixed | 12 +- tests/ui/needless_if.rs | 12 +- tests/ui/needless_if.stderr | 10 +- tests/ui/needless_late_init.fixed | 32 +-- tests/ui/needless_late_init.rs | 32 +-- tests/ui/needless_lifetimes.fixed | 52 +++- tests/ui/needless_lifetimes.rs | 52 +++- tests/ui/needless_lifetimes.stderr | 90 +++---- tests/ui/needless_match.fixed | 13 + tests/ui/needless_match.rs | 13 + tests/ui/needless_match.stderr | 26 +- tests/ui/needless_option_as_deref.fixed | 4 +- tests/ui/needless_option_as_deref.rs | 4 +- tests/ui/needless_option_as_deref.stderr | 4 +- tests/ui/needless_option_take.fixed | 2 +- tests/ui/needless_option_take.rs | 2 +- .../needless_parens_on_range_literals.fixed | 10 +- tests/ui/needless_parens_on_range_literals.rs | 10 +- .../needless_parens_on_range_literals.stderr | 8 +- tests/ui/needless_pass_by_ref_mut.rs | 18 +- tests/ui/needless_pass_by_ref_mut.stderr | 40 +-- tests/ui/needless_pub_self.fixed | 6 +- tests/ui/needless_pub_self.rs | 6 +- tests/ui/needless_question_mark.fixed | 29 +-- tests/ui/needless_question_mark.rs | 29 +-- tests/ui/needless_question_mark.stderr | 6 +- tests/ui/needless_raw_string.fixed | 13 +- tests/ui/needless_raw_string.rs | 13 +- tests/ui/needless_raw_string.stderr | 8 +- tests/ui/needless_raw_string_hashes.fixed | 29 +-- tests/ui/needless_raw_string_hashes.rs | 29 +-- tests/ui/needless_raw_string_hashes.stderr | 6 +- tests/ui/needless_return.fixed | 94 +++---- tests/ui/needless_return.rs | 94 +++---- tests/ui/needless_return.stderr | 82 +++--- .../needless_return_with_question_mark.fixed | 2 +- .../ui/needless_return_with_question_mark.rs | 2 +- tests/ui/needless_splitn.fixed | 23 +- tests/ui/needless_splitn.rs | 23 +- tests/ui/needless_splitn.stderr | 20 +- tests/ui/neg_multiply.fixed | 16 +- tests/ui/neg_multiply.rs | 16 +- tests/ui/new_without_default.fixed | 2 + tests/ui/new_without_default.rs | 2 + tests/ui/new_without_default.stderr | 12 +- tests/ui/non_canonical_clone_impl.fixed | 4 + tests/ui/non_canonical_clone_impl.rs | 4 + tests/ui/non_canonical_clone_impl.stderr | 8 +- tests/ui/non_canonical_partial_ord_impl.fixed | 2 + tests/ui/non_canonical_partial_ord_impl.rs | 2 + .../ui/non_canonical_partial_ord_impl.stderr | 4 +- ...n_canonical_partial_ord_impl_fully_qual.rs | 2 + ...nonical_partial_ord_impl_fully_qual.stderr | 4 +- tests/ui/non_minimal_cfg.fixed | 6 +- tests/ui/non_minimal_cfg.rs | 6 +- tests/ui/nonminimal_bool.rs | 9 + tests/ui/nonminimal_bool.stderr | 24 +- tests/ui/nonminimal_bool_methods.fixed | 26 +- tests/ui/nonminimal_bool_methods.rs | 26 +- tests/ui/numbered_fields.fixed | 2 + tests/ui/numbered_fields.rs | 2 + tests/ui/numbered_fields.stderr | 4 +- tests/ui/obfuscated_if_else.fixed | 2 +- tests/ui/obfuscated_if_else.rs | 2 +- tests/ui/option_as_ref_cloned.fixed | 3 + tests/ui/option_as_ref_cloned.rs | 3 + tests/ui/option_as_ref_cloned.stderr | 4 +- tests/ui/option_as_ref_deref.fixed | 21 +- tests/ui/option_as_ref_deref.rs | 21 +- tests/ui/option_as_ref_deref.stderr | 34 +-- tests/ui/option_env_unwrap.rs | 9 +- tests/ui/option_env_unwrap.stderr | 10 +- tests/ui/option_if_let_else.fixed | 27 ++ tests/ui/option_if_let_else.rs | 27 ++ tests/ui/option_if_let_else.stderr | 50 ++-- tests/ui/option_map_or_none.fixed | 6 + tests/ui/option_map_or_none.rs | 6 + tests/ui/option_map_or_none.stderr | 8 +- tests/ui/option_map_unit_fn_fixable.fixed | 23 +- tests/ui/option_map_unit_fn_fixable.rs | 23 +- tests/ui/option_map_unit_fn_fixable.stderr | 30 +-- tests/ui/or_fun_call.fixed | 49 ++-- tests/ui/or_fun_call.rs | 49 ++-- tests/ui/or_fun_call.stderr | 56 ++--- tests/ui/or_then_unwrap.fixed | 3 + tests/ui/or_then_unwrap.rs | 3 + tests/ui/or_then_unwrap.stderr | 6 +- tests/ui/partialeq_to_none.fixed | 29 +-- tests/ui/partialeq_to_none.rs | 29 +-- tests/ui/partialeq_to_none.stderr | 12 +- tests/ui/path_buf_push_overwrite.fixed | 2 +- tests/ui/path_buf_push_overwrite.rs | 2 +- tests/ui/pattern_type_mismatch/syntax.rs | 2 +- tests/ui/patterns.fixed | 5 +- tests/ui/patterns.rs | 5 +- tests/ui/patterns.stderr | 4 +- tests/ui/precedence.fixed | 24 +- tests/ui/precedence.rs | 24 +- tests/ui/print_literal.fixed | 15 +- tests/ui/print_literal.rs | 15 +- tests/ui/print_literal.stderr | 14 +- tests/ui/println_empty_string.fixed | 8 +- tests/ui/println_empty_string.rs | 8 +- tests/ui/ptr_as_ptr.fixed | 65 ++--- tests/ui/ptr_as_ptr.rs | 65 ++--- tests/ui/ptr_as_ptr.stderr | 64 ++--- tests/ui/ptr_cast_constness.fixed | 13 +- tests/ui/ptr_cast_constness.rs | 13 +- tests/ui/ptr_cast_constness.stderr | 12 +- tests/ui/ptr_eq.fixed | 3 +- tests/ui/ptr_eq.rs | 3 +- tests/ui/ptr_eq.stderr | 2 +- tests/ui/ptr_eq_no_std.fixed | 3 +- tests/ui/ptr_eq_no_std.rs | 3 +- tests/ui/ptr_eq_no_std.stderr | 2 +- tests/ui/ptr_offset_with_cast.fixed | 2 + tests/ui/ptr_offset_with_cast.rs | 2 + tests/ui/ptr_offset_with_cast.stderr | 2 +- tests/ui/pub_with_shorthand.fixed | 8 +- tests/ui/pub_with_shorthand.rs | 8 +- tests/ui/pub_without_shorthand.fixed | 6 +- tests/ui/pub_without_shorthand.rs | 6 +- tests/ui/question_mark.fixed | 16 ++ tests/ui/question_mark.rs | 16 ++ tests/ui/question_mark.stderr | 32 +-- tests/ui/range_contains.fixed | 38 +-- tests/ui/range_contains.rs | 38 +-- tests/ui/range_contains.stderr | 6 +- tests/ui/range_plus_minus_one.fixed | 18 +- tests/ui/range_plus_minus_one.rs | 18 +- tests/ui/rc_buffer.fixed | 16 +- tests/ui/rc_buffer.rs | 16 +- tests/ui/rc_buffer_arc.fixed | 16 +- tests/ui/rc_buffer_arc.rs | 16 +- tests/ui/read_line_without_trim.fixed | 6 +- tests/ui/read_line_without_trim.rs | 6 +- tests/ui/read_line_without_trim.stderr | 12 +- tests/ui/redundant_allocation_fixable.fixed | 21 +- tests/ui/redundant_allocation_fixable.rs | 21 +- tests/ui/redundant_allocation_fixable.stderr | 20 +- tests/ui/redundant_as_str.fixed | 2 + tests/ui/redundant_as_str.rs | 2 + tests/ui/redundant_as_str.stderr | 2 +- tests/ui/redundant_async_block.fixed | 18 +- tests/ui/redundant_async_block.rs | 18 +- tests/ui/redundant_async_block.stderr | 12 +- tests/ui/redundant_at_rest_pattern.fixed | 12 +- tests/ui/redundant_at_rest_pattern.rs | 12 +- tests/ui/redundant_clone.fixed | 25 +- tests/ui/redundant_clone.rs | 25 +- tests/ui/redundant_clone.stderr | 56 ++--- tests/ui/redundant_closure_call_fixable.fixed | 29 ++- tests/ui/redundant_closure_call_fixable.rs | 29 ++- .../ui/redundant_closure_call_fixable.stderr | 32 +-- tests/ui/redundant_field_names.fixed | 14 +- tests/ui/redundant_field_names.rs | 14 +- tests/ui/redundant_field_names.stderr | 4 +- tests/ui/redundant_guards.fixed | 42 ++-- tests/ui/redundant_guards.rs | 42 ++-- tests/ui/redundant_guards.stderr | 48 ++-- tests/ui/redundant_locals.rs | 28 +-- ...edundant_pattern_matching_drop_order.fixed | 23 +- .../redundant_pattern_matching_drop_order.rs | 23 +- ...dundant_pattern_matching_drop_order.stderr | 40 +-- ...dundant_pattern_matching_if_let_true.fixed | 12 +- .../redundant_pattern_matching_if_let_true.rs | 12 +- ...undant_pattern_matching_if_let_true.stderr | 8 +- .../redundant_pattern_matching_ipaddr.fixed | 21 +- tests/ui/redundant_pattern_matching_ipaddr.rs | 21 +- .../redundant_pattern_matching_ipaddr.stderr | 36 +-- .../redundant_pattern_matching_option.fixed | 44 ++-- tests/ui/redundant_pattern_matching_option.rs | 44 ++-- .../redundant_pattern_matching_option.stderr | 58 ++--- .../ui/redundant_pattern_matching_poll.fixed | 27 +- tests/ui/redundant_pattern_matching_poll.rs | 27 +- .../ui/redundant_pattern_matching_poll.stderr | 36 +-- .../redundant_pattern_matching_result.fixed | 33 ++- tests/ui/redundant_pattern_matching_result.rs | 33 ++- .../redundant_pattern_matching_result.stderr | 52 ++-- tests/ui/redundant_pub_crate.fixed | 16 ++ tests/ui/redundant_pub_crate.rs | 16 ++ tests/ui/redundant_pub_crate.stderr | 32 +-- tests/ui/redundant_slicing.fixed | 5 +- tests/ui/redundant_slicing.rs | 5 +- tests/ui/redundant_slicing.stderr | 6 +- tests/ui/redundant_static_lifetimes.fixed | 20 +- tests/ui/redundant_static_lifetimes.rs | 20 +- tests/ui/redundant_static_lifetimes.stderr | 36 +-- tests/ui/ref_as_ptr.fixed | 84 ++++--- tests/ui/ref_as_ptr.rs | 84 ++++--- tests/ui/ref_as_ptr.stderr | 28 +-- tests/ui/regex.rs | 7 +- tests/ui/regex.stderr | 34 +-- tests/ui/repeat_once.fixed | 12 +- tests/ui/repeat_once.rs | 12 +- tests/ui/reserve_after_initialization.fixed | 3 + tests/ui/reserve_after_initialization.rs | 3 + tests/ui/reserve_after_initialization.stderr | 6 +- tests/ui/result_map_unit_fn_fixable.fixed | 21 +- tests/ui/result_map_unit_fn_fixable.rs | 21 +- tests/ui/result_map_unit_fn_fixable.stderr | 28 +-- tests/ui/reversed_empty_ranges_fixable.fixed | 6 +- tests/ui/reversed_empty_ranges_fixable.rs | 6 +- tests/ui/reversed_empty_ranges_fixable.stderr | 6 +- .../reversed_empty_ranges_loops_fixable.fixed | 6 + .../ui/reversed_empty_ranges_loops_fixable.rs | 6 + ...reversed_empty_ranges_loops_fixable.stderr | 12 +- tests/ui/search_is_some.rs | 10 +- tests/ui/search_is_some.stderr | 16 +- tests/ui/search_is_some_fixable_none.fixed | 54 +++- tests/ui/search_is_some_fixable_none.rs | 54 +++- tests/ui/search_is_some_fixable_none.stderr | 84 +++---- tests/ui/search_is_some_fixable_some.fixed | 57 ++++- tests/ui/search_is_some_fixable_some.rs | 57 ++++- tests/ui/search_is_some_fixable_some.stderr | 92 +++---- tests/ui/seek_from_current.fixed | 2 +- tests/ui/seek_from_current.rs | 2 +- .../ui/seek_to_start_instead_of_rewind.fixed | 6 +- tests/ui/seek_to_start_instead_of_rewind.rs | 6 +- tests/ui/semicolon_if_nothing_returned.fixed | 9 +- tests/ui/semicolon_if_nothing_returned.rs | 9 +- tests/ui/semicolon_inside_block.fixed | 7 +- tests/ui/semicolon_inside_block.rs | 7 +- tests/ui/semicolon_inside_block.stderr | 4 +- tests/ui/semicolon_outside_block.fixed | 7 +- tests/ui/semicolon_outside_block.rs | 7 +- tests/ui/semicolon_outside_block.stderr | 4 +- tests/ui/shadow.rs | 43 ++-- tests/ui/shadow.stderr | 46 ++-- tests/ui/short_circuit_statement.fixed | 6 +- tests/ui/short_circuit_statement.rs | 6 +- tests/ui/should_panic_without_expect.rs | 2 +- tests/ui/significant_drop_tightening.fixed | 4 + tests/ui/significant_drop_tightening.rs | 4 + tests/ui/significant_drop_tightening.stderr | 12 +- tests/ui/single_call_fn.rs | 7 +- tests/ui/single_call_fn.stderr | 8 +- tests/ui/single_char_add_str.fixed | 30 +-- tests/ui/single_char_add_str.rs | 30 +-- tests/ui/single_char_pattern.fixed | 79 +++--- tests/ui/single_char_pattern.rs | 79 +++--- tests/ui/single_char_pattern.stderr | 18 +- tests/ui/single_component_path_imports.fixed | 4 +- tests/ui/single_component_path_imports.rs | 4 +- tests/ui/single_element_loop.fixed | 7 + tests/ui/single_element_loop.rs | 7 + tests/ui/single_element_loop.stderr | 14 +- tests/ui/single_match.fixed | 18 ++ tests/ui/single_match.rs | 18 ++ tests/ui/single_match.stderr | 36 +-- tests/ui/single_match_else.fixed | 9 + tests/ui/single_match_else.rs | 9 + tests/ui/single_match_else.stderr | 18 +- tests/ui/single_range_in_vec_init.rs | 20 +- tests/ui/skip_while_next.rs | 2 + tests/ui/skip_while_next.stderr | 2 +- tests/ui/stable_sort_primitive.fixed | 14 +- tests/ui/stable_sort_primitive.rs | 14 +- tests/ui/starts_ends_with.fixed | 26 +- tests/ui/starts_ends_with.rs | 26 +- tests/ui/starts_ends_with.stderr | 24 +- tests/ui/str_split.fixed | 19 +- tests/ui/str_split.rs | 19 +- tests/ui/string_add.rs | 6 +- tests/ui/string_add.stderr | 4 +- tests/ui/string_add_assign.fixed | 4 +- tests/ui/string_add_assign.rs | 4 +- tests/ui/string_add_assign.stderr | 2 +- tests/ui/string_extend.fixed | 8 +- tests/ui/string_extend.rs | 8 +- tests/ui/string_from_utf8_as_bytes.fixed | 1 + tests/ui/string_from_utf8_as_bytes.rs | 1 + tests/ui/string_lit_as_bytes.fixed | 9 +- tests/ui/string_lit_as_bytes.rs | 9 +- tests/ui/string_lit_as_bytes.stderr | 8 +- tests/ui/string_lit_chars_any.fixed | 5 + tests/ui/string_lit_chars_any.rs | 5 + tests/ui/string_lit_chars_any.stderr | 8 +- tests/ui/strlen_on_c_strings.fixed | 7 + tests/ui/strlen_on_c_strings.rs | 7 + tests/ui/strlen_on_c_strings.stderr | 12 +- tests/ui/struct_fields.rs | 10 +- tests/ui/struct_fields.stderr | 12 +- tests/ui/suspicious_doc_comments.fixed | 9 + tests/ui/suspicious_doc_comments.rs | 9 + tests/ui/suspicious_doc_comments.stderr | 18 +- tests/ui/suspicious_else_formatting.rs | 9 + tests/ui/suspicious_else_formatting.stderr | 18 +- tests/ui/suspicious_operation_groupings.fixed | 28 ++- tests/ui/suspicious_operation_groupings.rs | 28 ++- .../ui/suspicious_operation_groupings.stderr | 50 ++-- tests/ui/suspicious_xor_used_as_pow.rs | 1 + tests/ui/suspicious_xor_used_as_pow.stderr | 14 +- tests/ui/swap.fixed | 17 ++ tests/ui/swap.rs | 17 ++ tests/ui/swap.stderr | 34 +-- tests/ui/swap_ptr_to_ref.fixed | 7 +- tests/ui/swap_ptr_to_ref.rs | 7 +- tests/ui/tabs_in_doc_comments.fixed | 8 + tests/ui/tabs_in_doc_comments.rs | 8 + tests/ui/tabs_in_doc_comments.stderr | 16 +- tests/ui/test_attr_in_doctest.rs | 3 + tests/ui/test_attr_in_doctest.stderr | 6 +- tests/ui/to_digit_is_some.fixed | 4 +- tests/ui/to_digit_is_some.rs | 4 +- ...to_string_in_format_args_incremental.fixed | 2 +- .../to_string_in_format_args_incremental.rs | 2 +- tests/ui/to_string_trait_impl.rs | 2 + tests/ui/to_string_trait_impl.stderr | 4 +- tests/ui/toplevel_ref_arg.fixed | 12 +- tests/ui/toplevel_ref_arg.rs | 12 +- tests/ui/toplevel_ref_arg_non_rustfix.rs | 3 +- tests/ui/toplevel_ref_arg_non_rustfix.stderr | 4 +- tests/ui/trait_duplication_in_bounds.fixed | 11 +- tests/ui/trait_duplication_in_bounds.rs | 11 +- tests/ui/trait_duplication_in_bounds.stderr | 18 +- tests/ui/transmute_ptr_to_ref.fixed | 33 ++- tests/ui/transmute_ptr_to_ref.rs | 33 ++- tests/ui/transmute_ptr_to_ref.stderr | 36 +-- .../transmutes_expressible_as_ptr_casts.fixed | 10 + .../ui/transmutes_expressible_as_ptr_casts.rs | 10 + ...transmutes_expressible_as_ptr_casts.stderr | 18 +- tests/ui/trim_split_whitespace.fixed | 12 + tests/ui/trim_split_whitespace.rs | 12 + tests/ui/trim_split_whitespace.stderr | 16 +- tests/ui/trivially_copy_pass_by_ref.rs | 2 +- tests/ui/try_err.fixed | 20 +- tests/ui/try_err.rs | 20 +- tests/ui/try_err.stderr | 8 +- tests/ui/tuple_array_conversions.rs | 16 +- tests/ui/tuple_array_conversions.stderr | 14 +- tests/ui/type_id_on_box.fixed | 5 +- tests/ui/type_id_on_box.rs | 5 +- tests/ui/type_id_on_box.stderr | 4 +- tests/ui/types.fixed | 2 +- tests/ui/types.rs | 2 +- tests/ui/unchecked_duration_subtraction.fixed | 5 +- tests/ui/unchecked_duration_subtraction.rs | 5 +- .../ui/unchecked_duration_subtraction.stderr | 4 +- tests/ui/unconditional_recursion.rs | 15 +- tests/ui/unconditional_recursion.stderr | 82 +++--- tests/ui/unicode.fixed | 12 +- tests/ui/unicode.rs | 12 +- tests/ui/unicode.stderr | 18 +- tests/ui/uninhabited_references.rs | 6 +- tests/ui/uninhabited_references.stderr | 8 +- tests/ui/uninlined_format_args.fixed | 125 +++++---- tests/ui/uninlined_format_args.rs | 125 +++++---- tests/ui/uninlined_format_args.stderr | 140 +++++------ ...nlined_format_args_panic.edition2018.fixed | 9 +- ...nlined_format_args_panic.edition2021.fixed | 9 +- ...lined_format_args_panic.edition2021.stderr | 4 +- tests/ui/uninlined_format_args_panic.rs | 9 +- tests/ui/unit_arg.rs | 17 +- tests/ui/unit_arg.stderr | 22 +- tests/ui/unit_arg_empty_blocks.fixed | 8 +- tests/ui/unit_arg_empty_blocks.rs | 8 +- tests/ui/unnecessary_cast.fixed | 76 +++--- tests/ui/unnecessary_cast.rs | 76 +++--- tests/ui/unnecessary_cast.stderr | 60 ++--- tests/ui/unnecessary_filter_map.rs | 1 + tests/ui/unnecessary_find_map.rs | 1 + tests/ui/unnecessary_fold.fixed | 17 +- tests/ui/unnecessary_fold.rs | 17 +- tests/ui/unnecessary_fold.stderr | 30 +-- tests/ui/unnecessary_iter_cloned.fixed | 2 + tests/ui/unnecessary_iter_cloned.rs | 2 + tests/ui/unnecessary_iter_cloned.stderr | 4 +- tests/ui/unnecessary_join.fixed | 2 + tests/ui/unnecessary_join.rs | 2 + tests/ui/unnecessary_join.stderr | 4 +- tests/ui/unnecessary_lazy_eval.fixed | 45 +++- tests/ui/unnecessary_lazy_eval.rs | 45 +++- tests/ui/unnecessary_lazy_eval.stderr | 124 ++++----- tests/ui/unnecessary_lazy_eval_unfixable.rs | 1 + tests/ui/unnecessary_literal_unwrap.fixed | 68 +++-- tests/ui/unnecessary_literal_unwrap.rs | 68 +++-- tests/ui/unnecessary_literal_unwrap.stderr | 102 ++++---- tests/ui/unnecessary_map_on_constructor.fixed | 9 +- tests/ui/unnecessary_map_on_constructor.rs | 9 +- .../ui/unnecessary_map_on_constructor.stderr | 12 +- tests/ui/unnecessary_operation.fixed | 37 +-- tests/ui/unnecessary_operation.rs | 37 +-- tests/ui/unnecessary_operation.stderr | 4 +- .../ui/unnecessary_owned_empty_strings.fixed | 2 + tests/ui/unnecessary_owned_empty_strings.rs | 2 + .../ui/unnecessary_owned_empty_strings.stderr | 2 +- tests/ui/unnecessary_safety_comment.rs | 2 +- tests/ui/unnecessary_self_imports.fixed | 4 +- tests/ui/unnecessary_self_imports.rs | 4 +- tests/ui/unnecessary_sort_by.fixed | 14 +- tests/ui/unnecessary_sort_by.rs | 14 +- tests/ui/unnecessary_sort_by.stderr | 18 +- .../unnecessary_struct_initialization.fixed | 10 +- tests/ui/unnecessary_struct_initialization.rs | 10 +- .../unnecessary_struct_initialization.stderr | 4 +- tests/ui/unnecessary_to_owned.fixed | 111 +++++--- tests/ui/unnecessary_to_owned.rs | 111 +++++--- tests/ui/unnecessary_to_owned.stderr | 168 ++++++------- tests/ui/unnecessary_unsafety_doc.rs | 8 +- tests/ui/unnecessary_unsafety_doc.stderr | 14 +- tests/ui/unneeded_field_pattern.rs | 4 +- tests/ui/unneeded_wildcard_pattern.fixed | 28 +-- tests/ui/unneeded_wildcard_pattern.rs | 28 +-- tests/ui/unnested_or_patterns.fixed | 24 +- tests/ui/unnested_or_patterns.rs | 24 +- tests/ui/unnested_or_patterns.stderr | 30 +-- tests/ui/unnested_or_patterns2.fixed | 9 +- tests/ui/unnested_or_patterns2.rs | 9 +- tests/ui/unnested_or_patterns2.stderr | 14 +- tests/ui/unreadable_literal.fixed | 16 +- tests/ui/unreadable_literal.rs | 16 +- tests/ui/unreadable_literal.stderr | 12 +- tests/ui/unseparated_prefix_literals.fixed | 18 +- tests/ui/unseparated_prefix_literals.rs | 18 +- tests/ui/unused_enumerate_index.fixed | 2 + tests/ui/unused_enumerate_index.rs | 2 + tests/ui/unused_enumerate_index.stderr | 4 +- tests/ui/unused_io_amount.rs | 2 +- tests/ui/unused_rounding.fixed | 10 +- tests/ui/unused_rounding.rs | 10 +- tests/ui/unused_unit.fixed | 31 ++- tests/ui/unused_unit.rs | 31 ++- tests/ui/unused_unit.stderr | 34 +-- tests/ui/unwrap_or_else_default.fixed | 26 +- tests/ui/unwrap_or_else_default.rs | 26 +- tests/ui/unwrap_or_else_default.stderr | 28 +-- tests/ui/use_self.fixed | 68 +++-- tests/ui/use_self.rs | 68 +++-- tests/ui/use_self.stderr | 84 +++---- tests/ui/use_self_trait.fixed | 19 +- tests/ui/use_self_trait.rs | 19 +- tests/ui/use_self_trait.stderr | 32 +-- tests/ui/used_underscore_binding.rs | 10 +- tests/ui/used_underscore_binding.stderr | 8 +- tests/ui/useless_asref.fixed | 22 +- tests/ui/useless_asref.rs | 22 +- tests/ui/useless_attribute.fixed | 6 +- tests/ui/useless_attribute.rs | 6 +- tests/ui/useless_conversion.fixed | 46 ++-- tests/ui/useless_conversion.rs | 46 ++-- tests/ui/useless_conversion.stderr | 66 ++--- tests/ui/vec.fixed | 33 +-- tests/ui/vec.rs | 33 +-- tests/ui/vec.stderr | 12 +- tests/ui/vec_box_sized.rs | 14 +- tests/ui/vec_box_sized.stderr | 8 +- tests/ui/waker_clone_wake.fixed | 4 +- tests/ui/waker_clone_wake.rs | 4 +- tests/ui/while_let_on_iterator.fixed | 28 ++- tests/ui/while_let_on_iterator.rs | 28 ++- tests/ui/while_let_on_iterator.stderr | 54 ++-- tests/ui/wildcard_enum_match_arm.fixed | 10 +- tests/ui/wildcard_enum_match_arm.rs | 10 +- tests/ui/wildcard_enum_match_arm.stderr | 8 +- tests/ui/wildcard_imports.fixed | 40 +-- tests/ui/wildcard_imports.rs | 40 +-- tests/ui/wildcard_imports.stderr | 34 +-- .../wildcard_imports_2021.edition2018.fixed | 40 +-- .../wildcard_imports_2021.edition2018.stderr | 34 +-- .../wildcard_imports_2021.edition2021.fixed | 40 +-- .../wildcard_imports_2021.edition2021.stderr | 34 +-- tests/ui/wildcard_imports_2021.rs | 40 +-- tests/ui/write_literal_2.rs | 5 +- tests/ui/write_literal_2.stderr | 20 +- tests/ui/writeln_empty_string.fixed | 4 +- tests/ui/writeln_empty_string.rs | 4 +- tests/ui/zero_ptr.fixed | 8 +- tests/ui/zero_ptr.rs | 8 +- tests/ui/zero_ptr_no_std.fixed | 6 +- tests/ui/zero_ptr_no_std.rs | 6 +- 1174 files changed, 12849 insertions(+), 7994 deletions(-) diff --git a/tests/ui-toml/absolute_paths/absolute_paths.rs b/tests/ui-toml/absolute_paths/absolute_paths.rs index 0e6a54452ee8..efa5136cd33c 100644 --- a/tests/ui-toml/absolute_paths/absolute_paths.rs +++ b/tests/ui-toml/absolute_paths/absolute_paths.rs @@ -37,16 +37,16 @@ pub mod a { fn main() { f32::max(1.0, 2.0); - std::f32::MAX; - core::f32::MAX; - ::core::f32::MAX; - crate::a::b::c::C; - crate::a::b::c::d::e::f::F; - crate::a::A; - crate::a::b::B; - crate::a::b::c::C::ZERO; - helper::b::c::d::e::f(); - ::helper::b::c::d::e::f(); + std::f32::MAX; //~ absolute_paths + core::f32::MAX; //~ absolute_paths + ::core::f32::MAX; //~ absolute_paths + crate::a::b::c::C; //~[disallow_crates] absolute_paths + crate::a::b::c::d::e::f::F; //~[disallow_crates] absolute_paths + crate::a::A; //~[disallow_crates] absolute_paths + crate::a::b::B; //~[disallow_crates] absolute_paths + crate::a::b::c::C::ZERO; //~[disallow_crates] absolute_paths + helper::b::c::d::e::f(); //~[disallow_crates] absolute_paths + ::helper::b::c::d::e::f(); //~[disallow_crates] absolute_paths fn b() -> a::b::B { todo!() } @@ -55,7 +55,7 @@ fn main() { std::ptr::addr_of!(x); // Test we handle max segments with `PathRoot` properly; this has 4 segments but we should say it // has 3 - ::std::f32::MAX; + ::std::f32::MAX; //~ absolute_paths // Do not lint due to the above ::helper::a(); // Do not lint diff --git a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed index c04543da94b9..5cdfe4d11393 100644 --- a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed +++ b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed @@ -6,9 +6,14 @@ fn main() { let local_f64 = 2.0; let local_opt: Option = Some(3); - println!("val='{local_i32}'"); + println!("val='{local_i32}'"); //~ uninlined_format_args println!("Hello x is {local_f64:.local_i32$}"); + //~^ uninlined_format_args + //~| print_literal println!("Hello {local_i32} is {local_f64:.*}", 5); + //~^ uninlined_format_args println!("Hello {local_i32} is {local_f64:.*}", 5); + //~^ uninlined_format_args println!("{local_i32}, {}", local_opt.unwrap()); + //~^ uninlined_format_args } diff --git a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs index 813830d80b83..2a005b1c5fe8 100644 --- a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs +++ b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs @@ -6,9 +6,14 @@ fn main() { let local_f64 = 2.0; let local_opt: Option = Some(3); - println!("val='{}'", local_i32); + println!("val='{}'", local_i32); //~ uninlined_format_args println!("Hello {} is {:.*}", "x", local_i32, local_f64); + //~^ uninlined_format_args + //~| print_literal println!("Hello {} is {:.*}", local_i32, 5, local_f64); + //~^ uninlined_format_args println!("Hello {} is {2:.*}", local_i32, 5, local_f64); + //~^ uninlined_format_args println!("{}, {}", local_i32, local_opt.unwrap()); + //~^ uninlined_format_args } diff --git a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr index 7227a45bb436..312769905161 100644 --- a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr +++ b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr @@ -39,7 +39,7 @@ LL + println!("Hello x is {:.*}", local_i32, local_f64); | error: variables can be used directly in the `format!` string - --> $DIR/allow_mixed_uninlined_format_args/uninlined_format_args.rs:11:5 + --> $DIR/allow_mixed_uninlined_format_args/uninlined_format_args.rs:13:5 | LL | println!("Hello {} is {:.*}", local_i32, 5, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -51,7 +51,7 @@ LL + println!("Hello {local_i32} is {local_f64:.*}", 5); | error: variables can be used directly in the `format!` string - --> $DIR/allow_mixed_uninlined_format_args/uninlined_format_args.rs:12:5 + --> $DIR/allow_mixed_uninlined_format_args/uninlined_format_args.rs:15:5 | LL | println!("Hello {} is {2:.*}", local_i32, 5, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -63,7 +63,7 @@ LL + println!("Hello {local_i32} is {local_f64:.*}", 5); | error: variables can be used directly in the `format!` string - --> $DIR/allow_mixed_uninlined_format_args/uninlined_format_args.rs:13:5 + --> $DIR/allow_mixed_uninlined_format_args/uninlined_format_args.rs:17:5 | LL | println!("{}, {}", local_i32, local_opt.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs b/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs index 33f7c8ba8042..4a0629cf0e69 100644 --- a/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs +++ b/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs @@ -66,7 +66,7 @@ fn lhs_and_rhs_are_equal() { // is implicitly on the list let _ = Bar + Bar; // not on the list - let _ = Baz + Baz; + let _ = Baz + Baz; //~ arithmetic_side_effects } fn lhs_is_different() { @@ -77,14 +77,14 @@ fn lhs_is_different() { // is implicitly on the list let _ = 1i32 + Bar; // not on the list - let _ = 1i32 + Baz; + let _ = 1i32 + Baz; //~ arithmetic_side_effects // not on the list - let _ = 1i64 + Foo; + let _ = 1i64 + Foo; //~ arithmetic_side_effects // is implicitly on the list let _ = 1i64 + Bar; // not on the list - let _ = 1i64 + Baz; + let _ = 1i64 + Baz; //~ arithmetic_side_effects } fn rhs_is_different() { @@ -95,14 +95,14 @@ fn rhs_is_different() { // is implicitly on the list let _ = Bar + 1i32; // not on the list - let _ = Baz + 1i32; + let _ = Baz + 1i32; //~ arithmetic_side_effects // not on the list - let _ = Foo + 1i64; + let _ = Foo + 1i64; //~ arithmetic_side_effects // is implicitly on the list let _ = Bar + 1i64; // not on the list - let _ = Baz + 1i64; + let _ = Baz + 1i64; //~ arithmetic_side_effects } fn unary() { @@ -111,9 +111,9 @@ fn unary() { // is explicitly on the list let _ = -Foo; // not on the list - let _ = -Bar; + let _ = -Bar; //~ arithmetic_side_effects // not on the list - let _ = -Baz; + let _ = -Baz; //~ arithmetic_side_effects } fn main() {} diff --git a/tests/ui-toml/array_size_threshold/array_size_threshold.rs b/tests/ui-toml/array_size_threshold/array_size_threshold.rs index d36159e12639..1fb0c98bc708 100644 --- a/tests/ui-toml/array_size_threshold/array_size_threshold.rs +++ b/tests/ui-toml/array_size_threshold/array_size_threshold.rs @@ -2,9 +2,11 @@ #![warn(clippy::large_const_arrays, clippy::large_stack_arrays)] //@no-rustfix const ABOVE: [u8; 11] = [0; 11]; +//~^ large_const_arrays +//~| large_stack_arrays const BELOW: [u8; 10] = [0; 10]; fn main() { - let above = [0u8; 11]; + let above = [0u8; 11]; //~ large_stack_arrays let below = [0u8; 10]; } diff --git a/tests/ui-toml/array_size_threshold/array_size_threshold.stderr b/tests/ui-toml/array_size_threshold/array_size_threshold.stderr index 5ceea60a2aba..f14a307d803a 100644 --- a/tests/ui-toml/array_size_threshold/array_size_threshold.stderr +++ b/tests/ui-toml/array_size_threshold/array_size_threshold.stderr @@ -20,7 +20,7 @@ LL | const ABOVE: [u8; 11] = [0; 11]; = help: to override `-D warnings` add `#[allow(clippy::large_stack_arrays)]` error: allocating a local array larger than 10 bytes - --> $DIR/array_size_threshold/array_size_threshold.rs:8:17 + --> $DIR/array_size_threshold/array_size_threshold.rs:10:17 | LL | let above = [0u8; 11]; | ^^^^^^^^^ diff --git a/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs b/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs index 868cf00a8d46..418d724b782f 100644 --- a/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs +++ b/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs @@ -2,12 +2,13 @@ use std::net::Ipv4Addr; async fn bad() -> u32 { - let _x = String::from("hello"); + let _x = String::from("hello"); //~ await_holding_invalid_type baz().await } async fn bad_reason() -> u32 { let x = Ipv4Addr::new(127, 0, 0, 1); + //~^ await_holding_invalid_type let y = baz().await; let _x = x; y @@ -30,7 +31,7 @@ async fn baz() -> u32 { #[allow(clippy::manual_async_fn)] fn block_bad() -> impl std::future::Future { async move { - let _x = String::from("hi!"); + let _x = String::from("hi!"); //~ await_holding_invalid_type baz().await } } diff --git a/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr b/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr index ac5d0ea2bd97..aa6b721af0a3 100644 --- a/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr +++ b/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr @@ -15,7 +15,7 @@ LL | let x = Ipv4Addr::new(127, 0, 0, 1); | ^ error: `std::string::String` may not be held across an `await` point per `clippy.toml` - --> $DIR/await_holding_invalid_type/await_holding_invalid_type.rs:33:13 + --> $DIR/await_holding_invalid_type/await_holding_invalid_type.rs:34:13 | LL | let _x = String::from("hi!"); | ^^ diff --git a/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs index 7f1c512d7c97..132ad1f6afde 100644 --- a/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs +++ b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs @@ -3,6 +3,7 @@ fn main() {} #[warn(clippy::cognitive_complexity)] +//~v cognitive_complexity fn cognitive_complexity() { let x = vec![1, 2, 3]; for i in x { diff --git a/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr index 8502e3d42fc2..8805e6f07929 100644 --- a/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr +++ b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr @@ -11,7 +11,7 @@ LL | blacklisted-names = [ "..", "wibble" ] | ^^^^^^^^^^^^^^^^^ error: the function has a cognitive complexity of (3/2) - --> $DIR/conf_deprecated_key/conf_deprecated_key.rs:6:4 + --> $DIR/conf_deprecated_key/conf_deprecated_key.rs:7:4 | LL | fn cognitive_complexity() { | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/dbg_macro/dbg_macro.rs b/tests/ui-toml/dbg_macro/dbg_macro.rs index 67129e624771..9c5270f75ef7 100644 --- a/tests/ui-toml/dbg_macro/dbg_macro.rs +++ b/tests/ui-toml/dbg_macro/dbg_macro.rs @@ -3,22 +3,24 @@ //@no-rustfix fn foo(n: u32) -> u32 { if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } + //~^ dbg_macro } fn factorial(n: u32) -> u32 { + //~v dbg_macro if dbg!(n <= 1) { - dbg!(1) + dbg!(1) //~ dbg_macro } else { - dbg!(n * factorial(n - 1)) + dbg!(n * factorial(n - 1)) //~ dbg_macro } } fn main() { - dbg!(42); - dbg!(dbg!(dbg!(42))); - foo(3) + dbg!(factorial(4)); - dbg!(1, 2, dbg!(3, 4)); - dbg!(1, 2, 3, 4, 5); + dbg!(42); //~ dbg_macro + dbg!(dbg!(dbg!(42))); //~ dbg_macro + foo(3) + dbg!(factorial(4)); //~ dbg_macro + dbg!(1, 2, dbg!(3, 4)); //~ dbg_macro + dbg!(1, 2, 3, 4, 5); //~ dbg_macro } #[test] diff --git a/tests/ui-toml/dbg_macro/dbg_macro.stderr b/tests/ui-toml/dbg_macro/dbg_macro.stderr index 6042fa043f0d..055a541996de 100644 --- a/tests/ui-toml/dbg_macro/dbg_macro.stderr +++ b/tests/ui-toml/dbg_macro/dbg_macro.stderr @@ -12,7 +12,7 @@ LL | if let Some(n) = n.checked_sub(4) { n } else { n } | ~~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro/dbg_macro.rs:9:8 + --> $DIR/dbg_macro/dbg_macro.rs:11:8 | LL | if dbg!(n <= 1) { | ^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | if n <= 1 { | ~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro/dbg_macro.rs:10:9 + --> $DIR/dbg_macro/dbg_macro.rs:12:9 | LL | dbg!(1) | ^^^^^^^ @@ -31,10 +31,10 @@ LL | dbg!(1) help: remove the invocation before committing it to a version control system | LL | 1 - | + | ~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro/dbg_macro.rs:12:9 + --> $DIR/dbg_macro/dbg_macro.rs:14:9 | LL | dbg!(n * factorial(n - 1)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -42,10 +42,10 @@ LL | dbg!(n * factorial(n - 1)) help: remove the invocation before committing it to a version control system | LL | n * factorial(n - 1) - | + | ~~~~~~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro/dbg_macro.rs:17:5 + --> $DIR/dbg_macro/dbg_macro.rs:19:5 | LL | dbg!(42); | ^^^^^^^^ @@ -56,7 +56,7 @@ LL | 42; | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro/dbg_macro.rs:18:5 + --> $DIR/dbg_macro/dbg_macro.rs:20:5 | LL | dbg!(dbg!(dbg!(42))); | ^^^^^^^^^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | dbg!(dbg!(42)); | ~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro/dbg_macro.rs:19:14 + --> $DIR/dbg_macro/dbg_macro.rs:21:14 | LL | foo(3) + dbg!(factorial(4)); | ^^^^^^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | foo(3) + factorial(4); | ~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro/dbg_macro.rs:20:5 + --> $DIR/dbg_macro/dbg_macro.rs:22:5 | LL | dbg!(1, 2, dbg!(3, 4)); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | (1, 2, dbg!(3, 4)); | ~~~~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro/dbg_macro.rs:21:5 + --> $DIR/dbg_macro/dbg_macro.rs:23:5 | LL | dbg!(1, 2, 3, 4, 5); | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/disallowed_macros/disallowed_macros.rs b/tests/ui-toml/disallowed_macros/disallowed_macros.rs index e63a99e74cbb..dfe871115038 100644 --- a/tests/ui-toml/disallowed_macros/disallowed_macros.rs +++ b/tests/ui-toml/disallowed_macros/disallowed_macros.rs @@ -10,39 +10,40 @@ use proc_macros::Derive; use serde::Serialize; fn main() { - println!("one"); - println!("two"); - cfg!(unix); - vec![1, 2, 3]; + println!("one"); //~ disallowed_macros + println!("two"); //~ disallowed_macros + cfg!(unix); //~ disallowed_macros + vec![1, 2, 3]; //~ disallowed_macros - #[derive(Serialize)] + #[derive(Serialize)] //~ disallowed_macros struct Derive; - let _ = macros::expr!(); - macros::stmt!(); - let macros::pat!() = 1; - let _: macros::ty!() = ""; - macros::item!(); - let _ = macros::binop!(1); + let _ = macros::expr!(); //~ disallowed_macros + macros::stmt!(); //~ disallowed_macros + let macros::pat!() = 1; //~ disallowed_macros + let _: macros::ty!() = ""; //~ disallowed_macros + macros::item!(); //~ disallowed_macros + let _ = macros::binop!(1); //~ disallowed_macros eprintln!("allowed"); } +//~v disallowed_macros macros::attr! { struct S; } impl S { - macros::item!(); + macros::item!(); //~ disallowed_macros } trait Y { - macros::item!(); + macros::item!(); //~ disallowed_macros } impl Y for S { - macros::item!(); + macros::item!(); //~ disallowed_macros } -#[derive(Derive)] +#[derive(Derive)] //~ disallowed_macros struct Foo; diff --git a/tests/ui-toml/disallowed_macros/disallowed_macros.stderr b/tests/ui-toml/disallowed_macros/disallowed_macros.stderr index 8ccf567bba2b..aed5e92a0796 100644 --- a/tests/ui-toml/disallowed_macros/disallowed_macros.stderr +++ b/tests/ui-toml/disallowed_macros/disallowed_macros.stderr @@ -70,7 +70,7 @@ LL | let _ = macros::binop!(1); | ^^^^^^^^^^^^^^^^^ error: use of a disallowed macro `macros::attr` - --> $DIR/disallowed_macros/disallowed_macros.rs:31:1 + --> $DIR/disallowed_macros/disallowed_macros.rs:32:1 | LL | / macros::attr! { LL | | struct S; @@ -78,25 +78,25 @@ LL | | } | |_^ error: use of a disallowed macro `macros::item` - --> $DIR/disallowed_macros/disallowed_macros.rs:36:5 + --> $DIR/disallowed_macros/disallowed_macros.rs:37:5 | LL | macros::item!(); | ^^^^^^^^^^^^^^^ error: use of a disallowed macro `macros::item` - --> $DIR/disallowed_macros/disallowed_macros.rs:40:5 + --> $DIR/disallowed_macros/disallowed_macros.rs:41:5 | LL | macros::item!(); | ^^^^^^^^^^^^^^^ error: use of a disallowed macro `macros::item` - --> $DIR/disallowed_macros/disallowed_macros.rs:44:5 + --> $DIR/disallowed_macros/disallowed_macros.rs:45:5 | LL | macros::item!(); | ^^^^^^^^^^^^^^^ error: use of a disallowed macro `proc_macros::Derive` - --> $DIR/disallowed_macros/disallowed_macros.rs:47:10 + --> $DIR/disallowed_macros/disallowed_macros.rs:48:10 | LL | #[derive(Derive)] | ^^^^^^ diff --git a/tests/ui-toml/disallowed_names_append/disallowed_names.rs b/tests/ui-toml/disallowed_names_append/disallowed_names.rs index a2e2b46c4269..f7753ad2e7bc 100644 --- a/tests/ui-toml/disallowed_names_append/disallowed_names.rs +++ b/tests/ui-toml/disallowed_names_append/disallowed_names.rs @@ -2,9 +2,9 @@ fn main() { // `foo` is part of the default configuration - let foo = "bar"; + let foo = "bar"; //~ disallowed_names // `ducks` was unrightfully disallowed - let ducks = ["quack", "quack"]; + let ducks = ["quack", "quack"]; //~ disallowed_names // `fox` is okay let fox = ["what", "does", "the", "fox", "say", "?"]; } diff --git a/tests/ui-toml/disallowed_names_replace/disallowed_names.rs b/tests/ui-toml/disallowed_names_replace/disallowed_names.rs index a2e2b46c4269..c64ff418d87a 100644 --- a/tests/ui-toml/disallowed_names_replace/disallowed_names.rs +++ b/tests/ui-toml/disallowed_names_replace/disallowed_names.rs @@ -4,7 +4,7 @@ fn main() { // `foo` is part of the default configuration let foo = "bar"; // `ducks` was unrightfully disallowed - let ducks = ["quack", "quack"]; + let ducks = ["quack", "quack"]; //~ disallowed_names // `fox` is okay let fox = ["what", "does", "the", "fox", "say", "?"]; } diff --git a/tests/ui-toml/doc_valid_idents_append/doc_markdown.fixed b/tests/ui-toml/doc_valid_idents_append/doc_markdown.fixed index f16e138da2be..2133dddebb21 100644 --- a/tests/ui-toml/doc_valid_idents_append/doc_markdown.fixed +++ b/tests/ui-toml/doc_valid_idents_append/doc_markdown.fixed @@ -6,6 +6,7 @@ fn allowed_name() {} /// OAuth and LaTeX are inside Clippy's default list. fn default_name() {} +//~v doc_markdown /// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. fn unknown_name() {} diff --git a/tests/ui-toml/doc_valid_idents_append/doc_markdown.rs b/tests/ui-toml/doc_valid_idents_append/doc_markdown.rs index 327a592e9cad..35de058fee36 100644 --- a/tests/ui-toml/doc_valid_idents_append/doc_markdown.rs +++ b/tests/ui-toml/doc_valid_idents_append/doc_markdown.rs @@ -6,6 +6,7 @@ fn allowed_name() {} /// OAuth and LaTeX are inside Clippy's default list. fn default_name() {} +//~v doc_markdown /// TestItemThingyOfCoolness might sound cool but is not on the list and should be linted. fn unknown_name() {} diff --git a/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr b/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr index a0260fb16d81..8ac6f6d1454a 100644 --- a/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr +++ b/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr @@ -1,5 +1,5 @@ error: item in documentation is missing backticks - --> $DIR/doc_valid_idents_append/doc_markdown.rs:9:5 + --> $DIR/doc_valid_idents_append/doc_markdown.rs:10:5 | LL | /// TestItemThingyOfCoolness might sound cool but is not on the list and should be linted. | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.fixed b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.fixed index af6ec675e81b..21e4d05b19af 100644 --- a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.fixed +++ b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.fixed @@ -3,9 +3,12 @@ /// This is a special interface for ClipPy which doesn't require backticks fn allowed_name() {} +//~| doc_markdown +//~v doc_markdown /// `OAuth` and `LaTeX` are inside Clippy's default list. fn default_name() {} +//~v doc_markdown /// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. fn unknown_name() {} diff --git a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.rs b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.rs index 327a592e9cad..50162a7d0db3 100644 --- a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.rs +++ b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.rs @@ -3,9 +3,12 @@ /// This is a special interface for ClipPy which doesn't require backticks fn allowed_name() {} +//~| doc_markdown +//~v doc_markdown /// OAuth and LaTeX are inside Clippy's default list. fn default_name() {} +//~v doc_markdown /// TestItemThingyOfCoolness might sound cool but is not on the list and should be linted. fn unknown_name() {} diff --git a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr index b3b801661af5..9b34bbb3e7d0 100644 --- a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr +++ b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr @@ -1,5 +1,5 @@ error: item in documentation is missing backticks - --> $DIR/doc_valid_idents_replace/doc_markdown.rs:6:5 + --> $DIR/doc_valid_idents_replace/doc_markdown.rs:8:5 | LL | /// OAuth and LaTeX are inside Clippy's default list. | ^^^^^ @@ -12,7 +12,7 @@ LL | /// `OAuth` and LaTeX are inside Clippy's default list. | ~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc_valid_idents_replace/doc_markdown.rs:6:15 + --> $DIR/doc_valid_idents_replace/doc_markdown.rs:8:15 | LL | /// OAuth and LaTeX are inside Clippy's default list. | ^^^^^ @@ -23,7 +23,7 @@ LL | /// OAuth and `LaTeX` are inside Clippy's default list. | ~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc_valid_idents_replace/doc_markdown.rs:9:5 + --> $DIR/doc_valid_idents_replace/doc_markdown.rs:12:5 | LL | /// TestItemThingyOfCoolness might sound cool but is not on the list and should be linted. | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/excessive_nesting/excessive_nesting.rs b/tests/ui-toml/excessive_nesting/excessive_nesting.rs index 4375f324acaa..2a369e0f26d5 100644 --- a/tests/ui-toml/excessive_nesting/excessive_nesting.rs +++ b/tests/ui-toml/excessive_nesting/excessive_nesting.rs @@ -18,7 +18,7 @@ static X: u32 = { let x = { let y = { let z = { - let w = { 3 }; + let w = { 3 }; //~ excessive_nesting w }; z @@ -64,6 +64,7 @@ impl A { pub fn b() { struct C; + //~v excessive_nesting impl C { pub fn c() {} } @@ -78,6 +79,7 @@ trait Lol { fn lmao() { fn bb() { fn cc() { + //~v excessive_nesting let x = { 1 }; // not a warning, but cc is } @@ -95,6 +97,7 @@ pub mod a { pub mod b { pub mod c { pub mod d { + //~v excessive_nesting pub mod e { pub mod f {} } // not here @@ -108,13 +111,14 @@ fn a_but_not(v: u32) {} fn main() { let a = A; - a_but_not({{{{{{{{0}}}}}}}}); - a.a({{{{{{{{{0}}}}}}}}}); - (0, {{{{{{{1}}}}}}}); + a_but_not({{{{{{{{0}}}}}}}}); //~ excessive_nesting + a.a({{{{{{{{{0}}}}}}}}}); //~ excessive_nesting + (0, {{{{{{{1}}}}}}}); //~ excessive_nesting if true { if true { if true { + //~v excessive_nesting if true { if true { @@ -127,6 +131,7 @@ fn main() { let y = (|| { let x = (|| { let y = (|| { + //~v excessive_nesting let z = (|| { let w = { 3 }; w @@ -146,38 +151,52 @@ fn main() { // this is a mess, but that's intentional let mut y = 1; - y += {{{{{5}}}}}; - let z = y + {{{{{{{{{5}}}}}}}}}; - [0, {{{{{{{{{{0}}}}}}}}}}]; - let mut xx = [0; {{{{{{{{100}}}}}}}}]; + y += {{{{{5}}}}}; //~ excessive_nesting + let z = y + {{{{{{{{{5}}}}}}}}}; //~ excessive_nesting + [0, {{{{{{{{{{0}}}}}}}}}}]; //~ excessive_nesting + let mut xx = [0; {{{{{{{{100}}}}}}}}]; //~ excessive_nesting xx[{{{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}}}]; - &mut {{{{{{{{{{y}}}}}}}}}}; + //~^ excessive_nesting + &mut {{{{{{{{{{y}}}}}}}}}}; //~ excessive_nesting for i in {{{{xx}}}} {{{{{{{{}}}}}}}} + //~^ excessive_nesting + //~| excessive_nesting while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}} + //~^ excessive_nesting + //~| excessive_nesting while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}} + //~^ excessive_nesting + //~| excessive_nesting let d = D { d: {{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}} }; + //~^ excessive_nesting {{{{1;}}}}..{{{{{{3}}}}}}; + //~^ excessive_nesting + //~| excessive_nesting {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}}; - ..{{{{{{{5}}}}}}}; - ..={{{{{3}}}}}; - {{{{{1;}}}}}..; + //~^ excessive_nesting + //~| excessive_nesting + ..{{{{{{{5}}}}}}}; //~ excessive_nesting + ..={{{{{3}}}}}; //~ excessive_nesting + {{{{{1;}}}}}..; //~ excessive_nesting - loop { break {{{{1}}}} }; - loop {{{{{{}}}}}} + loop { break {{{{1}}}} }; //~ excessive_nesting + loop {{{{{{}}}}}} //~ excessive_nesting + //~v excessive_nesting match {{{{{{true}}}}}} { - true => {{{{}}}}, - false => {{{{}}}}, + true => {{{{}}}}, //~ excessive_nesting + false => {{{{}}}}, //~ excessive_nesting } { { { + //~v excessive_nesting { println!("warning! :)"); } @@ -187,11 +206,11 @@ fn main() { } async fn b() -> u32 { - async fn c() -> u32 {{{{{{{0}}}}}}} + async fn c() -> u32 {{{{{{{0}}}}}}} //~ excessive_nesting c().await } async fn a() { - {{{{b().await}}}}; + {{{{b().await}}}}; //~ excessive_nesting } diff --git a/tests/ui-toml/excessive_nesting/excessive_nesting.stderr b/tests/ui-toml/excessive_nesting/excessive_nesting.stderr index 856bbd93e0de..e6b16978131f 100644 --- a/tests/ui-toml/excessive_nesting/excessive_nesting.stderr +++ b/tests/ui-toml/excessive_nesting/excessive_nesting.stderr @@ -9,7 +9,7 @@ LL | let w = { 3 }; = help: to override `-D warnings` add `#[allow(clippy::excessive_nesting)]` error: this block is too nested - --> $DIR/excessive_nesting/excessive_nesting.rs:67:17 + --> $DIR/excessive_nesting/excessive_nesting.rs:68: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:81:25 + --> $DIR/excessive_nesting/excessive_nesting.rs:83: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:98:17 + --> $DIR/excessive_nesting/excessive_nesting.rs:101: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:111:18 + --> $DIR/excessive_nesting/excessive_nesting.rs:114: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:112:12 + --> $DIR/excessive_nesting/excessive_nesting.rs:115: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:113:12 + --> $DIR/excessive_nesting/excessive_nesting.rs:116: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:118:25 + --> $DIR/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 - --> $DIR/excessive_nesting/excessive_nesting.rs:130:29 + --> $DIR/excessive_nesting/excessive_nesting.rs:135:29 | LL | let z = (|| { | _____________________________^ @@ -86,7 +86,7 @@ LL | | })(); = help: try refactoring your code to minimize nesting error: this block is too nested - --> $DIR/excessive_nesting/excessive_nesting.rs:149:13 + --> $DIR/excessive_nesting/excessive_nesting.rs:154: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:150:20 + --> $DIR/excessive_nesting/excessive_nesting.rs:155: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:151:12 + --> $DIR/excessive_nesting/excessive_nesting.rs:156: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:152:25 + --> $DIR/excessive_nesting/excessive_nesting.rs:157: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:153:11 + --> $DIR/excessive_nesting/excessive_nesting.rs:158: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:154:13 + --> $DIR/excessive_nesting/excessive_nesting.rs:160: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:156:17 + --> $DIR/excessive_nesting/excessive_nesting.rs:162: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:156:28 + --> $DIR/excessive_nesting/excessive_nesting.rs:162: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:158:28 + --> $DIR/excessive_nesting/excessive_nesting.rs:166: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:158:48 + --> $DIR/excessive_nesting/excessive_nesting.rs:166: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:160:14 + --> $DIR/excessive_nesting/excessive_nesting.rs:170: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:160:35 + --> $DIR/excessive_nesting/excessive_nesting.rs:170: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:162:23 + --> $DIR/excessive_nesting/excessive_nesting.rs:174: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:164:8 + --> $DIR/excessive_nesting/excessive_nesting.rs:177: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:164:20 + --> $DIR/excessive_nesting/excessive_nesting.rs:177: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:165:8 + --> $DIR/excessive_nesting/excessive_nesting.rs:180: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:165:21 + --> $DIR/excessive_nesting/excessive_nesting.rs:180: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:166:10 + --> $DIR/excessive_nesting/excessive_nesting.rs:183:10 | LL | ..{{{{{{{5}}}}}}}; | ^^^^^^^^^ @@ -230,7 +230,7 @@ LL | ..{{{{{{{5}}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> $DIR/excessive_nesting/excessive_nesting.rs:167:11 + --> $DIR/excessive_nesting/excessive_nesting.rs:184:11 | LL | ..={{{{{3}}}}}; | ^^^^^ @@ -238,7 +238,7 @@ LL | ..={{{{{3}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> $DIR/excessive_nesting/excessive_nesting.rs:168:8 + --> $DIR/excessive_nesting/excessive_nesting.rs:185:8 | LL | {{{{{1;}}}}}..; | ^^^^^^ @@ -246,7 +246,7 @@ LL | {{{{{1;}}}}}..; = help: try refactoring your code to minimize nesting error: this block is too nested - --> $DIR/excessive_nesting/excessive_nesting.rs:170:20 + --> $DIR/excessive_nesting/excessive_nesting.rs:187: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:171:13 + --> $DIR/excessive_nesting/excessive_nesting.rs:188:13 | LL | loop {{{{{{}}}}}} | ^^^^^^ @@ -262,7 +262,7 @@ LL | loop {{{{{{}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> $DIR/excessive_nesting/excessive_nesting.rs:173:14 + --> $DIR/excessive_nesting/excessive_nesting.rs:191: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:174:20 + --> $DIR/excessive_nesting/excessive_nesting.rs:192:20 | LL | true => {{{{}}}}, | ^^ @@ -278,7 +278,7 @@ LL | true => {{{{}}}}, = help: try refactoring your code to minimize nesting error: this block is too nested - --> $DIR/excessive_nesting/excessive_nesting.rs:175:21 + --> $DIR/excessive_nesting/excessive_nesting.rs:193:21 | LL | false => {{{{}}}}, | ^^ @@ -286,7 +286,7 @@ LL | false => {{{{}}}}, = help: try refactoring your code to minimize nesting error: this block is too nested - --> $DIR/excessive_nesting/excessive_nesting.rs:181:17 + --> $DIR/excessive_nesting/excessive_nesting.rs:200:17 | LL | / { LL | | println!("warning! :)"); @@ -296,7 +296,7 @@ LL | | } = help: try refactoring your code to minimize nesting error: this block is too nested - --> $DIR/excessive_nesting/excessive_nesting.rs:190:28 + --> $DIR/excessive_nesting/excessive_nesting.rs:209: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 - --> $DIR/excessive_nesting/excessive_nesting.rs:196:8 + --> $DIR/excessive_nesting/excessive_nesting.rs:215:8 | LL | {{{{b().await}}}}; | ^^^^^^^^^^^ diff --git a/tests/ui-toml/expect_used/expect_used.rs b/tests/ui-toml/expect_used/expect_used.rs index 206788e19f02..4ca9072e69dc 100644 --- a/tests/ui-toml/expect_used/expect_used.rs +++ b/tests/ui-toml/expect_used/expect_used.rs @@ -4,12 +4,12 @@ fn expect_option() { let opt = Some(0); - let _ = opt.expect(""); + let _ = opt.expect(""); //~ expect_used } fn expect_result() { let res: Result = Ok(0); - let _ = res.expect(""); + let _ = res.expect(""); //~ expect_used } fn main() { diff --git a/tests/ui-toml/fn_params_excessive_bools/test.rs b/tests/ui-toml/fn_params_excessive_bools/test.rs index 42897b389edf..cbe7198f727b 100644 --- a/tests/ui-toml/fn_params_excessive_bools/test.rs +++ b/tests/ui-toml/fn_params_excessive_bools/test.rs @@ -1,6 +1,6 @@ #![warn(clippy::fn_params_excessive_bools)] fn f(_: bool) {} -fn g(_: bool, _: bool) {} +fn g(_: bool, _: bool) {} //~ fn_params_excessive_bools fn main() {} diff --git a/tests/ui-toml/functions_maxlines/test.rs b/tests/ui-toml/functions_maxlines/test.rs index 4ac0378544c7..5aa1822c9094 100644 --- a/tests/ui-toml/functions_maxlines/test.rs +++ b/tests/ui-toml/functions_maxlines/test.rs @@ -16,18 +16,21 @@ fn many_comments_but_one_line_of_code() { } // This should be considered two and a fail. +//~v too_many_lines fn too_many_lines() { println!("This is bad."); println!("This is bad."); } // This should only fail once (#7517). +//~v too_many_lines async fn async_too_many_lines() { println!("This is bad."); println!("This is bad."); } // This should fail only once, without failing on the closure. +//~v too_many_lines fn closure_too_many_lines() { let _ = { println!("This is bad."); @@ -50,6 +53,7 @@ fn comment_after_code() { // This should fail since it is technically two lines. #[rustfmt::skip] +//~v too_many_lines fn comment_before_code() { let _ = "test"; /* This comment extends to the front of diff --git a/tests/ui-toml/functions_maxlines/test.stderr b/tests/ui-toml/functions_maxlines/test.stderr index f7aa96f0dfbd..20103850e0e6 100644 --- a/tests/ui-toml/functions_maxlines/test.stderr +++ b/tests/ui-toml/functions_maxlines/test.stderr @@ -1,5 +1,5 @@ error: this function has too many lines (2/1) - --> $DIR/functions_maxlines/test.rs:19:1 + --> $DIR/functions_maxlines/test.rs:20:1 | LL | / fn too_many_lines() { LL | | println!("This is bad."); @@ -11,7 +11,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::too_many_lines)]` error: this function has too many lines (4/1) - --> $DIR/functions_maxlines/test.rs:25:1 + --> $DIR/functions_maxlines/test.rs:27:1 | LL | / async fn async_too_many_lines() { LL | | println!("This is bad."); @@ -20,7 +20,7 @@ LL | | } | |_^ error: this function has too many lines (4/1) - --> $DIR/functions_maxlines/test.rs:31:1 + --> $DIR/functions_maxlines/test.rs:34:1 | LL | / fn closure_too_many_lines() { LL | | let _ = { @@ -31,7 +31,7 @@ LL | | } | |_^ error: this function has too many lines (2/1) - --> $DIR/functions_maxlines/test.rs:53:1 + --> $DIR/functions_maxlines/test.rs:57:1 | LL | / fn comment_before_code() { LL | | let _ = "test"; diff --git a/tests/ui-toml/ifs_same_cond/ifs_same_cond.rs b/tests/ui-toml/ifs_same_cond/ifs_same_cond.rs index 4882416c414a..82dea474aed3 100644 --- a/tests/ui-toml/ifs_same_cond/ifs_same_cond.rs +++ b/tests/ui-toml/ifs_same_cond/ifs_same_cond.rs @@ -12,6 +12,7 @@ fn issue10272() { let x = Cell::new(true); if x.get() { } else if !x.take() { + //~v ifs_same_cond } else if x.get() { } else { } diff --git a/tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr b/tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr index e7c75e84f74c..337c55d24ee8 100644 --- a/tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr +++ b/tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr @@ -1,5 +1,5 @@ error: this `if` has the same condition as a previous `if` - --> $DIR/ifs_same_cond/ifs_same_cond.rs:15:15 + --> $DIR/ifs_same_cond/ifs_same_cond.rs:16:15 | LL | } else if x.get() { | ^^^^^^^ diff --git a/tests/ui-toml/large_futures/large_futures.fixed b/tests/ui-toml/large_futures/large_futures.fixed index 7dea9fb95b4b..38733205320a 100644 --- a/tests/ui-toml/large_futures/large_futures.fixed +++ b/tests/ui-toml/large_futures/large_futures.fixed @@ -15,7 +15,7 @@ pub async fn should_not_warn() { } pub async fn bar() { - Box::pin(should_warn()).await; + Box::pin(should_warn()).await; //~ large_futures async { let x = [0u8; 1024]; diff --git a/tests/ui-toml/large_futures/large_futures.rs b/tests/ui-toml/large_futures/large_futures.rs index 4158df8b5ff5..3cb8ce40e08c 100644 --- a/tests/ui-toml/large_futures/large_futures.rs +++ b/tests/ui-toml/large_futures/large_futures.rs @@ -15,7 +15,7 @@ pub async fn should_not_warn() { } pub async fn bar() { - should_warn().await; + should_warn().await; //~ large_futures async { let x = [0u8; 1024]; diff --git a/tests/ui-toml/large_include_file/large_include_file.rs b/tests/ui-toml/large_include_file/large_include_file.rs index 1c69654ea725..c89369749281 100644 --- a/tests/ui-toml/large_include_file/large_include_file.rs +++ b/tests/ui-toml/large_include_file/large_include_file.rs @@ -11,6 +11,8 @@ const ALLOWED_TOO_BIG_INCLUDE_STR: &str = include_str!("too_big.txt"); // Bad const TOO_BIG_INCLUDE_BYTES: &[u8] = include_bytes!("too_big.txt"); +//~^ large_include_file const TOO_BIG_INCLUDE_STR: &str = include_str!("too_big.txt"); +//~^ large_include_file fn main() {} diff --git a/tests/ui-toml/large_include_file/large_include_file.stderr b/tests/ui-toml/large_include_file/large_include_file.stderr index 3128964bba57..a669a61e9b5c 100644 --- a/tests/ui-toml/large_include_file/large_include_file.stderr +++ b/tests/ui-toml/large_include_file/large_include_file.stderr @@ -1,8 +1,8 @@ error: attempted to include a large file - --> $DIR/large_include_file/large_include_file.rs:13:43 + --> $DIR/large_include_file/large_include_file.rs:13:38 | -LL | const TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const TOO_BIG_INCLUDE_BYTES: &[u8] = include_bytes!("too_big.txt"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the configuration allows a maximum size of 600 bytes = note: `-D clippy::large-include-file` implied by `-D warnings` @@ -10,7 +10,7 @@ LL | const TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt"); = note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info) error: attempted to include a large file - --> $DIR/large_include_file/large_include_file.rs:14:35 + --> $DIR/large_include_file/large_include_file.rs:15:35 | LL | const TOO_BIG_INCLUDE_STR: &str = include_str!("too_big.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/lint_decimal_readability/test.fixed b/tests/ui-toml/lint_decimal_readability/test.fixed index f013153f5166..871d24a86b4a 100644 --- a/tests/ui-toml/lint_decimal_readability/test.fixed +++ b/tests/ui-toml/lint_decimal_readability/test.fixed @@ -17,7 +17,8 @@ fn main() { // due to clippy::inconsistent-digit-grouping let _fail1 = 100_200_300.123_456_789; + //~^ inconsistent_digit_grouping // fail due to the integer part - let _fail2 = 100_200_300.300_200_100; + let _fail2 = 100_200_300.300_200_100; //~ unreadable_literal } diff --git a/tests/ui-toml/lint_decimal_readability/test.rs b/tests/ui-toml/lint_decimal_readability/test.rs index bd5110138c8c..2270bc4b5ab8 100644 --- a/tests/ui-toml/lint_decimal_readability/test.rs +++ b/tests/ui-toml/lint_decimal_readability/test.rs @@ -17,7 +17,8 @@ fn main() { // due to clippy::inconsistent-digit-grouping let _fail1 = 100_200_300.123456789; + //~^ inconsistent_digit_grouping // fail due to the integer part - let _fail2 = 100200300.300200100; + let _fail2 = 100200300.300200100; //~ unreadable_literal } diff --git a/tests/ui-toml/lint_decimal_readability/test.stderr b/tests/ui-toml/lint_decimal_readability/test.stderr index ef4dd582bea0..ff6be5e711c5 100644 --- a/tests/ui-toml/lint_decimal_readability/test.stderr +++ b/tests/ui-toml/lint_decimal_readability/test.stderr @@ -8,7 +8,7 @@ LL | let _fail1 = 100_200_300.123456789; = help: to override `-D warnings` add `#[allow(clippy::inconsistent_digit_grouping)]` error: long literal lacking separators - --> $DIR/lint_decimal_readability/test.rs:22:18 + --> $DIR/lint_decimal_readability/test.rs:23:18 | LL | let _fail2 = 100200300.300200100; | ^^^^^^^^^^^^^^^^^^^ help: consider: `100_200_300.300_200_100` diff --git a/tests/ui-toml/min_ident_chars/min_ident_chars.rs b/tests/ui-toml/min_ident_chars/min_ident_chars.rs index ded3c72c3e04..c539f6cec591 100644 --- a/tests/ui-toml/min_ident_chars/min_ident_chars.rs +++ b/tests/ui-toml/min_ident_chars/min_ident_chars.rs @@ -3,20 +3,22 @@ #![warn(clippy::min_ident_chars)] extern crate extern_types; -use extern_types::{Aaa, LONGER, M, N as W}; +use extern_types::{Aaa, LONGER, M, N as W}; //~ min_ident_chars -pub const N: u32 = 0; +pub const N: u32 = 0; //~ min_ident_chars pub const LONG: u32 = 32; struct Owo { Uwu: u128, - aaa: Aaa, + aaa: Aaa, //~ min_ident_chars } fn main() { let wha = 1; - let vvv = 1; - let uuu = 1; + let vvv = 1; //~ min_ident_chars + let uuu = 1; //~ min_ident_chars let (mut a, mut b) = (1, 2); - for i in 0..1000 {} + //~^ min_ident_chars + //~| min_ident_chars + for i in 0..1000 {} //~ min_ident_chars } diff --git a/tests/ui-toml/min_ident_chars/min_ident_chars.stderr b/tests/ui-toml/min_ident_chars/min_ident_chars.stderr index dc02c9fbd732..98b628401a31 100644 --- a/tests/ui-toml/min_ident_chars/min_ident_chars.stderr +++ b/tests/ui-toml/min_ident_chars/min_ident_chars.stderr @@ -44,7 +44,7 @@ LL | let (mut a, mut b) = (1, 2); | ^ error: this ident is too short (1 <= 3) - --> $DIR/min_ident_chars/min_ident_chars.rs:21:9 + --> $DIR/min_ident_chars/min_ident_chars.rs:23:9 | LL | for i in 0..1000 {} | ^ diff --git a/tests/ui-toml/min_rust_version/min_rust_version.fixed b/tests/ui-toml/min_rust_version/min_rust_version.fixed index 497f783087a1..82da79472ce5 100644 --- a/tests/ui-toml/min_rust_version/min_rust_version.fixed +++ b/tests/ui-toml/min_rust_version/min_rust_version.fixed @@ -71,7 +71,7 @@ fn check_index_refutable_slice() { fn map_clone_suggest_copied() { // This should still trigger the lint but suggest `cloned()` instead of `copied()` - let _: Option = Some(&16).cloned(); + let _: Option = Some(&16).cloned(); //~ map_clone } fn borrow_as_ptr() { diff --git a/tests/ui-toml/min_rust_version/min_rust_version.rs b/tests/ui-toml/min_rust_version/min_rust_version.rs index 6e7874108a34..d2552f80b6e9 100644 --- a/tests/ui-toml/min_rust_version/min_rust_version.rs +++ b/tests/ui-toml/min_rust_version/min_rust_version.rs @@ -71,7 +71,7 @@ fn check_index_refutable_slice() { fn map_clone_suggest_copied() { // This should still trigger the lint but suggest `cloned()` instead of `copied()` - let _: Option = Some(&16).map(|b| *b); + let _: Option = Some(&16).map(|b| *b); //~ map_clone } fn borrow_as_ptr() { diff --git a/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.fixed b/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.fixed index 5f4f007cf5c7..d7c217e4901b 100644 --- a/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.fixed +++ b/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.fixed @@ -3,14 +3,16 @@ use std::alloc as colla; use std::option::Option as Maybe; use std::process::{exit as goodbye, Child as Kid}; -use std::thread::sleep as thread_sleep; +//~^ missing_enforced_import_renames +use std::thread::sleep as thread_sleep; //~ missing_enforced_import_renames #[rustfmt::skip] use std::{ - any::{type_name as ident, Any}, - clone as foo, - sync :: Mutex as StdMutie, + any::{type_name as ident, Any}, //~ missing_enforced_import_renames + clone as foo, //~ missing_enforced_import_renames + sync :: Mutex as StdMutie, //~ missing_enforced_import_renames }; fn main() { use std::collections::BTreeMap as Map; + //~^ missing_enforced_import_renames } diff --git a/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs b/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs index f60058c86288..be04c13d40b3 100644 --- a/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs +++ b/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs @@ -3,14 +3,16 @@ use std::alloc as colla; use std::option::Option as Maybe; use std::process::{exit as wrong_exit, Child as Kid}; -use std::thread::sleep; +//~^ missing_enforced_import_renames +use std::thread::sleep; //~ missing_enforced_import_renames #[rustfmt::skip] use std::{ - any::{type_name, Any}, - clone, - sync :: Mutex, + any::{type_name, Any}, //~ missing_enforced_import_renames + clone, //~ missing_enforced_import_renames + sync :: Mutex, //~ missing_enforced_import_renames }; fn main() { use std::collections::BTreeMap as OopsWrongRename; + //~^ missing_enforced_import_renames } diff --git a/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.stderr b/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.stderr index 74b0308c8495..98682a4e7924 100644 --- a/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.stderr +++ b/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.stderr @@ -8,31 +8,31 @@ LL | use std::process::{exit as wrong_exit, Child as Kid}; = help: to override `-D warnings` add `#[allow(clippy::missing_enforced_import_renames)]` error: this import should be renamed - --> $DIR/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:6:1 + --> $DIR/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:7:1 | LL | use std::thread::sleep; | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `use std::thread::sleep as thread_sleep` error: this import should be renamed - --> $DIR/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:9:11 + --> $DIR/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:10:11 | LL | any::{type_name, Any}, | ^^^^^^^^^ help: try: `type_name as ident` error: this import should be renamed - --> $DIR/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:10:5 + --> $DIR/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:11:5 | LL | clone, | ^^^^^ help: try: `clone as foo` error: this import should be renamed - --> $DIR/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:11:5 + --> $DIR/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:12:5 | LL | sync :: Mutex, | ^^^^^^^^^^^^^ help: try: `sync :: Mutex as StdMutie` error: this import should be renamed - --> $DIR/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:15:5 + --> $DIR/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:16:5 | LL | use std::collections::BTreeMap as OopsWrongRename; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `use std::collections::BTreeMap as Map` diff --git a/tests/ui-toml/module_inception/module_inception.rs b/tests/ui-toml/module_inception/module_inception.rs index cd495c884a43..e2057ecfc42b 100644 --- a/tests/ui-toml/module_inception/module_inception.rs +++ b/tests/ui-toml/module_inception/module_inception.rs @@ -3,11 +3,13 @@ // Lint pub mod foo2 { pub mod bar2 { + //~v module_inception pub mod bar2 { pub mod foo2 {} } pub mod foo2 {} } + //~v module_inception pub mod foo2 { pub mod bar2 {} } diff --git a/tests/ui-toml/module_inception/module_inception.stderr b/tests/ui-toml/module_inception/module_inception.stderr index ab2b30349ed3..c092bde1ff1f 100644 --- a/tests/ui-toml/module_inception/module_inception.stderr +++ b/tests/ui-toml/module_inception/module_inception.stderr @@ -1,5 +1,5 @@ error: module has the same name as its containing module - --> $DIR/module_inception/module_inception.rs:6:9 + --> $DIR/module_inception/module_inception.rs:7:9 | LL | / pub mod bar2 { LL | | pub mod foo2 {} @@ -10,7 +10,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::module_inception)]` error: module has the same name as its containing module - --> $DIR/module_inception/module_inception.rs:11:5 + --> $DIR/module_inception/module_inception.rs:13:5 | LL | / pub mod foo2 { LL | | pub mod bar2 {} diff --git a/tests/ui-toml/modulo_arithmetic/modulo_arithmetic.rs b/tests/ui-toml/modulo_arithmetic/modulo_arithmetic.rs index 27d27564baf3..826895ffde41 100644 --- a/tests/ui-toml/modulo_arithmetic/modulo_arithmetic.rs +++ b/tests/ui-toml/modulo_arithmetic/modulo_arithmetic.rs @@ -3,8 +3,8 @@ fn main() { let a = -1; let b = 2; - let c = a % b == 0; - let c = a % b != 0; - let c = 0 == a % b; - let c = 0 != a % b; + let c = a % b == 0; //~ modulo_arithmetic + let c = a % b != 0; //~ modulo_arithmetic + let c = 0 == a % b; //~ modulo_arithmetic + let c = 0 != a % b; //~ modulo_arithmetic } diff --git a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed index 673106f0b12d..e4b759a9ccc8 100644 --- a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed +++ b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed @@ -15,7 +15,7 @@ proc_macro_derive::foo_bar!(); #[rustfmt::skip] macro_rules! test { () => { - vec![0, 0, 0] + vec![0, 0, 0] //~ nonstandard_macro_braces }; } @@ -40,11 +40,13 @@ macro_rules! printlnfoo { #[rustfmt::skip] fn main() { - let _ = vec![1, 2, 3]; + let _ = vec![1, 2, 3]; //~ nonstandard_macro_braces let _ = format!("ugh {} stop being such a good compiler", "hello"); - let _ = matches!({}, ()); - let _ = quote!{let x = 1;}; + //~^ nonstandard_macro_braces + let _ = matches!({}, ()); //~ nonstandard_macro_braces + let _ = quote!{let x = 1;}; //~ nonstandard_macro_braces let _ = quote::quote!{match match match}; + //~^ nonstandard_macro_braces let _ = test!(); // trigger when macro def is inside our own crate let _ = vec![1,2,3]; @@ -53,9 +55,10 @@ fn main() { let _ = format!("fds{}fds", 10); let _ = test2!["{}{}{}", 1, 2, 3]; - let _: type_pos![usize] = vec![]; + let _: type_pos![usize] = vec![]; //~ nonstandard_macro_braces eprint!["test if user config overrides defaults"]; + //~^ nonstandard_macro_braces printlnfoo!["test if printlnfoo is triggered by println"]; } diff --git a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs index b9c69037be07..b7b036aaa39b 100644 --- a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs +++ b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs @@ -15,7 +15,7 @@ proc_macro_derive::foo_bar!(); #[rustfmt::skip] macro_rules! test { () => { - vec!{0, 0, 0} + vec!{0, 0, 0} //~ nonstandard_macro_braces }; } @@ -40,11 +40,13 @@ macro_rules! printlnfoo { #[rustfmt::skip] fn main() { - let _ = vec! {1, 2, 3}; + let _ = vec! {1, 2, 3}; //~ nonstandard_macro_braces let _ = format!["ugh {} stop being such a good compiler", "hello"]; - let _ = matches!{{}, ()}; - let _ = quote!(let x = 1;); + //~^ nonstandard_macro_braces + let _ = matches!{{}, ()}; //~ nonstandard_macro_braces + let _ = quote!(let x = 1;); //~ nonstandard_macro_braces let _ = quote::quote!(match match match); + //~^ nonstandard_macro_braces let _ = test!(); // trigger when macro def is inside our own crate let _ = vec![1,2,3]; @@ -53,9 +55,10 @@ fn main() { let _ = format!("fds{}fds", 10); let _ = test2!["{}{}{}", 1, 2, 3]; - let _: type_pos!(usize) = vec![]; + let _: type_pos!(usize) = vec![]; //~ nonstandard_macro_braces eprint!("test if user config overrides defaults"); + //~^ nonstandard_macro_braces printlnfoo!["test if printlnfoo is triggered by println"]; } diff --git a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr index 2162ffe47f7f..90ca59b4a651 100644 --- a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr +++ b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr @@ -14,19 +14,19 @@ LL | let _ = format!["ugh {} stop being such a good compiler", "hello"]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `format!("ugh {} stop being such a good compiler", "hello")` error: use of irregular braces for `matches!` macro - --> $DIR/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:45:13 + --> $DIR/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:46:13 | LL | let _ = matches!{{}, ()}; | ^^^^^^^^^^^^^^^^ help: consider writing: `matches!({}, ())` error: use of irregular braces for `quote!` macro - --> $DIR/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:46:13 + --> $DIR/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:47:13 | LL | let _ = quote!(let x = 1;); | ^^^^^^^^^^^^^^^^^^ help: consider writing: `quote!{let x = 1;}` error: use of irregular braces for `quote::quote!` macro - --> $DIR/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:47:13 + --> $DIR/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:48:13 | LL | let _ = quote::quote!(match match match); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `quote::quote!{match match match}` @@ -43,13 +43,13 @@ LL | let _ = test!(); // trigger when macro def is inside our own crate = note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `type_pos!` macro - --> $DIR/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:56:12 + --> $DIR/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:58:12 | LL | let _: type_pos!(usize) = vec![]; | ^^^^^^^^^^^^^^^^ help: consider writing: `type_pos![usize]` error: use of irregular braces for `eprint!` macro - --> $DIR/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:58:5 + --> $DIR/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:60:5 | LL | eprint!("test if user config overrides defaults"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `eprint!["test if user config overrides defaults"]` diff --git a/tests/ui-toml/print_macro/print_macro.rs b/tests/ui-toml/print_macro/print_macro.rs index 3a8b30cca36a..77d6953c524f 100644 --- a/tests/ui-toml/print_macro/print_macro.rs +++ b/tests/ui-toml/print_macro/print_macro.rs @@ -3,8 +3,8 @@ #![warn(clippy::print_stderr)] fn foo(n: u32) { - print!("{n}"); - eprint!("{n}"); + print!("{n}"); //~ print_stdout + eprint!("{n}"); //~ print_stderr } #[test] diff --git a/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs b/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs index cd53f5044599..c27a4f45e9d2 100644 --- a/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs +++ b/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs @@ -11,9 +11,11 @@ mod my_mod { /// some docs pub(crate) fn crate_with_docs() {} pub(crate) fn crate_no_docs() {} + //~^ missing_docs_in_private_items /// some docs pub(super) fn super_with_docs() {} pub(super) fn super_no_docs() {} + //~^ missing_docs_in_private_items mod my_sub { /// some docs @@ -22,6 +24,7 @@ mod my_mod { /// some docs pub(crate) fn sub_crate_with_docs() {} pub(crate) fn sub_crate_no_docs() {} + //~^ missing_docs_in_private_items /// some docs pub(super) fn sub_super_with_docs() {} pub(super) fn sub_super_no_docs() {} @@ -32,15 +35,18 @@ mod my_mod { /// some docs pub(crate) crate_field_with_docs: (), pub(crate) crate_field_no_docs: (), + //~^ missing_docs_in_private_items /// some docs priv_field_with_docs: (), priv_field_no_docs: (), } + //~v missing_docs_in_private_items pub(crate) struct CrateStructNoDocs { /// some docs pub(crate) crate_field_with_docs: (), pub(crate) crate_field_no_docs: (), + //~^ missing_docs_in_private_items /// some docs priv_field_with_docs: (), priv_field_no_docs: (), @@ -49,7 +55,7 @@ mod my_mod { /// some docs type CrateTypedefWithDocs = String; -type CrateTypedefNoDocs = String; +type CrateTypedefNoDocs = String; //~ missing_docs_in_private_items /// some docs pub type PubTypedefWithDocs = String; pub type PubTypedefNoDocs = String; diff --git a/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.stderr b/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.stderr index f987ff695694..e43958478d19 100644 --- a/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.stderr +++ b/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.stderr @@ -8,25 +8,25 @@ LL | pub(crate) fn crate_no_docs() {} = help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]` error: missing documentation for a function - --> $DIR/pub_crate_missing_docs/pub_crate_missing_doc.rs:16:5 + --> $DIR/pub_crate_missing_docs/pub_crate_missing_doc.rs:17:5 | LL | pub(super) fn super_no_docs() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/pub_crate_missing_docs/pub_crate_missing_doc.rs:24:9 + --> $DIR/pub_crate_missing_docs/pub_crate_missing_doc.rs:26:9 | LL | pub(crate) fn sub_crate_no_docs() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a struct field - --> $DIR/pub_crate_missing_docs/pub_crate_missing_doc.rs:34:9 + --> $DIR/pub_crate_missing_docs/pub_crate_missing_doc.rs:37:9 | LL | pub(crate) crate_field_no_docs: (), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a struct - --> $DIR/pub_crate_missing_docs/pub_crate_missing_doc.rs:40:5 + --> $DIR/pub_crate_missing_docs/pub_crate_missing_doc.rs:45:5 | LL | / pub(crate) struct CrateStructNoDocs { LL | | /// some docs @@ -38,13 +38,13 @@ LL | | } | |_____^ error: missing documentation for a struct field - --> $DIR/pub_crate_missing_docs/pub_crate_missing_doc.rs:43:9 + --> $DIR/pub_crate_missing_docs/pub_crate_missing_doc.rs:48:9 | LL | pub(crate) crate_field_no_docs: (), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a type alias - --> $DIR/pub_crate_missing_docs/pub_crate_missing_doc.rs:52:1 + --> $DIR/pub_crate_missing_docs/pub_crate_missing_doc.rs:58:1 | LL | type CrateTypedefNoDocs = String; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.all_pub_fields.stderr b/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.all_pub_fields.stderr index 5949e7e0ffc3..ac0b28386a34 100644 --- a/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.all_pub_fields.stderr +++ b/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.all_pub_fields.stderr @@ -17,7 +17,7 @@ LL | pub(in crate::inner) _f: Option<()>, = help: consider removing the underscore, or making the field private error: field marked as public but also inferred as unused because it's prefixed with `_` - --> $DIR/pub_underscore_fields/pub_underscore_fields.rs:27:13 + --> $DIR/pub_underscore_fields/pub_underscore_fields.rs:28:13 | LL | pub _g: String, | ^^^^^^ @@ -25,7 +25,7 @@ LL | pub _g: String, = help: consider removing the underscore, or making the field private error: field marked as public but also inferred as unused because it's prefixed with `_` - --> $DIR/pub_underscore_fields/pub_underscore_fields.rs:34:9 + --> $DIR/pub_underscore_fields/pub_underscore_fields.rs:35:9 | LL | pub _a: usize, | ^^^^^^ @@ -33,7 +33,7 @@ LL | pub _a: usize, = help: consider removing the underscore, or making the field private error: field marked as public but also inferred as unused because it's prefixed with `_` - --> $DIR/pub_underscore_fields/pub_underscore_fields.rs:41:9 + --> $DIR/pub_underscore_fields/pub_underscore_fields.rs:42:9 | LL | pub _c: i64, | ^^^^^^ @@ -41,7 +41,7 @@ LL | pub _c: i64, = help: consider removing the underscore, or making the field private error: field marked as public but also inferred as unused because it's prefixed with `_` - --> $DIR/pub_underscore_fields/pub_underscore_fields.rs:44:9 + --> $DIR/pub_underscore_fields/pub_underscore_fields.rs:45:9 | LL | pub _e: Option, | ^^^^^^ @@ -49,7 +49,7 @@ LL | pub _e: Option, = help: consider removing the underscore, or making the field private error: field marked as public but also inferred as unused because it's prefixed with `_` - --> $DIR/pub_underscore_fields/pub_underscore_fields.rs:57:9 + --> $DIR/pub_underscore_fields/pub_underscore_fields.rs:58:9 | LL | pub(crate) _b: Option, | ^^^^^^^^^^^^^ diff --git a/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs b/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs index 4ee8dbb88347..d7d8e4cd9c8a 100644 --- a/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs +++ b/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs @@ -12,7 +12,7 @@ pub mod inner { pub struct PubSuper { pub(super) a: usize, - pub _b: u8, + pub _b: u8, //~ pub_underscore_fields _c: i32, pub _mark: marker::PhantomData, } @@ -21,27 +21,28 @@ pub mod inner { pub struct PubModVisibility { pub(in crate::inner) e: bool, pub(in crate::inner) _f: Option<()>, + //~[all_pub_fields]^ pub_underscore_fields } struct PrivateStructPubField { - pub _g: String, + pub _g: String, //~[all_pub_fields] pub_underscore_fields } } } fn main() { pub struct StructWithOneViolation { - pub _a: usize, + pub _a: usize, //~[all_pub_fields] pub_underscore_fields } // should handle structs with multiple violations pub struct StructWithMultipleViolations { a: u8, _b: usize, - pub _c: i64, + pub _c: i64, //~[all_pub_fields] pub_underscore_fields #[doc(hidden)] pub d: String, - pub _e: Option, + pub _e: Option, //~[all_pub_fields] pub_underscore_fields } // shouldn't warn on anonymous fields @@ -55,6 +56,7 @@ fn main() { pub struct PubCrate { pub(crate) a: String, pub(crate) _b: Option, + //~[all_pub_fields]^ pub_underscore_fields } // shouldn't warn on fields named pub diff --git a/tests/ui-toml/semicolon_block/both.fixed b/tests/ui-toml/semicolon_block/both.fixed index 306cd23c8239..2564de2af02e 100644 --- a/tests/ui-toml/semicolon_block/both.fixed +++ b/tests/ui-toml/semicolon_block/both.fixed @@ -39,12 +39,13 @@ fn main() { { unit_fn_block() }; unsafe { unit_fn_block() }; - { unit_fn_block() }; - unsafe { unit_fn_block() }; + { unit_fn_block() }; //~ semicolon_outside_block + unsafe { unit_fn_block() }; //~ semicolon_outside_block { unit_fn_block(); }; unsafe { unit_fn_block(); }; + //~v semicolon_inside_block { unit_fn_block(); unit_fn_block(); @@ -59,7 +60,7 @@ fn main() { }; { m!(()) }; - { m!(()) }; + { m!(()) }; //~ semicolon_outside_block { m!(()); }; m!(0); m!(1); diff --git a/tests/ui-toml/semicolon_block/both.rs b/tests/ui-toml/semicolon_block/both.rs index b9f012cfbb0d..a089a44b7972 100644 --- a/tests/ui-toml/semicolon_block/both.rs +++ b/tests/ui-toml/semicolon_block/both.rs @@ -39,12 +39,13 @@ fn main() { { unit_fn_block() }; unsafe { unit_fn_block() }; - { unit_fn_block(); } - unsafe { unit_fn_block(); } + { unit_fn_block(); } //~ semicolon_outside_block + unsafe { unit_fn_block(); } //~ semicolon_outside_block { unit_fn_block(); }; unsafe { unit_fn_block(); }; + //~v semicolon_inside_block { unit_fn_block(); unit_fn_block() @@ -59,7 +60,7 @@ fn main() { }; { m!(()) }; - { m!(()); } + { m!(()); } //~ semicolon_outside_block { m!(()); }; m!(0); m!(1); diff --git a/tests/ui-toml/semicolon_block/both.stderr b/tests/ui-toml/semicolon_block/both.stderr index 8588b500d3e3..5b970cd2e031 100644 --- a/tests/ui-toml/semicolon_block/both.stderr +++ b/tests/ui-toml/semicolon_block/both.stderr @@ -25,7 +25,7 @@ LL + unsafe { unit_fn_block() }; | error: consider moving the `;` inside the block for consistent formatting - --> $DIR/semicolon_block/both.rs:48:5 + --> $DIR/semicolon_block/both.rs:49:5 | LL | / { LL | | unit_fn_block(); @@ -42,7 +42,7 @@ LL ~ } | error: consider moving the `;` outside the block for consistent formatting - --> $DIR/semicolon_block/both.rs:62:5 + --> $DIR/semicolon_block/both.rs:63:5 | LL | { m!(()); } | ^^^^^^^^^^^ diff --git a/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed b/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed index 5b7f8e00c7a0..0fce00a1d084 100644 --- a/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed +++ b/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed @@ -44,6 +44,7 @@ fn main() { { unit_fn_block(); }; unsafe { unit_fn_block(); }; + //~v semicolon_inside_block { unit_fn_block(); unit_fn_block(); diff --git a/tests/ui-toml/semicolon_block/semicolon_inside_block.rs b/tests/ui-toml/semicolon_block/semicolon_inside_block.rs index 3a81661cd16f..854e56b958c8 100644 --- a/tests/ui-toml/semicolon_block/semicolon_inside_block.rs +++ b/tests/ui-toml/semicolon_block/semicolon_inside_block.rs @@ -44,6 +44,7 @@ fn main() { { unit_fn_block(); }; unsafe { unit_fn_block(); }; + //~v semicolon_inside_block { unit_fn_block(); unit_fn_block() diff --git a/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr b/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr index 14aadaeb93d7..1fa551492e07 100644 --- a/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr +++ b/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr @@ -1,5 +1,5 @@ error: consider moving the `;` inside the block for consistent formatting - --> $DIR/semicolon_block/semicolon_inside_block.rs:47:5 + --> $DIR/semicolon_block/semicolon_inside_block.rs:48:5 | LL | / { LL | | unit_fn_block(); diff --git a/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed b/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed index 14604eaea7e4..b0f0196d8929 100644 --- a/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed +++ b/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed @@ -38,8 +38,8 @@ fn main() { { unit_fn_block() }; unsafe { unit_fn_block() }; - { unit_fn_block() }; - unsafe { unit_fn_block() }; + { unit_fn_block() }; //~ semicolon_outside_block + unsafe { unit_fn_block() }; //~ semicolon_outside_block { unit_fn_block(); }; unsafe { unit_fn_block(); }; @@ -58,7 +58,7 @@ fn main() { }; { m!(()) }; - { m!(()) }; + { m!(()) }; //~ semicolon_outside_block { m!(()); }; m!(0); m!(1); diff --git a/tests/ui-toml/semicolon_block/semicolon_outside_block.rs b/tests/ui-toml/semicolon_block/semicolon_outside_block.rs index c767201469ab..2ae820135309 100644 --- a/tests/ui-toml/semicolon_block/semicolon_outside_block.rs +++ b/tests/ui-toml/semicolon_block/semicolon_outside_block.rs @@ -38,8 +38,8 @@ fn main() { { unit_fn_block() }; unsafe { unit_fn_block() }; - { unit_fn_block(); } - unsafe { unit_fn_block(); } + { unit_fn_block(); } //~ semicolon_outside_block + unsafe { unit_fn_block(); } //~ semicolon_outside_block { unit_fn_block(); }; unsafe { unit_fn_block(); }; @@ -58,7 +58,7 @@ fn main() { }; { m!(()) }; - { m!(()); } + { m!(()); } //~ semicolon_outside_block { m!(()); }; m!(0); m!(1); diff --git a/tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs b/tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs index 90c2439dc34f..8d0871e22a36 100644 --- a/tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs +++ b/tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs @@ -8,7 +8,7 @@ pub struct NoGeneric { rc_is_not_send: Rc, } -unsafe impl Send for NoGeneric {} +unsafe impl Send for NoGeneric {} //~ non_send_fields_in_send_ty pub struct MultiField { field1: T, @@ -17,6 +17,7 @@ pub struct MultiField { } unsafe impl Send for MultiField {} +//~^ non_send_fields_in_send_ty pub enum MyOption { MySome(T), @@ -24,6 +25,7 @@ pub enum MyOption { } unsafe impl Send for MyOption {} +//~^ non_send_fields_in_send_ty // All fields are disallowed when raw pointer heuristic is off extern "C" { @@ -38,6 +40,6 @@ pub struct HeuristicTest { field5: Vec>, } -unsafe impl Send for HeuristicTest {} +unsafe impl Send for HeuristicTest {} //~ non_send_fields_in_send_ty fn main() {} diff --git a/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr b/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr index 1024ae1b9c22..2f79973d127b 100644 --- a/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr +++ b/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr @@ -39,50 +39,50 @@ LL | field3: T, = help: add `T: Send` bound in `Send` impl error: some fields in `MyOption` are not safe to be sent to another thread - --> $DIR/strict_non_send_fields_in_send_ty/test.rs:26:1 + --> $DIR/strict_non_send_fields_in_send_ty/test.rs:27:1 | LL | unsafe impl Send for MyOption {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `0` to another thread - --> $DIR/strict_non_send_fields_in_send_ty/test.rs:22:12 + --> $DIR/strict_non_send_fields_in_send_ty/test.rs:23:12 | LL | MySome(T), | ^ = help: add `T: Send` bound in `Send` impl error: some fields in `HeuristicTest` are not safe to be sent to another thread - --> $DIR/strict_non_send_fields_in_send_ty/test.rs:41:1 + --> $DIR/strict_non_send_fields_in_send_ty/test.rs:43:1 | LL | unsafe impl Send for HeuristicTest {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field1` to another thread - --> $DIR/strict_non_send_fields_in_send_ty/test.rs:34:5 + --> $DIR/strict_non_send_fields_in_send_ty/test.rs:36:5 | LL | field1: Vec<*const NonSend>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` note: it is not safe to send field `field2` to another thread - --> $DIR/strict_non_send_fields_in_send_ty/test.rs:35:5 + --> $DIR/strict_non_send_fields_in_send_ty/test.rs:37:5 | LL | field2: [*const NonSend; 3], | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` note: it is not safe to send field `field3` to another thread - --> $DIR/strict_non_send_fields_in_send_ty/test.rs:36:5 + --> $DIR/strict_non_send_fields_in_send_ty/test.rs:38:5 | LL | field3: (*const NonSend, *const NonSend, *const NonSend), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` note: it is not safe to send field `field4` to another thread - --> $DIR/strict_non_send_fields_in_send_ty/test.rs:37:5 + --> $DIR/strict_non_send_fields_in_send_ty/test.rs:39:5 | LL | field4: (*const NonSend, Rc), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` note: it is not safe to send field `field5` to another thread - --> $DIR/strict_non_send_fields_in_send_ty/test.rs:38:5 + --> $DIR/strict_non_send_fields_in_send_ty/test.rs:40:5 | LL | field5: Vec>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/struct_excessive_bools/test.rs b/tests/ui-toml/struct_excessive_bools/test.rs index 32dd80246fab..6d5371cceec5 100644 --- a/tests/ui-toml/struct_excessive_bools/test.rs +++ b/tests/ui-toml/struct_excessive_bools/test.rs @@ -1,5 +1,6 @@ #![warn(clippy::struct_excessive_bools)] +//~v struct_excessive_bools struct S { a: bool, } diff --git a/tests/ui-toml/struct_excessive_bools/test.stderr b/tests/ui-toml/struct_excessive_bools/test.stderr index c3ecfa1f91fa..c4e678786406 100644 --- a/tests/ui-toml/struct_excessive_bools/test.stderr +++ b/tests/ui-toml/struct_excessive_bools/test.stderr @@ -1,5 +1,5 @@ error: more than 0 bools in a struct - --> $DIR/struct_excessive_bools/test.rs:3:1 + --> $DIR/struct_excessive_bools/test.rs:4:1 | LL | / struct S { LL | | a: bool, diff --git a/tests/ui-toml/suppress_lint_in_const/test.rs b/tests/ui-toml/suppress_lint_in_const/test.rs index 3edb3a10b769..78813e774a7f 100644 --- a/tests/ui-toml/suppress_lint_in_const/test.rs +++ b/tests/ui-toml/suppress_lint_in_const/test.rs @@ -26,7 +26,7 @@ const fn idx4() -> usize { fn main() { let x = [1, 2, 3, 4]; let index: usize = 1; - x[index]; + x[index]; //~ indexing_slicing x[4]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. x[1 << 3]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. @@ -44,16 +44,16 @@ fn main() { y[4]; // Ok, rustc will handle references too. let v = vec![0; 5]; - v[0]; - v[10]; - v[1 << 3]; + v[0]; //~ indexing_slicing + v[10]; //~ indexing_slicing + v[1 << 3]; //~ indexing_slicing const N: usize = 15; // Out of bounds const M: usize = 3; // In bounds x[N]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. x[M]; // Ok, should not produce stderr. - v[N]; - v[M]; + v[N]; //~ indexing_slicing + v[M]; //~ indexing_slicing } /// An opaque integer representation diff --git a/tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs b/tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs index 2f86b3eda4c5..2fb36b7aa805 100644 --- a/tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs +++ b/tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs @@ -3,18 +3,21 @@ #![allow(unused_variables)] #![warn(clippy::disallowed_names)] -fn test(toto: ()) {} +fn test(toto: ()) {} //~ disallowed_names fn main() { - let toto = 42; - let tata = 42; - let titi = 42; + let toto = 42; //~ disallowed_names + let tata = 42; //~ disallowed_names + let titi = 42; //~ disallowed_names let tatab = 42; let tatatataic = 42; match (42, Some(1337), Some(0)) { (toto, Some(tata), titi @ Some(_)) => (), + //~^ disallowed_names + //~| disallowed_names + //~| disallowed_names _ => (), } } diff --git a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs index 63fdea710cb6..038197fb866e 100644 --- a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs +++ b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs @@ -32,30 +32,33 @@ mod local_mod { } fn main() { - let re = Regex::new(r"ab.*c").unwrap(); - re.is_match("abc"); + let re = Regex::new(r"ab.*c").unwrap(); //~ disallowed_methods + re.is_match("abc"); //~ disallowed_methods let mut a = vec![1, 2, 3, 4]; - a.iter().sum::(); + a.iter().sum::(); //~ disallowed_methods - a.sort_unstable(); + a.sort_unstable(); //~ disallowed_methods - let _ = 2.0f32.clamp(3.0f32, 4.0f32); + let _ = 2.0f32.clamp(3.0f32, 4.0f32); //~ disallowed_methods let _ = 2.0f64.clamp(3.0f64, 4.0f64); let indirect: fn(&str) -> Result = Regex::new; + //~^ disallowed_methods let re = indirect(".").unwrap(); - let in_call = Box::new(f32::clamp); + let in_call = Box::new(f32::clamp); //~ disallowed_methods let in_method_call = ["^", "$"].into_iter().map(Regex::new); + //~^ disallowed_methods // resolve ambiguity between `futures::stream::select_all` the module and the function let same_name_as_module = select_all(vec![empty::<()>()]); + //~^ disallowed_methods - local_fn(); - local_mod::f(); + local_fn(); //~ disallowed_methods + local_mod::f(); //~ disallowed_methods let s = Struct; - s.method(); - s.provided_method(); - s.implemented_method(); + s.method(); //~ disallowed_methods + s.provided_method(); //~ disallowed_methods + s.implemented_method(); //~ disallowed_methods } diff --git a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr index e68a8ebeaaa0..fdc3d3a954dc 100644 --- a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr +++ b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr @@ -40,49 +40,49 @@ LL | let indirect: fn(&str) -> Result = Regex::new; | ^^^^^^^^^^ error: use of a disallowed method `f32::clamp` - --> $DIR/toml_disallowed_methods/conf_disallowed_methods.rs:49:28 + --> $DIR/toml_disallowed_methods/conf_disallowed_methods.rs:50:28 | LL | let in_call = Box::new(f32::clamp); | ^^^^^^^^^^ error: use of a disallowed method `regex::Regex::new` - --> $DIR/toml_disallowed_methods/conf_disallowed_methods.rs:50:53 + --> $DIR/toml_disallowed_methods/conf_disallowed_methods.rs:51:53 | LL | let in_method_call = ["^", "$"].into_iter().map(Regex::new); | ^^^^^^^^^^ error: use of a disallowed method `futures::stream::select_all` - --> $DIR/toml_disallowed_methods/conf_disallowed_methods.rs:53:31 + --> $DIR/toml_disallowed_methods/conf_disallowed_methods.rs:55:31 | LL | let same_name_as_module = select_all(vec![empty::<()>()]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::local_fn` - --> $DIR/toml_disallowed_methods/conf_disallowed_methods.rs:55:5 + --> $DIR/toml_disallowed_methods/conf_disallowed_methods.rs:58:5 | LL | local_fn(); | ^^^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::local_mod::f` - --> $DIR/toml_disallowed_methods/conf_disallowed_methods.rs:56:5 + --> $DIR/toml_disallowed_methods/conf_disallowed_methods.rs:59:5 | LL | local_mod::f(); | ^^^^^^^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::Struct::method` - --> $DIR/toml_disallowed_methods/conf_disallowed_methods.rs:58:5 + --> $DIR/toml_disallowed_methods/conf_disallowed_methods.rs:61:5 | LL | s.method(); | ^^^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::Trait::provided_method` - --> $DIR/toml_disallowed_methods/conf_disallowed_methods.rs:59:5 + --> $DIR/toml_disallowed_methods/conf_disallowed_methods.rs:62:5 | LL | s.provided_method(); | ^^^^^^^^^^^^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::Trait::implemented_method` - --> $DIR/toml_disallowed_methods/conf_disallowed_methods.rs:60:5 + --> $DIR/toml_disallowed_methods/conf_disallowed_methods.rs:63:5 | LL | s.implemented_method(); | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs b/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs index 7f28efd676f2..1afc336db653 100644 --- a/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs +++ b/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs @@ -4,39 +4,49 @@ extern crate quote; extern crate syn; use std::sync as foo; -use std::sync::atomic::AtomicU32; -use std::time::Instant as Sneaky; +use std::sync::atomic::AtomicU32; //~ disallowed_types +use std::time::Instant as Sneaky; //~ disallowed_types struct HashMap; +//~v disallowed_types fn bad_return_type() -> fn() -> Sneaky { todo!() } fn bad_arg_type(_: impl Fn(Sneaky) -> foo::atomic::AtomicU32) {} +//~^ disallowed_types +//~| disallowed_types -fn trait_obj(_: &dyn std::io::Read) {} +fn trait_obj(_: &dyn std::io::Read) {} //~ disallowed_types fn full_and_single_path_prim(_: usize, _: bool) {} +//~^ disallowed_types +//~| disallowed_types -fn const_generics() {} +fn const_generics() {} //~ disallowed_types -struct GenArg([u8; U]); +struct GenArg([u8; U]); //~ disallowed_types static BAD: foo::atomic::AtomicPtr<()> = foo::atomic::AtomicPtr::new(std::ptr::null_mut()); -fn ip(_: std::net::Ipv4Addr) {} +fn ip(_: std::net::Ipv4Addr) {} //~ disallowed_types -fn listener(_: std::net::TcpListener) {} +fn listener(_: std::net::TcpListener) {} //~ disallowed_types #[allow(clippy::diverging_sub_expression)] fn main() { let _: std::collections::HashMap<(), ()> = std::collections::HashMap::new(); - let _ = Sneaky::now(); - let _ = foo::atomic::AtomicU32::new(0); + //~^ disallowed_types + //~| disallowed_types + let _ = Sneaky::now(); //~ disallowed_types + let _ = foo::atomic::AtomicU32::new(0); //~ disallowed_types static FOO: std::sync::atomic::AtomicU32 = foo::atomic::AtomicU32::new(1); + //~^ disallowed_types + //~| disallowed_types let _: std::collections::BTreeMap<(), syn::TypePath> = Default::default(); - let _ = syn::Ident::new("", todo!()); + //~^ disallowed_types + let _ = syn::Ident::new("", todo!()); //~ disallowed_types let _ = HashMap; - let _: usize = 64_usize; + let _: usize = 64_usize; //~ disallowed_types } diff --git a/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr b/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr index 476456107d78..cbc0d4d6b5da 100644 --- a/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr +++ b/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr @@ -14,55 +14,55 @@ LL | use std::time::Instant as Sneaky; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `std::time::Instant` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:12:33 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:13:33 | LL | fn bad_return_type() -> fn() -> Sneaky { | ^^^^^^ error: `std::time::Instant` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:16:28 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:17:28 | LL | fn bad_arg_type(_: impl Fn(Sneaky) -> foo::atomic::AtomicU32) {} | ^^^^^^ error: `std::sync::atomic::AtomicU32` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:16:39 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:17:39 | LL | fn bad_arg_type(_: impl Fn(Sneaky) -> foo::atomic::AtomicU32) {} | ^^^^^^^^^^^^^^^^^^^^^^ error: `std::io::Read` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:18:22 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:21:22 | LL | fn trait_obj(_: &dyn std::io::Read) {} | ^^^^^^^^^^^^^ error: `usize` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:20:33 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:23:33 | LL | fn full_and_single_path_prim(_: usize, _: bool) {} | ^^^^^ error: `bool` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:20:43 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:23:43 | LL | fn full_and_single_path_prim(_: usize, _: bool) {} | ^^^^ error: `usize` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:22:28 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:27:28 | LL | fn const_generics() {} | ^^^^^ error: `usize` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:24:24 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:29:24 | LL | struct GenArg([u8; U]); | ^^^^^ error: `std::net::Ipv4Addr` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:28:10 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:33:10 | LL | fn ip(_: std::net::Ipv4Addr) {} | ^^^^^^^^^^^^^^^^^^ @@ -70,61 +70,61 @@ LL | fn ip(_: std::net::Ipv4Addr) {} = note: no IPv4 allowed (from clippy.toml) error: `std::net::TcpListener` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:30:16 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:35:16 | LL | fn listener(_: std::net::TcpListener) {} | ^^^^^^^^^^^^^^^^^^^^^ error: `std::collections::HashMap` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:34:48 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:39:48 | LL | let _: std::collections::HashMap<(), ()> = std::collections::HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `std::collections::HashMap` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:34:12 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:39:12 | LL | let _: std::collections::HashMap<(), ()> = std::collections::HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `std::time::Instant` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:35:13 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:42:13 | LL | let _ = Sneaky::now(); | ^^^^^^ error: `std::sync::atomic::AtomicU32` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:36:13 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:43:13 | LL | let _ = foo::atomic::AtomicU32::new(0); | ^^^^^^^^^^^^^^^^^^^^^^ error: `std::sync::atomic::AtomicU32` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:37:17 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:44:17 | LL | static FOO: std::sync::atomic::AtomicU32 = foo::atomic::AtomicU32::new(1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `std::sync::atomic::AtomicU32` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:37:48 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:44:48 | LL | static FOO: std::sync::atomic::AtomicU32 = foo::atomic::AtomicU32::new(1); | ^^^^^^^^^^^^^^^^^^^^^^ error: `syn::TypePath` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:38:43 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:47:43 | LL | let _: std::collections::BTreeMap<(), syn::TypePath> = Default::default(); | ^^^^^^^^^^^^^ error: `syn::Ident` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:39:13 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:49:13 | LL | let _ = syn::Ident::new("", todo!()); | ^^^^^^^^^^ error: `usize` is not allowed according to config - --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:41:12 + --> $DIR/toml_disallowed_types/conf_disallowed_types.rs:51:12 | LL | let _: usize = 64_usize; | ^^^^^ diff --git a/tests/ui-toml/toml_trivially_copy/test.rs b/tests/ui-toml/toml_trivially_copy/test.rs index 145a2ce441d3..46f21eef9740 100644 --- a/tests/ui-toml/toml_trivially_copy/test.rs +++ b/tests/ui-toml/toml_trivially_copy/test.rs @@ -13,6 +13,8 @@ struct Bar(u32); fn good(a: &mut u32, b: u32, c: &Bar, d: &u32) {} fn bad(x: &u16, y: &Foo) {} +//~^ trivially_copy_pass_by_ref +//~| trivially_copy_pass_by_ref fn main() { let (mut a, b, c, d, x, y) = (0, 0, Bar(0), 0, 0, Foo(0)); diff --git a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr index 7fecb7f37dc1..19cf3c7dbb3c 100644 --- a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr +++ b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr @@ -41,7 +41,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:278:18 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:281:18 | LL | let _ = (42, unsafe {}, "test", unsafe {}); | ^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:278:37 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:281:37 | LL | let _ = (42, unsafe {}, "test", unsafe {}); | ^^^^^^^^^ @@ -57,7 +57,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:282:14 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:287:14 | LL | let _ = *unsafe { &42 }; | ^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | let _ = *unsafe { &42 }; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:287:19 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:293:19 | LL | let _ = match unsafe {} { | ^^^^^^^^^ @@ -73,7 +73,7 @@ LL | let _ = match unsafe {} { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:293:14 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:299:14 | LL | let _ = &unsafe {}; | ^^^^^^^^^ @@ -81,7 +81,7 @@ LL | let _ = &unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:297:14 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:303:14 | LL | let _ = [unsafe {}; 5]; | ^^^^^^^^^ @@ -89,7 +89,7 @@ LL | let _ = [unsafe {}; 5]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:301:13 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:307:13 | LL | let _ = unsafe {}; | ^^^^^^^^^ @@ -97,7 +97,7 @@ LL | let _ = unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:311:8 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:317:8 | LL | t!(unsafe {}); | ^^^^^^^^^ @@ -105,7 +105,7 @@ LL | t!(unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:317:13 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:323:13 | LL | unsafe {} | ^^^^^^^^^ @@ -117,7 +117,7 @@ LL | t!(); = note: this error originates in the macro `t` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:325:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:332:5 | LL | unsafe {} // SAFETY: | ^^^^^^^^^ @@ -125,7 +125,7 @@ LL | unsafe {} // SAFETY: = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:329:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:337:5 | LL | unsafe { | ^^^^^^^^ @@ -133,7 +133,7 @@ LL | unsafe { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:339:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:347:5 | LL | unsafe {}; | ^^^^^^^^^ @@ -141,7 +141,7 @@ LL | unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:343:20 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:351:20 | LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -149,7 +149,7 @@ LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) }); = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:350:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:359:5 | LL | unsafe impl A for () {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL | unsafe impl A for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:357:9 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:366:9 | LL | unsafe impl B for (u32) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -165,7 +165,7 @@ LL | unsafe impl B for (u32) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:378:13 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:387:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | no_safety_comment!(()); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:403:13 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:412:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -189,7 +189,7 @@ LL | no_safety_comment!(()); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:411:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:424:5 | LL | unsafe impl T for (i32) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -197,7 +197,7 @@ LL | unsafe impl T for (i32) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:403:13 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:412:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -209,7 +209,7 @@ LL | no_safety_comment!(u32); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:417:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:430:5 | LL | unsafe impl T for (bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL | unsafe impl T for (bool) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:463:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:476:5 | LL | unsafe impl NoComment for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -225,7 +225,7 @@ LL | unsafe impl NoComment for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:467:19 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:480:19 | LL | /* SAFETY: */ unsafe impl InlineComment for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -233,7 +233,7 @@ LL | /* SAFETY: */ unsafe impl InlineComment for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:471:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:486:5 | LL | unsafe impl TrailingComment for () {} // SAFETY: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -241,13 +241,13 @@ LL | unsafe impl TrailingComment for () {} // SAFETY: = help: consider adding a safety comment on the preceding line error: constant item has unnecessary safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:475:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:490:5 | LL | const BIG_NUMBER: i32 = 1000000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:474:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:489:5 | LL | // SAFETY: | ^^^^^^^^^^ @@ -255,7 +255,7 @@ LL | // SAFETY: = help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]` error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:476:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:491:5 | LL | unsafe impl Interference for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -263,7 +263,7 @@ LL | unsafe impl Interference for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:483:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:499:5 | LL | unsafe impl ImplInFn for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -271,7 +271,7 @@ LL | unsafe impl ImplInFn for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:492:1 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:508:1 | LL | unsafe impl CrateRoot for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -279,25 +279,25 @@ LL | unsafe impl CrateRoot for () {} = help: consider adding a safety comment on the preceding line error: statement has unnecessary safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:505:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:522:5 | LL | / let _ = { +LL | | LL | | if unsafe { true } { LL | | todo!(); -LL | | } else { ... | LL | | } LL | | }; | |______^ | help: consider removing the safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:504:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:520:5 | LL | // SAFETY: this is more than one level away, so it should warn | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:506:12 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:524:12 | LL | if unsafe { true } { | ^^^^^^^^^^^^^^^ @@ -305,7 +305,7 @@ LL | if unsafe { true } { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:509:23 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:527:23 | LL | let bar = unsafe {}; | ^^^^^^^^^ diff --git a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr index 03322de8be07..257846406834 100644 --- a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr +++ b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr @@ -41,7 +41,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:278:18 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:281:18 | LL | let _ = (42, unsafe {}, "test", unsafe {}); | ^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:278:37 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:281:37 | LL | let _ = (42, unsafe {}, "test", unsafe {}); | ^^^^^^^^^ @@ -57,7 +57,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:282:14 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:287:14 | LL | let _ = *unsafe { &42 }; | ^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | let _ = *unsafe { &42 }; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:287:19 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:293:19 | LL | let _ = match unsafe {} { | ^^^^^^^^^ @@ -73,7 +73,7 @@ LL | let _ = match unsafe {} { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:293:14 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:299:14 | LL | let _ = &unsafe {}; | ^^^^^^^^^ @@ -81,7 +81,7 @@ LL | let _ = &unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:297:14 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:303:14 | LL | let _ = [unsafe {}; 5]; | ^^^^^^^^^ @@ -89,7 +89,7 @@ LL | let _ = [unsafe {}; 5]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:301:13 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:307:13 | LL | let _ = unsafe {}; | ^^^^^^^^^ @@ -97,7 +97,7 @@ LL | let _ = unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:311:8 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:317:8 | LL | t!(unsafe {}); | ^^^^^^^^^ @@ -105,7 +105,7 @@ LL | t!(unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:317:13 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:323:13 | LL | unsafe {} | ^^^^^^^^^ @@ -117,7 +117,7 @@ LL | t!(); = note: this error originates in the macro `t` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:325:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:332:5 | LL | unsafe {} // SAFETY: | ^^^^^^^^^ @@ -125,7 +125,7 @@ LL | unsafe {} // SAFETY: = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:329:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:337:5 | LL | unsafe { | ^^^^^^^^ @@ -133,7 +133,7 @@ LL | unsafe { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:339:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:347:5 | LL | unsafe {}; | ^^^^^^^^^ @@ -141,7 +141,7 @@ LL | unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:343:20 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:351:20 | LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -149,7 +149,7 @@ LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) }); = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:350:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:359:5 | LL | unsafe impl A for () {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL | unsafe impl A for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:357:9 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:366:9 | LL | unsafe impl B for (u32) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -165,7 +165,7 @@ LL | unsafe impl B for (u32) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:378:13 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:387:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | no_safety_comment!(()); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:403:13 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:412:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -189,7 +189,7 @@ LL | no_safety_comment!(()); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:411:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:424:5 | LL | unsafe impl T for (i32) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -197,7 +197,7 @@ LL | unsafe impl T for (i32) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:403:13 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:412:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -209,7 +209,7 @@ LL | no_safety_comment!(u32); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:417:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:430:5 | LL | unsafe impl T for (bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL | unsafe impl T for (bool) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:463:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:476:5 | LL | unsafe impl NoComment for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -225,7 +225,7 @@ LL | unsafe impl NoComment for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:467:19 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:480:19 | LL | /* SAFETY: */ unsafe impl InlineComment for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -233,7 +233,7 @@ LL | /* SAFETY: */ unsafe impl InlineComment for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:471:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:486:5 | LL | unsafe impl TrailingComment for () {} // SAFETY: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -241,13 +241,13 @@ LL | unsafe impl TrailingComment for () {} // SAFETY: = help: consider adding a safety comment on the preceding line error: constant item has unnecessary safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:475:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:490:5 | LL | const BIG_NUMBER: i32 = 1000000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:474:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:489:5 | LL | // SAFETY: | ^^^^^^^^^^ @@ -255,7 +255,7 @@ LL | // SAFETY: = help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]` error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:476:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:491:5 | LL | unsafe impl Interference for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -263,7 +263,7 @@ LL | unsafe impl Interference for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:483:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:499:5 | LL | unsafe impl ImplInFn for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -271,7 +271,7 @@ LL | unsafe impl ImplInFn for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:492:1 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:508:1 | LL | unsafe impl CrateRoot for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -279,7 +279,7 @@ LL | unsafe impl CrateRoot for () {} = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:502:9 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:518:9 | LL | unsafe {}; | ^^^^^^^^^ @@ -287,25 +287,25 @@ LL | unsafe {}; = help: consider adding a safety comment on the preceding line error: statement has unnecessary safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:505:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:522:5 | LL | / let _ = { +LL | | LL | | if unsafe { true } { LL | | todo!(); -LL | | } else { ... | LL | | } LL | | }; | |______^ | help: consider removing the safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:504:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:520:5 | LL | // SAFETY: this is more than one level away, so it should warn | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:506:12 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:524:12 | LL | if unsafe { true } { | ^^^^^^^^^^^^^^^ @@ -313,7 +313,7 @@ LL | if unsafe { true } { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:509:23 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:527:23 | LL | let bar = unsafe {}; | ^^^^^^^^^ @@ -321,7 +321,7 @@ LL | let bar = unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:527:9 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:545:9 | LL | unsafe { a_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -329,7 +329,7 @@ LL | unsafe { a_function_with_a_very_long_name_to_break_the_line() }; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:531:9 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:550:9 | LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -337,7 +337,7 @@ LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:535:9 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:555:9 | LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -345,7 +345,7 @@ LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:541:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:562:5 | LL | unsafe {} | ^^^^^^^^^ @@ -353,7 +353,7 @@ LL | unsafe {} = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:545:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:567:5 | LL | unsafe { | ^^^^^^^^ @@ -361,7 +361,7 @@ LL | unsafe { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:552:9 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:574:9 | LL | unsafe { a_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -369,7 +369,7 @@ LL | unsafe { a_function_with_a_very_long_name_to_break_the_line() }; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:557:9 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:580:9 | LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -377,7 +377,7 @@ LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:563:9 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:587:9 | LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -385,7 +385,7 @@ LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:568:5 + --> $DIR/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:593:5 | LL | unsafe {} | ^^^^^^^^^ diff --git a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs index a27813987606..62f93428bf99 100644 --- a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs +++ b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs @@ -263,42 +263,48 @@ fn in_closure(x: *const u32) { #[rustfmt::skip] fn inline_block_comment() { - /* Safety: */ unsafe {} + /* Safety: */ unsafe {} //~ undocumented_unsafe_blocks } fn no_comment() { - unsafe {} + unsafe {} //~ undocumented_unsafe_blocks } fn no_comment_array() { let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; + //~^ undocumented_unsafe_blocks + //~| undocumented_unsafe_blocks + //~| undocumented_unsafe_blocks } fn no_comment_tuple() { let _ = (42, unsafe {}, "test", unsafe {}); + //~^ undocumented_unsafe_blocks + //~| undocumented_unsafe_blocks } fn no_comment_unary() { - let _ = *unsafe { &42 }; + let _ = *unsafe { &42 }; //~ undocumented_unsafe_blocks } #[allow(clippy::match_single_binding)] fn no_comment_match() { + //~v undocumented_unsafe_blocks let _ = match unsafe {} { _ => {}, }; } fn no_comment_addr_of() { - let _ = &unsafe {}; + let _ = &unsafe {}; //~ undocumented_unsafe_blocks } fn no_comment_repeat() { - let _ = [unsafe {}; 5]; + let _ = [unsafe {}; 5]; //~ undocumented_unsafe_blocks } fn local_no_comment() { - let _ = unsafe {}; + let _ = unsafe {}; //~ undocumented_unsafe_blocks } fn no_comment_macro_call() { @@ -308,13 +314,13 @@ fn no_comment_macro_call() { }; } - t!(unsafe {}); + t!(unsafe {}); //~ undocumented_unsafe_blocks } fn no_comment_macro_def() { macro_rules! t { () => { - unsafe {} + unsafe {} //~ undocumented_unsafe_blocks }; } @@ -322,10 +328,12 @@ fn no_comment_macro_def() { } fn trailing_comment() { + //~v undocumented_unsafe_blocks unsafe {} // SAFETY: } fn internal_comment() { + //~v undocumented_unsafe_blocks unsafe { // SAFETY: } @@ -336,25 +344,26 @@ fn interference() { let _ = 42; - unsafe {}; + unsafe {}; //~ undocumented_unsafe_blocks } pub fn print_binary_tree() { println!("{}", unsafe { String::from_utf8_unchecked(vec![]) }); + //~^ undocumented_unsafe_blocks } mod unsafe_impl_smoke_test { unsafe trait A {} // error: no safety comment - unsafe impl A for () {} + unsafe impl A for () {} //~ undocumented_unsafe_blocks // Safety: ok unsafe impl A for (i32) {} mod sub_mod { // error: - unsafe impl B for (u32) {} + unsafe impl B for (u32) {} //~ undocumented_unsafe_blocks unsafe trait B {} } @@ -375,7 +384,7 @@ mod unsafe_impl_from_macro { // error macro_rules! no_safety_comment { ($t:ty) => { - unsafe impl T for $t {} + unsafe impl T for $t {} //~ undocumented_unsafe_blocks }; } @@ -401,6 +410,10 @@ mod unsafe_impl_macro_and_not_macro { macro_rules! no_safety_comment { ($t:ty) => { unsafe impl T for $t {} + //~[default]^ undocumented_unsafe_blocks + //~[default]| undocumented_unsafe_blocks + //~[disabled]| undocumented_unsafe_blocks + //~[disabled]| undocumented_unsafe_blocks }; } @@ -408,13 +421,13 @@ mod unsafe_impl_macro_and_not_macro { no_safety_comment!(()); // error - unsafe impl T for (i32) {} + unsafe impl T for (i32) {} //~ undocumented_unsafe_blocks // ok no_safety_comment!(u32); // error - unsafe impl T for (bool) {} + unsafe impl T for (bool) {} //~ undocumented_unsafe_blocks } #[rustfmt::skip] @@ -460,27 +473,30 @@ mod unsafe_impl_valid_comment { mod unsafe_impl_invalid_comment { unsafe trait NoComment {} - unsafe impl NoComment for () {} + unsafe impl NoComment for () {} //~ undocumented_unsafe_blocks unsafe trait InlineComment {} /* SAFETY: */ unsafe impl InlineComment for () {} + //~^ undocumented_unsafe_blocks unsafe trait TrailingComment {} + //~v undocumented_unsafe_blocks unsafe impl TrailingComment for () {} // SAFETY: unsafe trait Interference {} // SAFETY: - const BIG_NUMBER: i32 = 1000000; + const BIG_NUMBER: i32 = 1000000; //~ unnecessary_safety_comment unsafe impl Interference for () {} + //~^ undocumented_unsafe_blocks } unsafe trait ImplInFn {} fn impl_in_fn() { // error - unsafe impl ImplInFn for () {} + unsafe impl ImplInFn for () {} //~ undocumented_unsafe_blocks // SAFETY: ok unsafe impl ImplInFn for (i32) {} @@ -489,7 +505,7 @@ fn impl_in_fn() { unsafe trait CrateRoot {} // error -unsafe impl CrateRoot for () {} +unsafe impl CrateRoot for () {} //~ undocumented_unsafe_blocks // SAFETY: ok unsafe impl CrateRoot for (i32) {} @@ -499,14 +515,16 @@ fn nested_block_separation_issue_9142() { let _ = // we need this comment to avoid rustfmt putting // it all on one line - unsafe {}; + unsafe {}; //~[disabled] undocumented_unsafe_blocks // SAFETY: this is more than one level away, so it should warn + //~v unnecessary_safety_comment let _ = { + //~v undocumented_unsafe_blocks if unsafe { true } { todo!(); } else { - let bar = unsafe {}; + let bar = unsafe {}; //~ undocumented_unsafe_blocks todo!(); bar } @@ -525,23 +543,27 @@ fn separate_line_from_let_issue_10832() { // SAFETY: fail ONLY if `accept-comment-above-statement = false` let _some_variable_with_a_very_long_name_to_break_the_line = unsafe { a_function_with_a_very_long_name_to_break_the_line() }; + //~[disabled]^ undocumented_unsafe_blocks // SAFETY: fail ONLY if `accept-comment-above-statement = false` const _SOME_CONST_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 = unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; + //~[disabled]^ undocumented_unsafe_blocks // SAFETY: fail ONLY if `accept-comment-above-statement = false` static _SOME_STATIC_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 = unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; + //~[disabled]^ undocumented_unsafe_blocks } fn above_expr_attribute_issue_8679() { // SAFETY: fail ONLY if `accept-comment-above-attribute = false` #[allow(unsafe_code)] - unsafe {} + unsafe {} //~[disabled] undocumented_unsafe_blocks // SAFETY: fail ONLY if `accept-comment-above-attribute = false` #[expect(unsafe_code, reason = "totally safe")] + //~[disabled]v undocumented_unsafe_blocks unsafe { *std::ptr::null::() }; @@ -550,22 +572,25 @@ fn above_expr_attribute_issue_8679() { #[allow(unsafe_code)] let _some_variable_with_a_very_long_name_to_break_the_line = unsafe { a_function_with_a_very_long_name_to_break_the_line() }; + //~[disabled]^ undocumented_unsafe_blocks // SAFETY: fail ONLY if `accept-comment-above-attribute = false` #[allow(unsafe_code)] const _SOME_CONST_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 = unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; + //~[disabled]^ undocumented_unsafe_blocks // SAFETY: fail ONLY if `accept-comment-above-attribute = false` #[allow(unsafe_code)] #[allow(non_upper_case_globals)] static _some_static_with_a_very_long_name_to_break_the_line: u32 = unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; + //~[disabled]^ undocumented_unsafe_blocks // SAFETY: #[allow(unsafe_code)] // This shouldn't work either - unsafe {} + unsafe {} //~[disabled] undocumented_unsafe_blocks } mod issue_11246 { diff --git a/tests/ui-toml/unwrap_used/unwrap_used.fixed b/tests/ui-toml/unwrap_used/unwrap_used.fixed index baf939af24ef..215f217cfcaa 100644 --- a/tests/ui-toml/unwrap_used/unwrap_used.fixed +++ b/tests/ui-toml/unwrap_used/unwrap_used.fixed @@ -36,23 +36,45 @@ fn main() { { // Test `get().unwrap()` let _ = &boxed_slice[1]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_slice[0]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_vec[0]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_vecdeque[0]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_hashmap[&1]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_btreemap[&1]; + //~^ get_unwrap + //~| unwrap_used #[allow(clippy::unwrap_used)] let _ = false_positive.get(0).unwrap(); // Test with deref let _: u8 = boxed_slice[1]; + //~^ get_unwrap + //~| unwrap_used } { // Test `get_mut().unwrap()` boxed_slice[0] = 1; + //~^ get_unwrap + //~| unwrap_used some_slice[0] = 1; + //~^ get_unwrap + //~| unwrap_used some_vec[0] = 1; + //~^ get_unwrap + //~| unwrap_used some_vecdeque[0] = 1; + //~^ get_unwrap + //~| unwrap_used // Check false positives #[allow(clippy::unwrap_used)] { @@ -65,14 +87,18 @@ fn main() { { // Test `get().unwrap().foo()` and `get_mut().unwrap().bar()` let _ = some_vec[0..1].to_vec(); + //~^ get_unwrap + //~| unwrap_used let _ = some_vec[0..1].to_vec(); + //~^ get_unwrap + //~| unwrap_used } } #[test] fn test() { let boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); - let _ = &boxed_slice[1]; + let _ = &boxed_slice[1]; //~ get_unwrap } #[cfg(test)] @@ -90,6 +116,6 @@ mod issue9612 { let _a: u8 = 4.try_into().unwrap(); let _a: u8 = 5.try_into().expect(""); // should still warn - let _ = &Box::new([0])[1]; + let _ = &Box::new([0])[1]; //~ get_unwrap } } diff --git a/tests/ui-toml/unwrap_used/unwrap_used.rs b/tests/ui-toml/unwrap_used/unwrap_used.rs index e300ba18c330..fe02890fa1ce 100644 --- a/tests/ui-toml/unwrap_used/unwrap_used.rs +++ b/tests/ui-toml/unwrap_used/unwrap_used.rs @@ -36,23 +36,45 @@ fn main() { { // Test `get().unwrap()` let _ = boxed_slice.get(1).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_slice.get(0).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_vec.get(0).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_vecdeque.get(0).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_hashmap.get(&1).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_btreemap.get(&1).unwrap(); + //~^ get_unwrap + //~| unwrap_used #[allow(clippy::unwrap_used)] let _ = false_positive.get(0).unwrap(); // Test with deref let _: u8 = *boxed_slice.get(1).unwrap(); + //~^ get_unwrap + //~| unwrap_used } { // Test `get_mut().unwrap()` *boxed_slice.get_mut(0).unwrap() = 1; + //~^ get_unwrap + //~| unwrap_used *some_slice.get_mut(0).unwrap() = 1; + //~^ get_unwrap + //~| unwrap_used *some_vec.get_mut(0).unwrap() = 1; + //~^ get_unwrap + //~| unwrap_used *some_vecdeque.get_mut(0).unwrap() = 1; + //~^ get_unwrap + //~| unwrap_used // Check false positives #[allow(clippy::unwrap_used)] { @@ -65,14 +87,18 @@ fn main() { { // Test `get().unwrap().foo()` and `get_mut().unwrap().bar()` let _ = some_vec.get(0..1).unwrap().to_vec(); + //~^ get_unwrap + //~| unwrap_used let _ = some_vec.get_mut(0..1).unwrap().to_vec(); + //~^ get_unwrap + //~| unwrap_used } } #[test] fn test() { let boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); - let _ = boxed_slice.get(1).unwrap(); + let _ = boxed_slice.get(1).unwrap(); //~ get_unwrap } #[cfg(test)] @@ -90,6 +116,6 @@ mod issue9612 { let _a: u8 = 4.try_into().unwrap(); let _a: u8 = 5.try_into().expect(""); // should still warn - let _ = Box::new([0]).get(1).unwrap(); + let _ = Box::new([0]).get(1).unwrap(); //~ get_unwrap } } diff --git a/tests/ui-toml/unwrap_used/unwrap_used.stderr b/tests/ui-toml/unwrap_used/unwrap_used.stderr index 964ace5cf987..96a1244fa363 100644 --- a/tests/ui-toml/unwrap_used/unwrap_used.stderr +++ b/tests/ui-toml/unwrap_used/unwrap_used.stderr @@ -19,13 +19,13 @@ LL | let _ = boxed_slice.get(1).unwrap(); = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/unwrap_used/unwrap_used.rs:39:17 + --> $DIR/unwrap_used/unwrap_used.rs:41:17 | LL | let _ = some_slice.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_slice[0]` error: used `unwrap()` on an `Option` value - --> $DIR/unwrap_used/unwrap_used.rs:39:17 + --> $DIR/unwrap_used/unwrap_used.rs:41:17 | LL | let _ = some_slice.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,13 +34,13 @@ LL | let _ = some_slice.get(0).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise - --> $DIR/unwrap_used/unwrap_used.rs:40:17 + --> $DIR/unwrap_used/unwrap_used.rs:44:17 | LL | let _ = some_vec.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_vec[0]` error: used `unwrap()` on an `Option` value - --> $DIR/unwrap_used/unwrap_used.rs:40:17 + --> $DIR/unwrap_used/unwrap_used.rs:44:17 | LL | let _ = some_vec.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,13 +49,13 @@ LL | let _ = some_vec.get(0).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more concise - --> $DIR/unwrap_used/unwrap_used.rs:41:17 + --> $DIR/unwrap_used/unwrap_used.rs:47:17 | LL | let _ = some_vecdeque.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_vecdeque[0]` error: used `unwrap()` on an `Option` value - --> $DIR/unwrap_used/unwrap_used.rs:41:17 + --> $DIR/unwrap_used/unwrap_used.rs:47:17 | LL | let _ = some_vecdeque.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,13 +64,13 @@ LL | let _ = some_vecdeque.get(0).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise - --> $DIR/unwrap_used/unwrap_used.rs:42:17 + --> $DIR/unwrap_used/unwrap_used.rs:50:17 | LL | let _ = some_hashmap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_hashmap[&1]` error: used `unwrap()` on an `Option` value - --> $DIR/unwrap_used/unwrap_used.rs:42:17 + --> $DIR/unwrap_used/unwrap_used.rs:50:17 | LL | let _ = some_hashmap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -79,13 +79,13 @@ LL | let _ = some_hashmap.get(&1).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more concise - --> $DIR/unwrap_used/unwrap_used.rs:43:17 + --> $DIR/unwrap_used/unwrap_used.rs:53:17 | LL | let _ = some_btreemap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_btreemap[&1]` error: used `unwrap()` on an `Option` value - --> $DIR/unwrap_used/unwrap_used.rs:43:17 + --> $DIR/unwrap_used/unwrap_used.rs:53:17 | LL | let _ = some_btreemap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -94,13 +94,13 @@ LL | let _ = some_btreemap.get(&1).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/unwrap_used/unwrap_used.rs:47:21 + --> $DIR/unwrap_used/unwrap_used.rs:59:21 | LL | let _: u8 = *boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice[1]` error: used `unwrap()` on an `Option` value - --> $DIR/unwrap_used/unwrap_used.rs:47:22 + --> $DIR/unwrap_used/unwrap_used.rs:59:22 | LL | let _: u8 = *boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,13 +109,13 @@ LL | let _: u8 = *boxed_slice.get(1).unwrap(); = 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 - --> $DIR/unwrap_used/unwrap_used.rs:52:9 + --> $DIR/unwrap_used/unwrap_used.rs:66:9 | LL | *boxed_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice[0]` error: used `unwrap()` on an `Option` value - --> $DIR/unwrap_used/unwrap_used.rs:52:10 + --> $DIR/unwrap_used/unwrap_used.rs:66:10 | LL | *boxed_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -124,13 +124,13 @@ LL | *boxed_slice.get_mut(0).unwrap() = 1; = 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 - --> $DIR/unwrap_used/unwrap_used.rs:53:9 + --> $DIR/unwrap_used/unwrap_used.rs:69:9 | LL | *some_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_slice[0]` error: used `unwrap()` on an `Option` value - --> $DIR/unwrap_used/unwrap_used.rs:53:10 + --> $DIR/unwrap_used/unwrap_used.rs:69:10 | LL | *some_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -139,13 +139,13 @@ LL | *some_slice.get_mut(0).unwrap() = 1; = 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 - --> $DIR/unwrap_used/unwrap_used.rs:54:9 + --> $DIR/unwrap_used/unwrap_used.rs:72:9 | LL | *some_vec.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0]` error: used `unwrap()` on an `Option` value - --> $DIR/unwrap_used/unwrap_used.rs:54:10 + --> $DIR/unwrap_used/unwrap_used.rs:72:10 | LL | *some_vec.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -154,13 +154,13 @@ LL | *some_vec.get_mut(0).unwrap() = 1; = 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 - --> $DIR/unwrap_used/unwrap_used.rs:55:9 + --> $DIR/unwrap_used/unwrap_used.rs:75:9 | LL | *some_vecdeque.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vecdeque[0]` error: used `unwrap()` on an `Option` value - --> $DIR/unwrap_used/unwrap_used.rs:55:10 + --> $DIR/unwrap_used/unwrap_used.rs:75:10 | LL | *some_vecdeque.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -169,13 +169,13 @@ LL | *some_vecdeque.get_mut(0).unwrap() = 1; = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise - --> $DIR/unwrap_used/unwrap_used.rs:67:17 + --> $DIR/unwrap_used/unwrap_used.rs:89:17 | LL | let _ = some_vec.get(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0..1]` error: used `unwrap()` on an `Option` value - --> $DIR/unwrap_used/unwrap_used.rs:67:17 + --> $DIR/unwrap_used/unwrap_used.rs:89:17 | LL | let _ = some_vec.get(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -184,13 +184,13 @@ LL | let _ = some_vec.get(0..1).unwrap().to_vec(); = 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 - --> $DIR/unwrap_used/unwrap_used.rs:68:17 + --> $DIR/unwrap_used/unwrap_used.rs:92:17 | LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0..1]` error: used `unwrap()` on an `Option` value - --> $DIR/unwrap_used/unwrap_used.rs:68:17 + --> $DIR/unwrap_used/unwrap_used.rs:92:17 | LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -199,13 +199,13 @@ LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/unwrap_used/unwrap_used.rs:75:13 + --> $DIR/unwrap_used/unwrap_used.rs:101:13 | LL | let _ = boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&boxed_slice[1]` error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/unwrap_used/unwrap_used.rs:93:17 + --> $DIR/unwrap_used/unwrap_used.rs:119:17 | LL | let _ = Box::new([0]).get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&Box::new([0])[1]` diff --git a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.fixed b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.fixed index afb889f157f0..9447604420cd 100644 --- a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.fixed +++ b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.fixed @@ -1,24 +1,26 @@ #![warn(clippy::upper_case_acronyms)] +//~v upper_case_acronyms struct HttpResponse; // not linted by default, but with cfg option struct CString; // not linted enum Flags { - Ns, // not linted - Cwr, - Ece, - Urg, - Ack, - Psh, - Rst, - Syn, - Fin, + //~v upper_case_acronyms + Ns, // not linted + Cwr, //~ upper_case_acronyms + Ece, //~ upper_case_acronyms + Urg, //~ upper_case_acronyms + Ack, //~ upper_case_acronyms + Psh, //~ upper_case_acronyms + Rst, //~ upper_case_acronyms + Syn, //~ upper_case_acronyms + Fin, //~ upper_case_acronyms } // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of // `GccLlvmSomething` -struct GccllvmSomething; +struct GccllvmSomething; //~ upper_case_acronyms // don't warn on public items pub struct MIXEDCapital; @@ -35,8 +37,8 @@ pub enum ParseError { // private, do lint here enum ParseErrorPrivate { - Wasd(u8), - WasdMixed(String), + Wasd(u8), //~ upper_case_acronyms + WasdMixed(String), //~ upper_case_acronyms Utf8(std::string::FromUtf8Error), Parse(T, String), } diff --git a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs index 1a5cf1b1947c..2603452098b7 100644 --- a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs +++ b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs @@ -1,24 +1,26 @@ #![warn(clippy::upper_case_acronyms)] +//~v upper_case_acronyms struct HTTPResponse; // not linted by default, but with cfg option struct CString; // not linted enum Flags { - NS, // not linted - CWR, - ECE, - URG, - ACK, - PSH, - RST, - SYN, - FIN, + //~v upper_case_acronyms + NS, // not linted + CWR, //~ upper_case_acronyms + ECE, //~ upper_case_acronyms + URG, //~ upper_case_acronyms + ACK, //~ upper_case_acronyms + PSH, //~ upper_case_acronyms + RST, //~ upper_case_acronyms + SYN, //~ upper_case_acronyms + FIN, //~ upper_case_acronyms } // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of // `GccLlvmSomething` -struct GCCLLVMSomething; +struct GCCLLVMSomething; //~ upper_case_acronyms // don't warn on public items pub struct MIXEDCapital; @@ -35,8 +37,8 @@ pub enum ParseError { // private, do lint here enum ParseErrorPrivate { - WASD(u8), - WASDMixed(String), + WASD(u8), //~ upper_case_acronyms + WASDMixed(String), //~ upper_case_acronyms Utf8(std::string::FromUtf8Error), Parse(T, String), } diff --git a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr index b7bf06850388..d41f1ac5487d 100644 --- a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr +++ b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr @@ -1,5 +1,5 @@ error: name `HTTPResponse` contains a capitalized acronym - --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:3:8 + --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:4:8 | LL | struct HTTPResponse; // not linted by default, but with cfg option | ^^^^^^^^^^^^ help: consider making the acronym lowercase, except the initial letter: `HttpResponse` @@ -8,73 +8,73 @@ LL | struct HTTPResponse; // not linted by default, but with cfg option = help: to override `-D warnings` add `#[allow(clippy::upper_case_acronyms)]` error: name `NS` contains a capitalized acronym - --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:8:5 + --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:10:5 | -LL | NS, // not linted +LL | NS, // not linted | ^^ help: consider making the acronym lowercase, except the initial letter (notice the capitalization): `Ns` error: name `CWR` contains a capitalized acronym - --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:9:5 + --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:11:5 | LL | CWR, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Cwr` error: name `ECE` contains a capitalized acronym - --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:10:5 + --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:12:5 | LL | ECE, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Ece` error: name `URG` contains a capitalized acronym - --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:11:5 + --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:13:5 | LL | URG, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Urg` error: name `ACK` contains a capitalized acronym - --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:12:5 + --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:14:5 | LL | ACK, | ^^^ help: consider making the acronym lowercase, except the initial letter (notice the capitalization): `Ack` error: name `PSH` contains a capitalized acronym - --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:13:5 + --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:15:5 | LL | PSH, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Psh` error: name `RST` contains a capitalized acronym - --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:14:5 + --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:16:5 | LL | RST, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Rst` error: name `SYN` contains a capitalized acronym - --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:15:5 + --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:17:5 | LL | SYN, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Syn` error: name `FIN` contains a capitalized acronym - --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:16:5 + --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:18:5 | LL | FIN, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Fin` error: name `GCCLLVMSomething` contains a capitalized acronym - --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:21:8 + --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:23:8 | LL | struct GCCLLVMSomething; | ^^^^^^^^^^^^^^^^ help: consider making the acronym lowercase, except the initial letter: `GccllvmSomething` error: name `WASD` contains a capitalized acronym - --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:38:5 + --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:40:5 | LL | WASD(u8), | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Wasd` error: name `WASDMixed` contains a capitalized acronym - --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:39:5 + --> $DIR/upper_case_acronyms_aggressive/upper_case_acronyms.rs:41:5 | LL | WASDMixed(String), | ^^^^^^^^^ help: consider making the acronym lowercase, except the initial letter: `WasdMixed` diff --git a/tests/ui-toml/vec_box_sized/test.fixed b/tests/ui-toml/vec_box_sized/test.fixed index bb4936401ceb..9afc41276f08 100644 --- a/tests/ui-toml/vec_box_sized/test.fixed +++ b/tests/ui-toml/vec_box_sized/test.fixed @@ -6,11 +6,11 @@ struct C { y: u16, } -struct Foo(Vec); -struct Bar(Vec); +struct Foo(Vec); //~ vec_box +struct Bar(Vec); //~ vec_box struct Quux(Vec>); struct Baz(Vec>); struct BarBaz(Vec>); -struct FooBarBaz(Vec); +struct FooBarBaz(Vec); //~ vec_box fn main() {} diff --git a/tests/ui-toml/vec_box_sized/test.rs b/tests/ui-toml/vec_box_sized/test.rs index 4c46deb585b6..5d22b5aad36f 100644 --- a/tests/ui-toml/vec_box_sized/test.rs +++ b/tests/ui-toml/vec_box_sized/test.rs @@ -6,11 +6,11 @@ struct C { y: u16, } -struct Foo(Vec>); -struct Bar(Vec>); +struct Foo(Vec>); //~ vec_box +struct Bar(Vec>); //~ vec_box struct Quux(Vec>); struct Baz(Vec>); struct BarBaz(Vec>); -struct FooBarBaz(Vec>); +struct FooBarBaz(Vec>); //~ vec_box fn main() {} diff --git a/tests/ui/allow_attributes.fixed b/tests/ui/allow_attributes.fixed index b506a9890f5b..4a4ce7cb34cb 100644 --- a/tests/ui/allow_attributes.fixed +++ b/tests/ui/allow_attributes.fixed @@ -10,7 +10,7 @@ use proc_macros::{external, with_span}; // Using clippy::needless_borrow just as a placeholder, it isn't relevant. // Should lint -#[expect(dead_code)] +#[expect(dead_code)] //~ allow_attributes struct T1; struct T2; // Should not lint @@ -19,7 +19,7 @@ struct T3; #[warn(clippy::needless_borrow)] // Should not lint struct T4; // `panic = "unwind"` should always be true -#[cfg_attr(panic = "unwind", expect(dead_code))] +#[cfg_attr(panic = "unwind", expect(dead_code))] //~ allow_attributes struct CfgT; #[allow(clippy::allow_attributes, unused)] diff --git a/tests/ui/allow_attributes.rs b/tests/ui/allow_attributes.rs index c7daa7abd9d4..becd49a1e433 100644 --- a/tests/ui/allow_attributes.rs +++ b/tests/ui/allow_attributes.rs @@ -10,7 +10,7 @@ use proc_macros::{external, with_span}; // Using clippy::needless_borrow just as a placeholder, it isn't relevant. // Should lint -#[allow(dead_code)] +#[allow(dead_code)] //~ allow_attributes struct T1; struct T2; // Should not lint @@ -19,7 +19,7 @@ struct T3; #[warn(clippy::needless_borrow)] // Should not lint struct T4; // `panic = "unwind"` should always be true -#[cfg_attr(panic = "unwind", allow(dead_code))] +#[cfg_attr(panic = "unwind", allow(dead_code))] //~ allow_attributes struct CfgT; #[allow(clippy::allow_attributes, unused)] diff --git a/tests/ui/allow_attributes_without_reason.rs b/tests/ui/allow_attributes_without_reason.rs index 663c2eb2c379..9c1bdca6cb8d 100644 --- a/tests/ui/allow_attributes_without_reason.rs +++ b/tests/ui/allow_attributes_without_reason.rs @@ -2,14 +2,15 @@ #![feature(lint_reasons)] #![deny(clippy::allow_attributes_without_reason)] #![allow(unfulfilled_lint_expectations)] +//~^ allow_attributes_without_reason extern crate proc_macros; use proc_macros::{external, with_span}; // These should trigger the lint -#[allow(dead_code)] -#[allow(dead_code, deprecated)] -#[expect(dead_code)] +#[allow(dead_code)] //~ allow_attributes_without_reason +#[allow(dead_code, deprecated)] //~ allow_attributes_without_reason +#[expect(dead_code)] //~ allow_attributes_without_reason // These should be fine #[allow(dead_code, reason = "This should be allowed")] #[warn(dyn_drop, reason = "Warnings can also have reasons")] diff --git a/tests/ui/allow_attributes_without_reason.stderr b/tests/ui/allow_attributes_without_reason.stderr index 96f747d0026d..bc429d77c1ae 100644 --- a/tests/ui/allow_attributes_without_reason.stderr +++ b/tests/ui/allow_attributes_without_reason.stderr @@ -12,7 +12,7 @@ LL | #![deny(clippy::allow_attributes_without_reason)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `allow` attribute without specifying a reason - --> $DIR/allow_attributes_without_reason.rs:10:1 + --> $DIR/allow_attributes_without_reason.rs:11:1 | LL | #[allow(dead_code)] | ^^^^^^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | #[allow(dead_code)] = help: try adding a reason at the end with `, reason = ".."` error: `allow` attribute without specifying a reason - --> $DIR/allow_attributes_without_reason.rs:11:1 + --> $DIR/allow_attributes_without_reason.rs:12:1 | LL | #[allow(dead_code, deprecated)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | #[allow(dead_code, deprecated)] = help: try adding a reason at the end with `, reason = ".."` error: `expect` attribute without specifying a reason - --> $DIR/allow_attributes_without_reason.rs:12:1 + --> $DIR/allow_attributes_without_reason.rs:13:1 | LL | #[expect(dead_code)] | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/almost_complete_range.fixed b/tests/ui/almost_complete_range.fixed index 21caeb153e77..146a2c8b9b35 100644 --- a/tests/ui/almost_complete_range.fixed +++ b/tests/ui/almost_complete_range.fixed @@ -15,31 +15,31 @@ use proc_macros::{external, inline_macros}; fn main() { #[rustfmt::skip] { - let _ = ('a') ..='z'; - let _ = 'A' ..= ('Z'); - let _ = ((('0'))) ..= ('9'); + let _ = ('a') ..='z'; //~ almost_complete_range + let _ = 'A' ..= ('Z'); //~ almost_complete_range + let _ = ((('0'))) ..= ('9'); //~ almost_complete_range } let _ = 'b'..'z'; let _ = 'B'..'Z'; let _ = '1'..'9'; - let _ = (b'a')..=(b'z'); - let _ = b'A'..=b'Z'; - let _ = b'0'..=b'9'; + let _ = (b'a')..=(b'z'); //~ almost_complete_range + let _ = b'A'..=b'Z'; //~ almost_complete_range + let _ = b'0'..=b'9'; //~ almost_complete_range let _ = b'b'..b'z'; let _ = b'B'..b'Z'; let _ = b'1'..b'9'; - let _ = inline!('a')..='z'; - let _ = inline!('A')..='Z'; - let _ = inline!('0')..='9'; + let _ = inline!('a')..='z'; //~ almost_complete_range + let _ = inline!('A')..='Z'; //~ almost_complete_range + let _ = inline!('0')..='9'; //~ almost_complete_range let _ = match 0u8 { - b'a'..=b'z' if true => 1, - b'A'..=b'Z' if true => 2, - b'0'..=b'9' if true => 3, + b'a'..=b'z' if true => 1, //~ almost_complete_range + b'A'..=b'Z' if true => 2, //~ almost_complete_range + b'0'..=b'9' if true => 3, //~ almost_complete_range b'b'..b'z' => 4, b'B'..b'Z' => 5, b'1'..b'9' => 6, @@ -47,9 +47,9 @@ fn main() { }; let _ = match 'x' { - 'a'..='z' if true => 1, - 'A'..='Z' if true => 2, - '0'..='9' if true => 3, + 'a'..='z' if true => 1, //~ almost_complete_range + 'A'..='Z' if true => 2, //~ almost_complete_range + '0'..='9' if true => 3, //~ almost_complete_range 'b'..'z' => 4, 'B'..'Z' => 5, '1'..'9' => 6, @@ -62,31 +62,31 @@ fn main() { let _ = '0'..'9'; ); inline!( - let _ = 'a'..='z'; - let _ = 'A'..='Z'; - let _ = '0'..='9'; + let _ = 'a'..='z'; //~ almost_complete_range + let _ = 'A'..='Z'; //~ almost_complete_range + let _ = '0'..='9'; //~ almost_complete_range ); } #[clippy::msrv = "1.25"] fn _under_msrv() { let _ = match 'a' { - 'a'...'z' => 1, - 'A'...'Z' => 2, - '0'...'9' => 3, + 'a'...'z' => 1, //~ almost_complete_range + 'A'...'Z' => 2, //~ almost_complete_range + '0'...'9' => 3, //~ almost_complete_range _ => 4, }; } #[clippy::msrv = "1.26"] fn _meets_msrv() { - let _ = 'a'..='z'; - let _ = 'A'..='Z'; - let _ = '0'..='9'; + let _ = 'a'..='z'; //~ almost_complete_range + let _ = 'A'..='Z'; //~ almost_complete_range + let _ = '0'..='9'; //~ almost_complete_range let _ = match 'a' { - 'a'..='z' => 1, - 'A'..='Z' => 1, - '0'..='9' => 3, + 'a'..='z' => 1, //~ almost_complete_range + 'A'..='Z' => 1, //~ almost_complete_range + '0'..='9' => 3, //~ almost_complete_range _ => 4, }; } diff --git a/tests/ui/almost_complete_range.rs b/tests/ui/almost_complete_range.rs index 556110a5c8aa..435e80cceb28 100644 --- a/tests/ui/almost_complete_range.rs +++ b/tests/ui/almost_complete_range.rs @@ -15,31 +15,31 @@ use proc_macros::{external, inline_macros}; fn main() { #[rustfmt::skip] { - let _ = ('a') ..'z'; - let _ = 'A' .. ('Z'); - let _ = ((('0'))) .. ('9'); + let _ = ('a') ..'z'; //~ almost_complete_range + let _ = 'A' .. ('Z'); //~ almost_complete_range + let _ = ((('0'))) .. ('9'); //~ almost_complete_range } let _ = 'b'..'z'; let _ = 'B'..'Z'; let _ = '1'..'9'; - let _ = (b'a')..(b'z'); - let _ = b'A'..b'Z'; - let _ = b'0'..b'9'; + let _ = (b'a')..(b'z'); //~ almost_complete_range + let _ = b'A'..b'Z'; //~ almost_complete_range + let _ = b'0'..b'9'; //~ almost_complete_range let _ = b'b'..b'z'; let _ = b'B'..b'Z'; let _ = b'1'..b'9'; - let _ = inline!('a')..'z'; - let _ = inline!('A')..'Z'; - let _ = inline!('0')..'9'; + let _ = inline!('a')..'z'; //~ almost_complete_range + let _ = inline!('A')..'Z'; //~ almost_complete_range + let _ = inline!('0')..'9'; //~ almost_complete_range let _ = match 0u8 { - b'a'..b'z' if true => 1, - b'A'..b'Z' if true => 2, - b'0'..b'9' if true => 3, + b'a'..b'z' if true => 1, //~ almost_complete_range + b'A'..b'Z' if true => 2, //~ almost_complete_range + b'0'..b'9' if true => 3, //~ almost_complete_range b'b'..b'z' => 4, b'B'..b'Z' => 5, b'1'..b'9' => 6, @@ -47,9 +47,9 @@ fn main() { }; let _ = match 'x' { - 'a'..'z' if true => 1, - 'A'..'Z' if true => 2, - '0'..'9' if true => 3, + 'a'..'z' if true => 1, //~ almost_complete_range + 'A'..'Z' if true => 2, //~ almost_complete_range + '0'..'9' if true => 3, //~ almost_complete_range 'b'..'z' => 4, 'B'..'Z' => 5, '1'..'9' => 6, @@ -62,31 +62,31 @@ fn main() { let _ = '0'..'9'; ); inline!( - let _ = 'a'..'z'; - let _ = 'A'..'Z'; - let _ = '0'..'9'; + let _ = 'a'..'z'; //~ almost_complete_range + let _ = 'A'..'Z'; //~ almost_complete_range + let _ = '0'..'9'; //~ almost_complete_range ); } #[clippy::msrv = "1.25"] fn _under_msrv() { let _ = match 'a' { - 'a'..'z' => 1, - 'A'..'Z' => 2, - '0'..'9' => 3, + 'a'..'z' => 1, //~ almost_complete_range + 'A'..'Z' => 2, //~ almost_complete_range + '0'..'9' => 3, //~ almost_complete_range _ => 4, }; } #[clippy::msrv = "1.26"] fn _meets_msrv() { - let _ = 'a'..'z'; - let _ = 'A'..'Z'; - let _ = '0'..'9'; + let _ = 'a'..'z'; //~ almost_complete_range + let _ = 'A'..'Z'; //~ almost_complete_range + let _ = '0'..'9'; //~ almost_complete_range let _ = match 'a' { - 'a'..'z' => 1, - 'A'..'Z' => 1, - '0'..'9' => 3, + 'a'..'z' => 1, //~ almost_complete_range + 'A'..'Z' => 1, //~ almost_complete_range + '0'..'9' => 3, //~ almost_complete_range _ => 4, }; } diff --git a/tests/ui/arithmetic_side_effects.rs b/tests/ui/arithmetic_side_effects.rs index b454c29aef4d..52feb587bcdf 100644 --- a/tests/ui/arithmetic_side_effects.rs +++ b/tests/ui/arithmetic_side_effects.rs @@ -301,115 +301,115 @@ pub fn unknown_ops_or_runtime_ops_that_can_overflow() { let mut _custom = Custom; // Assign - _n += 1; - _n += &1; - _n -= 1; - _n -= &1; - _n /= 0; - _n /= &0; - _n %= 0; - _n %= &0; - _n *= 2; - _n *= &2; - _n += -1; - _n += &-1; - _n -= -1; - _n -= &-1; - _n /= -0; - _n /= &-0; - _n %= -0; - _n %= &-0; - _n *= -2; - _n *= &-2; - _custom += Custom; - _custom += &Custom; - _custom -= Custom; - _custom -= &Custom; - _custom /= Custom; - _custom /= &Custom; - _custom %= Custom; - _custom %= &Custom; - _custom *= Custom; - _custom *= &Custom; - _custom >>= Custom; - _custom >>= &Custom; - _custom <<= Custom; - _custom <<= &Custom; - _custom += -Custom; - _custom += &-Custom; - _custom -= -Custom; - _custom -= &-Custom; - _custom /= -Custom; - _custom /= &-Custom; - _custom %= -Custom; - _custom %= &-Custom; - _custom *= -Custom; - _custom *= &-Custom; - _custom >>= -Custom; - _custom >>= &-Custom; - _custom <<= -Custom; - _custom <<= &-Custom; + _n += 1; //~ arithmetic_side_effects + _n += &1; //~ arithmetic_side_effects + _n -= 1; //~ arithmetic_side_effects + _n -= &1; //~ arithmetic_side_effects + _n /= 0; //~ arithmetic_side_effects + _n /= &0; //~ arithmetic_side_effects + _n %= 0; //~ arithmetic_side_effects + _n %= &0; //~ arithmetic_side_effects + _n *= 2; //~ arithmetic_side_effects + _n *= &2; //~ arithmetic_side_effects + _n += -1; //~ arithmetic_side_effects + _n += &-1; //~ arithmetic_side_effects + _n -= -1; //~ arithmetic_side_effects + _n -= &-1; //~ arithmetic_side_effects + _n /= -0; //~ arithmetic_side_effects + _n /= &-0; //~ arithmetic_side_effects + _n %= -0; //~ arithmetic_side_effects + _n %= &-0; //~ arithmetic_side_effects + _n *= -2; //~ arithmetic_side_effects + _n *= &-2; //~ arithmetic_side_effects + _custom += Custom; //~ arithmetic_side_effects + _custom += &Custom; //~ arithmetic_side_effects + _custom -= Custom; //~ arithmetic_side_effects + _custom -= &Custom; //~ arithmetic_side_effects + _custom /= Custom; //~ arithmetic_side_effects + _custom /= &Custom; //~ arithmetic_side_effects + _custom %= Custom; //~ arithmetic_side_effects + _custom %= &Custom; //~ arithmetic_side_effects + _custom *= Custom; //~ arithmetic_side_effects + _custom *= &Custom; //~ arithmetic_side_effects + _custom >>= Custom; //~ arithmetic_side_effects + _custom >>= &Custom; //~ arithmetic_side_effects + _custom <<= Custom; //~ arithmetic_side_effects + _custom <<= &Custom; //~ arithmetic_side_effects + _custom += -Custom; //~ arithmetic_side_effects + _custom += &-Custom; //~ arithmetic_side_effects + _custom -= -Custom; //~ arithmetic_side_effects + _custom -= &-Custom; //~ arithmetic_side_effects + _custom /= -Custom; //~ arithmetic_side_effects + _custom /= &-Custom; //~ arithmetic_side_effects + _custom %= -Custom; //~ arithmetic_side_effects + _custom %= &-Custom; //~ arithmetic_side_effects + _custom *= -Custom; //~ arithmetic_side_effects + _custom *= &-Custom; //~ arithmetic_side_effects + _custom >>= -Custom; //~ arithmetic_side_effects + _custom >>= &-Custom; //~ arithmetic_side_effects + _custom <<= -Custom; //~ arithmetic_side_effects + _custom <<= &-Custom; //~ arithmetic_side_effects // Binary - _n = _n + 1; - _n = _n + &1; - _n = 1 + _n; - _n = &1 + _n; - _n = _n - 1; - _n = _n - &1; - _n = 1 - _n; - _n = &1 - _n; - _n = _n / 0; - _n = _n / &0; - _n = _n % 0; - _n = _n % &0; - _n = _n * 2; - _n = _n * &2; - _n = 2 * _n; - _n = &2 * _n; - _n = 23 + &85; - _n = &23 + 85; - _n = &23 + &85; - _custom = _custom + _custom; - _custom = _custom + &_custom; - _custom = Custom + _custom; - _custom = &Custom + _custom; - _custom = _custom - Custom; - _custom = _custom - &Custom; - _custom = Custom - _custom; - _custom = &Custom - _custom; - _custom = _custom / Custom; - _custom = _custom / &Custom; - _custom = _custom % Custom; - _custom = _custom % &Custom; - _custom = _custom * Custom; - _custom = _custom * &Custom; - _custom = Custom * _custom; - _custom = &Custom * _custom; - _custom = Custom + &Custom; - _custom = &Custom + Custom; - _custom = &Custom + &Custom; - _custom = _custom >> _custom; - _custom = _custom >> &_custom; - _custom = Custom << _custom; - _custom = &Custom << _custom; + _n = _n + 1; //~ arithmetic_side_effects + _n = _n + &1; //~ arithmetic_side_effects + _n = 1 + _n; //~ arithmetic_side_effects + _n = &1 + _n; //~ arithmetic_side_effects + _n = _n - 1; //~ arithmetic_side_effects + _n = _n - &1; //~ arithmetic_side_effects + _n = 1 - _n; //~ arithmetic_side_effects + _n = &1 - _n; //~ arithmetic_side_effects + _n = _n / 0; //~ arithmetic_side_effects + _n = _n / &0; //~ arithmetic_side_effects + _n = _n % 0; //~ arithmetic_side_effects + _n = _n % &0; //~ arithmetic_side_effects + _n = _n * 2; //~ arithmetic_side_effects + _n = _n * &2; //~ arithmetic_side_effects + _n = 2 * _n; //~ arithmetic_side_effects + _n = &2 * _n; //~ arithmetic_side_effects + _n = 23 + &85; //~ arithmetic_side_effects + _n = &23 + 85; //~ arithmetic_side_effects + _n = &23 + &85; //~ arithmetic_side_effects + _custom = _custom + _custom; //~ arithmetic_side_effects + _custom = _custom + &_custom; //~ arithmetic_side_effects + _custom = Custom + _custom; //~ arithmetic_side_effects + _custom = &Custom + _custom; //~ arithmetic_side_effects + _custom = _custom - Custom; //~ arithmetic_side_effects + _custom = _custom - &Custom; //~ arithmetic_side_effects + _custom = Custom - _custom; //~ arithmetic_side_effects + _custom = &Custom - _custom; //~ arithmetic_side_effects + _custom = _custom / Custom; //~ arithmetic_side_effects + _custom = _custom / &Custom; //~ arithmetic_side_effects + _custom = _custom % Custom; //~ arithmetic_side_effects + _custom = _custom % &Custom; //~ arithmetic_side_effects + _custom = _custom * Custom; //~ arithmetic_side_effects + _custom = _custom * &Custom; //~ arithmetic_side_effects + _custom = Custom * _custom; //~ arithmetic_side_effects + _custom = &Custom * _custom; //~ arithmetic_side_effects + _custom = Custom + &Custom; //~ arithmetic_side_effects + _custom = &Custom + Custom; //~ arithmetic_side_effects + _custom = &Custom + &Custom; //~ arithmetic_side_effects + _custom = _custom >> _custom; //~ arithmetic_side_effects + _custom = _custom >> &_custom; //~ arithmetic_side_effects + _custom = Custom << _custom; //~ arithmetic_side_effects + _custom = &Custom << _custom; //~ arithmetic_side_effects // Method - _n.saturating_div(0); - _n.wrapping_div(0); - _n.wrapping_rem(0); - _n.wrapping_rem_euclid(0); + _n.saturating_div(0); //~ arithmetic_side_effects + _n.wrapping_div(0); //~ arithmetic_side_effects + _n.wrapping_rem(0); //~ arithmetic_side_effects + _n.wrapping_rem_euclid(0); //~ arithmetic_side_effects - _n.saturating_div(_n); - _n.wrapping_div(_n); - _n.wrapping_rem(_n); - _n.wrapping_rem_euclid(_n); + _n.saturating_div(_n); //~ arithmetic_side_effects + _n.wrapping_div(_n); //~ arithmetic_side_effects + _n.wrapping_rem(_n); //~ arithmetic_side_effects + _n.wrapping_rem_euclid(_n); //~ arithmetic_side_effects // Unary - _n = -_n; - _n = -&_n; - _custom = -_custom; - _custom = -&_custom; + _n = -_n; //~ arithmetic_side_effects + _n = -&_n; //~ arithmetic_side_effects + _custom = -_custom; //~ arithmetic_side_effects + _custom = -&_custom; //~ arithmetic_side_effects } // Copied and pasted from the `integer_arithmetic` lint for comparison. @@ -418,11 +418,11 @@ pub fn integer_arithmetic() { let mut var1 = 0i32; let mut var2 = -1i32; - 1 + i; - i * 2; - 1 % i / 2; - i - 2 + 2 - i; - -i; + 1 + i; //~ arithmetic_side_effects + i * 2; //~ arithmetic_side_effects + 1 % i / 2; //~ arithmetic_side_effects + i - 2 + 2 - i; //~ arithmetic_side_effects + -i; //~ arithmetic_side_effects i >> 1; i << 1; @@ -433,19 +433,19 @@ pub fn integer_arithmetic() { i | 1; i ^ 1; - i += 1; - i -= 1; - i *= 2; + i += 1; //~ arithmetic_side_effects + i -= 1; //~ arithmetic_side_effects + i *= 2; //~ arithmetic_side_effects i /= 2; - i /= 0; + i /= 0; //~ arithmetic_side_effects i /= -1; - i /= var1; - i /= var2; + i /= var1; //~ arithmetic_side_effects + i /= var2; //~ arithmetic_side_effects i %= 2; - i %= 0; + i %= 0; //~ arithmetic_side_effects i %= -1; - i %= var1; - i %= var2; + i %= var1; //~ arithmetic_side_effects + i %= var2; //~ arithmetic_side_effects i <<= 3; i >>= 2; @@ -455,7 +455,7 @@ pub fn integer_arithmetic() { } pub fn issue_10583(a: u16) -> u16 { - 10 / a + 10 / a //~ arithmetic_side_effects } pub fn issue_10767() { @@ -509,11 +509,11 @@ pub fn issue_11392() { pub fn issue_11393() { fn example_div(x: Wrapping, maybe_zero: Wrapping) -> Wrapping { - x / maybe_zero + x / maybe_zero //~ arithmetic_side_effects } fn example_rem(x: Wrapping, maybe_zero: Wrapping) -> Wrapping { - x % maybe_zero + x % maybe_zero //~ arithmetic_side_effects } let [x, maybe_zero] = [1, 0].map(Wrapping); diff --git a/tests/ui/as_conversions.rs b/tests/ui/as_conversions.rs index 8499c0ac5a0f..fba8913a2097 100644 --- a/tests/ui/as_conversions.rs +++ b/tests/ui/as_conversions.rs @@ -7,9 +7,11 @@ extern crate proc_macros; use proc_macros::{external, with_span}; fn main() { - let i = 0u32 as u64; + let i = 0u32 as u64; //~ as_conversions let j = &i as *const u64 as *mut u64; + //~^ as_conversions + //~| as_conversions external!(0u32 as u64); } diff --git a/tests/ui/as_underscore.fixed b/tests/ui/as_underscore.fixed index c7f26e64cce7..e09395b9303e 100644 --- a/tests/ui/as_underscore.fixed +++ b/tests/ui/as_underscore.fixed @@ -4,8 +4,8 @@ fn foo(_n: usize) {} fn main() { let n: u16 = 256; - foo(n as usize); + foo(n as usize); //~ as_underscore let n = 0_u128; - let _n: u8 = n as u8; + let _n: u8 = n as u8; //~ as_underscore } diff --git a/tests/ui/as_underscore.rs b/tests/ui/as_underscore.rs index 70f3b386631c..e54bdc150e90 100644 --- a/tests/ui/as_underscore.rs +++ b/tests/ui/as_underscore.rs @@ -4,8 +4,8 @@ fn foo(_n: usize) {} fn main() { let n: u16 = 256; - foo(n as _); + foo(n as _); //~ as_underscore let n = 0_u128; - let _n: u8 = n as _; + let _n: u8 = n as _; //~ as_underscore } diff --git a/tests/ui/assertions_on_result_states.fixed b/tests/ui/assertions_on_result_states.fixed index 14d9b8b99d5e..24acefc04cbf 100644 --- a/tests/ui/assertions_on_result_states.fixed +++ b/tests/ui/assertions_on_result_states.fixed @@ -21,7 +21,7 @@ fn main() { // test ok let r: Result = Ok(Foo); debug_assert!(r.is_ok()); - r.unwrap(); + r.unwrap(); //~ assertions_on_result_states // test ok with non-debug error type let r: Result = Ok(Foo); @@ -39,10 +39,11 @@ fn main() { fn get_ok() -> Result { Ok(Foo) } - get_ok().unwrap(); + get_ok().unwrap(); //~ assertions_on_result_states // test macro ok get_ok_macro!().unwrap(); + //~^ assertions_on_result_states // test ok that shouldn't be moved let r: Result = Ok(CopyFoo); @@ -55,13 +56,13 @@ fn main() { // test ok that is copied let r: Result = Ok(CopyFoo); - r.unwrap(); + r.unwrap(); //~ assertions_on_result_states r.unwrap(); // test reference to ok let r: Result = Ok(CopyFoo); fn test_ref_copy_ok(r: &Result) { - r.unwrap(); + r.unwrap(); //~ assertions_on_result_states } test_ref_copy_ok(&r); r.unwrap(); @@ -69,7 +70,7 @@ fn main() { // test err let r: Result = Err(Foo); debug_assert!(r.is_err()); - r.unwrap_err(); + r.unwrap_err(); //~ assertions_on_result_states // test err with non-debug value type let r: Result = Err(Foo); @@ -79,5 +80,5 @@ fn main() { #[allow(dead_code)] fn issue9450() { let res: Result = Ok(1); - res.unwrap_err(); + res.unwrap_err(); //~ assertions_on_result_states } diff --git a/tests/ui/assertions_on_result_states.rs b/tests/ui/assertions_on_result_states.rs index ac1911d87c93..f1008793816a 100644 --- a/tests/ui/assertions_on_result_states.rs +++ b/tests/ui/assertions_on_result_states.rs @@ -21,7 +21,7 @@ fn main() { // test ok let r: Result = Ok(Foo); debug_assert!(r.is_ok()); - assert!(r.is_ok()); + assert!(r.is_ok()); //~ assertions_on_result_states // test ok with non-debug error type let r: Result = Ok(Foo); @@ -39,10 +39,11 @@ fn main() { fn get_ok() -> Result { Ok(Foo) } - assert!(get_ok().is_ok()); + assert!(get_ok().is_ok()); //~ assertions_on_result_states // test macro ok assert!(get_ok_macro!().is_ok()); + //~^ assertions_on_result_states // test ok that shouldn't be moved let r: Result = Ok(CopyFoo); @@ -55,13 +56,13 @@ fn main() { // test ok that is copied let r: Result = Ok(CopyFoo); - assert!(r.is_ok()); + assert!(r.is_ok()); //~ assertions_on_result_states r.unwrap(); // test reference to ok let r: Result = Ok(CopyFoo); fn test_ref_copy_ok(r: &Result) { - assert!(r.is_ok()); + assert!(r.is_ok()); //~ assertions_on_result_states } test_ref_copy_ok(&r); r.unwrap(); @@ -69,7 +70,7 @@ fn main() { // test err let r: Result = Err(Foo); debug_assert!(r.is_err()); - assert!(r.is_err()); + assert!(r.is_err()); //~ assertions_on_result_states // test err with non-debug value type let r: Result = Err(Foo); @@ -79,5 +80,5 @@ fn main() { #[allow(dead_code)] fn issue9450() { let res: Result = Ok(1); - assert!(res.is_err()) + assert!(res.is_err()) //~ assertions_on_result_states } diff --git a/tests/ui/assertions_on_result_states.stderr b/tests/ui/assertions_on_result_states.stderr index 23af51cfe6fd..1b19e6a2387b 100644 --- a/tests/ui/assertions_on_result_states.stderr +++ b/tests/ui/assertions_on_result_states.stderr @@ -20,25 +20,25 @@ LL | assert!(get_ok_macro!().is_ok()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `get_ok_macro!().unwrap()` error: called `assert!` with `Result::is_ok` - --> $DIR/assertions_on_result_states.rs:58:5 + --> $DIR/assertions_on_result_states.rs:59:5 | LL | assert!(r.is_ok()); | ^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap()` error: called `assert!` with `Result::is_ok` - --> $DIR/assertions_on_result_states.rs:64:9 + --> $DIR/assertions_on_result_states.rs:65:9 | LL | assert!(r.is_ok()); | ^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap()` error: called `assert!` with `Result::is_err` - --> $DIR/assertions_on_result_states.rs:72:5 + --> $DIR/assertions_on_result_states.rs:73:5 | LL | assert!(r.is_err()); | ^^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap_err()` error: called `assert!` with `Result::is_err` - --> $DIR/assertions_on_result_states.rs:82:5 + --> $DIR/assertions_on_result_states.rs:83:5 | LL | assert!(res.is_err()) | ^^^^^^^^^^^^^^^^^^^^^ help: replace with: `res.unwrap_err();` diff --git a/tests/ui/assign_ops.fixed b/tests/ui/assign_ops.fixed index 2bd0807f4262..bfd74c56e3cc 100644 --- a/tests/ui/assign_ops.fixed +++ b/tests/ui/assign_ops.fixed @@ -4,26 +4,26 @@ use core::num::Wrapping; #[warn(clippy::assign_op_pattern)] fn main() { let mut a = 5; - a += 1; - a += 1; - a -= 1; - a *= 99; - a *= 42; - a /= 2; - a %= 5; - a &= 1; + a += 1; //~ assign_op_pattern + a += 1; //~ assign_op_pattern + a -= 1; //~ assign_op_pattern + a *= 99; //~ assign_op_pattern + a *= 42; //~ assign_op_pattern + a /= 2; //~ assign_op_pattern + a %= 5; //~ assign_op_pattern + a &= 1; //~ assign_op_pattern a = 1 - a; a = 5 / a; a = 42 % a; a = 6 << a; let mut s = String::new(); - s += "bla"; + s += "bla"; //~ assign_op_pattern // Issue #9180 let mut a = Wrapping(0u32); - a += Wrapping(1u32); + a += Wrapping(1u32); //~ assign_op_pattern let mut v = vec![0u32, 1u32]; - v[0] += v[1]; + v[0] += v[1]; //~ assign_op_pattern let mut v = vec![Wrapping(0u32), Wrapping(1u32)]; v[0] = v[0] + v[1]; let _ = || v[0] = v[0] + v[1]; diff --git a/tests/ui/assign_ops.rs b/tests/ui/assign_ops.rs index be3491a44c7e..43f14a63bd13 100644 --- a/tests/ui/assign_ops.rs +++ b/tests/ui/assign_ops.rs @@ -4,26 +4,26 @@ use core::num::Wrapping; #[warn(clippy::assign_op_pattern)] fn main() { let mut a = 5; - a = a + 1; - a = 1 + a; - a = a - 1; - a = a * 99; - a = 42 * a; - a = a / 2; - a = a % 5; - a = a & 1; + a = a + 1; //~ assign_op_pattern + a = 1 + a; //~ assign_op_pattern + a = a - 1; //~ assign_op_pattern + a = a * 99; //~ assign_op_pattern + a = 42 * a; //~ assign_op_pattern + a = a / 2; //~ assign_op_pattern + a = a % 5; //~ assign_op_pattern + a = a & 1; //~ assign_op_pattern a = 1 - a; a = 5 / a; a = 42 % a; a = 6 << a; let mut s = String::new(); - s = s + "bla"; + s = s + "bla"; //~ assign_op_pattern // Issue #9180 let mut a = Wrapping(0u32); - a = a + Wrapping(1u32); + a = a + Wrapping(1u32); //~ assign_op_pattern let mut v = vec![0u32, 1u32]; - v[0] = v[0] + v[1]; + v[0] = v[0] + v[1]; //~ assign_op_pattern let mut v = vec![Wrapping(0u32), Wrapping(1u32)]; v[0] = v[0] + v[1]; let _ = || v[0] = v[0] + v[1]; diff --git a/tests/ui/async_yields_async.fixed b/tests/ui/async_yields_async.fixed index cfad78138053..cc95e794100e 100644 --- a/tests/ui/async_yields_async.fixed +++ b/tests/ui/async_yields_async.fixed @@ -36,31 +36,33 @@ fn main() { 3 }; let _h = async { + //~v async_yields_async async { 3 }.await }; let _i = async { - CustomFutureType.await + CustomFutureType.await //~ async_yields_async }; let _i = async || { 3 }; let _j = async || { + //~v async_yields_async async { 3 }.await }; let _k = async || { - CustomFutureType.await + CustomFutureType.await //~ async_yields_async }; - let _l = async || CustomFutureType.await; + let _l = async || CustomFutureType.await; //~ async_yields_async let _m = async || { println!("I'm bored"); // Some more stuff // Finally something to await - CustomFutureType.await + CustomFutureType.await //~ async_yields_async }; let _n = async || custom_future_type_ctor(); let _o = async || f(); diff --git a/tests/ui/async_yields_async.rs b/tests/ui/async_yields_async.rs index 7bc26647943f..de8362db23c2 100644 --- a/tests/ui/async_yields_async.rs +++ b/tests/ui/async_yields_async.rs @@ -36,31 +36,33 @@ fn main() { 3 }; let _h = async { + //~v async_yields_async async { 3 } }; let _i = async { - CustomFutureType + CustomFutureType //~ async_yields_async }; let _i = async || { 3 }; let _j = async || { + //~v async_yields_async async { 3 } }; let _k = async || { - CustomFutureType + CustomFutureType //~ async_yields_async }; - let _l = async || CustomFutureType; + let _l = async || CustomFutureType; //~ async_yields_async let _m = async || { println!("I'm bored"); // Some more stuff // Finally something to await - CustomFutureType + CustomFutureType //~ async_yields_async }; let _n = async || custom_future_type_ctor(); let _o = async || f(); diff --git a/tests/ui/async_yields_async.stderr b/tests/ui/async_yields_async.stderr index c29e3c734b75..36103c86b3b0 100644 --- a/tests/ui/async_yields_async.stderr +++ b/tests/ui/async_yields_async.stderr @@ -1,8 +1,9 @@ error: an async construct yields a type which is itself awaitable - --> $DIR/async_yields_async.rs:39:9 + --> $DIR/async_yields_async.rs:40:9 | LL | let _h = async { | _____________________- +LL | | LL | |/ async { LL | || 3 LL | || } @@ -20,7 +21,7 @@ LL + }.await | error: an async construct yields a type which is itself awaitable - --> $DIR/async_yields_async.rs:44:9 + --> $DIR/async_yields_async.rs:45:9 | LL | let _i = async { | ____________________- @@ -33,10 +34,11 @@ LL | | }; | |_____- outer async construct error: an async construct yields a type which is itself awaitable - --> $DIR/async_yields_async.rs:50:9 + --> $DIR/async_yields_async.rs:52:9 | LL | let _j = async || { | ________________________- +LL | | LL | |/ async { LL | || 3 LL | || } @@ -52,7 +54,7 @@ LL + }.await | error: an async construct yields a type which is itself awaitable - --> $DIR/async_yields_async.rs:55:9 + --> $DIR/async_yields_async.rs:57:9 | LL | let _k = async || { | _______________________- @@ -65,7 +67,7 @@ LL | | }; | |_____- outer async construct error: an async construct yields a type which is itself awaitable - --> $DIR/async_yields_async.rs:57:23 + --> $DIR/async_yields_async.rs:59:23 | LL | let _l = async || CustomFutureType; | ^^^^^^^^^^^^^^^^ @@ -75,7 +77,7 @@ LL | let _l = async || CustomFutureType; | help: consider awaiting this value: `CustomFutureType.await` error: an async construct yields a type which is itself awaitable - --> $DIR/async_yields_async.rs:63:9 + --> $DIR/async_yields_async.rs:65:9 | LL | let _m = async || { | _______________________- diff --git a/tests/ui/bind_instead_of_map.fixed b/tests/ui/bind_instead_of_map.fixed index 910cec2f203d..f74b23e58788 100644 --- a/tests/ui/bind_instead_of_map.fixed +++ b/tests/ui/bind_instead_of_map.fixed @@ -5,14 +5,14 @@ pub fn main() { let x = Some(5); // the easiest cases - let _ = x; - let _ = x.map(|o| o + 1); + let _ = x; //~ bind_instead_of_map + let _ = x.map(|o| o + 1); //~ bind_instead_of_map // and an easy counter-example let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); // Different type let x: Result = Ok(1); - let _ = x; + let _ = x; //~ bind_instead_of_map } pub fn foo() -> Option { diff --git a/tests/ui/bind_instead_of_map.rs b/tests/ui/bind_instead_of_map.rs index 6d66f659ba78..c768d3ae49b1 100644 --- a/tests/ui/bind_instead_of_map.rs +++ b/tests/ui/bind_instead_of_map.rs @@ -5,14 +5,14 @@ pub fn main() { let x = Some(5); // the easiest cases - let _ = x.and_then(Some); - let _ = x.and_then(|o| Some(o + 1)); + let _ = x.and_then(Some); //~ bind_instead_of_map + let _ = x.and_then(|o| Some(o + 1)); //~ bind_instead_of_map // and an easy counter-example let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); // Different type let x: Result = Ok(1); - let _ = x.and_then(Ok); + let _ = x.and_then(Ok); //~ bind_instead_of_map } pub fn foo() -> Option { diff --git a/tests/ui/bind_instead_of_map_multipart.fixed b/tests/ui/bind_instead_of_map_multipart.fixed index 8c77039b3c01..480bd04e2306 100644 --- a/tests/ui/bind_instead_of_map_multipart.fixed +++ b/tests/ui/bind_instead_of_map_multipart.fixed @@ -3,12 +3,15 @@ pub fn main() { let _ = Some("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); + //~^ bind_instead_of_map let _ = Some("42").and_then(|s| if s.len() < 42 { None } else { Some(s.len()) }); let _ = Ok::<_, ()>("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); + //~^ bind_instead_of_map let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Err(()) } else { Ok(s.len()) }); let _ = Err::<(), _>("42").map_err(|s| if s.len() < 42 { s.len() + 20 } else { s.len() }); + //~^ bind_instead_of_map let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Ok(()) } else { Err(s.len()) }); hard_example(); @@ -16,6 +19,7 @@ pub fn main() { } fn hard_example() { + //~v bind_instead_of_map Some("42").map(|s| { if { if s == "43" { @@ -58,4 +62,5 @@ macro_rules! m { fn macro_example() { let _ = Some("").and_then(|s| if s.len() == 20 { m!() } else { Some(20) }); let _ = Some("").map(|s| if s.len() == 20 { m!() } else { Some(20) }); + //~^ bind_instead_of_map } diff --git a/tests/ui/bind_instead_of_map_multipart.rs b/tests/ui/bind_instead_of_map_multipart.rs index 44257f3a4698..db2efa879256 100644 --- a/tests/ui/bind_instead_of_map_multipart.rs +++ b/tests/ui/bind_instead_of_map_multipart.rs @@ -3,12 +3,15 @@ pub fn main() { let _ = Some("42").and_then(|s| if s.len() < 42 { Some(0) } else { Some(s.len()) }); + //~^ bind_instead_of_map let _ = Some("42").and_then(|s| if s.len() < 42 { None } else { Some(s.len()) }); let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Ok(0) } else { Ok(s.len()) }); + //~^ bind_instead_of_map let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Err(()) } else { Ok(s.len()) }); let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Err(s.len() + 20) } else { Err(s.len()) }); + //~^ bind_instead_of_map let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Ok(()) } else { Err(s.len()) }); hard_example(); @@ -16,6 +19,7 @@ pub fn main() { } fn hard_example() { + //~v bind_instead_of_map Some("42").and_then(|s| { if { if s == "43" { @@ -58,4 +62,5 @@ macro_rules! m { fn macro_example() { let _ = Some("").and_then(|s| if s.len() == 20 { m!() } else { Some(20) }); let _ = Some("").and_then(|s| if s.len() == 20 { Some(m!()) } else { Some(Some(20)) }); + //~^ bind_instead_of_map } diff --git a/tests/ui/bind_instead_of_map_multipart.stderr b/tests/ui/bind_instead_of_map_multipart.stderr index 63f25f26f240..2b8761e12abb 100644 --- a/tests/ui/bind_instead_of_map_multipart.stderr +++ b/tests/ui/bind_instead_of_map_multipart.stderr @@ -15,7 +15,7 @@ LL | let _ = Some("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); | ~~~ ~ ~~~~~~~ error: using `Result.and_then(|x| Ok(y))`, which is more succinctly expressed as `map(|x| y)` - --> $DIR/bind_instead_of_map_multipart.rs:8:13 + --> $DIR/bind_instead_of_map_multipart.rs:9:13 | LL | let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Ok(0) } else { Ok(s.len()) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | let _ = Ok::<_, ()>("42").map(|s| if s.len() < 42 { 0 } else { s.len() | ~~~ ~ ~~~~~~~ error: using `Result.or_else(|x| Err(y))`, which is more succinctly expressed as `map_err(|x| y)` - --> $DIR/bind_instead_of_map_multipart.rs:11:13 + --> $DIR/bind_instead_of_map_multipart.rs:13:13 | LL | let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Err(s.len() + 20) } else { Err(s.len()) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | let _ = Err::<(), _>("42").map_err(|s| if s.len() < 42 { s.len() + 20 } | ~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~ error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` - --> $DIR/bind_instead_of_map_multipart.rs:19:5 + --> $DIR/bind_instead_of_map_multipart.rs:23:5 | LL | / Some("42").and_then(|s| { LL | | if { @@ -77,7 +77,7 @@ LL ~ _ => 1, | error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` - --> $DIR/bind_instead_of_map_multipart.rs:60:13 + --> $DIR/bind_instead_of_map_multipart.rs:64:13 | LL | let _ = Some("").and_then(|s| if s.len() == 20 { Some(m!()) } else { Some(Some(20)) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/blocks_in_conditions.fixed b/tests/ui/blocks_in_conditions.fixed index caf29e23d545..dd54215e8174 100644 --- a/tests/ui/blocks_in_conditions.fixed +++ b/tests/ui/blocks_in_conditions.fixed @@ -40,7 +40,7 @@ fn condition_has_block_with_single_expression() -> i32 { fn condition_is_normal() -> i32 { let x = 3; - if x == 3 { 6 } else { 10 } + if x == 3 { 6 } else { 10 } //~ nonminimal_bool } fn condition_is_unsafe_block() { diff --git a/tests/ui/blocks_in_conditions.rs b/tests/ui/blocks_in_conditions.rs index e72daaa910d4..c464e09fc32e 100644 --- a/tests/ui/blocks_in_conditions.rs +++ b/tests/ui/blocks_in_conditions.rs @@ -40,7 +40,7 @@ fn condition_has_block_with_single_expression() -> i32 { fn condition_is_normal() -> i32 { let x = 3; - if true && x == 3 { 6 } else { 10 } + if true && x == 3 { 6 } else { 10 } //~ nonminimal_bool } fn condition_is_unsafe_block() { diff --git a/tests/ui/bool_assert_comparison.fixed b/tests/ui/bool_assert_comparison.fixed index 63b8e27e1c6c..f8c4409fef34 100644 --- a/tests/ui/bool_assert_comparison.fixed +++ b/tests/ui/bool_assert_comparison.fixed @@ -84,66 +84,78 @@ fn main() { let b = ImplNotTraitWithBool; assert_eq!("a".len(), 1); - assert!(!"a".is_empty()); - assert!("".is_empty()); - assert!("".is_empty()); + assert!(!"a".is_empty()); //~ bool_assert_comparison + assert!("".is_empty()); //~ bool_assert_comparison + assert!("".is_empty()); //~ bool_assert_comparison assert_eq!(a!(), b!()); assert_eq!(a!(), "".is_empty()); assert_eq!("".is_empty(), b!()); assert_eq!(a, true); - assert!(b); + assert!(b); //~ bool_assert_comparison assert_ne!("a".len(), 1); - assert!("a".is_empty()); - assert!(!"".is_empty()); - assert!(!"".is_empty()); + assert!("a".is_empty()); //~ bool_assert_comparison + assert!(!"".is_empty()); //~ bool_assert_comparison + assert!(!"".is_empty()); //~ bool_assert_comparison assert_ne!(a!(), b!()); assert_ne!(a!(), "".is_empty()); assert_ne!("".is_empty(), b!()); assert_ne!(a, true); - assert!(!b); + assert!(!b); //~ bool_assert_comparison debug_assert_eq!("a".len(), 1); debug_assert!(!"a".is_empty()); + //~^ bool_assert_comparison debug_assert!("".is_empty()); + //~^ bool_assert_comparison debug_assert!("".is_empty()); + //~^ bool_assert_comparison debug_assert_eq!(a!(), b!()); debug_assert_eq!(a!(), "".is_empty()); debug_assert_eq!("".is_empty(), b!()); debug_assert_eq!(a, true); - debug_assert!(b); + debug_assert!(b); //~ bool_assert_comparison debug_assert_ne!("a".len(), 1); debug_assert!("a".is_empty()); + //~^ bool_assert_comparison debug_assert!(!"".is_empty()); + //~^ bool_assert_comparison debug_assert!(!"".is_empty()); + //~^ bool_assert_comparison debug_assert_ne!(a!(), b!()); debug_assert_ne!(a!(), "".is_empty()); debug_assert_ne!("".is_empty(), b!()); debug_assert_ne!(a, true); - debug_assert!(!b); + debug_assert!(!b); //~ bool_assert_comparison // assert with error messages assert_eq!("a".len(), 1, "tadam {}", 1); assert_eq!("a".len(), 1, "tadam {}", true); assert!(!"a".is_empty(), "tadam {}", 1); + //~^ bool_assert_comparison assert!(!"a".is_empty(), "tadam {}", true); + //~^ bool_assert_comparison assert!(!"a".is_empty(), "tadam {}", true); + //~^ bool_assert_comparison assert_eq!(a, true, "tadam {}", false); debug_assert_eq!("a".len(), 1, "tadam {}", 1); debug_assert_eq!("a".len(), 1, "tadam {}", true); debug_assert!(!"a".is_empty(), "tadam {}", 1); + //~^ bool_assert_comparison debug_assert!(!"a".is_empty(), "tadam {}", true); + //~^ bool_assert_comparison debug_assert!(!"a".is_empty(), "tadam {}", true); + //~^ bool_assert_comparison debug_assert_eq!(a, true, "tadam {}", false); - assert!(a!()); - assert!(b!()); + assert!(a!()); //~ bool_assert_comparison + assert!(b!()); //~ bool_assert_comparison use debug_assert_eq as renamed; renamed!(a, true); - debug_assert!(b); + debug_assert!(b); //~ bool_assert_comparison let non_copy = NonCopy; assert_eq!(non_copy, true); @@ -157,13 +169,19 @@ fn main() { } in_macro!(a); - assert!("".is_empty()); - assert!("".is_empty()); + assert!("".is_empty()); //~ bool_assert_comparison + assert!("".is_empty()); //~ bool_assert_comparison assert!(!"requires negation".is_empty()); + //~^ bool_assert_comparison assert!(!"requires negation".is_empty()); + //~^ bool_assert_comparison debug_assert!("".is_empty()); + //~^ bool_assert_comparison debug_assert!("".is_empty()); + //~^ bool_assert_comparison debug_assert!(!"requires negation".is_empty()); + //~^ bool_assert_comparison debug_assert!(!"requires negation".is_empty()); + //~^ bool_assert_comparison } diff --git a/tests/ui/bool_assert_comparison.rs b/tests/ui/bool_assert_comparison.rs index 58f81fedb795..777bba47de54 100644 --- a/tests/ui/bool_assert_comparison.rs +++ b/tests/ui/bool_assert_comparison.rs @@ -84,66 +84,78 @@ fn main() { let b = ImplNotTraitWithBool; assert_eq!("a".len(), 1); - assert_eq!("a".is_empty(), false); - assert_eq!("".is_empty(), true); - assert_eq!(true, "".is_empty()); + assert_eq!("a".is_empty(), false); //~ bool_assert_comparison + assert_eq!("".is_empty(), true); //~ bool_assert_comparison + assert_eq!(true, "".is_empty()); //~ bool_assert_comparison assert_eq!(a!(), b!()); assert_eq!(a!(), "".is_empty()); assert_eq!("".is_empty(), b!()); assert_eq!(a, true); - assert_eq!(b, true); + assert_eq!(b, true); //~ bool_assert_comparison assert_ne!("a".len(), 1); - assert_ne!("a".is_empty(), false); - assert_ne!("".is_empty(), true); - assert_ne!(true, "".is_empty()); + assert_ne!("a".is_empty(), false); //~ bool_assert_comparison + assert_ne!("".is_empty(), true); //~ bool_assert_comparison + assert_ne!(true, "".is_empty()); //~ bool_assert_comparison assert_ne!(a!(), b!()); assert_ne!(a!(), "".is_empty()); assert_ne!("".is_empty(), b!()); assert_ne!(a, true); - assert_ne!(b, true); + assert_ne!(b, true); //~ bool_assert_comparison debug_assert_eq!("a".len(), 1); debug_assert_eq!("a".is_empty(), false); + //~^ bool_assert_comparison debug_assert_eq!("".is_empty(), true); + //~^ bool_assert_comparison debug_assert_eq!(true, "".is_empty()); + //~^ bool_assert_comparison debug_assert_eq!(a!(), b!()); debug_assert_eq!(a!(), "".is_empty()); debug_assert_eq!("".is_empty(), b!()); debug_assert_eq!(a, true); - debug_assert_eq!(b, true); + debug_assert_eq!(b, true); //~ bool_assert_comparison debug_assert_ne!("a".len(), 1); debug_assert_ne!("a".is_empty(), false); + //~^ bool_assert_comparison debug_assert_ne!("".is_empty(), true); + //~^ bool_assert_comparison debug_assert_ne!(true, "".is_empty()); + //~^ bool_assert_comparison debug_assert_ne!(a!(), b!()); debug_assert_ne!(a!(), "".is_empty()); debug_assert_ne!("".is_empty(), b!()); debug_assert_ne!(a, true); - debug_assert_ne!(b, true); + debug_assert_ne!(b, true); //~ bool_assert_comparison // assert with error messages assert_eq!("a".len(), 1, "tadam {}", 1); assert_eq!("a".len(), 1, "tadam {}", true); assert_eq!("a".is_empty(), false, "tadam {}", 1); + //~^ bool_assert_comparison assert_eq!("a".is_empty(), false, "tadam {}", true); + //~^ bool_assert_comparison assert_eq!(false, "a".is_empty(), "tadam {}", true); + //~^ bool_assert_comparison assert_eq!(a, true, "tadam {}", false); debug_assert_eq!("a".len(), 1, "tadam {}", 1); debug_assert_eq!("a".len(), 1, "tadam {}", true); debug_assert_eq!("a".is_empty(), false, "tadam {}", 1); + //~^ bool_assert_comparison debug_assert_eq!("a".is_empty(), false, "tadam {}", true); + //~^ bool_assert_comparison debug_assert_eq!(false, "a".is_empty(), "tadam {}", true); + //~^ bool_assert_comparison debug_assert_eq!(a, true, "tadam {}", false); - assert_eq!(a!(), true); - assert_eq!(true, b!()); + assert_eq!(a!(), true); //~ bool_assert_comparison + assert_eq!(true, b!()); //~ bool_assert_comparison use debug_assert_eq as renamed; renamed!(a, true); - renamed!(b, true); + renamed!(b, true); //~ bool_assert_comparison let non_copy = NonCopy; assert_eq!(non_copy, true); @@ -157,13 +169,19 @@ fn main() { } in_macro!(a); - assert_eq!("".is_empty(), true); - assert_ne!("".is_empty(), false); + assert_eq!("".is_empty(), true); //~ bool_assert_comparison + assert_ne!("".is_empty(), false); //~ bool_assert_comparison assert_ne!("requires negation".is_empty(), true); + //~^ bool_assert_comparison assert_eq!("requires negation".is_empty(), false); + //~^ bool_assert_comparison debug_assert_eq!("".is_empty(), true); + //~^ bool_assert_comparison debug_assert_ne!("".is_empty(), false); + //~^ bool_assert_comparison debug_assert_ne!("requires negation".is_empty(), true); + //~^ bool_assert_comparison debug_assert_eq!("requires negation".is_empty(), false); + //~^ bool_assert_comparison } diff --git a/tests/ui/bool_assert_comparison.stderr b/tests/ui/bool_assert_comparison.stderr index 5969e4faa1aa..a4e16f617852 100644 --- a/tests/ui/bool_assert_comparison.stderr +++ b/tests/ui/bool_assert_comparison.stderr @@ -109,7 +109,7 @@ LL + debug_assert!(!"a".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:108:5 + --> $DIR/bool_assert_comparison.rs:109:5 | LL | debug_assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:109:5 + --> $DIR/bool_assert_comparison.rs:111:5 | LL | debug_assert_eq!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:114:5 + --> $DIR/bool_assert_comparison.rs:117:5 | LL | debug_assert_eq!(b, true); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + debug_assert!(b); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:117:5 + --> $DIR/bool_assert_comparison.rs:120:5 | LL | debug_assert_ne!("a".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + debug_assert!("a".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:118:5 + --> $DIR/bool_assert_comparison.rs:122:5 | LL | debug_assert_ne!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + debug_assert!(!"".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:119:5 + --> $DIR/bool_assert_comparison.rs:124:5 | LL | debug_assert_ne!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + debug_assert!(!"".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:124:5 + --> $DIR/bool_assert_comparison.rs:130:5 | LL | debug_assert_ne!(b, true); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL + debug_assert!(!b); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:129:5 + --> $DIR/bool_assert_comparison.rs:135:5 | LL | assert_eq!("a".is_empty(), false, "tadam {}", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -205,7 +205,7 @@ LL + assert!(!"a".is_empty(), "tadam {}", 1); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:130:5 + --> $DIR/bool_assert_comparison.rs:137:5 | LL | assert_eq!("a".is_empty(), false, "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL + assert!(!"a".is_empty(), "tadam {}", true); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:131:5 + --> $DIR/bool_assert_comparison.rs:139:5 | LL | assert_eq!(false, "a".is_empty(), "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -229,7 +229,7 @@ LL + assert!(!"a".is_empty(), "tadam {}", true); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:136:5 + --> $DIR/bool_assert_comparison.rs:145:5 | LL | debug_assert_eq!("a".is_empty(), false, "tadam {}", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -241,7 +241,7 @@ LL + debug_assert!(!"a".is_empty(), "tadam {}", 1); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:137:5 + --> $DIR/bool_assert_comparison.rs:147:5 | LL | debug_assert_eq!("a".is_empty(), false, "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -253,7 +253,7 @@ LL + debug_assert!(!"a".is_empty(), "tadam {}", true); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:138:5 + --> $DIR/bool_assert_comparison.rs:149:5 | LL | debug_assert_eq!(false, "a".is_empty(), "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -265,7 +265,7 @@ LL + debug_assert!(!"a".is_empty(), "tadam {}", true); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:141:5 + --> $DIR/bool_assert_comparison.rs:153:5 | LL | assert_eq!(a!(), true); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -277,7 +277,7 @@ LL + assert!(a!()); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:142:5 + --> $DIR/bool_assert_comparison.rs:154:5 | LL | assert_eq!(true, b!()); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -289,7 +289,7 @@ LL + assert!(b!()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:146:5 + --> $DIR/bool_assert_comparison.rs:158:5 | LL | renamed!(b, true); | ^^^^^^^^^^^^^^^^^ @@ -301,7 +301,7 @@ LL + debug_assert!(b); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:160:5 + --> $DIR/bool_assert_comparison.rs:172:5 | LL | assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -313,7 +313,7 @@ LL + assert!("".is_empty()); | error: used `assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:161:5 + --> $DIR/bool_assert_comparison.rs:173:5 | LL | assert_ne!("".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -325,7 +325,7 @@ LL + assert!("".is_empty()); | error: used `assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:162:5 + --> $DIR/bool_assert_comparison.rs:174:5 | LL | assert_ne!("requires negation".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -337,7 +337,7 @@ LL + assert!(!"requires negation".is_empty()); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:163:5 + --> $DIR/bool_assert_comparison.rs:176:5 | LL | assert_eq!("requires negation".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -349,7 +349,7 @@ LL + assert!(!"requires negation".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:165:5 + --> $DIR/bool_assert_comparison.rs:179:5 | LL | debug_assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -361,7 +361,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:166:5 + --> $DIR/bool_assert_comparison.rs:181:5 | LL | debug_assert_ne!("".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -373,7 +373,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:167:5 + --> $DIR/bool_assert_comparison.rs:183:5 | LL | debug_assert_ne!("requires negation".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -385,7 +385,7 @@ LL + debug_assert!(!"requires negation".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:168:5 + --> $DIR/bool_assert_comparison.rs:185:5 | LL | debug_assert_eq!("requires negation".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/bool_comparison.fixed b/tests/ui/bool_comparison.fixed index 54bdf7f5d70a..f14d3b932c07 100644 --- a/tests/ui/bool_comparison.fixed +++ b/tests/ui/bool_comparison.fixed @@ -4,72 +4,86 @@ fn main() { let x = true; + //~v bool_comparison if x { "yes" } else { "no" }; + //~v bool_comparison if !x { "yes" } else { "no" }; + //~v bool_comparison if x { "yes" } else { "no" }; + //~v bool_comparison if !x { "yes" } else { "no" }; + //~v bool_comparison if !x { "yes" } else { "no" }; + //~v bool_comparison if x { "yes" } else { "no" }; + //~v bool_comparison if !x { "yes" } else { "no" }; + //~v bool_comparison if x { "yes" } else { "no" }; + //~v bool_comparison if !x { "yes" } else { "no" }; + //~v bool_comparison if x { "yes" } else { "no" }; + //~v bool_comparison if x { "yes" } else { "no" }; + //~v bool_comparison if !x { "yes" } else { "no" }; let y = true; + //~v bool_comparison if !x & y { "yes" } else { "no" }; + //~v bool_comparison if x & !y { "yes" } else { @@ -118,13 +132,13 @@ fn issue4983() { let a = true; let b = false; - if a != b {}; - if a != b {}; + if a != b {}; //~ bool_comparison + if a != b {}; //~ bool_comparison if a == b {}; if !a == !b {}; - if b != a {}; - if b != a {}; + if b != a {}; //~ bool_comparison + if b != a {}; //~ bool_comparison if b == a {}; if !b == !a {}; } @@ -148,10 +162,10 @@ fn issue3973() { if cfg!(feature = "debugging") == true {} // lint, could be simplified - if !m!(func) {} - if !m!(func) {} - if m!(func) {} - if m!(func) {} + if !m!(func) {} //~ bool_comparison + if !m!(func) {} //~ bool_comparison + if m!(func) {} //~ bool_comparison + if m!(func) {} //~ bool_comparison // no lint with a variable let is_debug = false; @@ -168,9 +182,9 @@ fn issue3973() { #[allow(clippy::unnecessary_cast)] fn issue9907() { - let _ = (1 >= 2) as usize; - let _ = (!m!(func)) as usize; + let _ = (1 >= 2) as usize; //~ bool_comparison + let _ = (!m!(func)) as usize; //~ bool_comparison // This is not part of the issue, but an unexpected found when fixing the issue, // the provided span was inside of macro rather than the macro callsite. - let _ = ((1 < 2) != m!(func)) as usize; + let _ = ((1 < 2) != m!(func)) as usize; //~ bool_comparison } diff --git a/tests/ui/bool_comparison.rs b/tests/ui/bool_comparison.rs index 4fdf23052425..7f00df39cdce 100644 --- a/tests/ui/bool_comparison.rs +++ b/tests/ui/bool_comparison.rs @@ -4,72 +4,86 @@ fn main() { let x = true; + //~v bool_comparison if x == true { "yes" } else { "no" }; + //~v bool_comparison if x == false { "yes" } else { "no" }; + //~v bool_comparison if true == x { "yes" } else { "no" }; + //~v bool_comparison if false == x { "yes" } else { "no" }; + //~v bool_comparison if x != true { "yes" } else { "no" }; + //~v bool_comparison if x != false { "yes" } else { "no" }; + //~v bool_comparison if true != x { "yes" } else { "no" }; + //~v bool_comparison if false != x { "yes" } else { "no" }; + //~v bool_comparison if x < true { "yes" } else { "no" }; + //~v bool_comparison if false < x { "yes" } else { "no" }; + //~v bool_comparison if x > false { "yes" } else { "no" }; + //~v bool_comparison if true > x { "yes" } else { "no" }; let y = true; + //~v bool_comparison if x < y { "yes" } else { "no" }; + //~v bool_comparison if x > y { "yes" } else { @@ -118,13 +132,13 @@ fn issue4983() { let a = true; let b = false; - if a == !b {}; - if !a == b {}; + if a == !b {}; //~ bool_comparison + if !a == b {}; //~ bool_comparison if a == b {}; if !a == !b {}; - if b == !a {}; - if !b == a {}; + if b == !a {}; //~ bool_comparison + if !b == a {}; //~ bool_comparison if b == a {}; if !b == !a {}; } @@ -148,10 +162,10 @@ fn issue3973() { if cfg!(feature = "debugging") == true {} // lint, could be simplified - if false == m!(func) {} - if m!(func) == false {} - if true == m!(func) {} - if m!(func) == true {} + if false == m!(func) {} //~ bool_comparison + if m!(func) == false {} //~ bool_comparison + if true == m!(func) {} //~ bool_comparison + if m!(func) == true {} //~ bool_comparison // no lint with a variable let is_debug = false; @@ -168,9 +182,9 @@ fn issue3973() { #[allow(clippy::unnecessary_cast)] fn issue9907() { - let _ = ((1 < 2) == false) as usize; - let _ = (false == m!(func)) as usize; + let _ = ((1 < 2) == false) as usize; //~ bool_comparison + let _ = (false == m!(func)) as usize; //~ bool_comparison // This is not part of the issue, but an unexpected found when fixing the issue, // the provided span was inside of macro rather than the macro callsite. - let _ = ((1 < 2) == !m!(func)) as usize; + let _ = ((1 < 2) == !m!(func)) as usize; //~ bool_comparison } diff --git a/tests/ui/bool_comparison.stderr b/tests/ui/bool_comparison.stderr index 6907dc0523fe..2536ffa53d07 100644 --- a/tests/ui/bool_comparison.stderr +++ b/tests/ui/bool_comparison.stderr @@ -1,5 +1,5 @@ error: equality checks against true are unnecessary - --> $DIR/bool_comparison.rs:7:8 + --> $DIR/bool_comparison.rs:8:8 | LL | if x == true { | ^^^^^^^^^ help: try simplifying it as shown: `x` @@ -8,145 +8,145 @@ LL | if x == true { = help: to override `-D warnings` add `#[allow(clippy::bool_comparison)]` error: equality checks against false can be replaced by a negation - --> $DIR/bool_comparison.rs:12:8 + --> $DIR/bool_comparison.rs:14:8 | LL | if x == false { | ^^^^^^^^^^ help: try simplifying it as shown: `!x` error: equality checks against true are unnecessary - --> $DIR/bool_comparison.rs:17:8 + --> $DIR/bool_comparison.rs:20:8 | LL | if true == x { | ^^^^^^^^^ help: try simplifying it as shown: `x` error: equality checks against false can be replaced by a negation - --> $DIR/bool_comparison.rs:22:8 + --> $DIR/bool_comparison.rs:26:8 | LL | if false == x { | ^^^^^^^^^^ help: try simplifying it as shown: `!x` error: inequality checks against true can be replaced by a negation - --> $DIR/bool_comparison.rs:27:8 + --> $DIR/bool_comparison.rs:32:8 | LL | if x != true { | ^^^^^^^^^ help: try simplifying it as shown: `!x` error: inequality checks against false are unnecessary - --> $DIR/bool_comparison.rs:32:8 + --> $DIR/bool_comparison.rs:38:8 | LL | if x != false { | ^^^^^^^^^^ help: try simplifying it as shown: `x` error: inequality checks against true can be replaced by a negation - --> $DIR/bool_comparison.rs:37:8 + --> $DIR/bool_comparison.rs:44:8 | LL | if true != x { | ^^^^^^^^^ help: try simplifying it as shown: `!x` error: inequality checks against false are unnecessary - --> $DIR/bool_comparison.rs:42:8 + --> $DIR/bool_comparison.rs:50:8 | LL | if false != x { | ^^^^^^^^^^ help: try simplifying it as shown: `x` error: less than comparison against true can be replaced by a negation - --> $DIR/bool_comparison.rs:47:8 + --> $DIR/bool_comparison.rs:56:8 | LL | if x < true { | ^^^^^^^^ help: try simplifying it as shown: `!x` error: greater than checks against false are unnecessary - --> $DIR/bool_comparison.rs:52:8 + --> $DIR/bool_comparison.rs:62:8 | LL | if false < x { | ^^^^^^^^^ help: try simplifying it as shown: `x` error: greater than checks against false are unnecessary - --> $DIR/bool_comparison.rs:57:8 + --> $DIR/bool_comparison.rs:68:8 | LL | if x > false { | ^^^^^^^^^ help: try simplifying it as shown: `x` error: less than comparison against true can be replaced by a negation - --> $DIR/bool_comparison.rs:62:8 + --> $DIR/bool_comparison.rs:74:8 | LL | if true > x { | ^^^^^^^^ help: try simplifying it as shown: `!x` error: order comparisons between booleans can be simplified - --> $DIR/bool_comparison.rs:68:8 + --> $DIR/bool_comparison.rs:81:8 | LL | if x < y { | ^^^^^ help: try simplifying it as shown: `!x & y` error: order comparisons between booleans can be simplified - --> $DIR/bool_comparison.rs:73:8 + --> $DIR/bool_comparison.rs:87:8 | LL | if x > y { | ^^^^^ help: try simplifying it as shown: `x & !y` error: this comparison might be written more concisely - --> $DIR/bool_comparison.rs:121:8 + --> $DIR/bool_comparison.rs:135:8 | LL | if a == !b {}; | ^^^^^^^ help: try simplifying it as shown: `a != b` error: this comparison might be written more concisely - --> $DIR/bool_comparison.rs:122:8 + --> $DIR/bool_comparison.rs:136:8 | LL | if !a == b {}; | ^^^^^^^ help: try simplifying it as shown: `a != b` error: this comparison might be written more concisely - --> $DIR/bool_comparison.rs:126:8 + --> $DIR/bool_comparison.rs:140:8 | LL | if b == !a {}; | ^^^^^^^ help: try simplifying it as shown: `b != a` error: this comparison might be written more concisely - --> $DIR/bool_comparison.rs:127:8 + --> $DIR/bool_comparison.rs:141:8 | LL | if !b == a {}; | ^^^^^^^ help: try simplifying it as shown: `b != a` error: equality checks against false can be replaced by a negation - --> $DIR/bool_comparison.rs:151:8 + --> $DIR/bool_comparison.rs:165:8 | LL | if false == m!(func) {} | ^^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `!m!(func)` error: equality checks against false can be replaced by a negation - --> $DIR/bool_comparison.rs:152:8 + --> $DIR/bool_comparison.rs:166:8 | LL | if m!(func) == false {} | ^^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `!m!(func)` error: equality checks against true are unnecessary - --> $DIR/bool_comparison.rs:153:8 + --> $DIR/bool_comparison.rs:167:8 | LL | if true == m!(func) {} | ^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `m!(func)` error: equality checks against true are unnecessary - --> $DIR/bool_comparison.rs:154:8 + --> $DIR/bool_comparison.rs:168:8 | LL | if m!(func) == true {} | ^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `m!(func)` error: equality checks against false can be replaced by a negation - --> $DIR/bool_comparison.rs:171:14 + --> $DIR/bool_comparison.rs:185:14 | LL | let _ = ((1 < 2) == false) as usize; | ^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `1 >= 2` error: equality checks against false can be replaced by a negation - --> $DIR/bool_comparison.rs:172:14 + --> $DIR/bool_comparison.rs:186:14 | LL | let _ = (false == m!(func)) as usize; | ^^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `!m!(func)` error: this comparison might be written more concisely - --> $DIR/bool_comparison.rs:175:14 + --> $DIR/bool_comparison.rs:189:14 | LL | let _ = ((1 < 2) == !m!(func)) as usize; | ^^^^^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `(1 < 2) != m!(func)` diff --git a/tests/ui/bool_to_int_with_if.fixed b/tests/ui/bool_to_int_with_if.fixed index 167263d31df8..0f52e266bf9f 100644 --- a/tests/ui/bool_to_int_with_if.fixed +++ b/tests/ui/bool_to_int_with_if.fixed @@ -11,21 +11,29 @@ fn main() { // Should lint // precedence + //~v bool_to_int_with_if i32::from(a); + //~v bool_to_int_with_if i32::from(!a); + //~v bool_to_int_with_if i32::from(!a); + //~v bool_to_int_with_if i32::from(a || b); + //~v bool_to_int_with_if i32::from(cond(a, b)); + //~v bool_to_int_with_if i32::from(x + y < 4); // if else if if a { 123 + //~v bool_to_int_with_if } else { i32::from(b) }; // if else if inverted if a { 123 + //~v bool_to_int_with_if } else { i32::from(!b) }; // Shouldn't lint @@ -87,7 +95,7 @@ fn main() { // Lint returns and type inference fn some_fn(a: bool) -> u8 { - u8::from(a) + u8::from(a) //~ bool_to_int_with_if } fn side_effect() {} diff --git a/tests/ui/bool_to_int_with_if.rs b/tests/ui/bool_to_int_with_if.rs index f3f055eb7f06..52036979b9c7 100644 --- a/tests/ui/bool_to_int_with_if.rs +++ b/tests/ui/bool_to_int_with_if.rs @@ -11,31 +11,37 @@ fn main() { // Should lint // precedence + //~v bool_to_int_with_if if a { 1 } else { 0 }; + //~v bool_to_int_with_if if a { 0 } else { 1 }; + //~v bool_to_int_with_if if !a { 1 } else { 0 }; + //~v bool_to_int_with_if if a || b { 1 } else { 0 }; + //~v bool_to_int_with_if if cond(a, b) { 1 } else { 0 }; + //~v bool_to_int_with_if if x + y < 4 { 1 } else { @@ -45,6 +51,7 @@ fn main() { // if else if if a { 123 + //~v bool_to_int_with_if } else if b { 1 } else { @@ -54,6 +61,7 @@ fn main() { // if else if inverted if a { 123 + //~v bool_to_int_with_if } else if b { 0 } else { @@ -119,7 +127,7 @@ fn main() { // Lint returns and type inference fn some_fn(a: bool) -> u8 { - if a { 1 } else { 0 } + if a { 1 } else { 0 } //~ bool_to_int_with_if } fn side_effect() {} diff --git a/tests/ui/bool_to_int_with_if.stderr b/tests/ui/bool_to_int_with_if.stderr index 714da8a41695..0f5833ff7016 100644 --- a/tests/ui/bool_to_int_with_if.stderr +++ b/tests/ui/bool_to_int_with_if.stderr @@ -1,5 +1,5 @@ error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:14:5 + --> $DIR/bool_to_int_with_if.rs:15:5 | LL | / if a { LL | | 1 @@ -13,7 +13,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::bool_to_int_with_if)]` error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:19:5 + --> $DIR/bool_to_int_with_if.rs:21:5 | LL | / if a { LL | | 0 @@ -25,7 +25,7 @@ LL | | }; = note: `!a as i32` or `(!a).into()` can also be valid options error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:24:5 + --> $DIR/bool_to_int_with_if.rs:27:5 | LL | / if !a { LL | | 1 @@ -37,7 +37,7 @@ LL | | }; = note: `!a as i32` or `(!a).into()` can also be valid options error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:29:5 + --> $DIR/bool_to_int_with_if.rs:33:5 | LL | / if a || b { LL | | 1 @@ -49,7 +49,7 @@ LL | | }; = note: `(a || b) as i32` or `(a || b).into()` can also be valid options error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:34:5 + --> $DIR/bool_to_int_with_if.rs:39:5 | LL | / if cond(a, b) { LL | | 1 @@ -61,7 +61,7 @@ LL | | }; = note: `cond(a, b) as i32` or `cond(a, b).into()` can also be valid options error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:39:5 + --> $DIR/bool_to_int_with_if.rs:45:5 | LL | / if x + y < 4 { LL | | 1 @@ -73,7 +73,7 @@ LL | | }; = note: `(x + y < 4) as i32` or `(x + y < 4).into()` can also be valid options error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:48:12 + --> $DIR/bool_to_int_with_if.rs:55:12 | LL | } else if b { | ____________^ @@ -86,7 +86,7 @@ LL | | }; = note: `b as i32` or `b.into()` can also be valid options error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:57:12 + --> $DIR/bool_to_int_with_if.rs:65:12 | LL | } else if b { | ____________^ @@ -99,7 +99,7 @@ LL | | }; = note: `!b as i32` or `(!b).into()` can also be valid options error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:122:5 + --> $DIR/bool_to_int_with_if.rs:130:5 | LL | if a { 1 } else { 0 } | ^^^^^^^^^^^^^^^^^^^^^ help: replace with from: `u8::from(a)` diff --git a/tests/ui/borrow_as_ptr.fixed b/tests/ui/borrow_as_ptr.fixed index 289a5ef38b8d..0e87d44d07bb 100644 --- a/tests/ui/borrow_as_ptr.fixed +++ b/tests/ui/borrow_as_ptr.fixed @@ -8,12 +8,12 @@ fn a() -> i32 { #[clippy::msrv = "1.75"] fn main() { let val = 1; - let _p = std::ptr::addr_of!(val); + let _p = std::ptr::addr_of!(val); //~ borrow_as_ptr let _p = &0 as *const i32; let _p = &a() as *const i32; let vec = vec![1]; let _p = &vec.len() as *const usize; let mut val_mut = 1; - let _p_mut = std::ptr::addr_of_mut!(val_mut); + let _p_mut = std::ptr::addr_of_mut!(val_mut); //~ borrow_as_ptr } diff --git a/tests/ui/borrow_as_ptr.rs b/tests/ui/borrow_as_ptr.rs index b5328cb22dcd..06a5795aeb14 100644 --- a/tests/ui/borrow_as_ptr.rs +++ b/tests/ui/borrow_as_ptr.rs @@ -8,12 +8,12 @@ fn a() -> i32 { #[clippy::msrv = "1.75"] fn main() { let val = 1; - let _p = &val as *const i32; + let _p = &val as *const i32; //~ borrow_as_ptr let _p = &0 as *const i32; let _p = &a() as *const i32; let vec = vec![1]; let _p = &vec.len() as *const usize; let mut val_mut = 1; - let _p_mut = &mut val_mut as *mut i32; + let _p_mut = &mut val_mut as *mut i32; //~ borrow_as_ptr } diff --git a/tests/ui/borrow_as_ptr_no_std.fixed b/tests/ui/borrow_as_ptr_no_std.fixed index f66554de3000..28c8168b5779 100644 --- a/tests/ui/borrow_as_ptr_no_std.fixed +++ b/tests/ui/borrow_as_ptr_no_std.fixed @@ -6,10 +6,10 @@ #[start] fn main(_argc: isize, _argv: *const *const u8) -> isize { let val = 1; - let _p = core::ptr::addr_of!(val); + let _p = core::ptr::addr_of!(val); //~ borrow_as_ptr let mut val_mut = 1; - let _p_mut = core::ptr::addr_of_mut!(val_mut); + let _p_mut = core::ptr::addr_of_mut!(val_mut); //~ borrow_as_ptr 0 } diff --git a/tests/ui/borrow_as_ptr_no_std.rs b/tests/ui/borrow_as_ptr_no_std.rs index 1fc254aafa77..ab2278c9a013 100644 --- a/tests/ui/borrow_as_ptr_no_std.rs +++ b/tests/ui/borrow_as_ptr_no_std.rs @@ -6,10 +6,10 @@ #[start] fn main(_argc: isize, _argv: *const *const u8) -> isize { let val = 1; - let _p = &val as *const i32; + let _p = &val as *const i32; //~ borrow_as_ptr let mut val_mut = 1; - let _p_mut = &mut val_mut as *mut i32; + let _p_mut = &mut val_mut as *mut i32; //~ borrow_as_ptr 0 } diff --git a/tests/ui/borrow_deref_ref.fixed b/tests/ui/borrow_deref_ref.fixed index ea5e983de3bd..b35df2579aec 100644 --- a/tests/ui/borrow_deref_ref.fixed +++ b/tests/ui/borrow_deref_ref.fixed @@ -10,9 +10,9 @@ fn main() {} mod should_lint { fn one_help() { let a = &12; - let b = a; + let b = a; //~ borrow_deref_ref - let b = &mut bar(&12); + let b = &mut bar(&12); //~ borrow_deref_ref } fn bar(x: &u32) -> &u32 { @@ -66,6 +66,7 @@ mod false_negative { fn foo() { let x = &12; let addr_x = &x as *const _ as usize; + //~v borrow_deref_ref let addr_y = &x as *const _ as usize; // assert ok // let addr_y = &x as *const _ as usize; // assert fail assert_ne!(addr_x, addr_y); diff --git a/tests/ui/borrow_deref_ref.rs b/tests/ui/borrow_deref_ref.rs index 8c8905b150e6..2047e354fc6f 100644 --- a/tests/ui/borrow_deref_ref.rs +++ b/tests/ui/borrow_deref_ref.rs @@ -10,9 +10,9 @@ fn main() {} mod should_lint { fn one_help() { let a = &12; - let b = &*a; + let b = &*a; //~ borrow_deref_ref - let b = &mut &*bar(&12); + let b = &mut &*bar(&12); //~ borrow_deref_ref } fn bar(x: &u32) -> &u32 { @@ -66,6 +66,7 @@ mod false_negative { fn foo() { let x = &12; let addr_x = &x as *const _ as usize; + //~v borrow_deref_ref let addr_y = &&*x as *const _ as usize; // assert ok // let addr_y = &x as *const _ as usize; // assert fail assert_ne!(addr_x, addr_y); diff --git a/tests/ui/borrow_deref_ref.stderr b/tests/ui/borrow_deref_ref.stderr index c389d6797388..4f7ec9e47fb0 100644 --- a/tests/ui/borrow_deref_ref.stderr +++ b/tests/ui/borrow_deref_ref.stderr @@ -14,7 +14,7 @@ LL | let b = &mut &*bar(&12); | ^^^^^^^^^^ help: if you would like to reborrow, try removing `&*`: `bar(&12)` error: deref on an immutable reference - --> $DIR/borrow_deref_ref.rs:69:23 + --> $DIR/borrow_deref_ref.rs:70:23 | LL | let addr_y = &&*x as *const _ as usize; // assert ok | ^^^ help: if you would like to reborrow, try removing `&*`: `x` diff --git a/tests/ui/box_default.fixed b/tests/ui/box_default.fixed index 48408e191257..9395c365e0b9 100644 --- a/tests/ui/box_default.fixed +++ b/tests/ui/box_default.fixed @@ -20,19 +20,27 @@ macro_rules! outer { fn main() { let _string: Box = Box::default(); - let _byte = Box::::default(); - let _vec = Box::>::default(); + //~^ box_default + let _byte = Box::::default(); //~ box_default + let _vec = Box::>::default(); //~ box_default let _impl = Box::::default(); + //~^ box_default let _impl2 = Box::::default(); + //~^ box_default let _impl3: Box = Box::default(); + //~^ box_default let _own = Box::new(OwnDefault::default()); // should not lint - let _in_macro = outer!(Box::::default()); + let _in_macro = outer!(Box::::default()); //~ box_default let _string_default = outer!(Box::::default()); + //~^ box_default let _vec2: Box> = Box::default(); + //~^ box_default let _vec3: Box> = Box::default(); + //~^ box_default let _vec4: Box<_> = Box::>::default(); + //~^ box_default let _more = ret_ty_fn(); - call_ty_fn(Box::default()); + call_ty_fn(Box::default()); //~ box_default issue_10381(); // `Box::>::default()` would be valid here, but not `Box::default()` or @@ -44,7 +52,7 @@ fn main() { } fn ret_ty_fn() -> Box { - Box::::default() + Box::::default() //~ box_default } #[allow(clippy::boxed_local)] @@ -62,6 +70,7 @@ impl Read for ImplementsDefault { fn issue_9621_dyn_trait() { let _: Box = Box::::default(); + //~^ box_default issue_10089(); } @@ -70,7 +79,7 @@ fn issue_10089() { #[derive(Default)] struct WeirdPathed; - let _ = Box::::default(); + let _ = Box::::default(); //~ box_default }; } @@ -82,7 +91,7 @@ fn issue_10381() { fn maybe_get_bar(i: u32) -> Option> { if i % 2 == 0 { - Some(Box::::default()) + Some(Box::::default()) //~ box_default } else { None } diff --git a/tests/ui/box_default.rs b/tests/ui/box_default.rs index 58b912707472..df31b1d5ba6d 100644 --- a/tests/ui/box_default.rs +++ b/tests/ui/box_default.rs @@ -20,19 +20,27 @@ macro_rules! outer { fn main() { let _string: Box = Box::new(Default::default()); - let _byte = Box::new(u8::default()); - let _vec = Box::new(Vec::::new()); + //~^ box_default + let _byte = Box::new(u8::default()); //~ box_default + let _vec = Box::new(Vec::::new()); //~ box_default let _impl = Box::new(ImplementsDefault::default()); + //~^ box_default let _impl2 = Box::new(::default()); + //~^ box_default let _impl3: Box = Box::new(Default::default()); + //~^ box_default let _own = Box::new(OwnDefault::default()); // should not lint - let _in_macro = outer!(Box::new(String::new())); + let _in_macro = outer!(Box::new(String::new())); //~ box_default let _string_default = outer!(Box::new(String::from(""))); + //~^ box_default let _vec2: Box> = Box::new(vec![]); + //~^ box_default let _vec3: Box> = Box::new(Vec::from([])); + //~^ box_default let _vec4: Box<_> = Box::new(Vec::from([false; 0])); + //~^ box_default let _more = ret_ty_fn(); - call_ty_fn(Box::new(u8::default())); + call_ty_fn(Box::new(u8::default())); //~ box_default issue_10381(); // `Box::>::default()` would be valid here, but not `Box::default()` or @@ -44,7 +52,7 @@ fn main() { } fn ret_ty_fn() -> Box { - Box::new(bool::default()) + Box::new(bool::default()) //~ box_default } #[allow(clippy::boxed_local)] @@ -62,6 +70,7 @@ impl Read for ImplementsDefault { fn issue_9621_dyn_trait() { let _: Box = Box::new(ImplementsDefault::default()); + //~^ box_default issue_10089(); } @@ -70,7 +79,7 @@ fn issue_10089() { #[derive(Default)] struct WeirdPathed; - let _ = Box::new(WeirdPathed::default()); + let _ = Box::new(WeirdPathed::default()); //~ box_default }; } @@ -82,7 +91,7 @@ fn issue_10381() { fn maybe_get_bar(i: u32) -> Option> { if i % 2 == 0 { - Some(Box::new(Foo::default())) + Some(Box::new(Foo::default())) //~ box_default } else { None } diff --git a/tests/ui/box_default.stderr b/tests/ui/box_default.stderr index 004550c6c64a..ba35a767d0bb 100644 --- a/tests/ui/box_default.stderr +++ b/tests/ui/box_default.stderr @@ -8,91 +8,91 @@ LL | let _string: Box = Box::new(Default::default()); = help: to override `-D warnings` add `#[allow(clippy::box_default)]` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:23:17 + --> $DIR/box_default.rs:24:17 | LL | let _byte = Box::new(u8::default()); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:24:16 + --> $DIR/box_default.rs:25:16 | LL | let _vec = Box::new(Vec::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::>::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:25:17 + --> $DIR/box_default.rs:26:17 | LL | let _impl = Box::new(ImplementsDefault::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:26:18 + --> $DIR/box_default.rs:28:18 | LL | let _impl2 = Box::new(::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:27:42 + --> $DIR/box_default.rs:30:42 | LL | let _impl3: Box = Box::new(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:29:28 + --> $DIR/box_default.rs:33:28 | LL | let _in_macro = outer!(Box::new(String::new())); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:30:34 + --> $DIR/box_default.rs:34:34 | LL | let _string_default = outer!(Box::new(String::from(""))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:31:46 + --> $DIR/box_default.rs:36:46 | LL | let _vec2: Box> = Box::new(vec![]); | ^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:32:33 + --> $DIR/box_default.rs:38:33 | LL | let _vec3: Box> = Box::new(Vec::from([])); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:33:25 + --> $DIR/box_default.rs:40:25 | LL | let _vec4: Box<_> = Box::new(Vec::from([false; 0])); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::>::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:35:16 + --> $DIR/box_default.rs:43:16 | LL | call_ty_fn(Box::new(u8::default())); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:47:5 + --> $DIR/box_default.rs:55:5 | LL | Box::new(bool::default()) | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:64:28 + --> $DIR/box_default.rs:72:28 | LL | let _: Box = Box::new(ImplementsDefault::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:73:17 + --> $DIR/box_default.rs:82:17 | LL | let _ = Box::new(WeirdPathed::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:85:18 + --> $DIR/box_default.rs:94:18 | LL | Some(Box::new(Foo::default())) | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` diff --git a/tests/ui/builtin_type_shadow.rs b/tests/ui/builtin_type_shadow.rs index c5addd53434c..bbde138fbff0 100644 --- a/tests/ui/builtin_type_shadow.rs +++ b/tests/ui/builtin_type_shadow.rs @@ -1,6 +1,7 @@ #![warn(clippy::builtin_type_shadow)] #![allow(non_camel_case_types)] +//~v builtin_type_shadow fn foo(a: u32) -> u32 { 42 //~^ ERROR: mismatched types diff --git a/tests/ui/builtin_type_shadow.stderr b/tests/ui/builtin_type_shadow.stderr index e051c00eb8d2..9b267bec5cae 100644 --- a/tests/ui/builtin_type_shadow.stderr +++ b/tests/ui/builtin_type_shadow.stderr @@ -1,5 +1,5 @@ error: this generic shadows the built-in type `u32` - --> $DIR/builtin_type_shadow.rs:4:8 + --> $DIR/builtin_type_shadow.rs:5:8 | LL | fn foo(a: u32) -> u32 { | ^^^ @@ -8,7 +8,7 @@ LL | fn foo(a: u32) -> u32 { = help: to override `-D warnings` add `#[allow(clippy::builtin_type_shadow)]` error[E0308]: mismatched types - --> $DIR/builtin_type_shadow.rs:5:5 + --> $DIR/builtin_type_shadow.rs:6:5 | LL | fn foo(a: u32) -> u32 { | --- --- expected `u32` because of return type diff --git a/tests/ui/bytes_count_to_len.fixed b/tests/ui/bytes_count_to_len.fixed index d20af22535a0..8c494cb6661c 100644 --- a/tests/ui/bytes_count_to_len.fixed +++ b/tests/ui/bytes_count_to_len.fixed @@ -5,15 +5,16 @@ use std::io::Read; fn main() { // should fix, because type is String let _ = String::from("foo").len(); + //~^ bytes_count_to_len let s1 = String::from("foo"); - let _ = s1.len(); + let _ = s1.len(); //~ bytes_count_to_len // should fix, because type is &str - let _ = "foo".len(); + let _ = "foo".len(); //~ bytes_count_to_len let s2 = "foo"; - let _ = s2.len(); + let _ = s2.len(); //~ bytes_count_to_len // make sure using count() normally doesn't trigger warning let vector = [0, 1, 2]; diff --git a/tests/ui/bytes_count_to_len.rs b/tests/ui/bytes_count_to_len.rs index 340e6b412556..286bdbce85d2 100644 --- a/tests/ui/bytes_count_to_len.rs +++ b/tests/ui/bytes_count_to_len.rs @@ -5,15 +5,16 @@ use std::io::Read; fn main() { // should fix, because type is String let _ = String::from("foo").bytes().count(); + //~^ bytes_count_to_len let s1 = String::from("foo"); - let _ = s1.bytes().count(); + let _ = s1.bytes().count(); //~ bytes_count_to_len // should fix, because type is &str - let _ = "foo".bytes().count(); + let _ = "foo".bytes().count(); //~ bytes_count_to_len let s2 = "foo"; - let _ = s2.bytes().count(); + let _ = s2.bytes().count(); //~ bytes_count_to_len // make sure using count() normally doesn't trigger warning let vector = [0, 1, 2]; diff --git a/tests/ui/bytes_count_to_len.stderr b/tests/ui/bytes_count_to_len.stderr index db0bb4099de9..0e1648d23591 100644 --- a/tests/ui/bytes_count_to_len.stderr +++ b/tests/ui/bytes_count_to_len.stderr @@ -8,19 +8,19 @@ LL | let _ = String::from("foo").bytes().count(); = help: to override `-D warnings` add `#[allow(clippy::bytes_count_to_len)]` error: using long and hard to read `.bytes().count()` - --> $DIR/bytes_count_to_len.rs:10:13 + --> $DIR/bytes_count_to_len.rs:11:13 | LL | let _ = s1.bytes().count(); | ^^^^^^^^^^^^^^^^^^ help: consider calling `.len()` instead: `s1.len()` error: using long and hard to read `.bytes().count()` - --> $DIR/bytes_count_to_len.rs:13:13 + --> $DIR/bytes_count_to_len.rs:14:13 | LL | let _ = "foo".bytes().count(); | ^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.len()` instead: `"foo".len()` error: using long and hard to read `.bytes().count()` - --> $DIR/bytes_count_to_len.rs:16:13 + --> $DIR/bytes_count_to_len.rs:17:13 | LL | let _ = s2.bytes().count(); | ^^^^^^^^^^^^^^^^^^ help: consider calling `.len()` instead: `s2.len()` diff --git a/tests/ui/bytes_nth.fixed b/tests/ui/bytes_nth.fixed index 11deb2390fd4..a97386a0a20d 100644 --- a/tests/ui/bytes_nth.fixed +++ b/tests/ui/bytes_nth.fixed @@ -3,7 +3,7 @@ fn main() { let s = String::from("String"); - let _ = s.as_bytes().get(3).copied(); - let _ = &s.as_bytes()[3]; - let _ = s[..].as_bytes().get(3).copied(); + let _ = s.as_bytes().get(3).copied(); //~ bytes_nth + let _ = &s.as_bytes()[3]; //~ bytes_nth + let _ = s[..].as_bytes().get(3).copied(); //~ bytes_nth } diff --git a/tests/ui/bytes_nth.rs b/tests/ui/bytes_nth.rs index 62d9c7a5ea79..62436c2e12a8 100644 --- a/tests/ui/bytes_nth.rs +++ b/tests/ui/bytes_nth.rs @@ -3,7 +3,7 @@ fn main() { let s = String::from("String"); - let _ = s.bytes().nth(3); - let _ = &s.bytes().nth(3).unwrap(); - let _ = s[..].bytes().nth(3); + let _ = s.bytes().nth(3); //~ bytes_nth + let _ = &s.bytes().nth(3).unwrap(); //~ bytes_nth + let _ = s[..].bytes().nth(3); //~ bytes_nth } diff --git a/tests/ui/case_sensitive_file_extension_comparisons.fixed b/tests/ui/case_sensitive_file_extension_comparisons.fixed index 8b4a165a97c6..8b083d820490 100644 --- a/tests/ui/case_sensitive_file_extension_comparisons.fixed +++ b/tests/ui/case_sensitive_file_extension_comparisons.fixed @@ -13,6 +13,7 @@ fn is_rust_file(filename: &str) -> bool { std::path::Path::new(filename) .extension() .map_or(false, |ext| ext.eq_ignore_ascii_case("rs")) + //~^ case_sensitive_file_extension_comparisons } fn main() { @@ -20,15 +21,18 @@ fn main() { let _ = std::path::Path::new(&String::new()) .extension() .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12")); + //~^ case_sensitive_file_extension_comparisons let _ = std::path::Path::new("str") .extension() .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12")); + //~^ case_sensitive_file_extension_comparisons // The fixup should preserve the indentation level { let _ = std::path::Path::new("str") .extension() .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12")); + //~^ case_sensitive_file_extension_comparisons } // The test struct should not trigger the lint failure with .ext12 @@ -38,9 +42,11 @@ fn main() { let _ = std::path::Path::new(&String::new()) .extension() .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12")); + //~^ case_sensitive_file_extension_comparisons let _ = std::path::Path::new("str") .extension() .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12")); + //~^ case_sensitive_file_extension_comparisons // Should not trigger the lint failure because of the calls to to_lowercase and to_uppercase let _ = String::new().to_lowercase().ends_with(".EXT12"); diff --git a/tests/ui/case_sensitive_file_extension_comparisons.rs b/tests/ui/case_sensitive_file_extension_comparisons.rs index e4b8178110b6..335331332bef 100644 --- a/tests/ui/case_sensitive_file_extension_comparisons.rs +++ b/tests/ui/case_sensitive_file_extension_comparisons.rs @@ -11,16 +11,20 @@ impl TestStruct { #[allow(dead_code)] fn is_rust_file(filename: &str) -> bool { filename.ends_with(".rs") + //~^ case_sensitive_file_extension_comparisons } fn main() { // std::string::String and &str should trigger the lint failure with .ext12 let _ = String::new().ends_with(".ext12"); + //~^ case_sensitive_file_extension_comparisons let _ = "str".ends_with(".ext12"); + //~^ case_sensitive_file_extension_comparisons // The fixup should preserve the indentation level { let _ = "str".ends_with(".ext12"); + //~^ case_sensitive_file_extension_comparisons } // The test struct should not trigger the lint failure with .ext12 @@ -28,7 +32,9 @@ fn main() { // std::string::String and &str should trigger the lint failure with .EXT12 let _ = String::new().ends_with(".EXT12"); + //~^ case_sensitive_file_extension_comparisons let _ = "str".ends_with(".EXT12"); + //~^ case_sensitive_file_extension_comparisons // Should not trigger the lint failure because of the calls to to_lowercase and to_uppercase let _ = String::new().to_lowercase().ends_with(".EXT12"); diff --git a/tests/ui/case_sensitive_file_extension_comparisons.stderr b/tests/ui/case_sensitive_file_extension_comparisons.stderr index 49c840bd7692..a7e32f9d0d70 100644 --- a/tests/ui/case_sensitive_file_extension_comparisons.stderr +++ b/tests/ui/case_sensitive_file_extension_comparisons.stderr @@ -15,7 +15,7 @@ LL + .map_or(false, |ext| ext.eq_ignore_ascii_case("rs")) | error: case-sensitive file extension comparison - --> $DIR/case_sensitive_file_extension_comparisons.rs:18:13 + --> $DIR/case_sensitive_file_extension_comparisons.rs:19:13 | LL | let _ = String::new().ends_with(".ext12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -29,7 +29,7 @@ LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12")); | error: case-sensitive file extension comparison - --> $DIR/case_sensitive_file_extension_comparisons.rs:19:13 + --> $DIR/case_sensitive_file_extension_comparisons.rs:21:13 | LL | let _ = "str".ends_with(".ext12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -43,7 +43,7 @@ LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12")); | error: case-sensitive file extension comparison - --> $DIR/case_sensitive_file_extension_comparisons.rs:23:17 + --> $DIR/case_sensitive_file_extension_comparisons.rs:26:17 | LL | let _ = "str".ends_with(".ext12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12")); | error: case-sensitive file extension comparison - --> $DIR/case_sensitive_file_extension_comparisons.rs:30:13 + --> $DIR/case_sensitive_file_extension_comparisons.rs:34:13 | LL | let _ = String::new().ends_with(".EXT12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -71,7 +71,7 @@ LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12")); | error: case-sensitive file extension comparison - --> $DIR/case_sensitive_file_extension_comparisons.rs:31:13 + --> $DIR/case_sensitive_file_extension_comparisons.rs:36:13 | LL | let _ = "str".ends_with(".EXT12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_abs_to_unsigned.fixed b/tests/ui/cast_abs_to_unsigned.fixed index 6ca01b7cc367..037237694ff6 100644 --- a/tests/ui/cast_abs_to_unsigned.fixed +++ b/tests/ui/cast_abs_to_unsigned.fixed @@ -3,31 +3,32 @@ fn main() { let x: i32 = -42; - let y: u32 = x.unsigned_abs(); + let y: u32 = x.unsigned_abs(); //~ cast_abs_to_unsigned println!("The absolute value of {} is {}", x, y); let a: i32 = -3; - let _: usize = a.unsigned_abs() as usize; - let _: usize = a.unsigned_abs() as _; - let _ = a.unsigned_abs() as usize; + let _: usize = a.unsigned_abs() as usize; //~ cast_abs_to_unsigned + let _: usize = a.unsigned_abs() as _; //~ cast_abs_to_unsigned + let _ = a.unsigned_abs() as usize; //~ cast_abs_to_unsigned let a: i64 = -3; - let _ = a.unsigned_abs() as usize; - let _ = a.unsigned_abs() as u8; - let _ = a.unsigned_abs() as u16; - let _ = a.unsigned_abs() as u32; - let _ = a.unsigned_abs(); - let _ = a.unsigned_abs() as u128; + let _ = a.unsigned_abs() as usize; //~ cast_abs_to_unsigned + let _ = a.unsigned_abs() as u8; //~ cast_abs_to_unsigned + let _ = a.unsigned_abs() as u16; //~ cast_abs_to_unsigned + let _ = a.unsigned_abs() as u32; //~ cast_abs_to_unsigned + let _ = a.unsigned_abs(); //~ cast_abs_to_unsigned + let _ = a.unsigned_abs() as u128; //~ cast_abs_to_unsigned let a: isize = -3; - let _ = a.unsigned_abs(); - let _ = a.unsigned_abs() as u8; - let _ = a.unsigned_abs() as u16; - let _ = a.unsigned_abs() as u32; - let _ = a.unsigned_abs() as u64; - let _ = a.unsigned_abs() as u128; + let _ = a.unsigned_abs(); //~ cast_abs_to_unsigned + let _ = a.unsigned_abs() as u8; //~ cast_abs_to_unsigned + let _ = a.unsigned_abs() as u16; //~ cast_abs_to_unsigned + let _ = a.unsigned_abs() as u32; //~ cast_abs_to_unsigned + let _ = a.unsigned_abs() as u64; //~ cast_abs_to_unsigned + let _ = a.unsigned_abs() as u128; //~ cast_abs_to_unsigned let _ = (x as i64 - y as i64).unsigned_abs() as u32; + //~^ cast_abs_to_unsigned } #[clippy::msrv = "1.50"] @@ -39,5 +40,5 @@ fn msrv_1_50() { #[clippy::msrv = "1.51"] fn msrv_1_51() { let x: i32 = 10; - assert_eq!(10u32, x.unsigned_abs()); + assert_eq!(10u32, x.unsigned_abs()); //~ cast_abs_to_unsigned } diff --git a/tests/ui/cast_abs_to_unsigned.rs b/tests/ui/cast_abs_to_unsigned.rs index 190a77c10232..3dc90813063b 100644 --- a/tests/ui/cast_abs_to_unsigned.rs +++ b/tests/ui/cast_abs_to_unsigned.rs @@ -3,31 +3,32 @@ fn main() { let x: i32 = -42; - let y: u32 = x.abs() as u32; + let y: u32 = x.abs() as u32; //~ cast_abs_to_unsigned println!("The absolute value of {} is {}", x, y); let a: i32 = -3; - let _: usize = a.abs() as usize; - let _: usize = a.abs() as _; - let _ = a.abs() as usize; + let _: usize = a.abs() as usize; //~ cast_abs_to_unsigned + let _: usize = a.abs() as _; //~ cast_abs_to_unsigned + let _ = a.abs() as usize; //~ cast_abs_to_unsigned let a: i64 = -3; - let _ = a.abs() as usize; - let _ = a.abs() as u8; - let _ = a.abs() as u16; - let _ = a.abs() as u32; - let _ = a.abs() as u64; - let _ = a.abs() as u128; + let _ = a.abs() as usize; //~ cast_abs_to_unsigned + let _ = a.abs() as u8; //~ cast_abs_to_unsigned + let _ = a.abs() as u16; //~ cast_abs_to_unsigned + let _ = a.abs() as u32; //~ cast_abs_to_unsigned + let _ = a.abs() as u64; //~ cast_abs_to_unsigned + let _ = a.abs() as u128; //~ cast_abs_to_unsigned let a: isize = -3; - let _ = a.abs() as usize; - let _ = a.abs() as u8; - let _ = a.abs() as u16; - let _ = a.abs() as u32; - let _ = a.abs() as u64; - let _ = a.abs() as u128; + let _ = a.abs() as usize; //~ cast_abs_to_unsigned + let _ = a.abs() as u8; //~ cast_abs_to_unsigned + let _ = a.abs() as u16; //~ cast_abs_to_unsigned + let _ = a.abs() as u32; //~ cast_abs_to_unsigned + let _ = a.abs() as u64; //~ cast_abs_to_unsigned + let _ = a.abs() as u128; //~ cast_abs_to_unsigned let _ = (x as i64 - y as i64).abs() as u32; + //~^ cast_abs_to_unsigned } #[clippy::msrv = "1.50"] @@ -39,5 +40,5 @@ fn msrv_1_50() { #[clippy::msrv = "1.51"] fn msrv_1_51() { let x: i32 = 10; - assert_eq!(10u32, x.abs() as u32); + assert_eq!(10u32, x.abs() as u32); //~ cast_abs_to_unsigned } diff --git a/tests/ui/cast_abs_to_unsigned.stderr b/tests/ui/cast_abs_to_unsigned.stderr index fbdb559fc421..e7cecc111cd9 100644 --- a/tests/ui/cast_abs_to_unsigned.stderr +++ b/tests/ui/cast_abs_to_unsigned.stderr @@ -104,7 +104,7 @@ LL | let _ = (x as i64 - y as i64).abs() as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `(x as i64 - y as i64).unsigned_abs()` error: casting the result of `i32::abs()` to u32 - --> $DIR/cast_abs_to_unsigned.rs:42:23 + --> $DIR/cast_abs_to_unsigned.rs:43:23 | LL | assert_eq!(10u32, x.abs() as u32); | ^^^^^^^^^^^^^^ help: replace with: `x.unsigned_abs()` diff --git a/tests/ui/cast_lossless_bool.fixed b/tests/ui/cast_lossless_bool.fixed index a4ce1c6f928e..3b626e4ca88c 100644 --- a/tests/ui/cast_lossless_bool.fixed +++ b/tests/ui/cast_lossless_bool.fixed @@ -3,22 +3,22 @@ fn main() { // Test clippy::cast_lossless with casts to integer types - let _ = u8::from(true); - let _ = u16::from(true); - let _ = u32::from(true); - let _ = u64::from(true); - let _ = u128::from(true); - let _ = usize::from(true); - - let _ = i8::from(true); - let _ = i16::from(true); - let _ = i32::from(true); - let _ = i64::from(true); - let _ = i128::from(true); - let _ = isize::from(true); + let _ = u8::from(true); //~ cast_lossless + let _ = u16::from(true); //~ cast_lossless + let _ = u32::from(true); //~ cast_lossless + let _ = u64::from(true); //~ cast_lossless + let _ = u128::from(true); //~ cast_lossless + let _ = usize::from(true); //~ cast_lossless + + let _ = i8::from(true); //~ cast_lossless + let _ = i16::from(true); //~ cast_lossless + let _ = i32::from(true); //~ cast_lossless + let _ = i64::from(true); //~ cast_lossless + let _ = i128::from(true); //~ cast_lossless + let _ = isize::from(true); //~ cast_lossless // Test with an expression wrapped in parens - let _ = u16::from(true | false); + let _ = u16::from(true | false); //~ cast_lossless } // The lint would suggest using `u32::from(input)` here but the `XX::from` function is not const, @@ -46,5 +46,5 @@ fn msrv_1_27() { #[clippy::msrv = "1.28"] fn msrv_1_28() { - let _ = u8::from(true); + let _ = u8::from(true); //~ cast_lossless } diff --git a/tests/ui/cast_lossless_bool.rs b/tests/ui/cast_lossless_bool.rs index e5b1c30c1035..d18b8480e3dd 100644 --- a/tests/ui/cast_lossless_bool.rs +++ b/tests/ui/cast_lossless_bool.rs @@ -3,22 +3,22 @@ fn main() { // Test clippy::cast_lossless with casts to integer types - let _ = true as u8; - let _ = true as u16; - let _ = true as u32; - let _ = true as u64; - let _ = true as u128; - let _ = true as usize; - - let _ = true as i8; - let _ = true as i16; - let _ = true as i32; - let _ = true as i64; - let _ = true as i128; - let _ = true as isize; + let _ = true as u8; //~ cast_lossless + let _ = true as u16; //~ cast_lossless + let _ = true as u32; //~ cast_lossless + let _ = true as u64; //~ cast_lossless + let _ = true as u128; //~ cast_lossless + let _ = true as usize; //~ cast_lossless + + let _ = true as i8; //~ cast_lossless + let _ = true as i16; //~ cast_lossless + let _ = true as i32; //~ cast_lossless + let _ = true as i64; //~ cast_lossless + let _ = true as i128; //~ cast_lossless + let _ = true as isize; //~ cast_lossless // Test with an expression wrapped in parens - let _ = (true | false) as u16; + let _ = (true | false) as u16; //~ cast_lossless } // The lint would suggest using `u32::from(input)` here but the `XX::from` function is not const, @@ -46,5 +46,5 @@ fn msrv_1_27() { #[clippy::msrv = "1.28"] fn msrv_1_28() { - let _ = true as u8; + let _ = true as u8; //~ cast_lossless } diff --git a/tests/ui/cast_lossless_float.fixed b/tests/ui/cast_lossless_float.fixed index f4f2e4773a53..a462187f1113 100644 --- a/tests/ui/cast_lossless_float.fixed +++ b/tests/ui/cast_lossless_float.fixed @@ -4,24 +4,24 @@ fn main() { // Test clippy::cast_lossless with casts to floating-point types let x0 = 1i8; - let _ = f32::from(x0); - let _ = f64::from(x0); + let _ = f32::from(x0); //~ cast_lossless + let _ = f64::from(x0); //~ cast_lossless let x1 = 1u8; - let _ = f32::from(x1); - let _ = f64::from(x1); + let _ = f32::from(x1); //~ cast_lossless + let _ = f64::from(x1); //~ cast_lossless let x2 = 1i16; - let _ = f32::from(x2); - let _ = f64::from(x2); + let _ = f32::from(x2); //~ cast_lossless + let _ = f64::from(x2); //~ cast_lossless let x3 = 1u16; - let _ = f32::from(x3); - let _ = f64::from(x3); + let _ = f32::from(x3); //~ cast_lossless + let _ = f64::from(x3); //~ cast_lossless let x4 = 1i32; - let _ = f64::from(x4); + let _ = f64::from(x4); //~ cast_lossless let x5 = 1u32; - let _ = f64::from(x5); + let _ = f64::from(x5); //~ cast_lossless // Test with casts from floating-point types - let _ = f64::from(1.0f32); + let _ = f64::from(1.0f32); //~ cast_lossless } // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const, diff --git a/tests/ui/cast_lossless_float.rs b/tests/ui/cast_lossless_float.rs index fdd88ed36fc6..e94619491732 100644 --- a/tests/ui/cast_lossless_float.rs +++ b/tests/ui/cast_lossless_float.rs @@ -4,24 +4,24 @@ fn main() { // Test clippy::cast_lossless with casts to floating-point types let x0 = 1i8; - let _ = x0 as f32; - let _ = x0 as f64; + let _ = x0 as f32; //~ cast_lossless + let _ = x0 as f64; //~ cast_lossless let x1 = 1u8; - let _ = x1 as f32; - let _ = x1 as f64; + let _ = x1 as f32; //~ cast_lossless + let _ = x1 as f64; //~ cast_lossless let x2 = 1i16; - let _ = x2 as f32; - let _ = x2 as f64; + let _ = x2 as f32; //~ cast_lossless + let _ = x2 as f64; //~ cast_lossless let x3 = 1u16; - let _ = x3 as f32; - let _ = x3 as f64; + let _ = x3 as f32; //~ cast_lossless + let _ = x3 as f64; //~ cast_lossless let x4 = 1i32; - let _ = x4 as f64; + let _ = x4 as f64; //~ cast_lossless let x5 = 1u32; - let _ = x5 as f64; + let _ = x5 as f64; //~ cast_lossless // Test with casts from floating-point types - let _ = 1.0f32 as f64; + let _ = 1.0f32 as f64; //~ cast_lossless } // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const, diff --git a/tests/ui/cast_lossless_integer.fixed b/tests/ui/cast_lossless_integer.fixed index 5e7e545e764a..cd99c0f91c41 100644 --- a/tests/ui/cast_lossless_integer.fixed +++ b/tests/ui/cast_lossless_integer.fixed @@ -3,27 +3,27 @@ fn main() { // Test clippy::cast_lossless with casts to integer types - let _ = i16::from(1i8); - let _ = i32::from(1i8); - let _ = i64::from(1i8); - let _ = i16::from(1u8); - let _ = i32::from(1u8); - let _ = i64::from(1u8); - let _ = u16::from(1u8); - let _ = u32::from(1u8); - let _ = u64::from(1u8); - let _ = i32::from(1i16); - let _ = i64::from(1i16); - let _ = i32::from(1u16); - let _ = i64::from(1u16); - let _ = u32::from(1u16); - let _ = u64::from(1u16); - let _ = i64::from(1i32); - let _ = i64::from(1u32); - let _ = u64::from(1u32); + let _ = i16::from(1i8); //~ cast_lossless + let _ = i32::from(1i8); //~ cast_lossless + let _ = i64::from(1i8); //~ cast_lossless + let _ = i16::from(1u8); //~ cast_lossless + let _ = i32::from(1u8); //~ cast_lossless + let _ = i64::from(1u8); //~ cast_lossless + let _ = u16::from(1u8); //~ cast_lossless + let _ = u32::from(1u8); //~ cast_lossless + let _ = u64::from(1u8); //~ cast_lossless + let _ = i32::from(1i16); //~ cast_lossless + let _ = i64::from(1i16); //~ cast_lossless + let _ = i32::from(1u16); //~ cast_lossless + let _ = i64::from(1u16); //~ cast_lossless + let _ = u32::from(1u16); //~ cast_lossless + let _ = u64::from(1u16); //~ cast_lossless + let _ = i64::from(1i32); //~ cast_lossless + let _ = i64::from(1u32); //~ cast_lossless + let _ = u64::from(1u32); //~ cast_lossless // Test with an expression wrapped in parens - let _ = u16::from(1u8 + 1u8); + let _ = u16::from(1u8 + 1u8); //~ cast_lossless } // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const, @@ -57,6 +57,6 @@ fn issue11458() { }; } let x = 10_u128; - let _ = i32::from(sign_cast!(x, u8, i8)); - let _ = i32::from(sign_cast!(x, u8, i8) + 1); + let _ = i32::from(sign_cast!(x, u8, i8)); //~ cast_lossless + let _ = i32::from(sign_cast!(x, u8, i8) + 1); //~ cast_lossless } diff --git a/tests/ui/cast_lossless_integer.rs b/tests/ui/cast_lossless_integer.rs index 0d69ddbd586a..7f7fca95560d 100644 --- a/tests/ui/cast_lossless_integer.rs +++ b/tests/ui/cast_lossless_integer.rs @@ -3,27 +3,27 @@ fn main() { // Test clippy::cast_lossless with casts to integer types - let _ = 1i8 as i16; - let _ = 1i8 as i32; - let _ = 1i8 as i64; - let _ = 1u8 as i16; - let _ = 1u8 as i32; - let _ = 1u8 as i64; - let _ = 1u8 as u16; - let _ = 1u8 as u32; - let _ = 1u8 as u64; - let _ = 1i16 as i32; - let _ = 1i16 as i64; - let _ = 1u16 as i32; - let _ = 1u16 as i64; - let _ = 1u16 as u32; - let _ = 1u16 as u64; - let _ = 1i32 as i64; - let _ = 1u32 as i64; - let _ = 1u32 as u64; + let _ = 1i8 as i16; //~ cast_lossless + let _ = 1i8 as i32; //~ cast_lossless + let _ = 1i8 as i64; //~ cast_lossless + let _ = 1u8 as i16; //~ cast_lossless + let _ = 1u8 as i32; //~ cast_lossless + let _ = 1u8 as i64; //~ cast_lossless + let _ = 1u8 as u16; //~ cast_lossless + let _ = 1u8 as u32; //~ cast_lossless + let _ = 1u8 as u64; //~ cast_lossless + let _ = 1i16 as i32; //~ cast_lossless + let _ = 1i16 as i64; //~ cast_lossless + let _ = 1u16 as i32; //~ cast_lossless + let _ = 1u16 as i64; //~ cast_lossless + let _ = 1u16 as u32; //~ cast_lossless + let _ = 1u16 as u64; //~ cast_lossless + let _ = 1i32 as i64; //~ cast_lossless + let _ = 1u32 as i64; //~ cast_lossless + let _ = 1u32 as u64; //~ cast_lossless // Test with an expression wrapped in parens - let _ = (1u8 + 1u8) as u16; + let _ = (1u8 + 1u8) as u16; //~ cast_lossless } // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const, @@ -57,6 +57,6 @@ fn issue11458() { }; } let x = 10_u128; - let _ = sign_cast!(x, u8, i8) as i32; - let _ = (sign_cast!(x, u8, i8) + 1) as i32; + let _ = sign_cast!(x, u8, i8) as i32; //~ cast_lossless + let _ = (sign_cast!(x, u8, i8) + 1) as i32; //~ cast_lossless } diff --git a/tests/ui/cast_raw_slice_pointer_cast.fixed b/tests/ui/cast_raw_slice_pointer_cast.fixed index e78bd66c3cb5..bddcb0ebf64e 100644 --- a/tests/ui/cast_raw_slice_pointer_cast.fixed +++ b/tests/ui/cast_raw_slice_pointer_cast.fixed @@ -6,18 +6,25 @@ fn main() { let ptr: *const u8 = vec.as_ptr(); let mptr = vec.as_mut_ptr(); let _: *const [u8] = unsafe { core::ptr::slice_from_raw_parts(ptr, 1) }; + //~^ cast_slice_from_raw_parts let _: *const [u8] = unsafe { core::ptr::slice_from_raw_parts_mut(mptr, 1) }; + //~^ cast_slice_from_raw_parts let _: *const [u8] = core::ptr::slice_from_raw_parts(ptr, 1); + //~^ cast_slice_from_raw_parts { use core::slice; let _: *const [u8] = core::ptr::slice_from_raw_parts(ptr, 1); + //~^ cast_slice_from_raw_parts use slice as one; let _: *const [u8] = core::ptr::slice_from_raw_parts(ptr, 1); + //~^ cast_slice_from_raw_parts } { use std::slice; let _: *const [u8] = core::ptr::slice_from_raw_parts(ptr, 1); + //~^ cast_slice_from_raw_parts use slice as one; let _: *const [u8] = core::ptr::slice_from_raw_parts(ptr, 1); + //~^ cast_slice_from_raw_parts } } diff --git a/tests/ui/cast_raw_slice_pointer_cast.rs b/tests/ui/cast_raw_slice_pointer_cast.rs index c3d8c7bee989..0a1eb276d5e9 100644 --- a/tests/ui/cast_raw_slice_pointer_cast.rs +++ b/tests/ui/cast_raw_slice_pointer_cast.rs @@ -6,18 +6,25 @@ fn main() { let ptr: *const u8 = vec.as_ptr(); let mptr = vec.as_mut_ptr(); let _: *const [u8] = unsafe { std::slice::from_raw_parts(ptr, 1) as *const [u8] }; + //~^ cast_slice_from_raw_parts let _: *const [u8] = unsafe { std::slice::from_raw_parts_mut(mptr, 1) as *mut [u8] }; + //~^ cast_slice_from_raw_parts let _: *const [u8] = unsafe { std::slice::from_raw_parts(ptr, 1) } as *const [u8]; + //~^ cast_slice_from_raw_parts { use core::slice; let _: *const [u8] = unsafe { slice::from_raw_parts(ptr, 1) } as *const [u8]; + //~^ cast_slice_from_raw_parts use slice as one; let _: *const [u8] = unsafe { one::from_raw_parts(ptr, 1) } as *const [u8]; + //~^ cast_slice_from_raw_parts } { use std::slice; let _: *const [u8] = unsafe { slice::from_raw_parts(ptr, 1) } as *const [u8]; + //~^ cast_slice_from_raw_parts use slice as one; let _: *const [u8] = unsafe { one::from_raw_parts(ptr, 1) } as *const [u8]; + //~^ cast_slice_from_raw_parts } } diff --git a/tests/ui/cast_raw_slice_pointer_cast.stderr b/tests/ui/cast_raw_slice_pointer_cast.stderr index 47dc39a30ef7..c29f8de457ce 100644 --- a/tests/ui/cast_raw_slice_pointer_cast.stderr +++ b/tests/ui/cast_raw_slice_pointer_cast.stderr @@ -8,37 +8,37 @@ LL | let _: *const [u8] = unsafe { std::slice::from_raw_parts(ptr, 1) as *co = help: to override `-D warnings` add `#[allow(clippy::cast_slice_from_raw_parts)]` error: casting the result of `from_raw_parts_mut` to *mut [u8] - --> $DIR/cast_raw_slice_pointer_cast.rs:9:35 + --> $DIR/cast_raw_slice_pointer_cast.rs:10:35 | LL | let _: *const [u8] = unsafe { std::slice::from_raw_parts_mut(mptr, 1) as *mut [u8] }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts_mut(mptr, 1)` error: casting the result of `from_raw_parts` to *const [u8] - --> $DIR/cast_raw_slice_pointer_cast.rs:10:26 + --> $DIR/cast_raw_slice_pointer_cast.rs:12:26 | LL | let _: *const [u8] = unsafe { std::slice::from_raw_parts(ptr, 1) } as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts(ptr, 1)` error: casting the result of `from_raw_parts` to *const [u8] - --> $DIR/cast_raw_slice_pointer_cast.rs:13:30 + --> $DIR/cast_raw_slice_pointer_cast.rs:16:30 | LL | let _: *const [u8] = unsafe { slice::from_raw_parts(ptr, 1) } as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts(ptr, 1)` error: casting the result of `from_raw_parts` to *const [u8] - --> $DIR/cast_raw_slice_pointer_cast.rs:15:30 + --> $DIR/cast_raw_slice_pointer_cast.rs:19:30 | LL | let _: *const [u8] = unsafe { one::from_raw_parts(ptr, 1) } as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts(ptr, 1)` error: casting the result of `from_raw_parts` to *const [u8] - --> $DIR/cast_raw_slice_pointer_cast.rs:19:30 + --> $DIR/cast_raw_slice_pointer_cast.rs:24:30 | LL | let _: *const [u8] = unsafe { slice::from_raw_parts(ptr, 1) } as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts(ptr, 1)` error: casting the result of `from_raw_parts` to *const [u8] - --> $DIR/cast_raw_slice_pointer_cast.rs:21:30 + --> $DIR/cast_raw_slice_pointer_cast.rs:27:30 | LL | let _: *const [u8] = unsafe { one::from_raw_parts(ptr, 1) } as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts(ptr, 1)` diff --git a/tests/ui/cast_size.64bit.stderr b/tests/ui/cast_size.64bit.stderr index 7fae92b12503..44019f48cdb7 100644 --- a/tests/ui/cast_size.64bit.stderr +++ b/tests/ui/cast_size.64bit.stderr @@ -97,7 +97,7 @@ LL | 1usize as i32; = help: to override `-D warnings` add `#[allow(clippy::cast_possible_wrap)]` error: casting `i64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:26:5 + --> $DIR/cast_size.rs:28:5 | LL | 1i64 as isize; | ^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL | isize::try_from(1i64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:27:5 + --> $DIR/cast_size.rs:29:5 | LL | 1i64 as usize; | ^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | usize::try_from(1i64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:28:5 + --> $DIR/cast_size.rs:30:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ @@ -133,13 +133,13 @@ LL | isize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:28:5 + --> $DIR/cast_size.rs:30:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:29:5 + --> $DIR/cast_size.rs:33:5 | LL | 1u64 as usize; | ^^^^^^^^^^^^^ @@ -151,19 +151,19 @@ LL | usize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:30:5 + --> $DIR/cast_size.rs:34:5 | LL | 1u32 as isize; | ^^^^^^^^^^^^^ error: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast_size.rs:35:5 + --> $DIR/cast_size.rs:39:5 | LL | 999_999_999 as f32; | ^^^^^^^^^^^^^^^^^^ error: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> $DIR/cast_size.rs:36:5 + --> $DIR/cast_size.rs:40:5 | LL | 9_999_999_999_999_999usize as f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_size.rs b/tests/ui/cast_size.rs index d063a70ccdfc..06134787e976 100644 --- a/tests/ui/cast_size.rs +++ b/tests/ui/cast_size.rs @@ -12,26 +12,30 @@ fn main() { // Casting from *size - 1isize as i8; + 1isize as i8; //~ cast_possible_truncation let x0 = 1isize; let x1 = 1usize; - x0 as f64; - x1 as f64; - x0 as f32; - x1 as f32; - 1isize as i32; - 1isize as u32; - 1usize as u32; + x0 as f64; //~ cast_precision_loss + x1 as f64; //~ cast_precision_loss + x0 as f32; //~ cast_precision_loss + x1 as f32; //~ cast_precision_loss + 1isize as i32; //~ cast_possible_truncation + 1isize as u32; //~ cast_possible_truncation + 1usize as u32; //~ cast_possible_truncation 1usize as i32; - 1i64 as isize; - 1i64 as usize; + //~^ cast_possible_truncation + //~| cast_possible_wrap + 1i64 as isize; //~ cast_possible_truncation + 1i64 as usize; //~ cast_possible_truncation 1u64 as isize; - 1u64 as usize; - 1u32 as isize; + //~^ cast_possible_truncation + //~| cast_possible_wrap + 1u64 as usize; //~ cast_possible_truncation + 1u32 as isize; //~ cast_possible_wrap 1u32 as usize; // Should not trigger any lint 1i32 as isize; // Neither should this 1i32 as usize; // Big integer literal to float - 999_999_999 as f32; - 9_999_999_999_999_999usize as f64; + 999_999_999 as f32; //~ cast_precision_loss + 9_999_999_999_999_999usize as f64; //~ cast_precision_loss } diff --git a/tests/ui/cfg_attr_rustfmt.fixed b/tests/ui/cfg_attr_rustfmt.fixed index 05d5b3d10eaf..5808faf03a85 100644 --- a/tests/ui/cfg_attr_rustfmt.fixed +++ b/tests/ui/cfg_attr_rustfmt.fixed @@ -15,11 +15,11 @@ fn foo( } fn skip_on_statements() { - #[rustfmt::skip] + #[rustfmt::skip] //~ deprecated_cfg_attr 5+3; } -#[rustfmt::skip] +#[rustfmt::skip] //~ deprecated_cfg_attr fn main() { foo::f(); } @@ -38,6 +38,6 @@ fn msrv_1_29() { #[clippy::msrv = "1.30"] fn msrv_1_30() { - #[rustfmt::skip] + #[rustfmt::skip] //~ deprecated_cfg_attr 1+30; } diff --git a/tests/ui/cfg_attr_rustfmt.rs b/tests/ui/cfg_attr_rustfmt.rs index bc29e20210e8..d68639639c4a 100644 --- a/tests/ui/cfg_attr_rustfmt.rs +++ b/tests/ui/cfg_attr_rustfmt.rs @@ -15,11 +15,11 @@ fn foo( } fn skip_on_statements() { - #[cfg_attr(rustfmt, rustfmt::skip)] + #[cfg_attr(rustfmt, rustfmt::skip)] //~ deprecated_cfg_attr 5+3; } -#[cfg_attr(rustfmt, rustfmt_skip)] +#[cfg_attr(rustfmt, rustfmt_skip)] //~ deprecated_cfg_attr fn main() { foo::f(); } @@ -38,6 +38,6 @@ fn msrv_1_29() { #[clippy::msrv = "1.30"] fn msrv_1_30() { - #[cfg_attr(rustfmt, rustfmt::skip)] + #[cfg_attr(rustfmt, rustfmt::skip)] //~ deprecated_cfg_attr 1+30; } diff --git a/tests/ui/char_lit_as_u8_suggestions.fixed b/tests/ui/char_lit_as_u8_suggestions.fixed index 6f13078a3ae9..60d6c2ab74ab 100644 --- a/tests/ui/char_lit_as_u8_suggestions.fixed +++ b/tests/ui/char_lit_as_u8_suggestions.fixed @@ -1,8 +1,8 @@ #![warn(clippy::char_lit_as_u8)] fn main() { - let _ = b'a'; - let _ = b'\n'; - let _ = b'\0'; - let _ = b'\x01'; + let _ = b'a'; //~ char_lit_as_u8 + let _ = b'\n'; //~ char_lit_as_u8 + let _ = b'\0'; //~ char_lit_as_u8 + let _ = b'\x01'; //~ char_lit_as_u8 } diff --git a/tests/ui/char_lit_as_u8_suggestions.rs b/tests/ui/char_lit_as_u8_suggestions.rs index 7737eb5135fb..8dbdd449a567 100644 --- a/tests/ui/char_lit_as_u8_suggestions.rs +++ b/tests/ui/char_lit_as_u8_suggestions.rs @@ -1,8 +1,8 @@ #![warn(clippy::char_lit_as_u8)] fn main() { - let _ = 'a' as u8; - let _ = '\n' as u8; - let _ = '\0' as u8; - let _ = '\x01' as u8; + let _ = 'a' as u8; //~ char_lit_as_u8 + let _ = '\n' as u8; //~ char_lit_as_u8 + let _ = '\0' as u8; //~ char_lit_as_u8 + let _ = '\x01' as u8; //~ char_lit_as_u8 } diff --git a/tests/ui/checked_conversions.fixed b/tests/ui/checked_conversions.fixed index 0e05a27429b0..ae9f681951df 100644 --- a/tests/ui/checked_conversions.fixed +++ b/tests/ui/checked_conversions.fixed @@ -12,46 +12,61 @@ pub fn i64_to_u32(value: i64) { let _ = u32::try_from(value).is_ok(); + //~^ checked_conversions let _ = u32::try_from(value).is_ok(); + //~^ checked_conversions } pub fn i64_to_u16(value: i64) { let _ = u16::try_from(value).is_ok(); + //~^ checked_conversions let _ = u16::try_from(value).is_ok(); + //~^ checked_conversions } pub fn isize_to_u8(value: isize) { let _ = u8::try_from(value).is_ok(); + //~^ checked_conversions let _ = u8::try_from(value).is_ok(); + //~^ checked_conversions } // Signed to signed pub fn i64_to_i32(value: i64) { let _ = i32::try_from(value).is_ok(); + //~^ checked_conversions let _ = i32::try_from(value).is_ok(); + //~^ checked_conversions } pub fn i64_to_i16(value: i64) { let _ = i16::try_from(value).is_ok(); + //~^ checked_conversions let _ = i16::try_from(value).is_ok(); + //~^ checked_conversions } // Unsigned to X pub fn u32_to_i32(value: u32) { let _ = i32::try_from(value).is_ok(); - let _ = i32::try_from(value).is_ok(); + //~^ checked_conversions + let _ = i32::try_from(value).is_ok(); //~ checked_conversions } pub fn usize_to_isize(value: usize) { let _ = isize::try_from(value).is_ok() && value as i32 == 5; + //~^ checked_conversions let _ = isize::try_from(value).is_ok() && value as i32 == 5; + //~^ checked_conversions } pub fn u32_to_u16(value: u32) { let _ = u16::try_from(value).is_ok() && value as i32 == 5; + //~^ checked_conversions let _ = u16::try_from(value).is_ok() && value as i32 == 5; + //~^ checked_conversions } // Negative tests @@ -85,6 +100,7 @@ fn msrv_1_33() { fn msrv_1_34() { let value: i64 = 34; let _ = u32::try_from(value).is_ok(); + //~^ checked_conversions } fn main() {} diff --git a/tests/ui/checked_conversions.rs b/tests/ui/checked_conversions.rs index ac7826992653..b017f7a5e713 100644 --- a/tests/ui/checked_conversions.rs +++ b/tests/ui/checked_conversions.rs @@ -12,46 +12,61 @@ pub fn i64_to_u32(value: i64) { let _ = value <= (u32::max_value() as i64) && value >= 0; + //~^ checked_conversions let _ = value <= (u32::MAX as i64) && value >= 0; + //~^ checked_conversions } pub fn i64_to_u16(value: i64) { let _ = value <= i64::from(u16::max_value()) && value >= 0; + //~^ checked_conversions let _ = value <= i64::from(u16::MAX) && value >= 0; + //~^ checked_conversions } pub fn isize_to_u8(value: isize) { let _ = value <= (u8::max_value() as isize) && value >= 0; + //~^ checked_conversions let _ = value <= (u8::MAX as isize) && value >= 0; + //~^ checked_conversions } // Signed to signed pub fn i64_to_i32(value: i64) { let _ = value <= (i32::max_value() as i64) && value >= (i32::min_value() as i64); + //~^ checked_conversions let _ = value <= (i32::MAX as i64) && value >= (i32::MIN as i64); + //~^ checked_conversions } pub fn i64_to_i16(value: i64) { let _ = value <= i64::from(i16::max_value()) && value >= i64::from(i16::min_value()); + //~^ checked_conversions let _ = value <= i64::from(i16::MAX) && value >= i64::from(i16::MIN); + //~^ checked_conversions } // Unsigned to X pub fn u32_to_i32(value: u32) { let _ = value <= i32::max_value() as u32; - let _ = value <= i32::MAX as u32; + //~^ checked_conversions + let _ = value <= i32::MAX as u32; //~ checked_conversions } pub fn usize_to_isize(value: usize) { let _ = value <= isize::max_value() as usize && value as i32 == 5; + //~^ checked_conversions let _ = value <= isize::MAX as usize && value as i32 == 5; + //~^ checked_conversions } pub fn u32_to_u16(value: u32) { let _ = value <= u16::max_value() as u32 && value as i32 == 5; + //~^ checked_conversions let _ = value <= u16::MAX as u32 && value as i32 == 5; + //~^ checked_conversions } // Negative tests @@ -85,6 +100,7 @@ fn msrv_1_33() { fn msrv_1_34() { let value: i64 = 34; let _ = value <= (u32::MAX as i64) && value >= 0; + //~^ checked_conversions } fn main() {} diff --git a/tests/ui/checked_conversions.stderr b/tests/ui/checked_conversions.stderr index 3e0169b74dab..6cd95adcfd1f 100644 --- a/tests/ui/checked_conversions.stderr +++ b/tests/ui/checked_conversions.stderr @@ -8,97 +8,97 @@ LL | let _ = value <= (u32::max_value() as i64) && value >= 0; = help: to override `-D warnings` add `#[allow(clippy::checked_conversions)]` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:15:13 + --> $DIR/checked_conversions.rs:16:13 | LL | let _ = value <= (u32::MAX as i64) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:19:13 + --> $DIR/checked_conversions.rs:21:13 | LL | let _ = value <= i64::from(u16::max_value()) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:20:13 + --> $DIR/checked_conversions.rs:23:13 | LL | let _ = value <= i64::from(u16::MAX) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:24:13 + --> $DIR/checked_conversions.rs:28:13 | LL | let _ = value <= (u8::max_value() as isize) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u8::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:25:13 + --> $DIR/checked_conversions.rs:30:13 | LL | let _ = value <= (u8::MAX as isize) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u8::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:31:13 + --> $DIR/checked_conversions.rs:37:13 | LL | let _ = value <= (i32::max_value() as i64) && value >= (i32::min_value() as i64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:32:13 + --> $DIR/checked_conversions.rs:39:13 | LL | let _ = value <= (i32::MAX as i64) && value >= (i32::MIN as i64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:36:13 + --> $DIR/checked_conversions.rs:44:13 | LL | let _ = value <= i64::from(i16::max_value()) && value >= i64::from(i16::min_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i16::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:37:13 + --> $DIR/checked_conversions.rs:46:13 | LL | let _ = value <= i64::from(i16::MAX) && value >= i64::from(i16::MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i16::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:43:13 + --> $DIR/checked_conversions.rs:53:13 | LL | let _ = value <= i32::max_value() as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:44:13 + --> $DIR/checked_conversions.rs:55:13 | LL | let _ = value <= i32::MAX as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:48:13 + --> $DIR/checked_conversions.rs:59:13 | LL | let _ = value <= isize::max_value() as usize && value as i32 == 5; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `isize::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:49:13 + --> $DIR/checked_conversions.rs:61:13 | LL | let _ = value <= isize::MAX as usize && value as i32 == 5; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `isize::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:53:13 + --> $DIR/checked_conversions.rs:66:13 | LL | let _ = value <= u16::max_value() as u32 && value as i32 == 5; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:54:13 + --> $DIR/checked_conversions.rs:68:13 | LL | let _ = value <= u16::MAX as u32 && value as i32 == 5; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:87:13 + --> $DIR/checked_conversions.rs:102:13 | LL | let _ = value <= (u32::MAX as i64) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()` diff --git a/tests/ui/checked_unwrap/simple_conditionals.rs b/tests/ui/checked_unwrap/simple_conditionals.rs index 02f80cc52ac7..a5c58d61479c 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.rs +++ b/tests/ui/checked_unwrap/simple_conditionals.rs @@ -11,7 +11,7 @@ macro_rules! m { ($a:expr) => { if $a.is_some() { // unnecessary - $a.unwrap(); + $a.unwrap(); //~ unnecessary_unwrap } }; } diff --git a/tests/ui/clear_with_drain.fixed b/tests/ui/clear_with_drain.fixed index 15777a4ea5b3..0e55b14b3e55 100644 --- a/tests/ui/clear_with_drain.fixed +++ b/tests/ui/clear_with_drain.fixed @@ -19,11 +19,11 @@ fn vec_range() { // Do lint let mut v = vec![1, 2, 3]; - v.clear(); + v.clear(); //~ clear_with_drain // Do lint let mut v = vec![1, 2, 3]; - v.clear(); + v.clear(); //~ clear_with_drain } fn vec_range_from() { @@ -42,11 +42,11 @@ fn vec_range_from() { // Do lint let mut v = vec![1, 2, 3]; - v.clear(); + v.clear(); //~ clear_with_drain // Do lint let mut v = vec![1, 2, 3]; - v.clear(); + v.clear(); //~ clear_with_drain } fn vec_range_full() { @@ -62,7 +62,7 @@ fn vec_range_full() { // Do lint let mut v = vec![1, 2, 3]; - v.clear(); + v.clear(); //~ clear_with_drain } fn vec_range_to() { @@ -79,7 +79,7 @@ fn vec_range_to() { // Do lint let mut v = vec![1, 2, 3]; - v.clear(); + v.clear(); //~ clear_with_drain } fn vec_partial_drains() { @@ -117,11 +117,11 @@ fn vec_deque_range() { // Do lint let mut deque = VecDeque::from([1, 2, 3]); - deque.clear(); + deque.clear(); //~ clear_with_drain // Do lint let mut deque = VecDeque::from([1, 2, 3]); - deque.clear(); + deque.clear(); //~ clear_with_drain } fn vec_deque_range_from() { @@ -140,11 +140,11 @@ fn vec_deque_range_from() { // Do lint let mut deque = VecDeque::from([1, 2, 3]); - deque.clear(); + deque.clear(); //~ clear_with_drain // Do lint let mut deque = VecDeque::from([1, 2, 3]); - deque.clear(); + deque.clear(); //~ clear_with_drain } fn vec_deque_range_full() { @@ -160,7 +160,7 @@ fn vec_deque_range_full() { // Do lint let mut deque = VecDeque::from([1, 2, 3]); - deque.clear(); + deque.clear(); //~ clear_with_drain } fn vec_deque_range_to() { @@ -177,7 +177,7 @@ fn vec_deque_range_to() { // Do lint let mut deque = VecDeque::from([1, 2, 3]); - deque.clear(); + deque.clear(); //~ clear_with_drain } fn vec_deque_partial_drains() { @@ -215,11 +215,11 @@ fn string_range() { // Do lint let mut s = String::from("Hello, world!"); - s.clear(); + s.clear(); //~ clear_with_drain // Do lint let mut s = String::from("Hello, world!"); - s.clear(); + s.clear(); //~ clear_with_drain } fn string_range_from() { @@ -238,11 +238,11 @@ fn string_range_from() { // Do lint let mut s = String::from("Hello, world!"); - s.clear(); + s.clear(); //~ clear_with_drain // Do lint let mut s = String::from("Hello, world!"); - s.clear(); + s.clear(); //~ clear_with_drain } fn string_range_full() { @@ -258,7 +258,7 @@ fn string_range_full() { // Do lint let mut s = String::from("Hello, world!"); - s.clear(); + s.clear(); //~ clear_with_drain } fn string_range_to() { @@ -275,7 +275,7 @@ fn string_range_to() { // Do lint let mut s = String::from("Hello, world!"); - s.clear(); + s.clear(); //~ clear_with_drain } fn string_partial_drains() { @@ -313,7 +313,7 @@ fn hash_set() { // Do lint let mut set = HashSet::from([1, 2, 3]); - set.clear(); + set.clear(); //~ clear_with_drain } fn hash_map() { @@ -332,7 +332,7 @@ fn hash_map() { // Do lint let mut map = HashMap::from([(1, "a"), (2, "b")]); - map.clear(); + map.clear(); //~ clear_with_drain } fn binary_heap() { @@ -351,7 +351,7 @@ fn binary_heap() { // Do lint let mut heap = BinaryHeap::from([1, 2]); - heap.clear(); + heap.clear(); //~ clear_with_drain } fn main() {} diff --git a/tests/ui/clear_with_drain.rs b/tests/ui/clear_with_drain.rs index 1dea7235ef66..7db7a9236386 100644 --- a/tests/ui/clear_with_drain.rs +++ b/tests/ui/clear_with_drain.rs @@ -19,11 +19,11 @@ fn vec_range() { // Do lint let mut v = vec![1, 2, 3]; - v.drain(0..v.len()); + v.drain(0..v.len()); //~ clear_with_drain // Do lint let mut v = vec![1, 2, 3]; - v.drain(usize::MIN..v.len()); + v.drain(usize::MIN..v.len()); //~ clear_with_drain } fn vec_range_from() { @@ -42,11 +42,11 @@ fn vec_range_from() { // Do lint let mut v = vec![1, 2, 3]; - v.drain(0..); + v.drain(0..); //~ clear_with_drain // Do lint let mut v = vec![1, 2, 3]; - v.drain(usize::MIN..); + v.drain(usize::MIN..); //~ clear_with_drain } fn vec_range_full() { @@ -62,7 +62,7 @@ fn vec_range_full() { // Do lint let mut v = vec![1, 2, 3]; - v.drain(..); + v.drain(..); //~ clear_with_drain } fn vec_range_to() { @@ -79,7 +79,7 @@ fn vec_range_to() { // Do lint let mut v = vec![1, 2, 3]; - v.drain(..v.len()); + v.drain(..v.len()); //~ clear_with_drain } fn vec_partial_drains() { @@ -117,11 +117,11 @@ fn vec_deque_range() { // Do lint let mut deque = VecDeque::from([1, 2, 3]); - deque.drain(0..deque.len()); + deque.drain(0..deque.len()); //~ clear_with_drain // Do lint let mut deque = VecDeque::from([1, 2, 3]); - deque.drain(usize::MIN..deque.len()); + deque.drain(usize::MIN..deque.len()); //~ clear_with_drain } fn vec_deque_range_from() { @@ -140,11 +140,11 @@ fn vec_deque_range_from() { // Do lint let mut deque = VecDeque::from([1, 2, 3]); - deque.drain(0..); + deque.drain(0..); //~ clear_with_drain // Do lint let mut deque = VecDeque::from([1, 2, 3]); - deque.drain(usize::MIN..); + deque.drain(usize::MIN..); //~ clear_with_drain } fn vec_deque_range_full() { @@ -160,7 +160,7 @@ fn vec_deque_range_full() { // Do lint let mut deque = VecDeque::from([1, 2, 3]); - deque.drain(..); + deque.drain(..); //~ clear_with_drain } fn vec_deque_range_to() { @@ -177,7 +177,7 @@ fn vec_deque_range_to() { // Do lint let mut deque = VecDeque::from([1, 2, 3]); - deque.drain(..deque.len()); + deque.drain(..deque.len()); //~ clear_with_drain } fn vec_deque_partial_drains() { @@ -215,11 +215,11 @@ fn string_range() { // Do lint let mut s = String::from("Hello, world!"); - s.drain(0..s.len()); + s.drain(0..s.len()); //~ clear_with_drain // Do lint let mut s = String::from("Hello, world!"); - s.drain(usize::MIN..s.len()); + s.drain(usize::MIN..s.len()); //~ clear_with_drain } fn string_range_from() { @@ -238,11 +238,11 @@ fn string_range_from() { // Do lint let mut s = String::from("Hello, world!"); - s.drain(0..); + s.drain(0..); //~ clear_with_drain // Do lint let mut s = String::from("Hello, world!"); - s.drain(usize::MIN..); + s.drain(usize::MIN..); //~ clear_with_drain } fn string_range_full() { @@ -258,7 +258,7 @@ fn string_range_full() { // Do lint let mut s = String::from("Hello, world!"); - s.drain(..); + s.drain(..); //~ clear_with_drain } fn string_range_to() { @@ -275,7 +275,7 @@ fn string_range_to() { // Do lint let mut s = String::from("Hello, world!"); - s.drain(..s.len()); + s.drain(..s.len()); //~ clear_with_drain } fn string_partial_drains() { @@ -313,7 +313,7 @@ fn hash_set() { // Do lint let mut set = HashSet::from([1, 2, 3]); - set.drain(); + set.drain(); //~ clear_with_drain } fn hash_map() { @@ -332,7 +332,7 @@ fn hash_map() { // Do lint let mut map = HashMap::from([(1, "a"), (2, "b")]); - map.drain(); + map.drain(); //~ clear_with_drain } fn binary_heap() { @@ -351,7 +351,7 @@ fn binary_heap() { // Do lint let mut heap = BinaryHeap::from([1, 2]); - heap.drain(); + heap.drain(); //~ clear_with_drain } fn main() {} diff --git a/tests/ui/clone_on_copy.fixed b/tests/ui/clone_on_copy.fixed index 9d9a5bf20f43..4929a41327c5 100644 --- a/tests/ui/clone_on_copy.fixed +++ b/tests/ui/clone_on_copy.fixed @@ -20,17 +20,17 @@ fn is_ascii(ch: char) -> bool { } fn clone_on_copy() -> Option<(i32)> { - 42; + 42; //~ clone_on_copy vec![1].clone(); // ok, not a Copy type Some(vec![1]).clone(); // ok, not a Copy type - *(&42); + *(&42); //~ clone_on_copy let rc = RefCell::new(0); - *rc.borrow(); + *rc.borrow(); //~ clone_on_copy let x = 0u32; - x.rotate_left(1); + x.rotate_left(1); //~ clone_on_copy #[derive(Clone, Copy)] struct Foo; @@ -44,7 +44,7 @@ fn clone_on_copy() -> Option<(i32)> { macro_rules! m { ($e:expr) => {{ $e }}; } - m!(42); + m!(42); //~ clone_on_copy struct Wrap([u32; 2]); impl core::ops::Deref for Wrap { @@ -54,7 +54,7 @@ fn clone_on_copy() -> Option<(i32)> { } } let x = Wrap([0, 0]); - (*x)[0]; + (*x)[0]; //~ clone_on_copy let x = 42; let ref y = x.clone(); // ok, binds by reference @@ -64,14 +64,15 @@ fn clone_on_copy() -> Option<(i32)> { let mut x = 43; let _ = &x.clone(); // ok, getting a ref 'a'.clone().make_ascii_uppercase(); // ok, clone and then mutate - is_ascii('z'); + is_ascii('z'); //~ clone_on_copy // Issue #5436 let mut vec = Vec::new(); - vec.push(42); + vec.push(42); //~ clone_on_copy // Issue #9277 let opt: &Option = &None; + //~v clone_on_copy let value = (*opt)?; // operator precedence needed (*opt)? None } diff --git a/tests/ui/clone_on_copy.rs b/tests/ui/clone_on_copy.rs index 305bc6816e1b..9338a8ced99d 100644 --- a/tests/ui/clone_on_copy.rs +++ b/tests/ui/clone_on_copy.rs @@ -20,17 +20,17 @@ fn is_ascii(ch: char) -> bool { } fn clone_on_copy() -> Option<(i32)> { - 42.clone(); + 42.clone(); //~ clone_on_copy vec![1].clone(); // ok, not a Copy type Some(vec![1]).clone(); // ok, not a Copy type - (&42).clone(); + (&42).clone(); //~ clone_on_copy let rc = RefCell::new(0); - rc.borrow().clone(); + rc.borrow().clone(); //~ clone_on_copy let x = 0u32; - x.clone().rotate_left(1); + x.clone().rotate_left(1); //~ clone_on_copy #[derive(Clone, Copy)] struct Foo; @@ -44,7 +44,7 @@ fn clone_on_copy() -> Option<(i32)> { macro_rules! m { ($e:expr) => {{ $e }}; } - m!(42).clone(); + m!(42).clone(); //~ clone_on_copy struct Wrap([u32; 2]); impl core::ops::Deref for Wrap { @@ -54,7 +54,7 @@ fn clone_on_copy() -> Option<(i32)> { } } let x = Wrap([0, 0]); - x.clone()[0]; + x.clone()[0]; //~ clone_on_copy let x = 42; let ref y = x.clone(); // ok, binds by reference @@ -64,14 +64,15 @@ fn clone_on_copy() -> Option<(i32)> { let mut x = 43; let _ = &x.clone(); // ok, getting a ref 'a'.clone().make_ascii_uppercase(); // ok, clone and then mutate - is_ascii('z'.clone()); + is_ascii('z'.clone()); //~ clone_on_copy // Issue #5436 let mut vec = Vec::new(); - vec.push(42.clone()); + vec.push(42.clone()); //~ clone_on_copy // Issue #9277 let opt: &Option = &None; + //~v clone_on_copy let value = opt.clone()?; // operator precedence needed (*opt)? None } diff --git a/tests/ui/clone_on_copy.stderr b/tests/ui/clone_on_copy.stderr index 0526c2f5a28a..cd079f5068bc 100644 --- a/tests/ui/clone_on_copy.stderr +++ b/tests/ui/clone_on_copy.stderr @@ -50,7 +50,7 @@ LL | vec.push(42.clone()); | ^^^^^^^^^^ help: try removing the `clone` call: `42` error: using `clone` on type `Option` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:75:17 + --> $DIR/clone_on_copy.rs:76:17 | LL | let value = opt.clone()?; // operator precedence needed (*opt)? | ^^^^^^^^^^^ help: try dereferencing it: `(*opt)` diff --git a/tests/ui/cloned_instead_of_copied.fixed b/tests/ui/cloned_instead_of_copied.fixed index bc939bb3dbb9..840f7ce5eca0 100644 --- a/tests/ui/cloned_instead_of_copied.fixed +++ b/tests/ui/cloned_instead_of_copied.fixed @@ -4,11 +4,13 @@ fn main() { // yay - let _ = [1].iter().copied(); - let _ = vec!["hi"].iter().copied(); - let _ = Some(&1).copied(); + let _ = [1].iter().copied(); //~ cloned_instead_of_copied + let _ = vec!["hi"].iter().copied(); //~ cloned_instead_of_copied + let _ = Some(&1).copied(); //~ cloned_instead_of_copied let _ = Box::new([1].iter()).copied(); + //~^ cloned_instead_of_copied let _ = Box::new(Some(&1)).copied(); + //~^ cloned_instead_of_copied // nay let _ = [String::new()].iter().cloned(); @@ -24,11 +26,13 @@ fn msrv_1_34() { #[clippy::msrv = "1.35"] fn msrv_1_35() { let _ = [1].iter().cloned(); + //~v cloned_instead_of_copied let _ = Some(&1).copied(); // Option::copied needs 1.35 } #[clippy::msrv = "1.36"] fn msrv_1_36() { + //~v cloned_instead_of_copied let _ = [1].iter().copied(); // Iterator::copied needs 1.36 - let _ = Some(&1).copied(); + let _ = Some(&1).copied(); //~ cloned_instead_of_copied } diff --git a/tests/ui/cloned_instead_of_copied.rs b/tests/ui/cloned_instead_of_copied.rs index 27346adbfbf1..5d06de56fc1b 100644 --- a/tests/ui/cloned_instead_of_copied.rs +++ b/tests/ui/cloned_instead_of_copied.rs @@ -4,11 +4,13 @@ fn main() { // yay - let _ = [1].iter().cloned(); - let _ = vec!["hi"].iter().cloned(); - let _ = Some(&1).cloned(); + let _ = [1].iter().cloned(); //~ cloned_instead_of_copied + let _ = vec!["hi"].iter().cloned(); //~ cloned_instead_of_copied + let _ = Some(&1).cloned(); //~ cloned_instead_of_copied let _ = Box::new([1].iter()).cloned(); + //~^ cloned_instead_of_copied let _ = Box::new(Some(&1)).cloned(); + //~^ cloned_instead_of_copied // nay let _ = [String::new()].iter().cloned(); @@ -24,11 +26,13 @@ fn msrv_1_34() { #[clippy::msrv = "1.35"] fn msrv_1_35() { let _ = [1].iter().cloned(); + //~v cloned_instead_of_copied let _ = Some(&1).cloned(); // Option::copied needs 1.35 } #[clippy::msrv = "1.36"] fn msrv_1_36() { + //~v cloned_instead_of_copied let _ = [1].iter().cloned(); // Iterator::copied needs 1.36 - let _ = Some(&1).cloned(); + let _ = Some(&1).cloned(); //~ cloned_instead_of_copied } diff --git a/tests/ui/cloned_instead_of_copied.stderr b/tests/ui/cloned_instead_of_copied.stderr index 69a3738dd05b..03a9b1f1a9aa 100644 --- a/tests/ui/cloned_instead_of_copied.stderr +++ b/tests/ui/cloned_instead_of_copied.stderr @@ -26,25 +26,25 @@ LL | let _ = Box::new([1].iter()).cloned(); | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> $DIR/cloned_instead_of_copied.rs:11:32 + --> $DIR/cloned_instead_of_copied.rs:12:32 | LL | let _ = Box::new(Some(&1)).cloned(); | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> $DIR/cloned_instead_of_copied.rs:27:22 + --> $DIR/cloned_instead_of_copied.rs:30:22 | LL | let _ = Some(&1).cloned(); // Option::copied needs 1.35 | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> $DIR/cloned_instead_of_copied.rs:32:24 + --> $DIR/cloned_instead_of_copied.rs:36:24 | LL | let _ = [1].iter().cloned(); // Iterator::copied needs 1.36 | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> $DIR/cloned_instead_of_copied.rs:33:22 + --> $DIR/cloned_instead_of_copied.rs:37:22 | LL | let _ = Some(&1).cloned(); | ^^^^^^ help: try: `copied` diff --git a/tests/ui/cmp_owned/asymmetric_partial_eq.fixed b/tests/ui/cmp_owned/asymmetric_partial_eq.fixed index 9fc70ab6f4a0..721613be9535 100644 --- a/tests/ui/cmp_owned/asymmetric_partial_eq.fixed +++ b/tests/ui/cmp_owned/asymmetric_partial_eq.fixed @@ -43,8 +43,8 @@ mod borrowed_eq_owned { let owned = Owned {}; let borrowed = Borrowed {}; - if borrowed == owned {} - if borrowed == owned {} + if borrowed == owned {} //~ cmp_owned + if borrowed == owned {} //~ cmp_owned } } @@ -62,8 +62,8 @@ mod owned_eq_borrowed { let owned = Owned {}; let borrowed = Borrowed {}; - if owned == borrowed {} - if owned == borrowed {} + if owned == borrowed {} //~ cmp_owned + if owned == borrowed {} //~ cmp_owned } } @@ -89,8 +89,8 @@ mod issue_4874 { fn compare() { let borrowed = Borrowed {}; - if borrowed == "Hi" {} - if borrowed == "Hi" {} + if borrowed == "Hi" {} //~ cmp_owned + if borrowed == "Hi" {} //~ cmp_owned } } diff --git a/tests/ui/cmp_owned/asymmetric_partial_eq.rs b/tests/ui/cmp_owned/asymmetric_partial_eq.rs index 5cd43ea1d411..ced7b2833148 100644 --- a/tests/ui/cmp_owned/asymmetric_partial_eq.rs +++ b/tests/ui/cmp_owned/asymmetric_partial_eq.rs @@ -43,8 +43,8 @@ mod borrowed_eq_owned { let owned = Owned {}; let borrowed = Borrowed {}; - if borrowed.to_owned() == owned {} - if owned == borrowed.to_owned() {} + if borrowed.to_owned() == owned {} //~ cmp_owned + if owned == borrowed.to_owned() {} //~ cmp_owned } } @@ -62,8 +62,8 @@ mod owned_eq_borrowed { let owned = Owned {}; let borrowed = Borrowed {}; - if owned == borrowed.to_owned() {} - if borrowed.to_owned() == owned {} + if owned == borrowed.to_owned() {} //~ cmp_owned + if borrowed.to_owned() == owned {} //~ cmp_owned } } @@ -89,8 +89,8 @@ mod issue_4874 { fn compare() { let borrowed = Borrowed {}; - if "Hi" == borrowed.to_string() {} - if borrowed.to_string() == "Hi" {} + if "Hi" == borrowed.to_string() {} //~ cmp_owned + if borrowed.to_string() == "Hi" {} //~ cmp_owned } } diff --git a/tests/ui/cmp_owned/comparison_flip.fixed b/tests/ui/cmp_owned/comparison_flip.fixed index 40d7b5e49fcd..cc5b90b1f815 100644 --- a/tests/ui/cmp_owned/comparison_flip.fixed +++ b/tests/ui/cmp_owned/comparison_flip.fixed @@ -3,10 +3,12 @@ use std::fmt::{self, Display}; fn main() { let a = Foo; + //~v cmp_owned if a != "bar" { println!("foo"); } + //~v cmp_owned if a != "bar" { println!("foo"); } diff --git a/tests/ui/cmp_owned/comparison_flip.rs b/tests/ui/cmp_owned/comparison_flip.rs index 59a945668b2e..207c0e542369 100644 --- a/tests/ui/cmp_owned/comparison_flip.rs +++ b/tests/ui/cmp_owned/comparison_flip.rs @@ -3,10 +3,12 @@ use std::fmt::{self, Display}; fn main() { let a = Foo; + //~v cmp_owned if a.to_string() != "bar" { println!("foo"); } + //~v cmp_owned if "bar" != a.to_string() { println!("foo"); } diff --git a/tests/ui/cmp_owned/comparison_flip.stderr b/tests/ui/cmp_owned/comparison_flip.stderr index 400da925c21d..3344e701cfde 100644 --- a/tests/ui/cmp_owned/comparison_flip.stderr +++ b/tests/ui/cmp_owned/comparison_flip.stderr @@ -1,5 +1,5 @@ error: this creates an owned instance just for comparison - --> $DIR/cmp_owned/comparison_flip.rs:6:8 + --> $DIR/cmp_owned/comparison_flip.rs:7:8 | LL | if a.to_string() != "bar" { | ^^^^^^^^^^^^^ help: try: `a` @@ -8,7 +8,7 @@ LL | if a.to_string() != "bar" { = help: to override `-D warnings` add `#[allow(clippy::cmp_owned)]` error: this creates an owned instance just for comparison - --> $DIR/cmp_owned/comparison_flip.rs:10:17 + --> $DIR/cmp_owned/comparison_flip.rs:12:17 | LL | if "bar" != a.to_string() { | ---------^^^^^^^^^^^^^ diff --git a/tests/ui/cmp_owned/with_suggestion.fixed b/tests/ui/cmp_owned/with_suggestion.fixed index ab72e096cc7c..826ca6cf91b8 100644 --- a/tests/ui/cmp_owned/with_suggestion.fixed +++ b/tests/ui/cmp_owned/with_suggestion.fixed @@ -2,24 +2,24 @@ #[allow(clippy::unnecessary_operation, clippy::no_effect, unused_must_use, clippy::eq_op)] fn main() { fn with_to_string(x: &str) { - x != "foo"; + x != "foo"; //~ cmp_owned - "foo" != x; + "foo" != x; //~ cmp_owned } let x = "oh"; with_to_string(x); - x != "foo"; + x != "foo"; //~ cmp_owned - x != "foo"; + x != "foo"; //~ cmp_owned 42.to_string() == "42"; - Foo == Foo; + Foo == Foo; //~ cmp_owned - "abc".chars().filter(|c| *c != 'X'); + "abc".chars().filter(|c| *c != 'X'); //~ cmp_owned "abc".chars().filter(|c| *c != 'X'); } diff --git a/tests/ui/cmp_owned/with_suggestion.rs b/tests/ui/cmp_owned/with_suggestion.rs index cb5268734d32..3b72072ccba3 100644 --- a/tests/ui/cmp_owned/with_suggestion.rs +++ b/tests/ui/cmp_owned/with_suggestion.rs @@ -2,24 +2,24 @@ #[allow(clippy::unnecessary_operation, clippy::no_effect, unused_must_use, clippy::eq_op)] fn main() { fn with_to_string(x: &str) { - x != "foo".to_string(); + x != "foo".to_string(); //~ cmp_owned - "foo".to_string() != x; + "foo".to_string() != x; //~ cmp_owned } let x = "oh"; with_to_string(x); - x != "foo".to_owned(); + x != "foo".to_owned(); //~ cmp_owned - x != String::from("foo"); + x != String::from("foo"); //~ cmp_owned 42.to_string() == "42"; - Foo.to_owned() == Foo; + Foo.to_owned() == Foo; //~ cmp_owned - "abc".chars().filter(|c| c.to_owned() != 'X'); + "abc".chars().filter(|c| c.to_owned() != 'X'); //~ cmp_owned "abc".chars().filter(|c| *c != 'X'); } diff --git a/tests/ui/collapsible_else_if.fixed b/tests/ui/collapsible_else_if.fixed index 3b410b2f17b8..508f24bd3a31 100644 --- a/tests/ui/collapsible_else_if.fixed +++ b/tests/ui/collapsible_else_if.fixed @@ -10,18 +10,21 @@ fn main() { // Collapse `else { if .. }` to `else if ..` if x == "hello" { print!("Hello "); + //~v collapsible_else_if } else if y == "world" { println!("world!") } if x == "hello" { print!("Hello "); + //~v collapsible_else_if } else if let Some(42) = Some(42) { println!("world!") } if x == "hello" { print!("Hello "); + //~v collapsible_else_if } else if y == "world" { println!("world") } @@ -31,6 +34,7 @@ fn main() { if x == "hello" { print!("Hello "); + //~v collapsible_else_if } else if let Some(42) = Some(42) { println!("world") } @@ -40,6 +44,7 @@ fn main() { if let Some(42) = Some(42) { print!("Hello "); + //~v collapsible_else_if } else if let Some(42) = Some(42) { println!("world") } @@ -49,6 +54,7 @@ fn main() { if let Some(42) = Some(42) { print!("Hello "); + //~v collapsible_else_if } else if x == "hello" { println!("world") } @@ -58,6 +64,7 @@ fn main() { if let Some(42) = Some(42) { print!("Hello "); + //~v collapsible_else_if } else if let Some(42) = Some(42) { println!("world") } @@ -79,5 +86,6 @@ fn main() { #[allow(dead_code)] fn issue_7318() { if true { println!("I've been resolved!") + //~v collapsible_else_if }else if false {} } diff --git a/tests/ui/collapsible_else_if.rs b/tests/ui/collapsible_else_if.rs index 772ef6f9fc60..25d3d5dc56ec 100644 --- a/tests/ui/collapsible_else_if.rs +++ b/tests/ui/collapsible_else_if.rs @@ -10,6 +10,7 @@ fn main() { // Collapse `else { if .. }` to `else if ..` if x == "hello" { print!("Hello "); + //~v collapsible_else_if } else { if y == "world" { println!("world!") @@ -18,6 +19,7 @@ fn main() { if x == "hello" { print!("Hello "); + //~v collapsible_else_if } else { if let Some(42) = Some(42) { println!("world!") @@ -26,6 +28,7 @@ fn main() { if x == "hello" { print!("Hello "); + //~v collapsible_else_if } else { if y == "world" { println!("world") @@ -37,6 +40,7 @@ fn main() { if x == "hello" { print!("Hello "); + //~v collapsible_else_if } else { if let Some(42) = Some(42) { println!("world") @@ -48,6 +52,7 @@ fn main() { if let Some(42) = Some(42) { print!("Hello "); + //~v collapsible_else_if } else { if let Some(42) = Some(42) { println!("world") @@ -59,6 +64,7 @@ fn main() { if let Some(42) = Some(42) { print!("Hello "); + //~v collapsible_else_if } else { if x == "hello" { println!("world") @@ -70,6 +76,7 @@ fn main() { if let Some(42) = Some(42) { print!("Hello "); + //~v collapsible_else_if } else { if let Some(42) = Some(42) { println!("world") @@ -93,6 +100,7 @@ fn main() { #[allow(dead_code)] fn issue_7318() { if true { println!("I've been resolved!") + //~v collapsible_else_if }else{ if false {} } diff --git a/tests/ui/collapsible_else_if.stderr b/tests/ui/collapsible_else_if.stderr index f0f840653f8a..94fe0dab5a00 100644 --- a/tests/ui/collapsible_else_if.stderr +++ b/tests/ui/collapsible_else_if.stderr @@ -1,5 +1,5 @@ error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:13:12 + --> $DIR/collapsible_else_if.rs:14:12 | LL | } else { | ____________^ @@ -19,7 +19,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:21:12 + --> $DIR/collapsible_else_if.rs:23:12 | LL | } else { | ____________^ @@ -37,7 +37,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:29:12 + --> $DIR/collapsible_else_if.rs:32:12 | LL | } else { | ____________^ @@ -60,7 +60,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:40:12 + --> $DIR/collapsible_else_if.rs:44:12 | LL | } else { | ____________^ @@ -83,7 +83,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:51:12 + --> $DIR/collapsible_else_if.rs:56:12 | LL | } else { | ____________^ @@ -106,7 +106,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:62:12 + --> $DIR/collapsible_else_if.rs:68:12 | LL | } else { | ____________^ @@ -129,7 +129,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:73:12 + --> $DIR/collapsible_else_if.rs:80:12 | LL | } else { | ____________^ @@ -152,7 +152,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:96:10 + --> $DIR/collapsible_else_if.rs:104:10 | LL | }else{ | __________^ diff --git a/tests/ui/collapsible_if.fixed b/tests/ui/collapsible_if.fixed index 44b0b6e73915..61301f284ee0 100644 --- a/tests/ui/collapsible_if.fixed +++ b/tests/ui/collapsible_if.fixed @@ -12,26 +12,32 @@ fn main() { let x = "hello"; let y = "world"; + //~v collapsible_if if x == "hello" && y == "world" { println!("Hello world!"); } + //~v collapsible_if if (x == "hello" || x == "world") && (y == "world" || y == "hello") { println!("Hello world!"); } + //~v collapsible_if if x == "hello" && x == "world" && (y == "world" || y == "hello") { println!("Hello world!"); } + //~v collapsible_if if (x == "hello" || x == "world") && y == "world" && y == "hello" { println!("Hello world!"); } + //~v collapsible_if if x == "hello" && x == "world" && y == "world" && y == "hello" { println!("Hello world!"); } + //~v collapsible_if if 42 == 1337 && 'a' != 'A' { println!("world!") } @@ -86,6 +92,7 @@ fn main() { } } + //~v collapsible_if if x == "hello" && y == "world" { // Collapsible println!("Hello world!"); } @@ -143,9 +150,11 @@ fn main() { } // Fix #5962 + //~v collapsible_if if matches!(true, true) && matches!(true, true) {} // Issue #9375 + //~v collapsible_if if matches!(true, true) && truth() && matches!(true, true) {} if true { diff --git a/tests/ui/collapsible_if.rs b/tests/ui/collapsible_if.rs index 563a273dcddd..3ea2037d4e87 100644 --- a/tests/ui/collapsible_if.rs +++ b/tests/ui/collapsible_if.rs @@ -12,36 +12,42 @@ fn main() { let x = "hello"; let y = "world"; + //~v collapsible_if if x == "hello" { if y == "world" { println!("Hello world!"); } } + //~v collapsible_if if x == "hello" || x == "world" { if y == "world" || y == "hello" { println!("Hello world!"); } } + //~v collapsible_if if x == "hello" && x == "world" { if y == "world" || y == "hello" { println!("Hello world!"); } } + //~v collapsible_if if x == "hello" || x == "world" { if y == "world" && y == "hello" { println!("Hello world!"); } } + //~v collapsible_if if x == "hello" && x == "world" { if y == "world" && y == "hello" { println!("Hello world!"); } } + //~v collapsible_if if 42 == 1337 { if 'a' != 'A' { println!("world!") @@ -98,6 +104,7 @@ fn main() { } } + //~v collapsible_if if x == "hello" { if y == "world" { // Collapsible println!("Hello world!"); @@ -157,11 +164,13 @@ fn main() { } // Fix #5962 + //~v collapsible_if if matches!(true, true) { if matches!(true, true) {} } // Issue #9375 + //~v collapsible_if if matches!(true, true) && truth() { if matches!(true, true) {} } diff --git a/tests/ui/collapsible_if.stderr b/tests/ui/collapsible_if.stderr index 16df3e433db4..c28cb59e1d13 100644 --- a/tests/ui/collapsible_if.stderr +++ b/tests/ui/collapsible_if.stderr @@ -1,5 +1,5 @@ error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:15:5 + --> $DIR/collapsible_if.rs:16:5 | LL | / if x == "hello" { LL | | if y == "world" { @@ -18,7 +18,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:21:5 + --> $DIR/collapsible_if.rs:23:5 | LL | / if x == "hello" || x == "world" { LL | | if y == "world" || y == "hello" { @@ -35,7 +35,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:27:5 + --> $DIR/collapsible_if.rs:30:5 | LL | / if x == "hello" && x == "world" { LL | | if y == "world" || y == "hello" { @@ -52,7 +52,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:33:5 + --> $DIR/collapsible_if.rs:37:5 | LL | / if x == "hello" || x == "world" { LL | | if y == "world" && y == "hello" { @@ -69,7 +69,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:39:5 + --> $DIR/collapsible_if.rs:44:5 | LL | / if x == "hello" && x == "world" { LL | | if y == "world" && y == "hello" { @@ -86,7 +86,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:45:5 + --> $DIR/collapsible_if.rs:51:5 | LL | / if 42 == 1337 { LL | | if 'a' != 'A' { @@ -103,7 +103,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:101:5 + --> $DIR/collapsible_if.rs:108:5 | LL | / if x == "hello" { LL | | if y == "world" { // Collapsible @@ -120,7 +120,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:160:5 + --> $DIR/collapsible_if.rs:168:5 | LL | / if matches!(true, true) { LL | | if matches!(true, true) {} @@ -128,7 +128,7 @@ LL | | } | |_____^ help: collapse nested if block: `if matches!(true, true) && matches!(true, true) {}` error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:165:5 + --> $DIR/collapsible_if.rs:174:5 | LL | / if matches!(true, true) && truth() { LL | | if matches!(true, true) {} diff --git a/tests/ui/collapsible_match2.rs b/tests/ui/collapsible_match2.rs index 56801f99e454..e639e47873f3 100644 --- a/tests/ui/collapsible_match2.rs +++ b/tests/ui/collapsible_match2.rs @@ -33,6 +33,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> macro_rules! mac { ($outer:expr => $pat:pat, $e:expr => $inner_pat:pat, $then:expr) => { match $outer { + //~v collapsible_match $pat => match $e { $inner_pat => $then, _ => return, diff --git a/tests/ui/collapsible_match2.stderr b/tests/ui/collapsible_match2.stderr index e008355bec8a..45776c75109a 100644 --- a/tests/ui/collapsible_match2.stderr +++ b/tests/ui/collapsible_match2.stderr @@ -41,7 +41,7 @@ LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match2.rs:36:29 + --> $DIR/collapsible_match2.rs:37:29 | LL | $pat => match $e { | _____________________________^ @@ -54,7 +54,7 @@ LL | mac!(res_opt => Ok(val), val => Some(n), foo(n)); | ------------------------------------------------ in this macro invocation | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match2.rs:48:28 + --> $DIR/collapsible_match2.rs:49:28 | LL | mac!(res_opt => Ok(val), val => Some(n), foo(n)); | ^^^ ^^^^^^^ with this pattern @@ -63,7 +63,7 @@ LL | mac!(res_opt => Ok(val), val => Some(n), foo(n)); = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match2.rs:53:20 + --> $DIR/collapsible_match2.rs:54:20 | LL | Some(s) => match *s { | ____________________^ @@ -74,7 +74,7 @@ LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match2.rs:53:14 + --> $DIR/collapsible_match2.rs:54:14 | LL | Some(s) => match *s { | ^ replace this binding @@ -83,7 +83,7 @@ LL | [n] => foo(n), | ^^^ with this pattern error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match2.rs:63:24 + --> $DIR/collapsible_match2.rs:64:24 | LL | Some(ref s) => match s { | ________________________^ @@ -94,7 +94,7 @@ LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match2.rs:63:14 + --> $DIR/collapsible_match2.rs:64:14 | LL | Some(ref s) => match s { | ^^^^^ replace this binding diff --git a/tests/ui/collapsible_str_replace.fixed b/tests/ui/collapsible_str_replace.fixed index 03b393d5a674..7eaab16e27a7 100644 --- a/tests/ui/collapsible_str_replace.fixed +++ b/tests/ui/collapsible_str_replace.fixed @@ -16,32 +16,45 @@ fn main() { // LINT CASES let _ = "hesuo worpd".replace(['s', 'u'], "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace(['s', 'u'], l); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace(['s', 'u', 'p'], "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd" + //~v collapsible_str_replace .replace(['s', 'u', 'p', 'd'], "l"); let _ = "hesuo world".replace([s, 'u'], "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace([s, 'u', 'p'], "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace([s, u, 'p'], "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace([s, u, p], "l"); + //~^ collapsible_str_replace let _ = "hesuo worlp".replace(['s', 'u'], "l").replace('p', "d"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace('s', "x").replace(['u', 'p'], "l"); + //~^ collapsible_str_replace // Note: Future iterations could lint `replace(|c| matches!(c, "su" | 'd' | 'p'), "l")` let _ = "hesudo worpd".replace("su", "l").replace(['d', 'p'], "l"); + //~^ collapsible_str_replace let _ = "hesudo worpd".replace([d, 'p'], "l").replace("su", "l"); + //~^ collapsible_str_replace let _ = "hesuo world".replace([get_filter(), 's'], "l"); + //~^ collapsible_str_replace // NO LINT CASES let _ = "hesuo world".replace('s', "l").replace('u', "p"); @@ -79,4 +92,5 @@ fn msrv_1_57() { #[clippy::msrv = "1.58"] fn msrv_1_58() { let _ = "".replace(['a', 'b'], "1.58"); + //~^ collapsible_str_replace } diff --git a/tests/ui/collapsible_str_replace.rs b/tests/ui/collapsible_str_replace.rs index 364e5493b872..a4e6e338a46d 100644 --- a/tests/ui/collapsible_str_replace.rs +++ b/tests/ui/collapsible_str_replace.rs @@ -16,35 +16,48 @@ fn main() { // LINT CASES let _ = "hesuo worpd".replace('s', "l").replace('u', "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace('s', l).replace('u', l); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace('s', "l").replace('u', "l").replace('p', "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd" + //~v collapsible_str_replace .replace('s', "l") .replace('u', "l") .replace('p', "l") .replace('d', "l"); let _ = "hesuo world".replace(s, "l").replace('u', "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace(s, "l").replace('u', "l").replace('p', "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace(s, "l").replace(u, "l").replace('p', "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace(s, "l").replace(u, "l").replace(p, "l"); + //~^ collapsible_str_replace let _ = "hesuo worlp".replace('s', "l").replace('u', "l").replace('p', "d"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace('s', "x").replace('u', "l").replace('p', "l"); + //~^ collapsible_str_replace // Note: Future iterations could lint `replace(|c| matches!(c, "su" | 'd' | 'p'), "l")` let _ = "hesudo worpd".replace("su", "l").replace('d', "l").replace('p', "l"); + //~^ collapsible_str_replace let _ = "hesudo worpd".replace(d, "l").replace('p', "l").replace("su", "l"); + //~^ collapsible_str_replace let _ = "hesuo world".replace(get_filter(), "l").replace('s', "l"); + //~^ collapsible_str_replace // NO LINT CASES let _ = "hesuo world".replace('s', "l").replace('u', "p"); @@ -82,4 +95,5 @@ fn msrv_1_57() { #[clippy::msrv = "1.58"] fn msrv_1_58() { let _ = "".replace('a', "1.58").replace('b', "1.58"); + //~^ collapsible_str_replace } diff --git a/tests/ui/collapsible_str_replace.stderr b/tests/ui/collapsible_str_replace.stderr index 4b0bd818d2f0..195f8cd917d5 100644 --- a/tests/ui/collapsible_str_replace.stderr +++ b/tests/ui/collapsible_str_replace.stderr @@ -8,19 +8,19 @@ LL | let _ = "hesuo worpd".replace('s', "l").replace('u', "l"); = help: to override `-D warnings` add `#[allow(clippy::collapsible_str_replace)]` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:20:27 + --> $DIR/collapsible_str_replace.rs:21:27 | LL | let _ = "hesuo worpd".replace('s', l).replace('u', l); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['s', 'u'], l)` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:22:27 + --> $DIR/collapsible_str_replace.rs:24:27 | LL | let _ = "hesuo worpd".replace('s', "l").replace('u', "l").replace('p', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['s', 'u', 'p'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:25:10 + --> $DIR/collapsible_str_replace.rs:29:10 | LL | .replace('s', "l") | __________^ @@ -30,61 +30,61 @@ LL | | .replace('d', "l"); | |__________________________^ help: replace with: `replace(['s', 'u', 'p', 'd'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:30:27 + --> $DIR/collapsible_str_replace.rs:34:27 | LL | let _ = "hesuo world".replace(s, "l").replace('u', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([s, 'u'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:32:27 + --> $DIR/collapsible_str_replace.rs:37:27 | LL | let _ = "hesuo worpd".replace(s, "l").replace('u', "l").replace('p', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([s, 'u', 'p'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:34:27 + --> $DIR/collapsible_str_replace.rs:40:27 | LL | let _ = "hesuo worpd".replace(s, "l").replace(u, "l").replace('p', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([s, u, 'p'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:36:27 + --> $DIR/collapsible_str_replace.rs:43:27 | LL | let _ = "hesuo worpd".replace(s, "l").replace(u, "l").replace(p, "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([s, u, p], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:38:27 + --> $DIR/collapsible_str_replace.rs:46:27 | LL | let _ = "hesuo worlp".replace('s', "l").replace('u', "l").replace('p', "d"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['s', 'u'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:40:45 + --> $DIR/collapsible_str_replace.rs:49:45 | LL | let _ = "hesuo worpd".replace('s', "x").replace('u', "l").replace('p', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['u', 'p'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:43:47 + --> $DIR/collapsible_str_replace.rs:53:47 | LL | let _ = "hesudo worpd".replace("su", "l").replace('d', "l").replace('p', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['d', 'p'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:45:28 + --> $DIR/collapsible_str_replace.rs:56:28 | LL | let _ = "hesudo worpd".replace(d, "l").replace('p', "l").replace("su", "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([d, 'p'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:47:27 + --> $DIR/collapsible_str_replace.rs:59:27 | LL | let _ = "hesuo world".replace(get_filter(), "l").replace('s', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([get_filter(), 's'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:84:16 + --> $DIR/collapsible_str_replace.rs:97:16 | LL | let _ = "".replace('a', "1.58").replace('b', "1.58"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['a', 'b'], "1.58")` diff --git a/tests/ui/comparison_to_empty.fixed b/tests/ui/comparison_to_empty.fixed index e102b13a7618..c9ee62f1dbcf 100644 --- a/tests/ui/comparison_to_empty.fixed +++ b/tests/ui/comparison_to_empty.fixed @@ -5,18 +5,19 @@ fn main() { // Disallow comparisons to empty let s = String::new(); - let _ = s.is_empty(); - let _ = !s.is_empty(); + let _ = s.is_empty(); //~ comparison_to_empty + let _ = !s.is_empty(); //~ comparison_to_empty let v = vec![0]; - let _ = v.is_empty(); - let _ = !v.is_empty(); - if (*v).is_empty() {} + let _ = v.is_empty(); //~ comparison_to_empty + let _ = !v.is_empty(); //~ comparison_to_empty + if (*v).is_empty() {} //~ comparison_to_empty let s = [0].as_slice(); - if s.is_empty() {} - if s.is_empty() {} - if s.is_empty() + if s.is_empty() {} //~ comparison_to_empty + if s.is_empty() {} //~ comparison_to_empty + if s.is_empty() //~ comparison_to_empty && s.is_empty() + //~^ comparison_to_empty {} // Allow comparisons to non-empty diff --git a/tests/ui/comparison_to_empty.rs b/tests/ui/comparison_to_empty.rs index 69a6c967d382..898980800523 100644 --- a/tests/ui/comparison_to_empty.rs +++ b/tests/ui/comparison_to_empty.rs @@ -5,18 +5,19 @@ fn main() { // Disallow comparisons to empty let s = String::new(); - let _ = s == ""; - let _ = s != ""; + let _ = s == ""; //~ comparison_to_empty + let _ = s != ""; //~ comparison_to_empty let v = vec![0]; - let _ = v == []; - let _ = v != []; - if let [] = &*v {} + let _ = v == []; //~ comparison_to_empty + let _ = v != []; //~ comparison_to_empty + if let [] = &*v {} //~ comparison_to_empty let s = [0].as_slice(); - if let [] = s {} - if let [] = &*s {} - if let [] = &*s + if let [] = s {} //~ comparison_to_empty + if let [] = &*s {} //~ comparison_to_empty + if let [] = &*s //~ comparison_to_empty && s == [] + //~^ comparison_to_empty {} // Allow comparisons to non-empty diff --git a/tests/ui/crashes/ice-10148.rs b/tests/ui/crashes/ice-10148.rs index d89d94edbcdb..c23ea59dfb45 100644 --- a/tests/ui/crashes/ice-10148.rs +++ b/tests/ui/crashes/ice-10148.rs @@ -5,5 +5,5 @@ extern crate proc_macros; use proc_macros::with_span; fn main() { - println!(with_span!(""something "")); + println!(with_span!(""something "")); //~ println_empty_string } diff --git a/tests/ui/crashes/ice-11422.fixed b/tests/ui/crashes/ice-11422.fixed index ca5721cbb2ba..30bd3ac9d8f5 100644 --- a/tests/ui/crashes/ice-11422.fixed +++ b/tests/ui/crashes/ice-11422.fixed @@ -4,6 +4,7 @@ use std::fmt::Debug; use std::ops::*; fn gen() -> impl PartialOrd + Debug {} +//~^ implied_bounds_in_impls struct Bar {} trait Foo {} diff --git a/tests/ui/crashes/ice-11422.rs b/tests/ui/crashes/ice-11422.rs index 355ec2480bba..09c62e5cc35b 100644 --- a/tests/ui/crashes/ice-11422.rs +++ b/tests/ui/crashes/ice-11422.rs @@ -4,6 +4,7 @@ use std::fmt::Debug; use std::ops::*; fn gen() -> impl PartialOrd + PartialEq + Debug {} +//~^ implied_bounds_in_impls struct Bar {} trait Foo {} diff --git a/tests/ui/crashes/ice-11803.rs b/tests/ui/crashes/ice-11803.rs index 1bb8bf0c746b..37935f4f4280 100644 --- a/tests/ui/crashes/ice-11803.rs +++ b/tests/ui/crashes/ice-11803.rs @@ -2,6 +2,8 @@ #![warn(clippy::impl_trait_in_params)] +//~| impl_trait_in_params +//~v impl_trait_in_params pub fn g>>() { extern "C" fn implementation_detail() {} } diff --git a/tests/ui/crashes/ice-11803.stderr b/tests/ui/crashes/ice-11803.stderr index 338ce6371c95..6ee350038b3b 100644 --- a/tests/ui/crashes/ice-11803.stderr +++ b/tests/ui/crashes/ice-11803.stderr @@ -1,5 +1,5 @@ error: `impl Trait` used as a function parameter - --> $DIR/crashes/ice-11803.rs:5:54 + --> $DIR/crashes/ice-11803.rs:7:54 | LL | pub fn g>>() { | ^^^^^^^^^^ @@ -12,7 +12,7 @@ LL | pub fn g>, { /* Gen | +++++++++++++++++++++++++++++++ error: `impl Trait` used as a function parameter - --> $DIR/crashes/ice-11803.rs:5:33 + --> $DIR/crashes/ice-11803.rs:7:33 | LL | pub fn g>>() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/crate_in_macro_def.fixed b/tests/ui/crate_in_macro_def.fixed index bd91389c8219..d7d8e2a64419 100644 --- a/tests/ui/crate_in_macro_def.fixed +++ b/tests/ui/crate_in_macro_def.fixed @@ -16,6 +16,7 @@ mod unhygienic { macro_rules! print_message_unhygienic { () => { println!("{}", $crate::unhygienic::MESSAGE); + //~^ crate_in_macro_def }; } diff --git a/tests/ui/crate_in_macro_def.rs b/tests/ui/crate_in_macro_def.rs index f6fa338eedbf..9ed9dacee48b 100644 --- a/tests/ui/crate_in_macro_def.rs +++ b/tests/ui/crate_in_macro_def.rs @@ -16,6 +16,7 @@ mod unhygienic { macro_rules! print_message_unhygienic { () => { println!("{}", crate::unhygienic::MESSAGE); + //~^ crate_in_macro_def }; } diff --git a/tests/ui/create_dir.fixed b/tests/ui/create_dir.fixed index 8fbf7dd19b83..2262213aaf7e 100644 --- a/tests/ui/create_dir.fixed +++ b/tests/ui/create_dir.fixed @@ -7,8 +7,8 @@ fn create_dir() {} fn main() { // Should be warned - create_dir_all("foo"); - create_dir_all("bar").unwrap(); + create_dir_all("foo"); //~ create_dir + create_dir_all("bar").unwrap(); //~ create_dir // Shouldn't be warned create_dir(); diff --git a/tests/ui/create_dir.rs b/tests/ui/create_dir.rs index af2c326ec436..de4933e73517 100644 --- a/tests/ui/create_dir.rs +++ b/tests/ui/create_dir.rs @@ -7,8 +7,8 @@ fn create_dir() {} fn main() { // Should be warned - std::fs::create_dir("foo"); - std::fs::create_dir("bar").unwrap(); + std::fs::create_dir("foo"); //~ create_dir + std::fs::create_dir("bar").unwrap(); //~ create_dir // Shouldn't be warned create_dir(); diff --git a/tests/ui/decimal_literal_representation.fixed b/tests/ui/decimal_literal_representation.fixed index e34f48b65dd1..7d750bef8238 100644 --- a/tests/ui/decimal_literal_representation.fixed +++ b/tests/ui/decimal_literal_representation.fixed @@ -13,13 +13,26 @@ fn main() { 2_131_750_925, // 0x7F0F_F00D ); let bad = ( // Hex: + + //~v decimal_literal_representation 0x8005, // 0x8005 + + //~v decimal_literal_representation 0xFF00, // 0xFF00 + + //~v decimal_literal_representation 0x7F0F_F00F, // 0x7F0F_F00F + + //~v decimal_literal_representation 0x7FFF_FFFF, // 0x7FFF_FFFF #[allow(overflowing_literals)] + //~v decimal_literal_representation 0xF0F0_F0F0, // 0xF0F0_F0F0 + + //~v decimal_literal_representation 0x8005_usize, // 0x8005_usize + + //~v decimal_literal_representation 0x7F0F_F00F_isize, // 0x7F0F_F00F_isize ); } diff --git a/tests/ui/decimal_literal_representation.rs b/tests/ui/decimal_literal_representation.rs index bcc4d0df9c0e..6b1c39588d0a 100644 --- a/tests/ui/decimal_literal_representation.rs +++ b/tests/ui/decimal_literal_representation.rs @@ -13,13 +13,26 @@ fn main() { 2_131_750_925, // 0x7F0F_F00D ); let bad = ( // Hex: + + //~v decimal_literal_representation 32_773, // 0x8005 + + //~v decimal_literal_representation 65_280, // 0xFF00 + + //~v decimal_literal_representation 2_131_750_927, // 0x7F0F_F00F + + //~v decimal_literal_representation 2_147_483_647, // 0x7FFF_FFFF #[allow(overflowing_literals)] + //~v decimal_literal_representation 4_042_322_160, // 0xF0F0_F0F0 + + //~v decimal_literal_representation 32_773usize, // 0x8005_usize + + //~v decimal_literal_representation 2_131_750_927isize, // 0x7F0F_F00F_isize ); } diff --git a/tests/ui/decimal_literal_representation.stderr b/tests/ui/decimal_literal_representation.stderr index f1d4d744e731..e21fd1e1b88a 100644 --- a/tests/ui/decimal_literal_representation.stderr +++ b/tests/ui/decimal_literal_representation.stderr @@ -1,5 +1,5 @@ error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:16:9 + --> $DIR/decimal_literal_representation.rs:18:9 | LL | 32_773, // 0x8005 | ^^^^^^ help: consider: `0x8005` @@ -8,37 +8,37 @@ LL | 32_773, // 0x8005 = help: to override `-D warnings` add `#[allow(clippy::decimal_literal_representation)]` error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:17:9 + --> $DIR/decimal_literal_representation.rs:21:9 | LL | 65_280, // 0xFF00 | ^^^^^^ help: consider: `0xFF00` error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:18:9 + --> $DIR/decimal_literal_representation.rs:24:9 | LL | 2_131_750_927, // 0x7F0F_F00F | ^^^^^^^^^^^^^ help: consider: `0x7F0F_F00F` error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:19:9 + --> $DIR/decimal_literal_representation.rs:27:9 | LL | 2_147_483_647, // 0x7FFF_FFFF | ^^^^^^^^^^^^^ help: consider: `0x7FFF_FFFF` error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:21:9 + --> $DIR/decimal_literal_representation.rs:30:9 | LL | 4_042_322_160, // 0xF0F0_F0F0 | ^^^^^^^^^^^^^ help: consider: `0xF0F0_F0F0` error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:22:9 + --> $DIR/decimal_literal_representation.rs:33:9 | LL | 32_773usize, // 0x8005_usize | ^^^^^^^^^^^ help: consider: `0x8005_usize` error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:23:9 + --> $DIR/decimal_literal_representation.rs:36:9 | LL | 2_131_750_927isize, // 0x7F0F_F00F_isize | ^^^^^^^^^^^^^^^^^^ help: consider: `0x7F0F_F00F_isize` diff --git a/tests/ui/declare_interior_mutable_const/others.rs b/tests/ui/declare_interior_mutable_const/others.rs index f0ff1946513b..5f632ba4a1ec 100644 --- a/tests/ui/declare_interior_mutable_const/others.rs +++ b/tests/ui/declare_interior_mutable_const/others.rs @@ -13,7 +13,7 @@ const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec, u8) = ([ATOMIC], Vec::n macro_rules! declare_const { ($name:ident: $ty:ty = $e:expr) => { - const $name: $ty = $e; + const $name: $ty = $e; //~ declare_interior_mutable_const }; } declare_const!(_ONCE: Once = Once::new()); @@ -41,6 +41,7 @@ mod issue_8493 { macro_rules! issue_8493 { () => { const _BAZ: Cell = Cell::new(0); + //~^ declare_interior_mutable_const static _FOOBAR: () = { thread_local! { static _VAR: Cell = const { Cell::new(0) }; diff --git a/tests/ui/declare_interior_mutable_const/traits.rs b/tests/ui/declare_interior_mutable_const/traits.rs index d91da14cb999..c5e37da9d744 100644 --- a/tests/ui/declare_interior_mutable_const/traits.rs +++ b/tests/ui/declare_interior_mutable_const/traits.rs @@ -6,7 +6,7 @@ use std::sync::atomic::AtomicUsize; macro_rules! declare_const { ($name:ident: $ty:ty = $e:expr) => { - const $name: $ty = $e; + const $name: $ty = $e; //~ declare_interior_mutable_const }; } diff --git a/tests/ui/default_constructed_unit_structs.fixed b/tests/ui/default_constructed_unit_structs.fixed index 3047c221d457..76a1893e3b2f 100644 --- a/tests/ui/default_constructed_unit_structs.fixed +++ b/tests/ui/default_constructed_unit_structs.fixed @@ -8,7 +8,7 @@ struct UnitStruct; impl UnitStruct { fn new() -> Self { //should lint - Self + Self //~ default_constructed_unit_structs } } @@ -51,6 +51,7 @@ impl NormalStruct { // should lint Self { inner: PhantomData, + //~^ default_constructed_unit_structs } } @@ -124,9 +125,13 @@ mod issue_10755 { fn main() { // should lint let _ = PhantomData::; + //~^ default_constructed_unit_structs let _: PhantomData = PhantomData; + //~^ default_constructed_unit_structs let _: PhantomData = std::marker::PhantomData; + //~^ default_constructed_unit_structs let _ = UnitStruct; + //~^ default_constructed_unit_structs // should not lint let _ = TupleStruct::default(); diff --git a/tests/ui/default_constructed_unit_structs.rs b/tests/ui/default_constructed_unit_structs.rs index 66afedb23801..937edf7c0285 100644 --- a/tests/ui/default_constructed_unit_structs.rs +++ b/tests/ui/default_constructed_unit_structs.rs @@ -8,7 +8,7 @@ struct UnitStruct; impl UnitStruct { fn new() -> Self { //should lint - Self::default() + Self::default() //~ default_constructed_unit_structs } } @@ -51,6 +51,7 @@ impl NormalStruct { // should lint Self { inner: PhantomData::default(), + //~^ default_constructed_unit_structs } } @@ -124,9 +125,13 @@ mod issue_10755 { fn main() { // should lint let _ = PhantomData::::default(); + //~^ default_constructed_unit_structs let _: PhantomData = PhantomData::default(); + //~^ default_constructed_unit_structs let _: PhantomData = std::marker::PhantomData::default(); + //~^ default_constructed_unit_structs let _ = UnitStruct::default(); + //~^ default_constructed_unit_structs // should not lint let _ = TupleStruct::default(); diff --git a/tests/ui/default_constructed_unit_structs.stderr b/tests/ui/default_constructed_unit_structs.stderr index 434c72aa9b17..1488b6f9189b 100644 --- a/tests/ui/default_constructed_unit_structs.stderr +++ b/tests/ui/default_constructed_unit_structs.stderr @@ -14,25 +14,25 @@ LL | inner: PhantomData::default(), | ^^^^^^^^^^^ help: remove this call to `default` error: use of `default` to create a unit struct - --> $DIR/default_constructed_unit_structs.rs:126:33 + --> $DIR/default_constructed_unit_structs.rs:127:33 | LL | let _ = PhantomData::::default(); | ^^^^^^^^^^^ help: remove this call to `default` error: use of `default` to create a unit struct - --> $DIR/default_constructed_unit_structs.rs:127:42 + --> $DIR/default_constructed_unit_structs.rs:129:42 | LL | let _: PhantomData = PhantomData::default(); | ^^^^^^^^^^^ help: remove this call to `default` error: use of `default` to create a unit struct - --> $DIR/default_constructed_unit_structs.rs:128:55 + --> $DIR/default_constructed_unit_structs.rs:131:55 | LL | let _: PhantomData = std::marker::PhantomData::default(); | ^^^^^^^^^^^ help: remove this call to `default` error: use of `default` to create a unit struct - --> $DIR/default_constructed_unit_structs.rs:129:23 + --> $DIR/default_constructed_unit_structs.rs:133:23 | LL | let _ = UnitStruct::default(); | ^^^^^^^^^^^ help: remove this call to `default` diff --git a/tests/ui/default_instead_of_iter_empty.fixed b/tests/ui/default_instead_of_iter_empty.fixed index 3298a222bda6..548de9379927 100644 --- a/tests/ui/default_instead_of_iter_empty.fixed +++ b/tests/ui/default_instead_of_iter_empty.fixed @@ -10,8 +10,11 @@ struct Iter { fn main() { // Do lint. let _ = std::iter::empty::(); + //~^ default_instead_of_iter_empty let _ = std::iter::empty::>(); + //~^ default_instead_of_iter_empty let _foo: std::iter::Empty = std::iter::empty(); + //~^ default_instead_of_iter_empty // Do not lint. let _ = Vec::::default(); diff --git a/tests/ui/default_instead_of_iter_empty.rs b/tests/ui/default_instead_of_iter_empty.rs index 75b088a99590..824cc20566de 100644 --- a/tests/ui/default_instead_of_iter_empty.rs +++ b/tests/ui/default_instead_of_iter_empty.rs @@ -10,8 +10,11 @@ struct Iter { fn main() { // Do lint. let _ = std::iter::Empty::::default(); + //~^ default_instead_of_iter_empty let _ = std::iter::Empty::>::default(); + //~^ default_instead_of_iter_empty let _foo: std::iter::Empty = std::iter::Empty::default(); + //~^ default_instead_of_iter_empty // Do not lint. let _ = Vec::::default(); diff --git a/tests/ui/default_instead_of_iter_empty.stderr b/tests/ui/default_instead_of_iter_empty.stderr index 48d6c02d150d..47428ca7ccd0 100644 --- a/tests/ui/default_instead_of_iter_empty.stderr +++ b/tests/ui/default_instead_of_iter_empty.stderr @@ -8,13 +8,13 @@ LL | let _ = std::iter::Empty::::default(); = help: to override `-D warnings` add `#[allow(clippy::default_instead_of_iter_empty)]` error: `std::iter::empty()` is the more idiomatic way - --> $DIR/default_instead_of_iter_empty.rs:13:13 + --> $DIR/default_instead_of_iter_empty.rs:14:13 | LL | let _ = std::iter::Empty::>::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::empty::>()` error: `std::iter::empty()` is the more idiomatic way - --> $DIR/default_instead_of_iter_empty.rs:14:41 + --> $DIR/default_instead_of_iter_empty.rs:16:41 | LL | let _foo: std::iter::Empty = std::iter::Empty::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::empty()` diff --git a/tests/ui/default_instead_of_iter_empty_no_std.fixed b/tests/ui/default_instead_of_iter_empty_no_std.fixed index 7300bd9bd2ab..76d75ea7e591 100644 --- a/tests/ui/default_instead_of_iter_empty_no_std.fixed +++ b/tests/ui/default_instead_of_iter_empty_no_std.fixed @@ -21,7 +21,9 @@ struct Iter { fn main() { // Do lint. let _ = core::iter::empty::(); + //~^ default_instead_of_iter_empty let _foo: core::iter::Empty = core::iter::empty(); + //~^ default_instead_of_iter_empty // Do not lint. let _ = Iter::default(); diff --git a/tests/ui/default_instead_of_iter_empty_no_std.rs b/tests/ui/default_instead_of_iter_empty_no_std.rs index 0bc5c7169d12..639b73ba38de 100644 --- a/tests/ui/default_instead_of_iter_empty_no_std.rs +++ b/tests/ui/default_instead_of_iter_empty_no_std.rs @@ -21,7 +21,9 @@ struct Iter { fn main() { // Do lint. let _ = core::iter::Empty::::default(); + //~^ default_instead_of_iter_empty let _foo: core::iter::Empty = core::iter::Empty::default(); + //~^ default_instead_of_iter_empty // Do not lint. let _ = Iter::default(); diff --git a/tests/ui/default_instead_of_iter_empty_no_std.stderr b/tests/ui/default_instead_of_iter_empty_no_std.stderr index 747a31ecbf36..60f657d269aa 100644 --- a/tests/ui/default_instead_of_iter_empty_no_std.stderr +++ b/tests/ui/default_instead_of_iter_empty_no_std.stderr @@ -8,7 +8,7 @@ LL | let _ = core::iter::Empty::::default(); = help: to override `-D warnings` add `#[allow(clippy::default_instead_of_iter_empty)]` error: `core::iter::empty()` is the more idiomatic way - --> $DIR/default_instead_of_iter_empty_no_std.rs:24:42 + --> $DIR/default_instead_of_iter_empty_no_std.rs:25:42 | LL | let _foo: core::iter::Empty = core::iter::Empty::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `core::iter::empty()` diff --git a/tests/ui/default_numeric_fallback_f64.fixed b/tests/ui/default_numeric_fallback_f64.fixed index 00f0d7644340..a64b7342aca2 100644 --- a/tests/ui/default_numeric_fallback_f64.fixed +++ b/tests/ui/default_numeric_fallback_f64.fixed @@ -18,11 +18,20 @@ use proc_macros::{external, inline_macros}; mod basic_expr { fn test() { // Should lint unsuffixed literals typed `f64`. - let x = 0.12_f64; + let x = 0.12_f64; //~ default_numeric_fallback let x = [1.0_f64, 2.0_f64, 3.0_f64]; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback let x = if true { (1.0_f64, 2.0_f64) } else { (3.0_f64, 4.0_f64) }; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback + + //~v default_numeric_fallback let x = match 1.0_f64 { - _ => 1.0_f64, + _ => 1.0_f64, //~ default_numeric_fallback }; // Should NOT lint suffixed literals. @@ -41,7 +50,7 @@ mod nested_local { fn test() { let x: _ = { // Should lint this because this literal is not bound to any types. - let y = 1.0_f64; + let y = 1.0_f64; //~ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1. @@ -49,13 +58,13 @@ mod nested_local { let x: _ = if true { // Should lint this because this literal is not bound to any types. - let y = 1.0_f64; + let y = 1.0_f64; //~ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1. } else { // Should lint this because this literal is not bound to any types. - let y = 1.0_f64; + let y = 1.0_f64; //~ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 2. @@ -63,7 +72,7 @@ mod nested_local { const X: f32 = { // Should lint this because this literal is not bound to any types. - let y = 1.0_f64; + let y = 1.0_f64; //~ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1. @@ -79,11 +88,11 @@ mod function_def { fn test() { // Should lint this because return type is inferred to `f64` and NOT bound to a concrete // type. - let f = || -> _ { 1.0_f64 }; + let f = || -> _ { 1.0_f64 }; //~ default_numeric_fallback // Even though the output type is specified, // this unsuffixed literal is linted to reduce heuristics and keep codebase simple. - let f = || -> f64 { 1.0_f64 }; + let f = || -> f64 { 1.0_f64 }; //~ default_numeric_fallback } } @@ -97,10 +106,10 @@ mod function_calls { concrete_arg(1.); // Should lint this because the argument type is inferred to `f64` and NOT bound to a concrete type. - generic_arg(1.0_f64); + generic_arg(1.0_f64); //~ default_numeric_fallback // Should lint this because the argument type is inferred to `f64` and NOT bound to a concrete type. - let x: _ = generic_arg(1.0_f64); + let x: _ = generic_arg(1.0_f64); //~ default_numeric_fallback } } @@ -118,10 +127,11 @@ mod struct_ctor { ConcreteStruct { x: 1. }; // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. - GenericStruct { x: 1.0_f64 }; + GenericStruct { x: 1.0_f64 }; //~ default_numeric_fallback // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. let _ = GenericStruct { x: 1.0_f64 }; + //~^ default_numeric_fallback } } @@ -139,7 +149,7 @@ mod enum_ctor { ConcreteEnum::X(1.); // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. - GenericEnum::X(1.0_f64); + GenericEnum::X(1.0_f64); //~ default_numeric_fallback } } @@ -159,7 +169,7 @@ mod method_calls { s.concrete_arg(1.); // Should lint this because the argument type is bound to a concrete type. - s.generic_arg(1.0_f64); + s.generic_arg(1.0_f64); //~ default_numeric_fallback } } @@ -169,7 +179,7 @@ mod in_macro { // Should lint in internal macro. #[inline_macros] fn internal() { - inline!(let x = 22.0_f64;); + inline!(let x = 22.0_f64;); //~ default_numeric_fallback } // Should NOT lint in external macro. diff --git a/tests/ui/default_numeric_fallback_f64.rs b/tests/ui/default_numeric_fallback_f64.rs index 942cedac2753..92f71da38de1 100644 --- a/tests/ui/default_numeric_fallback_f64.rs +++ b/tests/ui/default_numeric_fallback_f64.rs @@ -18,11 +18,20 @@ use proc_macros::{external, inline_macros}; mod basic_expr { fn test() { // Should lint unsuffixed literals typed `f64`. - let x = 0.12; + let x = 0.12; //~ default_numeric_fallback let x = [1., 2., 3.]; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback let x = if true { (1., 2.) } else { (3., 4.) }; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback + + //~v default_numeric_fallback let x = match 1. { - _ => 1., + _ => 1., //~ default_numeric_fallback }; // Should NOT lint suffixed literals. @@ -41,7 +50,7 @@ mod nested_local { fn test() { let x: _ = { // Should lint this because this literal is not bound to any types. - let y = 1.; + let y = 1.; //~ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1. @@ -49,13 +58,13 @@ mod nested_local { let x: _ = if true { // Should lint this because this literal is not bound to any types. - let y = 1.; + let y = 1.; //~ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1. } else { // Should lint this because this literal is not bound to any types. - let y = 1.; + let y = 1.; //~ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 2. @@ -63,7 +72,7 @@ mod nested_local { const X: f32 = { // Should lint this because this literal is not bound to any types. - let y = 1.; + let y = 1.; //~ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1. @@ -79,11 +88,11 @@ mod function_def { fn test() { // Should lint this because return type is inferred to `f64` and NOT bound to a concrete // type. - let f = || -> _ { 1. }; + let f = || -> _ { 1. }; //~ default_numeric_fallback // Even though the output type is specified, // this unsuffixed literal is linted to reduce heuristics and keep codebase simple. - let f = || -> f64 { 1. }; + let f = || -> f64 { 1. }; //~ default_numeric_fallback } } @@ -97,10 +106,10 @@ mod function_calls { concrete_arg(1.); // Should lint this because the argument type is inferred to `f64` and NOT bound to a concrete type. - generic_arg(1.); + generic_arg(1.); //~ default_numeric_fallback // Should lint this because the argument type is inferred to `f64` and NOT bound to a concrete type. - let x: _ = generic_arg(1.); + let x: _ = generic_arg(1.); //~ default_numeric_fallback } } @@ -118,10 +127,11 @@ mod struct_ctor { ConcreteStruct { x: 1. }; // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. - GenericStruct { x: 1. }; + GenericStruct { x: 1. }; //~ default_numeric_fallback // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. let _ = GenericStruct { x: 1. }; + //~^ default_numeric_fallback } } @@ -139,7 +149,7 @@ mod enum_ctor { ConcreteEnum::X(1.); // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. - GenericEnum::X(1.); + GenericEnum::X(1.); //~ default_numeric_fallback } } @@ -159,7 +169,7 @@ mod method_calls { s.concrete_arg(1.); // Should lint this because the argument type is bound to a concrete type. - s.generic_arg(1.); + s.generic_arg(1.); //~ default_numeric_fallback } } @@ -169,7 +179,7 @@ mod in_macro { // Should lint in internal macro. #[inline_macros] fn internal() { - inline!(let x = 22.;); + inline!(let x = 22.;); //~ default_numeric_fallback } // Should NOT lint in external macro. diff --git a/tests/ui/default_numeric_fallback_f64.stderr b/tests/ui/default_numeric_fallback_f64.stderr index c95679c9eb81..6eab0fdc2640 100644 --- a/tests/ui/default_numeric_fallback_f64.stderr +++ b/tests/ui/default_numeric_fallback_f64.stderr @@ -26,115 +26,115 @@ LL | let x = [1., 2., 3.]; | ^^ help: consider adding suffix: `3.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:23:28 + --> $DIR/default_numeric_fallback_f64.rs:26:28 | LL | let x = if true { (1., 2.) } else { (3., 4.) }; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:23:32 + --> $DIR/default_numeric_fallback_f64.rs:26:32 | LL | let x = if true { (1., 2.) } else { (3., 4.) }; | ^^ help: consider adding suffix: `2.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:23:46 + --> $DIR/default_numeric_fallback_f64.rs:26:46 | LL | let x = if true { (1., 2.) } else { (3., 4.) }; | ^^ help: consider adding suffix: `3.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:23:50 + --> $DIR/default_numeric_fallback_f64.rs:26:50 | LL | let x = if true { (1., 2.) } else { (3., 4.) }; | ^^ help: consider adding suffix: `4.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:24:23 + --> $DIR/default_numeric_fallback_f64.rs:33:23 | LL | let x = match 1. { | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:25:18 + --> $DIR/default_numeric_fallback_f64.rs:34:18 | LL | _ => 1., | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:44:21 + --> $DIR/default_numeric_fallback_f64.rs:53:21 | LL | let y = 1.; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:52:21 + --> $DIR/default_numeric_fallback_f64.rs:61:21 | LL | let y = 1.; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:58:21 + --> $DIR/default_numeric_fallback_f64.rs:67:21 | LL | let y = 1.; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:66:21 + --> $DIR/default_numeric_fallback_f64.rs:75:21 | LL | let y = 1.; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:82:27 + --> $DIR/default_numeric_fallback_f64.rs:91:27 | LL | let f = || -> _ { 1. }; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:86:29 + --> $DIR/default_numeric_fallback_f64.rs:95:29 | LL | let f = || -> f64 { 1. }; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:100:21 + --> $DIR/default_numeric_fallback_f64.rs:109:21 | LL | generic_arg(1.); | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:103:32 + --> $DIR/default_numeric_fallback_f64.rs:112:32 | LL | let x: _ = generic_arg(1.); | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:121:28 + --> $DIR/default_numeric_fallback_f64.rs:130:28 | LL | GenericStruct { x: 1. }; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:124:36 + --> $DIR/default_numeric_fallback_f64.rs:133:36 | LL | let _ = GenericStruct { x: 1. }; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:142:24 + --> $DIR/default_numeric_fallback_f64.rs:152:24 | LL | GenericEnum::X(1.); | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:162:23 + --> $DIR/default_numeric_fallback_f64.rs:172:23 | LL | s.generic_arg(1.); | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:172:25 + --> $DIR/default_numeric_fallback_f64.rs:182:25 | LL | inline!(let x = 22.;); | ^^^ help: consider adding suffix: `22.0_f64` diff --git a/tests/ui/default_numeric_fallback_i32.fixed b/tests/ui/default_numeric_fallback_i32.fixed index e7038082c089..f45014bced1f 100644 --- a/tests/ui/default_numeric_fallback_i32.fixed +++ b/tests/ui/default_numeric_fallback_i32.fixed @@ -18,12 +18,23 @@ use proc_macros::{external, inline_macros}; mod basic_expr { fn test() { // Should lint unsuffixed literals typed `i32`. - let x = 22_i32; + let x = 22_i32; //~ default_numeric_fallback let x = [1_i32, 2_i32, 3_i32]; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback let x = if true { (1_i32, 2_i32) } else { (3_i32, 4_i32) }; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback + + //~v default_numeric_fallback let x = match 1_i32 { 1_i32 => 1_i32, - _ => 2_i32, + //~^ default_numeric_fallback + //~| default_numeric_fallback + _ => 2_i32, //~ default_numeric_fallback }; // Should NOT lint suffixed literals. @@ -42,7 +53,7 @@ mod nested_local { fn test() { let x: _ = { // Should lint this because this literal is not bound to any types. - let y = 1_i32; + let y = 1_i32; //~ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1 @@ -50,13 +61,13 @@ mod nested_local { let x: _ = if true { // Should lint this because this literal is not bound to any types. - let y = 1_i32; + let y = 1_i32; //~ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1 } else { // Should lint this because this literal is not bound to any types. - let y = 1_i32; + let y = 1_i32; //~ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 2 @@ -64,7 +75,7 @@ mod nested_local { const CONST_X: i32 = { // Should lint this because this literal is not bound to any types. - let y = 1_i32; + let y = 1_i32; //~ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1 @@ -80,11 +91,11 @@ mod function_def { fn test() { // Should lint this because return type is inferred to `i32` and NOT bound to a concrete // type. - let f = || -> _ { 1_i32 }; + let f = || -> _ { 1_i32 }; //~ default_numeric_fallback // Even though the output type is specified, // this unsuffixed literal is linted to reduce heuristics and keep codebase simple. - let f = || -> i32 { 1_i32 }; + let f = || -> i32 { 1_i32 }; //~ default_numeric_fallback } } @@ -98,10 +109,10 @@ mod function_calls { concrete_arg(1); // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type. - generic_arg(1_i32); + generic_arg(1_i32); //~ default_numeric_fallback // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type. - let x: _ = generic_arg(1_i32); + let x: _ = generic_arg(1_i32); //~ default_numeric_fallback } } @@ -119,10 +130,10 @@ mod struct_ctor { ConcreteStruct { x: 1 }; // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type. - GenericStruct { x: 1_i32 }; + GenericStruct { x: 1_i32 }; //~ default_numeric_fallback // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type. - let _ = GenericStruct { x: 1_i32 }; + let _ = GenericStruct { x: 1_i32 }; //~ default_numeric_fallback } } @@ -140,7 +151,7 @@ mod enum_ctor { ConcreteEnum::X(1); // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type. - GenericEnum::X(1_i32); + GenericEnum::X(1_i32); //~ default_numeric_fallback } } @@ -160,7 +171,7 @@ mod method_calls { s.concrete_arg(1); // Should lint this because the argument type is bound to a concrete type. - s.generic_arg(1_i32); + s.generic_arg(1_i32); //~ default_numeric_fallback } } @@ -170,7 +181,7 @@ mod in_macro { // Should lint in internal macro. #[inline_macros] fn internal() { - inline!(let x = 22_i32;); + inline!(let x = 22_i32;); //~ default_numeric_fallback } // Should NOT lint in external macro. @@ -213,6 +224,9 @@ mod type_already_inferred { // Should NOT lint in `vec!` call if the type was already stated let data_i32: Vec = vec![1, 2, 3]; let data_i32 = vec![1_i32, 2_i32, 3_i32]; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback } } diff --git a/tests/ui/default_numeric_fallback_i32.rs b/tests/ui/default_numeric_fallback_i32.rs index d8eeda704919..539d54998027 100644 --- a/tests/ui/default_numeric_fallback_i32.rs +++ b/tests/ui/default_numeric_fallback_i32.rs @@ -18,12 +18,23 @@ use proc_macros::{external, inline_macros}; mod basic_expr { fn test() { // Should lint unsuffixed literals typed `i32`. - let x = 22; + let x = 22; //~ default_numeric_fallback let x = [1, 2, 3]; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback let x = if true { (1, 2) } else { (3, 4) }; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback + + //~v default_numeric_fallback let x = match 1 { 1 => 1, - _ => 2, + //~^ default_numeric_fallback + //~| default_numeric_fallback + _ => 2, //~ default_numeric_fallback }; // Should NOT lint suffixed literals. @@ -42,7 +53,7 @@ mod nested_local { fn test() { let x: _ = { // Should lint this because this literal is not bound to any types. - let y = 1; + let y = 1; //~ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1 @@ -50,13 +61,13 @@ mod nested_local { let x: _ = if true { // Should lint this because this literal is not bound to any types. - let y = 1; + let y = 1; //~ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1 } else { // Should lint this because this literal is not bound to any types. - let y = 1; + let y = 1; //~ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 2 @@ -64,7 +75,7 @@ mod nested_local { const CONST_X: i32 = { // Should lint this because this literal is not bound to any types. - let y = 1; + let y = 1; //~ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1 @@ -80,11 +91,11 @@ mod function_def { fn test() { // Should lint this because return type is inferred to `i32` and NOT bound to a concrete // type. - let f = || -> _ { 1 }; + let f = || -> _ { 1 }; //~ default_numeric_fallback // Even though the output type is specified, // this unsuffixed literal is linted to reduce heuristics and keep codebase simple. - let f = || -> i32 { 1 }; + let f = || -> i32 { 1 }; //~ default_numeric_fallback } } @@ -98,10 +109,10 @@ mod function_calls { concrete_arg(1); // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type. - generic_arg(1); + generic_arg(1); //~ default_numeric_fallback // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type. - let x: _ = generic_arg(1); + let x: _ = generic_arg(1); //~ default_numeric_fallback } } @@ -119,10 +130,10 @@ mod struct_ctor { ConcreteStruct { x: 1 }; // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type. - GenericStruct { x: 1 }; + GenericStruct { x: 1 }; //~ default_numeric_fallback // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type. - let _ = GenericStruct { x: 1 }; + let _ = GenericStruct { x: 1 }; //~ default_numeric_fallback } } @@ -140,7 +151,7 @@ mod enum_ctor { ConcreteEnum::X(1); // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type. - GenericEnum::X(1); + GenericEnum::X(1); //~ default_numeric_fallback } } @@ -160,7 +171,7 @@ mod method_calls { s.concrete_arg(1); // Should lint this because the argument type is bound to a concrete type. - s.generic_arg(1); + s.generic_arg(1); //~ default_numeric_fallback } } @@ -170,7 +181,7 @@ mod in_macro { // Should lint in internal macro. #[inline_macros] fn internal() { - inline!(let x = 22;); + inline!(let x = 22;); //~ default_numeric_fallback } // Should NOT lint in external macro. @@ -213,6 +224,9 @@ mod type_already_inferred { // Should NOT lint in `vec!` call if the type was already stated let data_i32: Vec = vec![1, 2, 3]; let data_i32 = vec![1, 2, 3]; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback } } diff --git a/tests/ui/default_numeric_fallback_i32.stderr b/tests/ui/default_numeric_fallback_i32.stderr index 7663977fb65a..78e9e8e563d1 100644 --- a/tests/ui/default_numeric_fallback_i32.stderr +++ b/tests/ui/default_numeric_fallback_i32.stderr @@ -26,127 +26,127 @@ LL | let x = [1, 2, 3]; | ^ help: consider adding suffix: `3_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:23:28 + --> $DIR/default_numeric_fallback_i32.rs:26:28 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:23:31 + --> $DIR/default_numeric_fallback_i32.rs:26:31 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:23:44 + --> $DIR/default_numeric_fallback_i32.rs:26:44 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `3_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:23:47 + --> $DIR/default_numeric_fallback_i32.rs:26:47 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `4_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:24:23 + --> $DIR/default_numeric_fallback_i32.rs:33:23 | LL | let x = match 1 { | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:25:13 + --> $DIR/default_numeric_fallback_i32.rs:34:13 | LL | 1 => 1, | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:25:18 + --> $DIR/default_numeric_fallback_i32.rs:34:18 | LL | 1 => 1, | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:26:18 + --> $DIR/default_numeric_fallback_i32.rs:37:18 | LL | _ => 2, | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:45:21 + --> $DIR/default_numeric_fallback_i32.rs:56:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:53:21 + --> $DIR/default_numeric_fallback_i32.rs:64:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:59:21 + --> $DIR/default_numeric_fallback_i32.rs:70:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:67:21 + --> $DIR/default_numeric_fallback_i32.rs:78:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:83:27 + --> $DIR/default_numeric_fallback_i32.rs:94:27 | LL | let f = || -> _ { 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:87:29 + --> $DIR/default_numeric_fallback_i32.rs:98:29 | LL | let f = || -> i32 { 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:101:21 + --> $DIR/default_numeric_fallback_i32.rs:112:21 | LL | generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:104:32 + --> $DIR/default_numeric_fallback_i32.rs:115:32 | LL | let x: _ = generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:122:28 + --> $DIR/default_numeric_fallback_i32.rs:133:28 | LL | GenericStruct { x: 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:125:36 + --> $DIR/default_numeric_fallback_i32.rs:136:36 | LL | let _ = GenericStruct { x: 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:143:24 + --> $DIR/default_numeric_fallback_i32.rs:154:24 | LL | GenericEnum::X(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:163:23 + --> $DIR/default_numeric_fallback_i32.rs:174:23 | LL | s.generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:173:25 + --> $DIR/default_numeric_fallback_i32.rs:184:25 | LL | inline!(let x = 22;); | ^^ help: consider adding suffix: `22_i32` @@ -154,19 +154,19 @@ LL | inline!(let x = 22;); = note: this error originates in the macro `__inline_mac_fn_internal` (in Nightly builds, run with -Z macro-backtrace for more info) error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:215:29 + --> $DIR/default_numeric_fallback_i32.rs:226:29 | LL | let data_i32 = vec![1, 2, 3]; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:215:32 + --> $DIR/default_numeric_fallback_i32.rs:226:32 | LL | let data_i32 = vec![1, 2, 3]; | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:215:35 + --> $DIR/default_numeric_fallback_i32.rs:226:35 | LL | let data_i32 = vec![1, 2, 3]; | ^ help: consider adding suffix: `3_i32` diff --git a/tests/ui/default_trait_access.fixed b/tests/ui/default_trait_access.fixed index 6f1e72c5a6c0..86b2b902136d 100644 --- a/tests/ui/default_trait_access.fixed +++ b/tests/ui/default_trait_access.fixed @@ -10,17 +10,19 @@ use std::default::Default as D2; use std::{default, string}; fn main() { - let s1: String = String::default(); + let s1: String = String::default(); //~ default_trait_access let s2 = String::default(); - let s3: String = String::default(); + let s3: String = String::default(); //~ default_trait_access let s4: String = String::default(); + //~^ default_trait_access let s5 = string::String::default(); let s6: String = String::default(); + //~^ default_trait_access let s7 = std::string::String::default(); @@ -31,18 +33,22 @@ fn main() { let s10 = DerivedDefault::default(); let s11: GenericDerivedDefault = GenericDerivedDefault::default(); + //~^ default_trait_access let s12 = GenericDerivedDefault::::default(); let s13 = TupleDerivedDefault::default(); let s14: TupleDerivedDefault = TupleDerivedDefault::default(); + //~^ default_trait_access let s15: ArrayDerivedDefault = ArrayDerivedDefault::default(); + //~^ default_trait_access let s16 = ArrayDerivedDefault::default(); let s17: TupleStructDerivedDefault = TupleStructDerivedDefault::default(); + //~^ default_trait_access let s18 = TupleStructDerivedDefault::default(); diff --git a/tests/ui/default_trait_access.rs b/tests/ui/default_trait_access.rs index 5528ca8b7936..f69d2d23a8f4 100644 --- a/tests/ui/default_trait_access.rs +++ b/tests/ui/default_trait_access.rs @@ -10,17 +10,19 @@ use std::default::Default as D2; use std::{default, string}; fn main() { - let s1: String = Default::default(); + let s1: String = Default::default(); //~ default_trait_access let s2 = String::default(); - let s3: String = D2::default(); + let s3: String = D2::default(); //~ default_trait_access let s4: String = std::default::Default::default(); + //~^ default_trait_access let s5 = string::String::default(); let s6: String = default::Default::default(); + //~^ default_trait_access let s7 = std::string::String::default(); @@ -31,18 +33,22 @@ fn main() { let s10 = DerivedDefault::default(); let s11: GenericDerivedDefault = Default::default(); + //~^ default_trait_access let s12 = GenericDerivedDefault::::default(); let s13 = TupleDerivedDefault::default(); let s14: TupleDerivedDefault = Default::default(); + //~^ default_trait_access let s15: ArrayDerivedDefault = Default::default(); + //~^ default_trait_access let s16 = ArrayDerivedDefault::default(); let s17: TupleStructDerivedDefault = Default::default(); + //~^ default_trait_access let s18 = TupleStructDerivedDefault::default(); diff --git a/tests/ui/default_trait_access.stderr b/tests/ui/default_trait_access.stderr index e53c8e2c79ff..14245f961e6d 100644 --- a/tests/ui/default_trait_access.stderr +++ b/tests/ui/default_trait_access.stderr @@ -23,31 +23,31 @@ LL | let s4: String = std::default::Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `String::default()` error: calling `String::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:23:22 + --> $DIR/default_trait_access.rs:24:22 | LL | let s6: String = default::Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `String::default()` error: calling `GenericDerivedDefault::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:33:46 + --> $DIR/default_trait_access.rs:35:46 | LL | let s11: GenericDerivedDefault = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `GenericDerivedDefault::default()` error: calling `TupleDerivedDefault::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:39:36 + --> $DIR/default_trait_access.rs:42:36 | LL | let s14: TupleDerivedDefault = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `TupleDerivedDefault::default()` error: calling `ArrayDerivedDefault::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:41:36 + --> $DIR/default_trait_access.rs:45:36 | LL | let s15: ArrayDerivedDefault = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `ArrayDerivedDefault::default()` error: calling `TupleStructDerivedDefault::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:45:42 + --> $DIR/default_trait_access.rs:50:42 | LL | let s17: TupleStructDerivedDefault = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `TupleStructDerivedDefault::default()` diff --git a/tests/ui/deref_addrof.fixed b/tests/ui/deref_addrof.fixed index aa1cf19b76f9..861b4e2cc40e 100644 --- a/tests/ui/deref_addrof.fixed +++ b/tests/ui/deref_addrof.fixed @@ -20,27 +20,27 @@ fn main() { let a = 10; let aref = &a; - let b = a; + let b = a; //~ deref_addrof - let b = get_number(); + let b = get_number(); //~ deref_addrof let b = *get_reference(&a); let bytes: Vec = vec![1, 2, 3, 4]; - let b = bytes[1..2][0]; + let b = bytes[1..2][0]; //~ deref_addrof //This produces a suggestion of 'let b = (a);' which //will trigger the 'unused_parens' lint - let b = (a); + let b = (a); //~ deref_addrof - let b = a; + let b = a; //~ deref_addrof #[rustfmt::skip] - let b = a; + let b = a; //~ deref_addrof - let b = &a; + let b = &a; //~ deref_addrof - let b = *aref; + let b = *aref; //~ deref_addrof let _ = unsafe { *core::ptr::addr_of!(a) }; } @@ -50,10 +50,10 @@ pub struct S; #[inline_macros] impl S { pub fn f(&self) -> &Self { - inline!($(@expr self)) + inline!($(@expr self)) //~ deref_addrof } #[allow(unused_mut)] // mut will be unused, once the macro is fixed pub fn f_mut(mut self) -> Self { - inline!($(@expr self)) + inline!($(@expr self)) //~ deref_addrof } } diff --git a/tests/ui/deref_addrof.rs b/tests/ui/deref_addrof.rs index 38796aef390e..c22515634af9 100644 --- a/tests/ui/deref_addrof.rs +++ b/tests/ui/deref_addrof.rs @@ -20,27 +20,27 @@ fn main() { let a = 10; let aref = &a; - let b = *&a; + let b = *&a; //~ deref_addrof - let b = *&get_number(); + let b = *&get_number(); //~ deref_addrof let b = *get_reference(&a); let bytes: Vec = vec![1, 2, 3, 4]; - let b = *&bytes[1..2][0]; + let b = *&bytes[1..2][0]; //~ deref_addrof //This produces a suggestion of 'let b = (a);' which //will trigger the 'unused_parens' lint - let b = *&(a); + let b = *&(a); //~ deref_addrof - let b = *(&a); + let b = *(&a); //~ deref_addrof #[rustfmt::skip] - let b = *((&a)); + let b = *((&a)); //~ deref_addrof - let b = *&&a; + let b = *&&a; //~ deref_addrof - let b = **&aref; + let b = **&aref; //~ deref_addrof let _ = unsafe { *core::ptr::addr_of!(a) }; } @@ -50,10 +50,10 @@ pub struct S; #[inline_macros] impl S { pub fn f(&self) -> &Self { - inline!(*& $(@expr self)) + inline!(*& $(@expr self)) //~ deref_addrof } #[allow(unused_mut)] // mut will be unused, once the macro is fixed pub fn f_mut(mut self) -> Self { - inline!(*&mut $(@expr self)) + inline!(*&mut $(@expr self)) //~ deref_addrof } } diff --git a/tests/ui/deref_by_slicing.fixed b/tests/ui/deref_by_slicing.fixed index a3c2e8456668..c90a3bcc2889 100644 --- a/tests/ui/deref_by_slicing.fixed +++ b/tests/ui/deref_by_slicing.fixed @@ -5,24 +5,29 @@ use std::io::Read; fn main() { let mut vec = vec![0]; - let _ = &*vec; - let _ = &mut *vec; + let _ = &*vec; //~ deref_by_slicing + let _ = &mut *vec; //~ deref_by_slicing let ref_vec = &mut vec; - let _ = &**ref_vec; - let mut_slice = &mut **ref_vec; + let _ = &**ref_vec; //~ deref_by_slicing + let mut_slice = &mut **ref_vec; //~ deref_by_slicing + + //~v deref_by_slicing let _ = &mut *mut_slice; // Err, re-borrows slice let s = String::new(); - let _ = &*s; + let _ = &*s; //~ deref_by_slicing static S: &[u8] = &[0, 1, 2]; + //~v deref_by_slicing let _ = &mut &*S; // Err, re-borrows slice let slice: &[u32] = &[0u32, 1u32]; let slice_ref = &slice; + //~v deref_by_slicing let _ = *slice_ref; // Err, derefs slice let bytes: &[u8] = &[]; + //~v deref_by_slicing let _ = (&*bytes).read_to_end(&mut vec![]).unwrap(); // Err, re-borrows slice } diff --git a/tests/ui/deref_by_slicing.rs b/tests/ui/deref_by_slicing.rs index 5b4a73712ee6..8f9698f9dde2 100644 --- a/tests/ui/deref_by_slicing.rs +++ b/tests/ui/deref_by_slicing.rs @@ -5,24 +5,29 @@ use std::io::Read; fn main() { let mut vec = vec![0]; - let _ = &vec[..]; - let _ = &mut vec[..]; + let _ = &vec[..]; //~ deref_by_slicing + let _ = &mut vec[..]; //~ deref_by_slicing let ref_vec = &mut vec; - let _ = &ref_vec[..]; - let mut_slice = &mut ref_vec[..]; + let _ = &ref_vec[..]; //~ deref_by_slicing + let mut_slice = &mut ref_vec[..]; //~ deref_by_slicing + + //~v deref_by_slicing let _ = &mut mut_slice[..]; // Err, re-borrows slice let s = String::new(); - let _ = &s[..]; + let _ = &s[..]; //~ deref_by_slicing static S: &[u8] = &[0, 1, 2]; + //~v deref_by_slicing let _ = &mut &S[..]; // Err, re-borrows slice let slice: &[u32] = &[0u32, 1u32]; let slice_ref = &slice; + //~v deref_by_slicing let _ = &slice_ref[..]; // Err, derefs slice let bytes: &[u8] = &[]; + //~v deref_by_slicing let _ = (&bytes[..]).read_to_end(&mut vec![]).unwrap(); // Err, re-borrows slice } diff --git a/tests/ui/deref_by_slicing.stderr b/tests/ui/deref_by_slicing.stderr index 7b8144a9a6e1..3e85a352ff44 100644 --- a/tests/ui/deref_by_slicing.stderr +++ b/tests/ui/deref_by_slicing.stderr @@ -26,31 +26,31 @@ LL | let mut_slice = &mut ref_vec[..]; | ^^^^^^^^^^^^^^^^ help: dereference the original value instead: `&mut **ref_vec` error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:14:13 + --> $DIR/deref_by_slicing.rs:16:13 | LL | let _ = &mut mut_slice[..]; // Err, re-borrows slice | ^^^^^^^^^^^^^^^^^^ help: reborrow the original value instead: `&mut *mut_slice` error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:17:13 + --> $DIR/deref_by_slicing.rs:19:13 | LL | let _ = &s[..]; | ^^^^^^ help: dereference the original value instead: `&*s` error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:20:18 + --> $DIR/deref_by_slicing.rs:23:18 | LL | let _ = &mut &S[..]; // Err, re-borrows slice | ^^^^^^ help: reborrow the original value instead: `&*S` error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:24:13 + --> $DIR/deref_by_slicing.rs:28:13 | LL | let _ = &slice_ref[..]; // Err, derefs slice | ^^^^^^^^^^^^^^ help: dereference the original value instead: `*slice_ref` error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:27:13 + --> $DIR/deref_by_slicing.rs:32:13 | LL | let _ = (&bytes[..]).read_to_end(&mut vec![]).unwrap(); // Err, re-borrows slice | ^^^^^^^^^^^^ help: reborrow the original value instead: `(&*bytes)` diff --git a/tests/ui/derivable_impls.fixed b/tests/ui/derivable_impls.fixed index 68c5a5c5ca45..e6fb7edc7eff 100644 --- a/tests/ui/derivable_impls.fixed +++ b/tests/ui/derivable_impls.fixed @@ -18,11 +18,13 @@ struct FooDefault<'a> { l: &'a [i32], } +//~v derivable_impls #[derive(Default)] struct TupleDefault(bool, i32, u64); +//~v derivable_impls struct FooND1 { @@ -72,6 +74,7 @@ impl Default for FooNDVec { #[derive(Default)] struct StrDefault<'a>(&'a str); +//~v derivable_impls #[derive(Default)] @@ -95,6 +98,7 @@ mac!(0); #[derive(Default)] struct Y(u32); +//~v derivable_impls struct RustIssue26925 { @@ -131,11 +135,13 @@ struct WithoutSelfCurly { a: bool, } +//~v derivable_impls #[derive(Default)] struct WithoutSelfParan(bool); +//~v derivable_impls // https://github.com/rust-lang/rust-clippy/issues/7655 @@ -183,6 +189,7 @@ pub struct RepeatDefault1 { a: [i8; 32], } +//~v derivable_impls pub struct RepeatDefault2 { @@ -215,6 +222,7 @@ pub enum SimpleEnum { Bar, } +//~v derivable_impls pub enum NonExhaustiveEnum { diff --git a/tests/ui/derivable_impls.rs b/tests/ui/derivable_impls.rs index 21d73ba8b777..8e4a639272ee 100644 --- a/tests/ui/derivable_impls.rs +++ b/tests/ui/derivable_impls.rs @@ -17,6 +17,7 @@ struct FooDefault<'a> { l: &'a [i32], } +//~v derivable_impls impl std::default::Default for FooDefault<'_> { fn default() -> Self { Self { @@ -38,6 +39,7 @@ impl std::default::Default for FooDefault<'_> { struct TupleDefault(bool, i32, u64); +//~v derivable_impls impl std::default::Default for TupleDefault { fn default() -> Self { Self(false, 0, 0u64) @@ -90,6 +92,7 @@ impl Default for FooNDVec { struct StrDefault<'a>(&'a str); +//~v derivable_impls impl Default for StrDefault<'_> { fn default() -> Self { Self("") @@ -116,6 +119,7 @@ macro_rules! mac { mac!(0); struct Y(u32); +//~v derivable_impls impl Default for Y { fn default() -> Self { Self(mac!()) @@ -155,6 +159,7 @@ struct WithoutSelfCurly { a: bool, } +//~v derivable_impls impl Default for WithoutSelfCurly { fn default() -> Self { WithoutSelfCurly { a: false } @@ -163,6 +168,7 @@ impl Default for WithoutSelfCurly { struct WithoutSelfParan(bool); +//~v derivable_impls impl Default for WithoutSelfParan { fn default() -> Self { WithoutSelfParan(false) @@ -213,6 +219,7 @@ pub struct RepeatDefault1 { a: [i8; 32], } +//~v derivable_impls impl Default for RepeatDefault1 { fn default() -> Self { RepeatDefault1 { a: [0; 32] } @@ -247,6 +254,7 @@ pub enum SimpleEnum { Bar, } +//~v derivable_impls impl Default for SimpleEnum { fn default() -> Self { SimpleEnum::Bar diff --git a/tests/ui/derivable_impls.stderr b/tests/ui/derivable_impls.stderr index 98e2f3612904..409aa0a52022 100644 --- a/tests/ui/derivable_impls.stderr +++ b/tests/ui/derivable_impls.stderr @@ -1,5 +1,5 @@ error: this `impl` can be derived - --> $DIR/derivable_impls.rs:20:1 + --> $DIR/derivable_impls.rs:21:1 | LL | / impl std::default::Default for FooDefault<'_> { LL | | fn default() -> Self { @@ -20,7 +20,7 @@ LL | struct FooDefault<'a> { | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:41:1 + --> $DIR/derivable_impls.rs:43:1 | LL | / impl std::default::Default for TupleDefault { LL | | fn default() -> Self { @@ -37,7 +37,7 @@ LL | struct TupleDefault(bool, i32, u64); | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:93:1 + --> $DIR/derivable_impls.rs:96:1 | LL | / impl Default for StrDefault<'_> { LL | | fn default() -> Self { @@ -54,7 +54,7 @@ LL | struct StrDefault<'a>(&'a str); | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:119:1 + --> $DIR/derivable_impls.rs:123:1 | LL | / impl Default for Y { LL | | fn default() -> Self { @@ -71,7 +71,7 @@ LL | struct Y(u32); | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:158:1 + --> $DIR/derivable_impls.rs:163:1 | LL | / impl Default for WithoutSelfCurly { LL | | fn default() -> Self { @@ -88,7 +88,7 @@ LL | struct WithoutSelfCurly { | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:166:1 + --> $DIR/derivable_impls.rs:172:1 | LL | / impl Default for WithoutSelfParan { LL | | fn default() -> Self { @@ -105,7 +105,7 @@ LL | struct WithoutSelfParan(bool); | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:216:1 + --> $DIR/derivable_impls.rs:223:1 | LL | / impl Default for RepeatDefault1 { LL | | fn default() -> Self { @@ -122,7 +122,7 @@ LL | pub struct RepeatDefault1 { | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:250:1 + --> $DIR/derivable_impls.rs:258:1 | LL | / impl Default for SimpleEnum { LL | | fn default() -> Self { diff --git a/tests/ui/derive_partial_eq_without_eq.fixed b/tests/ui/derive_partial_eq_without_eq.fixed index aa7a95405e02..1265679b2b96 100644 --- a/tests/ui/derive_partial_eq_without_eq.fixed +++ b/tests/ui/derive_partial_eq_without_eq.fixed @@ -8,7 +8,7 @@ pub struct NotPartialEq { } // Eq can be derived but is missing -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq)] //~ derive_partial_eq_without_eq pub struct MissingEq { foo: u32, bar: String, @@ -50,34 +50,34 @@ impl PartialEq for ManualPartialEqImpl { } // Generic fields should be properly checked for Eq-ness -#[derive(PartialEq, Eq)] +#[derive(PartialEq, Eq)] //~ derive_partial_eq_without_eq pub struct GenericNotEq { foo: T, bar: U, } -#[derive(PartialEq, Eq)] +#[derive(PartialEq, Eq)] //~ derive_partial_eq_without_eq pub struct GenericEq { foo: T, bar: U, } -#[derive(PartialEq, Eq)] +#[derive(PartialEq, Eq)] //~ derive_partial_eq_without_eq pub struct TupleStruct(u32); -#[derive(PartialEq, Eq)] +#[derive(PartialEq, Eq)] //~ derive_partial_eq_without_eq pub struct GenericTupleStruct(T); #[derive(PartialEq)] pub struct TupleStructNotEq(f32); -#[derive(PartialEq, Eq)] +#[derive(PartialEq, Eq)] //~ derive_partial_eq_without_eq pub enum Enum { Foo(u32), Bar { a: String, b: () }, } -#[derive(PartialEq, Eq)] +#[derive(PartialEq, Eq)] //~ derive_partial_eq_without_eq pub enum GenericEnum { Foo(T), Bar { a: U, b: V }, @@ -90,20 +90,20 @@ pub enum EnumNotEq { } // Ensure that rustfix works properly when `PartialEq` has other derives on either side -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Debug, PartialEq, Eq, Clone)] //~ derive_partial_eq_without_eq pub struct RustFixWithOtherDerives; -#[derive(PartialEq, Eq)] +#[derive(PartialEq, Eq)] //~ derive_partial_eq_without_eq pub struct Generic(T); #[derive(PartialEq, Eq)] pub struct GenericPhantom(core::marker::PhantomData); mod _hidden { - #[derive(PartialEq, Eq)] + #[derive(PartialEq, Eq)] //~ derive_partial_eq_without_eq pub struct Reexported; - #[derive(PartialEq, Eq)] + #[derive(PartialEq, Eq)] //~ derive_partial_eq_without_eq pub struct InPubFn; #[derive(PartialEq)] diff --git a/tests/ui/derive_partial_eq_without_eq.rs b/tests/ui/derive_partial_eq_without_eq.rs index 90ac7a7989e0..6574ff8c3a85 100644 --- a/tests/ui/derive_partial_eq_without_eq.rs +++ b/tests/ui/derive_partial_eq_without_eq.rs @@ -8,7 +8,7 @@ pub struct NotPartialEq { } // Eq can be derived but is missing -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq)] //~ derive_partial_eq_without_eq pub struct MissingEq { foo: u32, bar: String, @@ -50,34 +50,34 @@ impl PartialEq for ManualPartialEqImpl { } // Generic fields should be properly checked for Eq-ness -#[derive(PartialEq)] +#[derive(PartialEq)] //~ derive_partial_eq_without_eq pub struct GenericNotEq { foo: T, bar: U, } -#[derive(PartialEq)] +#[derive(PartialEq)] //~ derive_partial_eq_without_eq pub struct GenericEq { foo: T, bar: U, } -#[derive(PartialEq)] +#[derive(PartialEq)] //~ derive_partial_eq_without_eq pub struct TupleStruct(u32); -#[derive(PartialEq)] +#[derive(PartialEq)] //~ derive_partial_eq_without_eq pub struct GenericTupleStruct(T); #[derive(PartialEq)] pub struct TupleStructNotEq(f32); -#[derive(PartialEq)] +#[derive(PartialEq)] //~ derive_partial_eq_without_eq pub enum Enum { Foo(u32), Bar { a: String, b: () }, } -#[derive(PartialEq)] +#[derive(PartialEq)] //~ derive_partial_eq_without_eq pub enum GenericEnum { Foo(T), Bar { a: U, b: V }, @@ -90,20 +90,20 @@ pub enum EnumNotEq { } // Ensure that rustfix works properly when `PartialEq` has other derives on either side -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, PartialEq, Clone)] //~ derive_partial_eq_without_eq pub struct RustFixWithOtherDerives; -#[derive(PartialEq)] +#[derive(PartialEq)] //~ derive_partial_eq_without_eq pub struct Generic(T); #[derive(PartialEq, Eq)] pub struct GenericPhantom(core::marker::PhantomData); mod _hidden { - #[derive(PartialEq)] + #[derive(PartialEq)] //~ derive_partial_eq_without_eq pub struct Reexported; - #[derive(PartialEq)] + #[derive(PartialEq)] //~ derive_partial_eq_without_eq pub struct InPubFn; #[derive(PartialEq)] diff --git a/tests/ui/doc/doc-fixable.fixed b/tests/ui/doc/doc-fixable.fixed index 16f7bafd44b7..e9edbb1b7752 100644 --- a/tests/ui/doc/doc-fixable.fixed +++ b/tests/ui/doc/doc-fixable.fixed @@ -6,13 +6,22 @@ #![feature(custom_inner_attributes, generic_const_exprs, const_option)] #![rustfmt::skip] +//~| doc_markdown +//~v doc_markdown /// The `foo_bar` function does _nothing_. See also `foo::bar`. (note the dot there) +//~v doc_markdown /// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not `Foo::some_fun` /// which should be reported only once despite being __doubly bad__. +//~| doc_markdown +//~v doc_markdown /// Here be `::a::global:path`, and _`::another::global::path`_. :: is not a path though. +//~v doc_markdown /// Import an item from `::awesome::global::blob::` (Intended postfix) +//~v doc_markdown /// These are the options for `::Cat`: (Intended trailing single colon, shouldn't be linted) +//~v doc_markdown /// That's not code ~`NotInCodeBlock`~. +//~v doc_markdown /// `be_sure_we_got_to_the_end_of_it` fn foo_bar() { } @@ -27,6 +36,7 @@ fn foo_bar() { /// foo_bar FOO_BAR /// _foo bar_ /// ~~~ +//~v doc_markdown /// `be_sure_we_got_to_the_end_of_it` fn multiline_codeblock() { } @@ -34,6 +44,7 @@ fn multiline_codeblock() { /// This _is a test for /// multiline /// emphasis_. +//~v doc_markdown /// `be_sure_we_got_to_the_end_of_it` fn test_emphasis() { } @@ -48,6 +59,7 @@ fn test_emphasis() { /// 32kB 32MB 32GB 32TB 32PB 32EB /// 32kb 32Mb 32Gb 32Tb 32Pb 32Eb /// NaN +//~v doc_markdown /// `be_sure_we_got_to_the_end_of_it` fn test_units() { } @@ -72,6 +84,7 @@ fn test_units() { /// TeX LaTeX BibTeX BibLaTeX /// MinGW /// CamelCase (see also #2395) +//~v doc_markdown /// `be_sure_we_got_to_the_end_of_it` fn test_allowed() { } @@ -89,6 +102,7 @@ fn test_allowed() { /// /// expression of the type `_ m c` (where `` /// is one of {`&`, '|'} and `` is one of {`!=`, `>=`, `>` , +//~v doc_markdown /// `be_sure_we_got_to_the_end_of_it` fn main() { foo_bar(); @@ -97,12 +111,16 @@ fn main() { test_units(); } +//~v doc_markdown /// ## `CamelCaseThing` /// Talks about `CamelCaseThing`. Titles should be ignored; see issue #897. /// +//~v doc_markdown /// # `CamelCaseThing` /// +//~v doc_markdown /// Not a title #897 `CamelCaseThing` +//~v doc_markdown /// `be_sure_we_got_to_the_end_of_it` fn issue897() { } @@ -110,6 +128,7 @@ fn issue897() { /// I am confused by brackets? (`x_y`) /// I am confused by brackets? (foo `x_y`) /// I am confused by brackets? (`x_y` foo) +//~v doc_markdown /// `be_sure_we_got_to_the_end_of_it` fn issue900() { } @@ -123,6 +142,7 @@ fn issue900() { /// /// [iterator]: https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html /// [helper_types]: ../helper_types/index.html +//~v doc_markdown /// `be_sure_we_got_to_the_end_of_it` fn issue883() { } @@ -134,23 +154,31 @@ fn issue883() { fn multiline() { } +//~vvvvvvvvvv doc_markdown +//~vvvvvvv doc_markdown +//~v doc_markdown /** E.g., serialization of an empty list: `FooBar` ``` That's in a code block: `PackedNode` ``` And `BarQuz` too. + `be_sure_we_got_to_the_end_of_it` */ fn issue1073() { } +//~vvvvvvvvvv doc_markdown +//~vvvvvvv doc_markdown +//~v doc_markdown /** E.g., serialization of an empty list: `FooBar` ``` That's in a code block: PackedNode ``` And `BarQuz` too. + `be_sure_we_got_to_the_end_of_it` */ fn issue1073_alt() { @@ -162,6 +190,7 @@ fn issue1073_alt() { /// ``` /// StillDont /// ```` +//~v doc_markdown /// `be_sure_we_got_to_the_end_of_it` fn four_quotes() { } @@ -181,6 +210,7 @@ fn issue_1469() {} */ fn issue_1920() {} +//~v doc_markdown /// An iterator over `mycrate::Collection`'s values. /// It should not lint a `'static` lifetime in ticks. fn issue_2210() {} @@ -205,6 +235,7 @@ fn intra_doc_link() {} /// \\] fn issue_2581() {} +//~v doc_markdown /// Foo \[bar\] \[baz\] \[qux\]. `DocMarkdownLint` fn lint_after_escaped_chars() {} @@ -228,5 +259,7 @@ where [(); N.checked_next_power_of_two().unwrap()]: { /// this checks if the lowerCamelCase issue is fixed fn issue_11568() {} +//~| doc_markdown +//~v doc_markdown /// There is no try (`do()` or `do_not()`). fn parenthesized_word() {} diff --git a/tests/ui/doc/doc-fixable.rs b/tests/ui/doc/doc-fixable.rs index 4058b2bad74f..29c374743122 100644 --- a/tests/ui/doc/doc-fixable.rs +++ b/tests/ui/doc/doc-fixable.rs @@ -6,13 +6,22 @@ #![feature(custom_inner_attributes, generic_const_exprs, const_option)] #![rustfmt::skip] +//~| doc_markdown +//~v doc_markdown /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) +//~v doc_markdown /// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not Foo::some_fun /// which should be reported only once despite being __doubly bad__. +//~| doc_markdown +//~v doc_markdown /// Here be ::a::global:path, and _::another::global::path_. :: is not a path though. +//~v doc_markdown /// Import an item from ::awesome::global::blob:: (Intended postfix) +//~v doc_markdown /// These are the options for ::Cat: (Intended trailing single colon, shouldn't be linted) +//~v doc_markdown /// That's not code ~NotInCodeBlock~. +//~v doc_markdown /// be_sure_we_got_to_the_end_of_it fn foo_bar() { } @@ -27,6 +36,7 @@ fn foo_bar() { /// foo_bar FOO_BAR /// _foo bar_ /// ~~~ +//~v doc_markdown /// be_sure_we_got_to_the_end_of_it fn multiline_codeblock() { } @@ -34,6 +44,7 @@ fn multiline_codeblock() { /// This _is a test for /// multiline /// emphasis_. +//~v doc_markdown /// be_sure_we_got_to_the_end_of_it fn test_emphasis() { } @@ -48,6 +59,7 @@ fn test_emphasis() { /// 32kB 32MB 32GB 32TB 32PB 32EB /// 32kb 32Mb 32Gb 32Tb 32Pb 32Eb /// NaN +//~v doc_markdown /// be_sure_we_got_to_the_end_of_it fn test_units() { } @@ -72,6 +84,7 @@ fn test_units() { /// TeX LaTeX BibTeX BibLaTeX /// MinGW /// CamelCase (see also #2395) +//~v doc_markdown /// be_sure_we_got_to_the_end_of_it fn test_allowed() { } @@ -89,6 +102,7 @@ fn test_allowed() { /// /// expression of the type `_ m c` (where `` /// is one of {`&`, '|'} and `` is one of {`!=`, `>=`, `>` , +//~v doc_markdown /// be_sure_we_got_to_the_end_of_it fn main() { foo_bar(); @@ -97,12 +111,16 @@ fn main() { test_units(); } +//~v doc_markdown /// ## CamelCaseThing /// Talks about `CamelCaseThing`. Titles should be ignored; see issue #897. /// +//~v doc_markdown /// # CamelCaseThing /// +//~v doc_markdown /// Not a title #897 CamelCaseThing +//~v doc_markdown /// be_sure_we_got_to_the_end_of_it fn issue897() { } @@ -110,6 +128,7 @@ fn issue897() { /// I am confused by brackets? (`x_y`) /// I am confused by brackets? (foo `x_y`) /// I am confused by brackets? (`x_y` foo) +//~v doc_markdown /// be_sure_we_got_to_the_end_of_it fn issue900() { } @@ -123,6 +142,7 @@ fn issue900() { /// /// [iterator]: https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html /// [helper_types]: ../helper_types/index.html +//~v doc_markdown /// be_sure_we_got_to_the_end_of_it fn issue883() { } @@ -134,23 +154,31 @@ fn issue883() { fn multiline() { } +//~vvvvvvvvvv doc_markdown +//~vvvvvvv doc_markdown +//~v doc_markdown /** E.g., serialization of an empty list: FooBar ``` That's in a code block: `PackedNode` ``` And BarQuz too. + be_sure_we_got_to_the_end_of_it */ fn issue1073() { } +//~vvvvvvvvvv doc_markdown +//~vvvvvvv doc_markdown +//~v doc_markdown /** E.g., serialization of an empty list: FooBar ``` That's in a code block: PackedNode ``` And BarQuz too. + be_sure_we_got_to_the_end_of_it */ fn issue1073_alt() { @@ -162,6 +190,7 @@ fn issue1073_alt() { /// ``` /// StillDont /// ```` +//~v doc_markdown /// be_sure_we_got_to_the_end_of_it fn four_quotes() { } @@ -181,6 +210,7 @@ fn issue_1469() {} */ fn issue_1920() {} +//~v doc_markdown /// An iterator over mycrate::Collection's values. /// It should not lint a `'static` lifetime in ticks. fn issue_2210() {} @@ -205,6 +235,7 @@ fn intra_doc_link() {} /// \\] fn issue_2581() {} +//~v doc_markdown /// Foo \[bar\] \[baz\] \[qux\]. DocMarkdownLint fn lint_after_escaped_chars() {} @@ -228,5 +259,7 @@ where [(); N.checked_next_power_of_two().unwrap()]: { /// this checks if the lowerCamelCase issue is fixed fn issue_11568() {} +//~| doc_markdown +//~v doc_markdown /// There is no try (do() or do_not()). fn parenthesized_word() {} diff --git a/tests/ui/doc/doc-fixable.stderr b/tests/ui/doc/doc-fixable.stderr index 8d2ef481eb10..9b024cd1f057 100644 --- a/tests/ui/doc/doc-fixable.stderr +++ b/tests/ui/doc/doc-fixable.stderr @@ -1,5 +1,5 @@ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:9:9 + --> $DIR/doc/doc-fixable.rs:11:9 | LL | /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) | ^^^^^^^ @@ -12,7 +12,7 @@ LL | /// The `foo_bar` function does _nothing_. See also foo::bar. (note the dot | ~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:9:51 + --> $DIR/doc/doc-fixable.rs:11:51 | LL | /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) | ^^^^^^^^ @@ -23,7 +23,7 @@ LL | /// The foo_bar function does _nothing_. See also `foo::bar`. (note the dot | ~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:10:83 + --> $DIR/doc/doc-fixable.rs:13:83 | LL | /// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not Foo::some_fun | ^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | /// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. B | ~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:12:13 + --> $DIR/doc/doc-fixable.rs:17:13 | LL | /// Here be ::a::global:path, and _::another::global::path_. :: is not a path though. | ^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | /// Here be `::a::global:path`, and _::another::global::path_. :: is not a | ~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:12:36 + --> $DIR/doc/doc-fixable.rs:17:36 | LL | /// Here be ::a::global:path, and _::another::global::path_. :: is not a path though. | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | /// Here be ::a::global:path, and _`::another::global::path`_. :: is not a | ~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:13:25 + --> $DIR/doc/doc-fixable.rs:19:25 | LL | /// Import an item from ::awesome::global::blob:: (Intended postfix) | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | /// Import an item from `::awesome::global::blob::` (Intended postfix) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:14:31 + --> $DIR/doc/doc-fixable.rs:21:31 | LL | /// These are the options for ::Cat: (Intended trailing single colon, shouldn't be linted) | ^^^^^ @@ -78,7 +78,7 @@ LL | /// These are the options for `::Cat`: (Intended trailing single colon, sho | ~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:15:22 + --> $DIR/doc/doc-fixable.rs:23:22 | LL | /// That's not code ~NotInCodeBlock~. | ^^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | /// That's not code ~`NotInCodeBlock`~. | ~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:16:5 + --> $DIR/doc/doc-fixable.rs:25:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:30:5 + --> $DIR/doc/doc-fixable.rs:40:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -111,7 +111,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:37:5 + --> $DIR/doc/doc-fixable.rs:48:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:51:5 + --> $DIR/doc/doc-fixable.rs:63:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:75:5 + --> $DIR/doc/doc-fixable.rs:88:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:92:5 + --> $DIR/doc/doc-fixable.rs:106:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -155,7 +155,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:100:8 + --> $DIR/doc/doc-fixable.rs:115:8 | LL | /// ## CamelCaseThing | ^^^^^^^^^^^^^^ @@ -166,7 +166,7 @@ LL | /// ## `CamelCaseThing` | ~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:103:7 + --> $DIR/doc/doc-fixable.rs:119:7 | LL | /// # CamelCaseThing | ^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | /// # `CamelCaseThing` | ~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:105:22 + --> $DIR/doc/doc-fixable.rs:122:22 | LL | /// Not a title #897 CamelCaseThing | ^^^^^^^^^^^^^^ @@ -188,7 +188,7 @@ LL | /// Not a title #897 `CamelCaseThing` | ~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:106:5 + --> $DIR/doc/doc-fixable.rs:124:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -199,7 +199,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:113:5 + --> $DIR/doc/doc-fixable.rs:132:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -210,7 +210,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:126:5 + --> $DIR/doc/doc-fixable.rs:146:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -221,7 +221,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:137:43 + --> $DIR/doc/doc-fixable.rs:160:43 | LL | /** E.g., serialization of an empty list: FooBar | ^^^^^^ @@ -232,7 +232,7 @@ LL | /** E.g., serialization of an empty list: `FooBar` | ~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:142:5 + --> $DIR/doc/doc-fixable.rs:165:5 | LL | And BarQuz too. | ^^^^^^ @@ -243,7 +243,7 @@ LL | And `BarQuz` too. | ~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:143:1 + --> $DIR/doc/doc-fixable.rs:167:1 | LL | be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -254,7 +254,7 @@ LL | `be_sure_we_got_to_the_end_of_it` | error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:148:43 + --> $DIR/doc/doc-fixable.rs:175:43 | LL | /** E.g., serialization of an empty list: FooBar | ^^^^^^ @@ -265,7 +265,7 @@ LL | /** E.g., serialization of an empty list: `FooBar` | ~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:153:5 + --> $DIR/doc/doc-fixable.rs:180:5 | LL | And BarQuz too. | ^^^^^^ @@ -276,7 +276,7 @@ LL | And `BarQuz` too. | ~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:154:1 + --> $DIR/doc/doc-fixable.rs:182:1 | LL | be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -287,7 +287,7 @@ LL | `be_sure_we_got_to_the_end_of_it` | error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:165:5 + --> $DIR/doc/doc-fixable.rs:194:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -298,7 +298,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:184:22 + --> $DIR/doc/doc-fixable.rs:214:22 | LL | /// An iterator over mycrate::Collection's values. | ^^^^^^^^^^^^^^^^^^^ @@ -309,7 +309,7 @@ LL | /// An iterator over `mycrate::Collection`'s values. | ~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:208:34 + --> $DIR/doc/doc-fixable.rs:239:34 | LL | /// Foo \[bar\] \[baz\] \[qux\]. DocMarkdownLint | ^^^^^^^^^^^^^^^ @@ -320,7 +320,7 @@ LL | /// Foo \[bar\] \[baz\] \[qux\]. `DocMarkdownLint` | ~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:231:22 + --> $DIR/doc/doc-fixable.rs:264:22 | LL | /// There is no try (do() or do_not()). | ^^^^ @@ -331,7 +331,7 @@ LL | /// There is no try (`do()` or do_not()). | ~~~~~~ error: item in documentation is missing backticks - --> $DIR/doc/doc-fixable.rs:231:30 + --> $DIR/doc/doc-fixable.rs:264:30 | LL | /// There is no try (do() or do_not()). | ^^^^^^^^ diff --git a/tests/ui/doc_unsafe.rs b/tests/ui/doc_unsafe.rs index f7f41c915e3f..0bb04be03998 100644 --- a/tests/ui/doc_unsafe.rs +++ b/tests/ui/doc_unsafe.rs @@ -6,6 +6,7 @@ extern crate proc_macros; use proc_macros::external; /// This is not sufficiently documented +//~v missing_safety_doc pub unsafe fn destroy_the_planet() { unimplemented!(); } @@ -29,6 +30,7 @@ mod private_mod { unimplemented!(); } + //~v missing_safety_doc pub unsafe fn republished() { unimplemented!(); } @@ -37,12 +39,13 @@ mod private_mod { pub use private_mod::republished; pub trait SafeTraitUnsafeMethods { - unsafe fn woefully_underdocumented(self); + unsafe fn woefully_underdocumented(self); //~ missing_safety_doc /// # Safety unsafe fn at_least_somewhat_documented(self); } +//~v missing_safety_doc pub unsafe trait UnsafeTrait { fn method(); } @@ -73,6 +76,7 @@ unsafe impl DocumentedUnsafeTrait for Struct { } impl Struct { + //~v missing_safety_doc pub unsafe fn more_undocumented_unsafe() -> Self { unimplemented!(); } @@ -89,6 +93,7 @@ impl Struct { macro_rules! very_unsafe { () => { + //~v missing_safety_doc pub unsafe fn whee() { unimplemented!() } diff --git a/tests/ui/doc_unsafe.stderr b/tests/ui/doc_unsafe.stderr index ab3fb3c029dd..e79d3f8d4efd 100644 --- a/tests/ui/doc_unsafe.stderr +++ b/tests/ui/doc_unsafe.stderr @@ -1,5 +1,5 @@ error: unsafe function's docs miss `# Safety` section - --> $DIR/doc_unsafe.rs:9:1 + --> $DIR/doc_unsafe.rs:10:1 | LL | pub unsafe fn destroy_the_planet() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,31 +8,31 @@ LL | pub unsafe fn destroy_the_planet() { = help: to override `-D warnings` add `#[allow(clippy::missing_safety_doc)]` error: unsafe function's docs miss `# Safety` section - --> $DIR/doc_unsafe.rs:32:5 + --> $DIR/doc_unsafe.rs:34:5 | LL | pub unsafe fn republished() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unsafe function's docs miss `# Safety` section - --> $DIR/doc_unsafe.rs:40:5 + --> $DIR/doc_unsafe.rs:42:5 | LL | unsafe fn woefully_underdocumented(self); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for unsafe trait missing `# Safety` section - --> $DIR/doc_unsafe.rs:46:1 + --> $DIR/doc_unsafe.rs:49:1 | LL | pub unsafe trait UnsafeTrait { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unsafe function's docs miss `# Safety` section - --> $DIR/doc_unsafe.rs:76:5 + --> $DIR/doc_unsafe.rs:80:5 | LL | pub unsafe fn more_undocumented_unsafe() -> Self { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unsafe function's docs miss `# Safety` section - --> $DIR/doc_unsafe.rs:92:9 + --> $DIR/doc_unsafe.rs:97:9 | LL | pub unsafe fn whee() { | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/double_comparison.fixed b/tests/ui/double_comparison.fixed index 788f3224b418..0990ebd6aa0e 100644 --- a/tests/ui/double_comparison.fixed +++ b/tests/ui/double_comparison.fixed @@ -3,27 +3,35 @@ fn main() { let x = 1; let y = 2; + //~v double_comparisons if x <= y { // do something } + //~v double_comparisons if x <= y { // do something } + //~v double_comparisons if x >= y { // do something } + //~v double_comparisons if x >= y { // do something } + //~v double_comparisons if x != y { // do something } + //~v double_comparisons if x != y { // do something } + //~v double_comparisons if x == y { // do something } + //~v double_comparisons if x == y { // do something } diff --git a/tests/ui/double_comparison.rs b/tests/ui/double_comparison.rs index 245a83d5709d..3fc95ed6e25d 100644 --- a/tests/ui/double_comparison.rs +++ b/tests/ui/double_comparison.rs @@ -3,27 +3,35 @@ fn main() { let x = 1; let y = 2; + //~v double_comparisons if x == y || x < y { // do something } + //~v double_comparisons if x < y || x == y { // do something } + //~v double_comparisons if x == y || x > y { // do something } + //~v double_comparisons if x > y || x == y { // do something } + //~v double_comparisons if x < y || x > y { // do something } + //~v double_comparisons if x > y || x < y { // do something } + //~v double_comparisons if x <= y && x >= y { // do something } + //~v double_comparisons if x >= y && x <= y { // do something } diff --git a/tests/ui/double_comparison.stderr b/tests/ui/double_comparison.stderr index 02f0a960974b..afcd4087f0b5 100644 --- a/tests/ui/double_comparison.stderr +++ b/tests/ui/double_comparison.stderr @@ -1,5 +1,5 @@ error: this binary expression can be simplified - --> $DIR/double_comparison.rs:6:8 + --> $DIR/double_comparison.rs:7:8 | LL | if x == y || x < y { | ^^^^^^^^^^^^^^^ help: try: `x <= y` @@ -8,43 +8,43 @@ LL | if x == y || x < y { = help: to override `-D warnings` add `#[allow(clippy::double_comparisons)]` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:9:8 + --> $DIR/double_comparison.rs:11:8 | LL | if x < y || x == y { | ^^^^^^^^^^^^^^^ help: try: `x <= y` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:12:8 + --> $DIR/double_comparison.rs:15:8 | LL | if x == y || x > y { | ^^^^^^^^^^^^^^^ help: try: `x >= y` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:15:8 + --> $DIR/double_comparison.rs:19:8 | LL | if x > y || x == y { | ^^^^^^^^^^^^^^^ help: try: `x >= y` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:18:8 + --> $DIR/double_comparison.rs:23:8 | LL | if x < y || x > y { | ^^^^^^^^^^^^^^ help: try: `x != y` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:21:8 + --> $DIR/double_comparison.rs:27:8 | LL | if x > y || x < y { | ^^^^^^^^^^^^^^ help: try: `x != y` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:24:8 + --> $DIR/double_comparison.rs:31:8 | LL | if x <= y && x >= y { | ^^^^^^^^^^^^^^^^ help: try: `x == y` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:27:8 + --> $DIR/double_comparison.rs:35:8 | LL | if x >= y && x <= y { | ^^^^^^^^^^^^^^^^ help: try: `x == y` diff --git a/tests/ui/drain_collect.fixed b/tests/ui/drain_collect.fixed index 6f597243fe6f..694096afd74a 100644 --- a/tests/ui/drain_collect.fixed +++ b/tests/ui/drain_collect.fixed @@ -4,7 +4,7 @@ use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque}; fn binaryheap(b: &mut BinaryHeap) -> BinaryHeap { - std::mem::take(b) + std::mem::take(b) //~ drain_collect } fn binaryheap_dont_lint(b: &mut BinaryHeap) -> HashSet { @@ -12,7 +12,7 @@ fn binaryheap_dont_lint(b: &mut BinaryHeap) -> HashSet { } fn hashmap(b: &mut HashMap) -> HashMap { - std::mem::take(b) + std::mem::take(b) //~ drain_collect } fn hashmap_dont_lint(b: &mut HashMap) -> Vec<(i32, i32)> { @@ -20,7 +20,7 @@ fn hashmap_dont_lint(b: &mut HashMap) -> Vec<(i32, i32)> { } fn hashset(b: &mut HashSet) -> HashSet { - std::mem::take(b) + std::mem::take(b) //~ drain_collect } fn hashset_dont_lint(b: &mut HashSet) -> Vec { @@ -28,7 +28,7 @@ fn hashset_dont_lint(b: &mut HashSet) -> Vec { } fn vecdeque(b: &mut VecDeque) -> VecDeque { - std::mem::take(b) + std::mem::take(b) //~ drain_collect } fn vecdeque_dont_lint(b: &mut VecDeque) -> HashSet { @@ -36,24 +36,24 @@ fn vecdeque_dont_lint(b: &mut VecDeque) -> HashSet { } fn vec(b: &mut Vec) -> Vec { - std::mem::take(b) + std::mem::take(b) //~ drain_collect } fn vec2(b: &mut Vec) -> Vec { - std::mem::take(b) + std::mem::take(b) //~ drain_collect } fn vec3(b: &mut Vec) -> Vec { - std::mem::take(b) + std::mem::take(b) //~ drain_collect } fn vec4(b: &mut Vec) -> Vec { - std::mem::take(b) + std::mem::take(b) //~ drain_collect } fn vec_no_reborrow() -> Vec { let mut b = vec![1, 2, 3]; - std::mem::take(&mut b) + std::mem::take(&mut b) //~ drain_collect } fn vec_dont_lint(b: &mut Vec) -> HashSet { @@ -61,7 +61,7 @@ fn vec_dont_lint(b: &mut Vec) -> HashSet { } fn string(b: &mut String) -> String { - std::mem::take(b) + std::mem::take(b) //~ drain_collect } fn string_dont_lint(b: &mut String) -> HashSet { diff --git a/tests/ui/drain_collect.rs b/tests/ui/drain_collect.rs index 353aac4da9a4..b09d7e39a287 100644 --- a/tests/ui/drain_collect.rs +++ b/tests/ui/drain_collect.rs @@ -4,7 +4,7 @@ use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque}; fn binaryheap(b: &mut BinaryHeap) -> BinaryHeap { - b.drain().collect() + b.drain().collect() //~ drain_collect } fn binaryheap_dont_lint(b: &mut BinaryHeap) -> HashSet { @@ -12,7 +12,7 @@ fn binaryheap_dont_lint(b: &mut BinaryHeap) -> HashSet { } fn hashmap(b: &mut HashMap) -> HashMap { - b.drain().collect() + b.drain().collect() //~ drain_collect } fn hashmap_dont_lint(b: &mut HashMap) -> Vec<(i32, i32)> { @@ -20,7 +20,7 @@ fn hashmap_dont_lint(b: &mut HashMap) -> Vec<(i32, i32)> { } fn hashset(b: &mut HashSet) -> HashSet { - b.drain().collect() + b.drain().collect() //~ drain_collect } fn hashset_dont_lint(b: &mut HashSet) -> Vec { @@ -28,7 +28,7 @@ fn hashset_dont_lint(b: &mut HashSet) -> Vec { } fn vecdeque(b: &mut VecDeque) -> VecDeque { - b.drain(..).collect() + b.drain(..).collect() //~ drain_collect } fn vecdeque_dont_lint(b: &mut VecDeque) -> HashSet { @@ -36,24 +36,24 @@ fn vecdeque_dont_lint(b: &mut VecDeque) -> HashSet { } fn vec(b: &mut Vec) -> Vec { - b.drain(..).collect() + b.drain(..).collect() //~ drain_collect } fn vec2(b: &mut Vec) -> Vec { - b.drain(0..).collect() + b.drain(0..).collect() //~ drain_collect } fn vec3(b: &mut Vec) -> Vec { - b.drain(..b.len()).collect() + b.drain(..b.len()).collect() //~ drain_collect } fn vec4(b: &mut Vec) -> Vec { - b.drain(0..b.len()).collect() + b.drain(0..b.len()).collect() //~ drain_collect } fn vec_no_reborrow() -> Vec { let mut b = vec![1, 2, 3]; - b.drain(..).collect() + b.drain(..).collect() //~ drain_collect } fn vec_dont_lint(b: &mut Vec) -> HashSet { @@ -61,7 +61,7 @@ fn vec_dont_lint(b: &mut Vec) -> HashSet { } fn string(b: &mut String) -> String { - b.drain(..).collect() + b.drain(..).collect() //~ drain_collect } fn string_dont_lint(b: &mut String) -> HashSet { diff --git a/tests/ui/duration_subsec.fixed b/tests/ui/duration_subsec.fixed index 114c516ed1a1..5cb6d5f8b006 100644 --- a/tests/ui/duration_subsec.fixed +++ b/tests/ui/duration_subsec.fixed @@ -7,21 +7,23 @@ fn main() { let dur = Duration::new(5, 0); let bad_millis_1 = dur.subsec_millis(); + //~^ duration_subsec let bad_millis_2 = dur.subsec_millis(); + //~^ duration_subsec let good_millis = dur.subsec_millis(); assert_eq!(bad_millis_1, good_millis); assert_eq!(bad_millis_2, good_millis); - let bad_micros = dur.subsec_micros(); + let bad_micros = dur.subsec_micros(); //~ duration_subsec let good_micros = dur.subsec_micros(); assert_eq!(bad_micros, good_micros); // Handle refs - let _ = (&dur).subsec_micros(); + let _ = (&dur).subsec_micros(); //~ duration_subsec // Handle constants const NANOS_IN_MICRO: u32 = 1_000; - let _ = dur.subsec_micros(); + let _ = dur.subsec_micros(); //~ duration_subsec // Other literals aren't linted let _ = dur.subsec_nanos() / 699; diff --git a/tests/ui/duration_subsec.rs b/tests/ui/duration_subsec.rs index 8469fe086b10..8af1fb32f904 100644 --- a/tests/ui/duration_subsec.rs +++ b/tests/ui/duration_subsec.rs @@ -7,21 +7,23 @@ fn main() { let dur = Duration::new(5, 0); let bad_millis_1 = dur.subsec_micros() / 1_000; + //~^ duration_subsec let bad_millis_2 = dur.subsec_nanos() / 1_000_000; + //~^ duration_subsec let good_millis = dur.subsec_millis(); assert_eq!(bad_millis_1, good_millis); assert_eq!(bad_millis_2, good_millis); - let bad_micros = dur.subsec_nanos() / 1_000; + let bad_micros = dur.subsec_nanos() / 1_000; //~ duration_subsec let good_micros = dur.subsec_micros(); assert_eq!(bad_micros, good_micros); // Handle refs - let _ = (&dur).subsec_nanos() / 1_000; + let _ = (&dur).subsec_nanos() / 1_000; //~ duration_subsec // Handle constants const NANOS_IN_MICRO: u32 = 1_000; - let _ = dur.subsec_nanos() / NANOS_IN_MICRO; + let _ = dur.subsec_nanos() / NANOS_IN_MICRO; //~ duration_subsec // Other literals aren't linted let _ = dur.subsec_nanos() / 699; diff --git a/tests/ui/duration_subsec.stderr b/tests/ui/duration_subsec.stderr index 705683837123..c7e23ac1bb69 100644 --- a/tests/ui/duration_subsec.stderr +++ b/tests/ui/duration_subsec.stderr @@ -8,25 +8,25 @@ LL | let bad_millis_1 = dur.subsec_micros() / 1_000; = help: to override `-D warnings` add `#[allow(clippy::duration_subsec)]` error: calling `subsec_millis()` is more concise than this calculation - --> $DIR/duration_subsec.rs:10:24 + --> $DIR/duration_subsec.rs:11:24 | LL | let bad_millis_2 = dur.subsec_nanos() / 1_000_000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_millis()` error: calling `subsec_micros()` is more concise than this calculation - --> $DIR/duration_subsec.rs:15:22 + --> $DIR/duration_subsec.rs:17:22 | LL | let bad_micros = dur.subsec_nanos() / 1_000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_micros()` error: calling `subsec_micros()` is more concise than this calculation - --> $DIR/duration_subsec.rs:20:13 + --> $DIR/duration_subsec.rs:22:13 | LL | let _ = (&dur).subsec_nanos() / 1_000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(&dur).subsec_micros()` error: calling `subsec_micros()` is more concise than this calculation - --> $DIR/duration_subsec.rs:24:13 + --> $DIR/duration_subsec.rs:26:13 | LL | let _ = dur.subsec_nanos() / NANOS_IN_MICRO; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_micros()` diff --git a/tests/ui/eager_transmute.fixed b/tests/ui/eager_transmute.fixed index bece09bba1ab..71cfa748d8d7 100644 --- a/tests/ui/eager_transmute.fixed +++ b/tests/ui/eager_transmute.fixed @@ -19,20 +19,27 @@ struct Data { fn int_to_opcode(op: u8) -> Option { (op < 4).then(|| unsafe { std::mem::transmute(op) }) + //~^ eager_transmute } fn f(op: u8, op2: Data, unrelated: u8) { true.then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); (unrelated < 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); (op < 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); + //~^ eager_transmute (op > 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); + //~^ eager_transmute (op == 0).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); + //~^ eager_transmute let _: Option = (op > 0 && op < 10).then(|| unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (op > 0 && op < 10 && unrelated == 0).then(|| unsafe { std::mem::transmute(op) }); + //~^ eager_transmute // lint even when the transmutable goes through field/array accesses let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then(|| unsafe { std::mem::transmute(op2.foo[0]) }); + //~^ eager_transmute // don't lint: wrong index used in the transmute let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then_some(unsafe { std::mem::transmute(op2.foo[1]) }); @@ -45,11 +52,17 @@ fn f(op: u8, op2: Data, unrelated: u8) { // range contains checks let _: Option = (1..=3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = ((1..=3).contains(&op) || op == 4).then(|| unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (1..3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (1..).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (..3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (..=3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + //~^ eager_transmute // unrelated binding in contains let _: Option = (1..=3) @@ -59,6 +72,7 @@ fn f(op: u8, op2: Data, unrelated: u8) { unsafe fn f2(op: u8) { (op < 4).then(|| std::mem::transmute::<_, Opcode>(op)); + //~^ eager_transmute } #[rustc_layout_scalar_valid_range_end(254)] @@ -88,18 +102,21 @@ impls!(NonMaxU8, NonZeroNonMaxU8); fn niche_tests(v1: u8, v2: NonZeroU8, v3: NonZeroNonMaxU8) { // u8 -> NonZeroU8, do lint let _: Option = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) }); + //~^ eager_transmute // NonZeroU8 -> u8, don't lint, target type has no niche and therefore a higher validity range let _: Option = (v2 > NonZeroU8::new(1).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); // NonZeroU8 -> NonMaxU8, do lint, different niche let _: Option = (v2 < NonZeroU8::new(255).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); + //~^ eager_transmute // NonZeroNonMaxU8 -> NonMaxU8, don't lint, target type has more validity let _: Option = (v3 < 255).then_some(unsafe { std::mem::transmute(v2) }); // NonZeroU8 -> NonZeroNonMaxU8, do lint, target type has less validity let _: Option = (v2 < NonZeroU8::new(255).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); + //~^ eager_transmute } fn main() {} diff --git a/tests/ui/eager_transmute.rs b/tests/ui/eager_transmute.rs index a82bd578f76c..9b9fef136e8c 100644 --- a/tests/ui/eager_transmute.rs +++ b/tests/ui/eager_transmute.rs @@ -19,20 +19,27 @@ struct Data { fn int_to_opcode(op: u8) -> Option { (op < 4).then_some(unsafe { std::mem::transmute(op) }) + //~^ eager_transmute } fn f(op: u8, op2: Data, unrelated: u8) { true.then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); (unrelated < 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); (op < 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); + //~^ eager_transmute (op > 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); + //~^ eager_transmute (op == 0).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); + //~^ eager_transmute let _: Option = (op > 0 && op < 10).then_some(unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (op > 0 && op < 10 && unrelated == 0).then_some(unsafe { std::mem::transmute(op) }); + //~^ eager_transmute // lint even when the transmutable goes through field/array accesses let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then_some(unsafe { std::mem::transmute(op2.foo[0]) }); + //~^ eager_transmute // don't lint: wrong index used in the transmute let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then_some(unsafe { std::mem::transmute(op2.foo[1]) }); @@ -45,11 +52,17 @@ fn f(op: u8, op2: Data, unrelated: u8) { // range contains checks let _: Option = (1..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = ((1..=3).contains(&op) || op == 4).then_some(unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (1..3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (1..).contains(&op).then_some(unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (..3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); + //~^ eager_transmute // unrelated binding in contains let _: Option = (1..=3) @@ -59,6 +72,7 @@ fn f(op: u8, op2: Data, unrelated: u8) { unsafe fn f2(op: u8) { (op < 4).then_some(std::mem::transmute::<_, Opcode>(op)); + //~^ eager_transmute } #[rustc_layout_scalar_valid_range_end(254)] @@ -88,18 +102,21 @@ impls!(NonMaxU8, NonZeroNonMaxU8); fn niche_tests(v1: u8, v2: NonZeroU8, v3: NonZeroNonMaxU8) { // u8 -> NonZeroU8, do lint let _: Option = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) }); + //~^ eager_transmute // NonZeroU8 -> u8, don't lint, target type has no niche and therefore a higher validity range let _: Option = (v2 > NonZeroU8::new(1).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); // NonZeroU8 -> NonMaxU8, do lint, different niche let _: Option = (v2 < NonZeroU8::new(255).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); + //~^ eager_transmute // NonZeroNonMaxU8 -> NonMaxU8, don't lint, target type has more validity let _: Option = (v3 < 255).then_some(unsafe { std::mem::transmute(v2) }); // NonZeroU8 -> NonZeroNonMaxU8, do lint, target type has less validity let _: Option = (v2 < NonZeroU8::new(255).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); + //~^ eager_transmute } fn main() {} diff --git a/tests/ui/eager_transmute.stderr b/tests/ui/eager_transmute.stderr index 5f42eec544fa..aa3e53b5f8d1 100644 --- a/tests/ui/eager_transmute.stderr +++ b/tests/ui/eager_transmute.stderr @@ -12,7 +12,7 @@ LL | (op < 4).then(|| unsafe { std::mem::transmute(op) }) | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> $DIR/eager_transmute.rs:27:33 + --> $DIR/eager_transmute.rs:28:33 | LL | (op < 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | (op < 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> $DIR/eager_transmute.rs:28:33 + --> $DIR/eager_transmute.rs:30:33 | LL | (op > 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | (op > 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> $DIR/eager_transmute.rs:29:34 + --> $DIR/eager_transmute.rs:32:34 | LL | (op == 0).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | (op == 0).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> $DIR/eager_transmute.rs:31:68 + --> $DIR/eager_transmute.rs:35:68 | LL | let _: Option = (op > 0 && op < 10).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let _: Option = (op > 0 && op < 10).then(|| unsafe { std::mem:: | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> $DIR/eager_transmute.rs:32:86 + --> $DIR/eager_transmute.rs:37:86 | LL | let _: Option = (op > 0 && op < 10 && unrelated == 0).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | let _: Option = (op > 0 && op < 10 && unrelated == 0).then(|| u | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> $DIR/eager_transmute.rs:35:84 + --> $DIR/eager_transmute.rs:41:84 | LL | let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then_some(unsafe { std::mem::transmute(op2.foo[0]) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then(|| uns | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> $DIR/eager_transmute.rs:47:70 + --> $DIR/eager_transmute.rs:54:70 | LL | let _: Option = (1..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | let _: Option = (1..=3).contains(&op).then(|| unsafe { std::mem | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> $DIR/eager_transmute.rs:48:83 + --> $DIR/eager_transmute.rs:56:83 | LL | let _: Option = ((1..=3).contains(&op) || op == 4).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | let _: Option = ((1..=3).contains(&op) || op == 4).then(|| unsa | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> $DIR/eager_transmute.rs:49:69 + --> $DIR/eager_transmute.rs:58:69 | LL | let _: Option = (1..3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -111,7 +111,7 @@ LL | let _: Option = (1..3).contains(&op).then(|| unsafe { std::mem: | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> $DIR/eager_transmute.rs:50:68 + --> $DIR/eager_transmute.rs:60:68 | LL | let _: Option = (1..).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | let _: Option = (1..).contains(&op).then(|| unsafe { std::mem:: | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> $DIR/eager_transmute.rs:51:68 + --> $DIR/eager_transmute.rs:62:68 | LL | let _: Option = (..3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | let _: Option = (..3).contains(&op).then(|| unsafe { std::mem:: | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> $DIR/eager_transmute.rs:52:69 + --> $DIR/eager_transmute.rs:64:69 | LL | let _: Option = (..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | let _: Option = (..=3).contains(&op).then(|| unsafe { std::mem: | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> $DIR/eager_transmute.rs:61:24 + --> $DIR/eager_transmute.rs:74:24 | LL | (op < 4).then_some(std::mem::transmute::<_, Opcode>(op)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -155,7 +155,7 @@ LL | (op < 4).then(|| std::mem::transmute::<_, Opcode>(op)); | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> $DIR/eager_transmute.rs:90:60 + --> $DIR/eager_transmute.rs:104:60 | LL | let _: Option = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -166,7 +166,7 @@ LL | let _: Option = (v1 > 0).then(|| unsafe { std::mem::transmut | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> $DIR/eager_transmute.rs:96:86 + --> $DIR/eager_transmute.rs:111:86 | LL | let _: Option = (v2 < NonZeroU8::new(255).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | let _: Option = (v2 < NonZeroU8::new(255).unwrap()).then(|| u | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> $DIR/eager_transmute.rs:102:93 + --> $DIR/eager_transmute.rs:118:93 | LL | let _: Option = (v2 < NonZeroU8::new(255).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/empty_drop.fixed b/tests/ui/empty_drop.fixed index 949d0d8b3997..6ea9e0594716 100644 --- a/tests/ui/empty_drop.fixed +++ b/tests/ui/empty_drop.fixed @@ -4,6 +4,7 @@ // should cause an error struct Foo; +//~v empty_drop // shouldn't cause an error @@ -18,6 +19,7 @@ impl Drop for Bar { // should error struct Baz; +//~v empty_drop fn main() {} diff --git a/tests/ui/empty_drop.rs b/tests/ui/empty_drop.rs index 74822ea50ec7..6aa53a794480 100644 --- a/tests/ui/empty_drop.rs +++ b/tests/ui/empty_drop.rs @@ -4,6 +4,7 @@ // should cause an error struct Foo; +//~v empty_drop impl Drop for Foo { fn drop(&mut self) {} } @@ -20,6 +21,7 @@ impl Drop for Bar { // should error struct Baz; +//~v empty_drop impl Drop for Baz { fn drop(&mut self) { {} diff --git a/tests/ui/empty_drop.stderr b/tests/ui/empty_drop.stderr index 5848eab74474..d1f5e1d68e0e 100644 --- a/tests/ui/empty_drop.stderr +++ b/tests/ui/empty_drop.stderr @@ -1,5 +1,5 @@ error: empty drop implementation - --> $DIR/empty_drop.rs:7:1 + --> $DIR/empty_drop.rs:8:1 | LL | / impl Drop for Foo { LL | | fn drop(&mut self) {} @@ -10,7 +10,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::empty_drop)]` error: empty drop implementation - --> $DIR/empty_drop.rs:23:1 + --> $DIR/empty_drop.rs:25:1 | LL | / impl Drop for Baz { LL | | fn drop(&mut self) { diff --git a/tests/ui/empty_line_after_doc_comments.rs b/tests/ui/empty_line_after_doc_comments.rs index e843770f5785..61e386067996 100644 --- a/tests/ui/empty_line_after_doc_comments.rs +++ b/tests/ui/empty_line_after_doc_comments.rs @@ -15,6 +15,7 @@ mod some_mod { } } +//~v empty_line_after_doc_comments /// This should produce a warning fn with_doc_and_newline() { assert!(true)} @@ -65,8 +66,10 @@ struct Foo { mod foo { } +//~v empty_line_after_doc_comments /// This doc comment should produce a warning +//~v empty_line_after_doc_comments /** This is also a doc comment and should produce a warning */ diff --git a/tests/ui/empty_line_after_doc_comments.stderr b/tests/ui/empty_line_after_doc_comments.stderr index 2cf5b5b0f549..70e6c41169e7 100644 --- a/tests/ui/empty_line_after_doc_comments.stderr +++ b/tests/ui/empty_line_after_doc_comments.stderr @@ -1,5 +1,5 @@ error: found an empty line after a doc comment. Perhaps you need to use `//!` to make a comment on a module, remove the empty line, or make a regular comment with `//`? - --> $DIR/empty_line_after_doc_comments.rs:18:1 + --> $DIR/empty_line_after_doc_comments.rs:19:1 | LL | / /// This should produce a warning LL | | @@ -10,19 +10,19 @@ LL | | fn with_doc_and_newline() { assert!(true)} = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_doc_comments)]` error: found an empty line after a doc comment. Perhaps you need to use `//!` to make a comment on a module, remove the empty line, or make a regular comment with `//`? - --> $DIR/empty_line_after_doc_comments.rs:68:1 + --> $DIR/empty_line_after_doc_comments.rs:70:1 | LL | / /// This doc comment should produce a warning LL | | +LL | | LL | | /** This is also a doc comment and should produce a warning -LL | | */ ... | LL | | #[allow(missing_docs)] LL | | fn three_attributes() { assert!(true) } | |_ error: found an empty line after a doc comment. Perhaps you need to use `//!` to make a comment on a module, remove the empty line, or make a regular comment with `//`? - --> $DIR/empty_line_after_doc_comments.rs:70:1 + --> $DIR/empty_line_after_doc_comments.rs:73:1 | LL | / /** This is also a doc comment and should produce a warning LL | | */ diff --git a/tests/ui/empty_line_after_outer_attribute.rs b/tests/ui/empty_line_after_outer_attribute.rs index 269e66ea0a81..0a80d630c3ab 100644 --- a/tests/ui/empty_line_after_outer_attribute.rs +++ b/tests/ui/empty_line_after_outer_attribute.rs @@ -8,6 +8,7 @@ extern crate proc_macro_attr; // This should produce a warning +//~v empty_line_after_outer_attr #[crate_type = "lib"] /// some comment @@ -20,11 +21,13 @@ fn with_no_newline_and_comment() { assert!(true) } // This should produce a warning +//~v empty_line_after_outer_attr #[crate_type = "lib"] fn with_one_newline() { assert!(true) } // This should produce a warning, too +//~v empty_line_after_outer_attr #[crate_type = "lib"] @@ -32,6 +35,7 @@ fn with_two_newlines() { assert!(true) } // This should produce a warning +//~v empty_line_after_outer_attr #[crate_type = "lib"] enum Baz { @@ -40,6 +44,7 @@ enum Baz { } // This should produce a warning +//~v empty_line_after_outer_attr #[crate_type = "lib"] struct Foo { @@ -48,6 +53,7 @@ struct Foo { } // This should produce a warning +//~v empty_line_after_outer_attr #[crate_type = "lib"] mod foo { diff --git a/tests/ui/empty_line_after_outer_attribute.stderr b/tests/ui/empty_line_after_outer_attribute.stderr index 0cb848c20dde..0ae091a9313c 100644 --- a/tests/ui/empty_line_after_outer_attribute.stderr +++ b/tests/ui/empty_line_after_outer_attribute.stderr @@ -1,5 +1,5 @@ error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:11:1 + --> $DIR/empty_line_after_outer_attribute.rs:12:1 | LL | / #[crate_type = "lib"] LL | | @@ -11,7 +11,7 @@ LL | | fn with_one_newline_and_comment() { assert!(true) } = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_outer_attr)]` error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:23:1 + --> $DIR/empty_line_after_outer_attribute.rs:25:1 | LL | / #[crate_type = "lib"] LL | | @@ -19,7 +19,7 @@ LL | | fn with_one_newline() { assert!(true) } | |_ error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:28:1 + --> $DIR/empty_line_after_outer_attribute.rs:31:1 | LL | / #[crate_type = "lib"] LL | | @@ -28,7 +28,7 @@ LL | | fn with_two_newlines() { assert!(true) } | |_ error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:35:1 + --> $DIR/empty_line_after_outer_attribute.rs:39:1 | LL | / #[crate_type = "lib"] LL | | @@ -36,7 +36,7 @@ LL | | enum Baz { | |_ error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:43:1 + --> $DIR/empty_line_after_outer_attribute.rs:48:1 | LL | / #[crate_type = "lib"] LL | | @@ -44,7 +44,7 @@ LL | | struct Foo { | |_ error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:51:1 + --> $DIR/empty_line_after_outer_attribute.rs:57:1 | LL | / #[crate_type = "lib"] LL | | diff --git a/tests/ui/empty_loop.rs b/tests/ui/empty_loop.rs index be347563135c..691f466348bd 100644 --- a/tests/ui/empty_loop.rs +++ b/tests/ui/empty_loop.rs @@ -6,15 +6,15 @@ extern crate proc_macros; use proc_macros::{external, inline_macros}; fn should_trigger() { - loop {} + loop {} //~ empty_loop #[allow(clippy::never_loop)] loop { - loop {} + loop {} //~ empty_loop } #[allow(clippy::never_loop)] 'outer: loop { - 'inner: loop {} + 'inner: loop {} //~ empty_loop } } diff --git a/tests/ui/empty_structs_with_brackets.fixed b/tests/ui/empty_structs_with_brackets.fixed index 80572645f5d1..52083cb8b1e0 100644 --- a/tests/ui/empty_structs_with_brackets.fixed +++ b/tests/ui/empty_structs_with_brackets.fixed @@ -1,7 +1,10 @@ #![warn(clippy::empty_structs_with_brackets)] #![allow(dead_code)] +//~v empty_structs_with_brackets pub struct MyEmptyStruct; // should trigger lint + +//~v empty_structs_with_brackets struct MyEmptyTupleStruct; // should trigger lint // should not trigger lint diff --git a/tests/ui/empty_structs_with_brackets.rs b/tests/ui/empty_structs_with_brackets.rs index 8fb3e247a419..3e4947160da5 100644 --- a/tests/ui/empty_structs_with_brackets.rs +++ b/tests/ui/empty_structs_with_brackets.rs @@ -1,7 +1,10 @@ #![warn(clippy::empty_structs_with_brackets)] #![allow(dead_code)] +//~v empty_structs_with_brackets pub struct MyEmptyStruct {} // should trigger lint + +//~v empty_structs_with_brackets struct MyEmptyTupleStruct(); // should trigger lint // should not trigger lint diff --git a/tests/ui/empty_structs_with_brackets.stderr b/tests/ui/empty_structs_with_brackets.stderr index 4b8572d5c9ef..ce2822804cc7 100644 --- a/tests/ui/empty_structs_with_brackets.stderr +++ b/tests/ui/empty_structs_with_brackets.stderr @@ -1,5 +1,5 @@ error: found empty brackets on struct declaration - --> $DIR/empty_structs_with_brackets.rs:4:25 + --> $DIR/empty_structs_with_brackets.rs:5:25 | LL | pub struct MyEmptyStruct {} // should trigger lint | ^^^ @@ -9,7 +9,7 @@ LL | pub struct MyEmptyStruct {} // should trigger lint = help: remove the brackets error: found empty brackets on struct declaration - --> $DIR/empty_structs_with_brackets.rs:5:26 + --> $DIR/empty_structs_with_brackets.rs:8:26 | LL | struct MyEmptyTupleStruct(); // should trigger lint | ^^^ diff --git a/tests/ui/endian_bytes.rs b/tests/ui/endian_bytes.rs index 6bf014fc8095..53da63b19c96 100644 --- a/tests/ui/endian_bytes.rs +++ b/tests/ui/endian_bytes.rs @@ -4,63 +4,63 @@ macro_rules! fn_body { () => { - 2u8.to_ne_bytes(); - 2i8.to_ne_bytes(); - 2u16.to_ne_bytes(); - 2i16.to_ne_bytes(); - 2u32.to_ne_bytes(); - 2i32.to_ne_bytes(); - 2u64.to_ne_bytes(); - 2i64.to_ne_bytes(); - 2u128.to_ne_bytes(); - 2i128.to_ne_bytes(); - 2.0f32.to_ne_bytes(); - 2.0f64.to_ne_bytes(); - 2usize.to_ne_bytes(); - 2isize.to_ne_bytes(); - u8::from_ne_bytes(todo!()); - i8::from_ne_bytes(todo!()); - u16::from_ne_bytes(todo!()); - i16::from_ne_bytes(todo!()); - u32::from_ne_bytes(todo!()); - i32::from_ne_bytes(todo!()); - u64::from_ne_bytes(todo!()); - i64::from_ne_bytes(todo!()); - u128::from_ne_bytes(todo!()); - i128::from_ne_bytes(todo!()); - usize::from_ne_bytes(todo!()); - isize::from_ne_bytes(todo!()); - f32::from_ne_bytes(todo!()); - f64::from_ne_bytes(todo!()); + 2u8.to_ne_bytes(); //~ host_endian_bytes + 2i8.to_ne_bytes(); //~ host_endian_bytes + 2u16.to_ne_bytes(); //~ host_endian_bytes + 2i16.to_ne_bytes(); //~ host_endian_bytes + 2u32.to_ne_bytes(); //~ host_endian_bytes + 2i32.to_ne_bytes(); //~ host_endian_bytes + 2u64.to_ne_bytes(); //~ host_endian_bytes + 2i64.to_ne_bytes(); //~ host_endian_bytes + 2u128.to_ne_bytes(); //~ host_endian_bytes + 2i128.to_ne_bytes(); //~ host_endian_bytes + 2.0f32.to_ne_bytes(); //~ host_endian_bytes + 2.0f64.to_ne_bytes(); //~ host_endian_bytes + 2usize.to_ne_bytes(); //~ host_endian_bytes + 2isize.to_ne_bytes(); //~ host_endian_bytes + u8::from_ne_bytes(todo!()); //~ host_endian_bytes + i8::from_ne_bytes(todo!()); //~ host_endian_bytes + u16::from_ne_bytes(todo!()); //~ host_endian_bytes + i16::from_ne_bytes(todo!()); //~ host_endian_bytes + u32::from_ne_bytes(todo!()); //~ host_endian_bytes + i32::from_ne_bytes(todo!()); //~ host_endian_bytes + u64::from_ne_bytes(todo!()); //~ host_endian_bytes + i64::from_ne_bytes(todo!()); //~ host_endian_bytes + u128::from_ne_bytes(todo!()); //~ host_endian_bytes + i128::from_ne_bytes(todo!()); //~ host_endian_bytes + usize::from_ne_bytes(todo!()); //~ host_endian_bytes + isize::from_ne_bytes(todo!()); //~ host_endian_bytes + f32::from_ne_bytes(todo!()); //~ host_endian_bytes + f64::from_ne_bytes(todo!()); //~ host_endian_bytes - 2u8.to_le_bytes(); - 2i8.to_le_bytes(); - 2u16.to_le_bytes(); - 2i16.to_le_bytes(); - 2u32.to_le_bytes(); - 2i32.to_le_bytes(); - 2u64.to_le_bytes(); - 2i64.to_le_bytes(); - 2u128.to_le_bytes(); - 2i128.to_le_bytes(); - 2.0f32.to_le_bytes(); - 2.0f64.to_le_bytes(); - 2usize.to_le_bytes(); - 2isize.to_le_bytes(); - u8::from_le_bytes(todo!()); - i8::from_le_bytes(todo!()); - u16::from_le_bytes(todo!()); - i16::from_le_bytes(todo!()); - u32::from_le_bytes(todo!()); - i32::from_le_bytes(todo!()); - u64::from_le_bytes(todo!()); - i64::from_le_bytes(todo!()); - u128::from_le_bytes(todo!()); - i128::from_le_bytes(todo!()); - usize::from_le_bytes(todo!()); - isize::from_le_bytes(todo!()); - f32::from_le_bytes(todo!()); - f64::from_le_bytes(todo!()); + 2u8.to_le_bytes(); //~ little_endian_bytes + 2i8.to_le_bytes(); //~ little_endian_bytes + 2u16.to_le_bytes(); //~ little_endian_bytes + 2i16.to_le_bytes(); //~ little_endian_bytes + 2u32.to_le_bytes(); //~ little_endian_bytes + 2i32.to_le_bytes(); //~ little_endian_bytes + 2u64.to_le_bytes(); //~ little_endian_bytes + 2i64.to_le_bytes(); //~ little_endian_bytes + 2u128.to_le_bytes(); //~ little_endian_bytes + 2i128.to_le_bytes(); //~ little_endian_bytes + 2.0f32.to_le_bytes(); //~ little_endian_bytes + 2.0f64.to_le_bytes(); //~ little_endian_bytes + 2usize.to_le_bytes(); //~ little_endian_bytes + 2isize.to_le_bytes(); //~ little_endian_bytes + u8::from_le_bytes(todo!()); //~ little_endian_bytes + i8::from_le_bytes(todo!()); //~ little_endian_bytes + u16::from_le_bytes(todo!()); //~ little_endian_bytes + i16::from_le_bytes(todo!()); //~ little_endian_bytes + u32::from_le_bytes(todo!()); //~ little_endian_bytes + i32::from_le_bytes(todo!()); //~ little_endian_bytes + u64::from_le_bytes(todo!()); //~ little_endian_bytes + i64::from_le_bytes(todo!()); //~ little_endian_bytes + u128::from_le_bytes(todo!()); //~ little_endian_bytes + i128::from_le_bytes(todo!()); //~ little_endian_bytes + usize::from_le_bytes(todo!()); //~ little_endian_bytes + isize::from_le_bytes(todo!()); //~ little_endian_bytes + f32::from_le_bytes(todo!()); //~ little_endian_bytes + f64::from_le_bytes(todo!()); //~ little_endian_bytes }; } @@ -68,13 +68,43 @@ macro_rules! fn_body { macro_rules! fn_body_smol { () => { 2u8.to_ne_bytes(); + //~^ host_endian_bytes + //~| host_endian_bytes + //~| host_endian_bytes + //~| host_endian_bytes + //~| host_endian_bytes u8::from_ne_bytes(todo!()); + //~^ host_endian_bytes + //~| host_endian_bytes + //~| host_endian_bytes + //~| host_endian_bytes + //~| host_endian_bytes 2u8.to_le_bytes(); + //~^ little_endian_bytes + //~| little_endian_bytes + //~| little_endian_bytes + //~| little_endian_bytes + //~| little_endian_bytes u8::from_le_bytes(todo!()); + //~^ little_endian_bytes + //~| little_endian_bytes + //~| little_endian_bytes + //~| little_endian_bytes + //~| little_endian_bytes 2u8.to_be_bytes(); + //~^ big_endian_bytes + //~| big_endian_bytes + //~| big_endian_bytes + //~| big_endian_bytes + //~| big_endian_bytes u8::from_be_bytes(todo!()); + //~^ big_endian_bytes + //~| big_endian_bytes + //~| big_endian_bytes + //~| big_endian_bytes + //~| big_endian_bytes }; } diff --git a/tests/ui/endian_bytes.stderr b/tests/ui/endian_bytes.stderr index a458c46fa69a..e0d997171efe 100644 --- a/tests/ui/endian_bytes.stderr +++ b/tests/ui/endian_bytes.stderr @@ -687,7 +687,7 @@ LL | fn host_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_ne_bytes` - --> $DIR/endian_bytes.rs:71:9 + --> $DIR/endian_bytes.rs:76:9 | LL | u8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -699,7 +699,7 @@ LL | fn host_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_be_bytes` method - --> $DIR/endian_bytes.rs:76:9 + --> $DIR/endian_bytes.rs:96:9 | LL | 2u8.to_be_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -713,7 +713,7 @@ LL | fn host_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_be_bytes` - --> $DIR/endian_bytes.rs:77:9 + --> $DIR/endian_bytes.rs:102:9 | LL | u8::from_be_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -737,7 +737,7 @@ LL | fn host_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_ne_bytes` - --> $DIR/endian_bytes.rs:71:9 + --> $DIR/endian_bytes.rs:76:9 | LL | u8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -749,7 +749,7 @@ LL | fn host_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_le_bytes` method - --> $DIR/endian_bytes.rs:73:9 + --> $DIR/endian_bytes.rs:83:9 | LL | 2u8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -761,7 +761,7 @@ LL | fn host_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_le_bytes` - --> $DIR/endian_bytes.rs:74:9 + --> $DIR/endian_bytes.rs:89:9 | LL | u8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -784,7 +784,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_ne_bytes` - --> $DIR/endian_bytes.rs:71:9 + --> $DIR/endian_bytes.rs:76:9 | LL | u8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -795,7 +795,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_le_bytes` method - --> $DIR/endian_bytes.rs:73:9 + --> $DIR/endian_bytes.rs:83:9 | LL | 2u8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -806,7 +806,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_le_bytes` - --> $DIR/endian_bytes.rs:74:9 + --> $DIR/endian_bytes.rs:89:9 | LL | u8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -817,7 +817,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_be_bytes` method - --> $DIR/endian_bytes.rs:76:9 + --> $DIR/endian_bytes.rs:96:9 | LL | 2u8.to_be_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -828,7 +828,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_be_bytes` - --> $DIR/endian_bytes.rs:77:9 + --> $DIR/endian_bytes.rs:102:9 | LL | u8::from_be_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -839,7 +839,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_le_bytes` method - --> $DIR/endian_bytes.rs:73:9 + --> $DIR/endian_bytes.rs:83:9 | LL | 2u8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -851,7 +851,7 @@ LL | fn little_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_le_bytes` - --> $DIR/endian_bytes.rs:74:9 + --> $DIR/endian_bytes.rs:89:9 | LL | u8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -863,7 +863,7 @@ LL | fn little_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_be_bytes` method - --> $DIR/endian_bytes.rs:76:9 + --> $DIR/endian_bytes.rs:96:9 | LL | 2u8.to_be_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -875,7 +875,7 @@ LL | fn little_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_be_bytes` - --> $DIR/endian_bytes.rs:77:9 + --> $DIR/endian_bytes.rs:102:9 | LL | u8::from_be_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -899,7 +899,7 @@ LL | fn little_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_ne_bytes` - --> $DIR/endian_bytes.rs:71:9 + --> $DIR/endian_bytes.rs:76:9 | LL | u8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -911,7 +911,7 @@ LL | fn little_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_le_bytes` method - --> $DIR/endian_bytes.rs:73:9 + --> $DIR/endian_bytes.rs:83:9 | LL | 2u8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -923,7 +923,7 @@ LL | fn little_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_le_bytes` - --> $DIR/endian_bytes.rs:74:9 + --> $DIR/endian_bytes.rs:89:9 | LL | u8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -935,7 +935,7 @@ LL | fn little_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_le_bytes` method - --> $DIR/endian_bytes.rs:73:9 + --> $DIR/endian_bytes.rs:83:9 | LL | 2u8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -947,7 +947,7 @@ LL | fn big_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_le_bytes` - --> $DIR/endian_bytes.rs:74:9 + --> $DIR/endian_bytes.rs:89:9 | LL | u8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -959,7 +959,7 @@ LL | fn big_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_be_bytes` method - --> $DIR/endian_bytes.rs:76:9 + --> $DIR/endian_bytes.rs:96:9 | LL | 2u8.to_be_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -971,7 +971,7 @@ LL | fn big_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_be_bytes` - --> $DIR/endian_bytes.rs:77:9 + --> $DIR/endian_bytes.rs:102:9 | LL | u8::from_be_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -995,7 +995,7 @@ LL | fn big_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_ne_bytes` - --> $DIR/endian_bytes.rs:71:9 + --> $DIR/endian_bytes.rs:76:9 | LL | u8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -1007,7 +1007,7 @@ LL | fn big_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_be_bytes` method - --> $DIR/endian_bytes.rs:76:9 + --> $DIR/endian_bytes.rs:96:9 | LL | 2u8.to_be_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -1019,7 +1019,7 @@ LL | fn big_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_be_bytes` - --> $DIR/endian_bytes.rs:77:9 + --> $DIR/endian_bytes.rs:102:9 | LL | u8::from_be_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/entry.fixed b/tests/ui/entry.fixed index 4099fe7e1393..09ac2ada3028 100644 --- a/tests/ui/entry.fixed +++ b/tests/ui/entry.fixed @@ -21,9 +21,11 @@ fn foo() {} fn hash_map(m: &mut HashMap, m2: &mut HashMap, k: K, k2: K, v: V, v2: V) { // or_insert(v) + //~v map_entry m.entry(k).or_insert(v); // semicolon on insert, use or_insert_with(..) + //~v map_entry m.entry(k).or_insert_with(|| { if true { v @@ -33,6 +35,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa }); // semicolon on if, use or_insert_with(..) + //~v map_entry m.entry(k).or_insert_with(|| { if true { v @@ -42,6 +45,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa }); // early return, use if let + //~v map_entry if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { if true { e.insert(v); @@ -52,12 +56,14 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa } // use or_insert_with(..) + //~v map_entry m.entry(k).or_insert_with(|| { foo(); v }); // semicolon on insert and match, use or_insert_with(..) + //~v map_entry m.entry(k).or_insert_with(|| { match 0 { 1 if true => { @@ -70,6 +76,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa }); // one branch doesn't insert, use if let + //~v map_entry if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { match 0 { 0 => foo(), @@ -80,6 +87,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa } // use or_insert_with + //~v map_entry m.entry(k).or_insert_with(|| { foo(); match 0 { @@ -114,6 +122,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa } // macro_expansion test, use or_insert(..) + //~v map_entry m.entry(m!(k)).or_insert_with(|| m!(v)); // ok, map used before insertion @@ -144,6 +153,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa } // or_insert_with. Partial move of a local declared in the closure is ok. + //~v map_entry m.entry(k).or_insert_with(|| { let x = (String::new(), String::new()); let _ = x.0; diff --git a/tests/ui/entry.rs b/tests/ui/entry.rs index 409be0aa0601..c08cee3d8386 100644 --- a/tests/ui/entry.rs +++ b/tests/ui/entry.rs @@ -21,11 +21,13 @@ fn foo() {} fn hash_map(m: &mut HashMap, m2: &mut HashMap, k: K, k2: K, v: V, v2: V) { // or_insert(v) + //~v map_entry if !m.contains_key(&k) { m.insert(k, v); } // semicolon on insert, use or_insert_with(..) + //~v map_entry if !m.contains_key(&k) { if true { m.insert(k, v); @@ -35,6 +37,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa } // semicolon on if, use or_insert_with(..) + //~v map_entry if !m.contains_key(&k) { if true { m.insert(k, v) @@ -44,6 +47,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa } // early return, use if let + //~v map_entry if !m.contains_key(&k) { if true { m.insert(k, v); @@ -54,12 +58,14 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa } // use or_insert_with(..) + //~v map_entry if !m.contains_key(&k) { foo(); m.insert(k, v); } // semicolon on insert and match, use or_insert_with(..) + //~v map_entry if !m.contains_key(&k) { match 0 { 1 if true => { @@ -72,6 +78,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa } // one branch doesn't insert, use if let + //~v map_entry if !m.contains_key(&k) { match 0 { 0 => foo(), @@ -82,6 +89,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa } // use or_insert_with + //~v map_entry if !m.contains_key(&k) { foo(); match 0 { @@ -116,6 +124,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa } // macro_expansion test, use or_insert(..) + //~v map_entry if !m.contains_key(&m!(k)) { m.insert(m!(k), m!(v)); } @@ -148,6 +157,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa } // or_insert_with. Partial move of a local declared in the closure is ok. + //~v map_entry if !m.contains_key(&k) { let x = (String::new(), String::new()); let _ = x.0; diff --git a/tests/ui/entry.stderr b/tests/ui/entry.stderr index b01f0a9a0e56..1bfd9a7f8503 100644 --- a/tests/ui/entry.stderr +++ b/tests/ui/entry.stderr @@ -1,5 +1,5 @@ error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:24:5 + --> $DIR/entry.rs:25:5 | LL | / if !m.contains_key(&k) { LL | | m.insert(k, v); @@ -10,7 +10,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::map_entry)]` error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:29:5 + --> $DIR/entry.rs:31:5 | LL | / if !m.contains_key(&k) { LL | | if true { @@ -33,7 +33,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:38:5 + --> $DIR/entry.rs:41:5 | LL | / if !m.contains_key(&k) { LL | | if true { @@ -56,7 +56,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:47:5 + --> $DIR/entry.rs:51:5 | LL | / if !m.contains_key(&k) { LL | | if true { @@ -80,7 +80,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:57:5 + --> $DIR/entry.rs:62:5 | LL | / if !m.contains_key(&k) { LL | | foo(); @@ -97,7 +97,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:63:5 + --> $DIR/entry.rs:69:5 | LL | / if !m.contains_key(&k) { LL | | match 0 { @@ -123,7 +123,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:75:5 + --> $DIR/entry.rs:82:5 | LL | / if !m.contains_key(&k) { LL | | match 0 { @@ -147,7 +147,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:85:5 + --> $DIR/entry.rs:93:5 | LL | / if !m.contains_key(&k) { LL | | foo(); @@ -188,7 +188,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:119:5 + --> $DIR/entry.rs:128:5 | LL | / if !m.contains_key(&m!(k)) { LL | | m.insert(m!(k), m!(v)); @@ -196,7 +196,7 @@ LL | | } | |_____^ help: try: `m.entry(m!(k)).or_insert_with(|| m!(v));` error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:151:5 + --> $DIR/entry.rs:161:5 | LL | / if !m.contains_key(&k) { LL | | let x = (String::new(), String::new()); diff --git a/tests/ui/entry_btree.fixed b/tests/ui/entry_btree.fixed index 228212c79eaf..5f58476c7ca7 100644 --- a/tests/ui/entry_btree.fixed +++ b/tests/ui/entry_btree.fixed @@ -7,6 +7,7 @@ fn foo() {} fn btree_map(m: &mut BTreeMap, k: K, v: V) { // insert then do something, use if let + //~v map_entry if let std::collections::btree_map::Entry::Vacant(e) = m.entry(k) { e.insert(v); foo(); diff --git a/tests/ui/entry_btree.rs b/tests/ui/entry_btree.rs index 44703c567113..dfedebef3770 100644 --- a/tests/ui/entry_btree.rs +++ b/tests/ui/entry_btree.rs @@ -7,6 +7,7 @@ fn foo() {} fn btree_map(m: &mut BTreeMap, k: K, v: V) { // insert then do something, use if let + //~v map_entry if !m.contains_key(&k) { m.insert(k, v); foo(); diff --git a/tests/ui/entry_btree.stderr b/tests/ui/entry_btree.stderr index 63e9a0af8b6b..26993e00dd42 100644 --- a/tests/ui/entry_btree.stderr +++ b/tests/ui/entry_btree.stderr @@ -1,5 +1,5 @@ error: usage of `contains_key` followed by `insert` on a `BTreeMap` - --> $DIR/entry_btree.rs:10:5 + --> $DIR/entry_btree.rs:11:5 | LL | / if !m.contains_key(&k) { LL | | m.insert(k, v); diff --git a/tests/ui/entry_with_else.fixed b/tests/ui/entry_with_else.fixed index 34804b9ee5d7..d1b3c5242692 100644 --- a/tests/ui/entry_with_else.fixed +++ b/tests/ui/entry_with_else.fixed @@ -11,6 +11,7 @@ macro_rules! m { fn foo() {} fn insert_if_absent0(m: &mut HashMap, k: K, v: V, v2: V) { + //~v map_entry match m.entry(k) { std::collections::hash_map::Entry::Vacant(e) => { e.insert(v); @@ -20,6 +21,7 @@ fn insert_if_absent0(m: &mut HashMap, k: K, } } + //~v map_entry match m.entry(k) { std::collections::hash_map::Entry::Occupied(mut e) => { e.insert(v); @@ -29,18 +31,21 @@ fn insert_if_absent0(m: &mut HashMap, k: K, } } + //~v map_entry if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { e.insert(v); } else { foo(); } + //~v map_entry if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) { e.insert(v); } else { foo(); } + //~v map_entry match m.entry(k) { std::collections::hash_map::Entry::Vacant(e) => { e.insert(v); @@ -50,6 +55,7 @@ fn insert_if_absent0(m: &mut HashMap, k: K, } } + //~v map_entry match m.entry(k) { std::collections::hash_map::Entry::Occupied(mut e) => { if true { Some(e.insert(v)) } else { Some(e.insert(v2)) } @@ -60,6 +66,7 @@ fn insert_if_absent0(m: &mut HashMap, k: K, } }; + //~v map_entry if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) { foo(); Some(e.insert(v)) diff --git a/tests/ui/entry_with_else.rs b/tests/ui/entry_with_else.rs index 0515748fd733..ba11afcc4c42 100644 --- a/tests/ui/entry_with_else.rs +++ b/tests/ui/entry_with_else.rs @@ -11,42 +11,49 @@ macro_rules! m { fn foo() {} fn insert_if_absent0(m: &mut HashMap, k: K, v: V, v2: V) { + //~v map_entry if !m.contains_key(&k) { m.insert(k, v); } else { m.insert(k, v2); } + //~v map_entry if m.contains_key(&k) { m.insert(k, v); } else { m.insert(k, v2); } + //~v map_entry if !m.contains_key(&k) { m.insert(k, v); } else { foo(); } + //~v map_entry if !m.contains_key(&k) { foo(); } else { m.insert(k, v); } + //~v map_entry if !m.contains_key(&k) { m.insert(k, v); } else { m.insert(k, v2); } + //~v map_entry if m.contains_key(&k) { if true { m.insert(k, v) } else { m.insert(k, v2) } } else { m.insert(k, v) }; + //~v map_entry if m.contains_key(&k) { foo(); m.insert(k, v) diff --git a/tests/ui/entry_with_else.stderr b/tests/ui/entry_with_else.stderr index 425e87122d57..d62e0b6ab46e 100644 --- a/tests/ui/entry_with_else.stderr +++ b/tests/ui/entry_with_else.stderr @@ -1,5 +1,5 @@ error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:14:5 + --> $DIR/entry_with_else.rs:15:5 | LL | / if !m.contains_key(&k) { LL | | m.insert(k, v); @@ -23,7 +23,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:20:5 + --> $DIR/entry_with_else.rs:22:5 | LL | / if m.contains_key(&k) { LL | | m.insert(k, v); @@ -45,7 +45,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:26:5 + --> $DIR/entry_with_else.rs:29:5 | LL | / if !m.contains_key(&k) { LL | | m.insert(k, v); @@ -64,7 +64,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:32:5 + --> $DIR/entry_with_else.rs:36:5 | LL | / if !m.contains_key(&k) { LL | | foo(); @@ -83,7 +83,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:38:5 + --> $DIR/entry_with_else.rs:43:5 | LL | / if !m.contains_key(&k) { LL | | m.insert(k, v); @@ -105,7 +105,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:44:5 + --> $DIR/entry_with_else.rs:50:5 | LL | / if m.contains_key(&k) { LL | | if true { m.insert(k, v) } else { m.insert(k, v2) } @@ -128,7 +128,7 @@ LL ~ }; | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:50:5 + --> $DIR/entry_with_else.rs:57:5 | LL | / if m.contains_key(&k) { LL | | foo(); diff --git a/tests/ui/enum_glob_use.fixed b/tests/ui/enum_glob_use.fixed index 3c0db9beb1a6..012f9e56ae25 100644 --- a/tests/ui/enum_glob_use.fixed +++ b/tests/ui/enum_glob_use.fixed @@ -2,17 +2,17 @@ #![allow(unused)] #![warn(unused_imports)] -use std::cmp::Ordering::Less; +use std::cmp::Ordering::Less; //~ enum_glob_use enum Enum { Foo, } -use self::Enum::Foo; +use self::Enum::Foo; //~ enum_glob_use mod in_fn_test { fn blarg() { - use crate::Enum::Foo; + use crate::Enum::Foo; //~ enum_glob_use let _ = Foo; } diff --git a/tests/ui/enum_glob_use.rs b/tests/ui/enum_glob_use.rs index 2538477f7978..ae48280ff56a 100644 --- a/tests/ui/enum_glob_use.rs +++ b/tests/ui/enum_glob_use.rs @@ -2,17 +2,17 @@ #![allow(unused)] #![warn(unused_imports)] -use std::cmp::Ordering::*; +use std::cmp::Ordering::*; //~ enum_glob_use enum Enum { Foo, } -use self::Enum::*; +use self::Enum::*; //~ enum_glob_use mod in_fn_test { fn blarg() { - use crate::Enum::*; + use crate::Enum::*; //~ enum_glob_use let _ = Foo; } diff --git a/tests/ui/eq_op_macros.rs b/tests/ui/eq_op_macros.rs index a511af4a31c8..b2a3f53fafe7 100644 --- a/tests/ui/eq_op_macros.rs +++ b/tests/ui/eq_op_macros.rs @@ -5,10 +5,10 @@ macro_rules! assert_in_macro_def { () => { let a = 42; - assert_eq!(a, a); - assert_ne!(a, a); - debug_assert_eq!(a, a); - debug_assert_ne!(a, a); + assert_eq!(a, a); //~ eq_op + assert_ne!(a, a); //~ eq_op + debug_assert_eq!(a, a); //~ eq_op + debug_assert_ne!(a, a); //~ eq_op }; } diff --git a/tests/ui/equatable_if_let.fixed b/tests/ui/equatable_if_let.fixed index 2b523e1e185c..3d97c396efa6 100644 --- a/tests/ui/equatable_if_let.fixed +++ b/tests/ui/equatable_if_let.fixed @@ -61,14 +61,16 @@ fn main() { // true - if a == 2 {} - if a.cmp(&b) == Ordering::Greater {} - if c == Some(2) {} - if d == (Struct { a: 2, b: false }) {} - if e == Enum::TupleVariant(32, 64) {} + if a == 2 {} //~ equatable_if_let + if a.cmp(&b) == Ordering::Greater {} //~ equatable_if_let + if c == Some(2) {} //~ equatable_if_let + if d == (Struct { a: 2, b: false }) {} //~ equatable_if_let + if e == Enum::TupleVariant(32, 64) {} //~ equatable_if_let if e == (Enum::RecordVariant { a: 64, b: 32 }) {} - if e == Enum::UnitVariant {} + //~^ equatable_if_let + if e == Enum::UnitVariant {} //~ equatable_if_let if (e, &d) == (Enum::UnitVariant, &Struct { a: 2, b: false }) {} + //~^ equatable_if_let // false @@ -77,12 +79,15 @@ fn main() { if let Some(3 | 4) = c {} if let Struct { a, b: false } = d {} if let Struct { a: 2, b: x } = d {} - if matches!(f, NotPartialEq::A) {} - if g == NotStructuralEq::A {} - if matches!(Some(f), Some(NotPartialEq::A)) {} + if matches!(f, NotPartialEq::A) {} //~ equatable_if_let + if g == NotStructuralEq::A {} //~ equatable_if_let + if matches!(Some(f), Some(NotPartialEq::A)) {} //~ equatable_if_let if Some(g) == Some(NotStructuralEq::A) {} + //~^ equatable_if_let if matches!(h, NoPartialEqStruct { a: 2, b: false }) {} + //~^ equatable_if_let + //~v equatable_if_let if "abc" == inline!("abc") { println!("OK"); } diff --git a/tests/ui/equatable_if_let.rs b/tests/ui/equatable_if_let.rs index f7e3bb2964da..f55fcc9fa43d 100644 --- a/tests/ui/equatable_if_let.rs +++ b/tests/ui/equatable_if_let.rs @@ -61,14 +61,16 @@ fn main() { // true - if let 2 = a {} - if let Ordering::Greater = a.cmp(&b) {} - if let Some(2) = c {} - if let Struct { a: 2, b: false } = d {} - if let Enum::TupleVariant(32, 64) = e {} + if let 2 = a {} //~ equatable_if_let + if let Ordering::Greater = a.cmp(&b) {} //~ equatable_if_let + if let Some(2) = c {} //~ equatable_if_let + if let Struct { a: 2, b: false } = d {} //~ equatable_if_let + if let Enum::TupleVariant(32, 64) = e {} //~ equatable_if_let if let Enum::RecordVariant { a: 64, b: 32 } = e {} - if let Enum::UnitVariant = e {} + //~^ equatable_if_let + if let Enum::UnitVariant = e {} //~ equatable_if_let if let (Enum::UnitVariant, &Struct { a: 2, b: false }) = (e, &d) {} + //~^ equatable_if_let // false @@ -77,12 +79,15 @@ fn main() { if let Some(3 | 4) = c {} if let Struct { a, b: false } = d {} if let Struct { a: 2, b: x } = d {} - if let NotPartialEq::A = f {} - if let NotStructuralEq::A = g {} - if let Some(NotPartialEq::A) = Some(f) {} + if let NotPartialEq::A = f {} //~ equatable_if_let + if let NotStructuralEq::A = g {} //~ equatable_if_let + if let Some(NotPartialEq::A) = Some(f) {} //~ equatable_if_let if let Some(NotStructuralEq::A) = Some(g) {} + //~^ equatable_if_let if let NoPartialEqStruct { a: 2, b: false } = h {} + //~^ equatable_if_let + //~v equatable_if_let if let inline!("abc") = "abc" { println!("OK"); } diff --git a/tests/ui/equatable_if_let.stderr b/tests/ui/equatable_if_let.stderr index 6cc19d829edc..881187cbcdab 100644 --- a/tests/ui/equatable_if_let.stderr +++ b/tests/ui/equatable_if_let.stderr @@ -38,49 +38,49 @@ LL | if let Enum::RecordVariant { a: 64, b: 32 } = e {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `e == (Enum::RecordVariant { a: 64, b: 32 })` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:70:8 + --> $DIR/equatable_if_let.rs:71:8 | LL | if let Enum::UnitVariant = e {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `e == Enum::UnitVariant` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:71:8 + --> $DIR/equatable_if_let.rs:72:8 | LL | if let (Enum::UnitVariant, &Struct { a: 2, b: false }) = (e, &d) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(e, &d) == (Enum::UnitVariant, &Struct { a: 2, b: false })` error: this pattern matching can be expressed using `matches!` - --> $DIR/equatable_if_let.rs:80:8 + --> $DIR/equatable_if_let.rs:82:8 | LL | if let NotPartialEq::A = f {} | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(f, NotPartialEq::A)` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:81:8 + --> $DIR/equatable_if_let.rs:83:8 | LL | if let NotStructuralEq::A = g {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `g == NotStructuralEq::A` error: this pattern matching can be expressed using `matches!` - --> $DIR/equatable_if_let.rs:82:8 + --> $DIR/equatable_if_let.rs:84:8 | LL | if let Some(NotPartialEq::A) = Some(f) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(Some(f), Some(NotPartialEq::A))` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:83:8 + --> $DIR/equatable_if_let.rs:85:8 | LL | if let Some(NotStructuralEq::A) = Some(g) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(g) == Some(NotStructuralEq::A)` error: this pattern matching can be expressed using `matches!` - --> $DIR/equatable_if_let.rs:84:8 + --> $DIR/equatable_if_let.rs:87:8 | LL | if let NoPartialEqStruct { a: 2, b: false } = h {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(h, NoPartialEqStruct { a: 2, b: false })` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:86:8 + --> $DIR/equatable_if_let.rs:91:8 | LL | if let inline!("abc") = "abc" { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"abc" == inline!("abc")` diff --git a/tests/ui/err_expect.fixed b/tests/ui/err_expect.fixed index abbc6dbebedb..04aec76351b9 100644 --- a/tests/ui/err_expect.fixed +++ b/tests/ui/err_expect.fixed @@ -7,7 +7,7 @@ struct MyTypeDebug; fn main() { let test_debug: Result = Ok(MyTypeDebug); - test_debug.expect_err("Testing debug type"); + test_debug.expect_err("Testing debug type"); //~ err_expect let test_non_debug: Result = Ok(MyTypeNonDebug); test_non_debug.err().expect("Testing non debug type"); @@ -22,5 +22,5 @@ fn msrv_1_16() { #[clippy::msrv = "1.17"] fn msrv_1_17() { let x: Result = Ok(17); - x.expect_err("17"); + x.expect_err("17"); //~ err_expect } diff --git a/tests/ui/err_expect.rs b/tests/ui/err_expect.rs index 0c7ad185dfbe..e457bac9819f 100644 --- a/tests/ui/err_expect.rs +++ b/tests/ui/err_expect.rs @@ -7,7 +7,7 @@ struct MyTypeDebug; fn main() { let test_debug: Result = Ok(MyTypeDebug); - test_debug.err().expect("Testing debug type"); + test_debug.err().expect("Testing debug type"); //~ err_expect let test_non_debug: Result = Ok(MyTypeNonDebug); test_non_debug.err().expect("Testing non debug type"); @@ -22,5 +22,5 @@ fn msrv_1_16() { #[clippy::msrv = "1.17"] fn msrv_1_17() { let x: Result = Ok(17); - x.err().expect("17"); + x.err().expect("17"); //~ err_expect } diff --git a/tests/ui/eta.fixed b/tests/ui/eta.fixed index da28ec2e653a..8e1bcd83b975 100644 --- a/tests/ui/eta.fixed +++ b/tests/ui/eta.fixed @@ -26,12 +26,18 @@ macro_rules! closure_mac { } fn main() { - let a = Some(1u8).map(foo); + let a = Some(1u8).map(foo); //~ redundant_closure let c = Some(1u8).map(|a| {1+2; foo}(a)); true.then(|| mac!()); // don't lint function in macro expansion Some(1).map(closure_mac!()); // don't lint closure in macro expansion + + //~v redundant_closure let _: Option> = true.then(std::vec::Vec::new); // special case vec! + + //~v redundant_closure let d = Some(1u8).map(|a| foo(foo2(a))); //is adjusted? + + //~v redundant_closure all(&[1, 2, 3], &&2, below); //is adjusted unsafe { Some(1u8).map(|a| unsafe_fn(a)); // unsafe fn @@ -39,7 +45,7 @@ fn main() { // See #815 let e = Some(1u8).map(|a| divergent(a)); - let e = Some(1u8).map(generic); + let e = Some(1u8).map(generic); //~ redundant_closure let e = Some(1u8).map(generic); // See #515 let a: Option)>> = @@ -92,16 +98,22 @@ impl<'a> std::ops::Deref for TestStruct<'a> { fn test_redundant_closures_containing_method_calls() { let i = 10; let e = Some(TestStruct { some_ref: &i }).map(TestStruct::foo); + //~^ redundant_closure_for_method_calls let e = Some(TestStruct { some_ref: &i }).map(TestTrait::trait_foo); + //~^ redundant_closure_for_method_calls let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo_ref()); let e = Some(&mut vec![1, 2, 3]).map(std::vec::Vec::clear); + //~^ redundant_closure_for_method_calls unsafe { let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo_unsafe()); } let e = Some("str").map(std::string::ToString::to_string); + //~^ redundant_closure_for_method_calls let e = Some('a').map(char::to_uppercase); + //~^ redundant_closure_for_method_calls let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(|c| c.len_utf8()).collect(); let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(char::to_ascii_uppercase).collect(); + //~^ redundant_closure_for_method_calls let e = Some(PathBuf::new()).as_ref().and_then(|s| s.to_str()); let c = Some(TestStruct { some_ref: &i }) .as_ref() @@ -164,19 +176,19 @@ fn generic(_: T) -> u8 { } fn passes_fn_mut(mut x: Box) { - requires_fn_once(x); + requires_fn_once(x); //~ redundant_closure } fn requires_fn_once(_: T) {} fn test_redundant_closure_with_function_pointer() { type FnPtrType = fn(u8); let foo_ptr: FnPtrType = foo; - let a = Some(1u8).map(foo_ptr); + let a = Some(1u8).map(foo_ptr); //~ redundant_closure } fn test_redundant_closure_with_another_closure() { let closure = |a| println!("{}", a); - let a = Some(1u8).map(closure); + let a = Some(1u8).map(closure); //~ redundant_closure } fn make_lazy(f: impl Fn() -> fn(u8) -> u8) -> impl Fn(u8) -> u8 { @@ -208,20 +220,20 @@ fn test_deref_with_trait_method() { fn mutable_closure_used_again(x: Vec, y: Vec, z: Vec) { let mut res = Vec::new(); let mut add_to_res = |n| res.push(n); - x.into_iter().for_each(&mut add_to_res); - y.into_iter().for_each(&mut add_to_res); - z.into_iter().for_each(add_to_res); + x.into_iter().for_each(&mut add_to_res); //~ redundant_closure + y.into_iter().for_each(&mut add_to_res); //~ redundant_closure + z.into_iter().for_each(add_to_res); //~ redundant_closure } fn mutable_closure_in_loop() { let mut value = 0; let mut closure = |n| value += n; for _ in 0..5 { - Some(1).map(&mut closure); + Some(1).map(&mut closure); //~ redundant_closure let mut value = 0; let mut in_loop = |n| value += n; - Some(1).map(in_loop); + Some(1).map(in_loop); //~ redundant_closure } } @@ -314,14 +326,14 @@ fn not_general_enough() { // https://github.com/rust-lang/rust-clippy/issues/9369 pub fn mutable_impl_fn_mut(mut f: impl FnMut(), mut f_used_once: impl FnMut()) -> impl FnMut() { fn takes_fn_mut(_: impl FnMut()) {} - takes_fn_mut(&mut f); + takes_fn_mut(&mut f); //~ redundant_closure fn takes_fn_once(_: impl FnOnce()) {} - takes_fn_once(&mut f); + takes_fn_once(&mut f); //~ redundant_closure f(); - move || takes_fn_mut(&mut f_used_once) + move || takes_fn_mut(&mut f_used_once) //~ redundant_closure } impl dyn TestTrait + '_ { @@ -334,16 +346,20 @@ impl dyn TestTrait + '_ { fn angle_brackets_and_args() { let array_opt: Option<&[u8; 3]> = Some(&[4, 8, 7]); array_opt.map(<[u8; 3]>::as_slice); + //~^ redundant_closure_for_method_calls let slice_opt: Option<&[u8]> = Some(b"slice"); slice_opt.map(<[u8]>::len); + //~^ redundant_closure_for_method_calls let ptr_opt: Option<*const usize> = Some(&487); ptr_opt.map(<*const usize>::is_null); + //~^ redundant_closure_for_method_calls let test_struct = TestStruct { some_ref: &487 }; let dyn_opt: Option<&dyn TestTrait> = Some(&test_struct); dyn_opt.map(::method_on_dyn); + //~^ redundant_closure_for_method_calls } // https://github.com/rust-lang/rust-clippy/issues/12199 @@ -403,7 +419,7 @@ fn _mixed_late_bound_and_early_bound_regions() { fn f2<'a, T: 'a>(_: &'a T, y: &u32) -> u32 { *y } - let _ = f(&0, f2); + let _ = f(&0, f2); //~ redundant_closure } fn _closure_with_types() { @@ -432,10 +448,12 @@ mod issue_10854 { pub fn calls_test(test: Option) -> Option { test.map(Test::method) + //~^ redundant_closure_for_method_calls } pub fn calls_outer(test: Option) -> Option { test.map(super::Outer::method) + //~^ redundant_closure_for_method_calls } } @@ -449,6 +467,7 @@ mod issue_10854 { pub fn calls_into_mod(test: Option) -> Option { test.map(test_mod::Test::method) + //~^ redundant_closure_for_method_calls } mod a { @@ -456,6 +475,7 @@ mod issue_10854 { pub mod c { pub fn extreme_nesting(test: Option) -> Option { test.map(crate::issue_10854::d::Test::method) + //~^ redundant_closure_for_method_calls } } } diff --git a/tests/ui/eta.rs b/tests/ui/eta.rs index f924100f8f41..4ec1c963e41d 100644 --- a/tests/ui/eta.rs +++ b/tests/ui/eta.rs @@ -26,12 +26,18 @@ macro_rules! closure_mac { } fn main() { - let a = Some(1u8).map(|a| foo(a)); + let a = Some(1u8).map(|a| foo(a)); //~ redundant_closure let c = Some(1u8).map(|a| {1+2; foo}(a)); true.then(|| mac!()); // don't lint function in macro expansion Some(1).map(closure_mac!()); // don't lint closure in macro expansion + + //~v redundant_closure let _: Option> = true.then(|| vec![]); // special case vec! + + //~v redundant_closure let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted? + + //~v redundant_closure all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted unsafe { Some(1u8).map(|a| unsafe_fn(a)); // unsafe fn @@ -39,7 +45,7 @@ fn main() { // See #815 let e = Some(1u8).map(|a| divergent(a)); - let e = Some(1u8).map(|a| generic(a)); + let e = Some(1u8).map(|a| generic(a)); //~ redundant_closure let e = Some(1u8).map(generic); // See #515 let a: Option)>> = @@ -92,16 +98,22 @@ impl<'a> std::ops::Deref for TestStruct<'a> { fn test_redundant_closures_containing_method_calls() { let i = 10; let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); + //~^ redundant_closure_for_method_calls let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo()); + //~^ redundant_closure_for_method_calls let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo_ref()); let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear()); + //~^ redundant_closure_for_method_calls unsafe { let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo_unsafe()); } let e = Some("str").map(|s| s.to_string()); + //~^ redundant_closure_for_method_calls let e = Some('a').map(|s| s.to_uppercase()); + //~^ redundant_closure_for_method_calls let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(|c| c.len_utf8()).collect(); let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect(); + //~^ redundant_closure_for_method_calls let e = Some(PathBuf::new()).as_ref().and_then(|s| s.to_str()); let c = Some(TestStruct { some_ref: &i }) .as_ref() @@ -164,19 +176,19 @@ fn generic(_: T) -> u8 { } fn passes_fn_mut(mut x: Box) { - requires_fn_once(|| x()); + requires_fn_once(|| x()); //~ redundant_closure } fn requires_fn_once(_: T) {} fn test_redundant_closure_with_function_pointer() { type FnPtrType = fn(u8); let foo_ptr: FnPtrType = foo; - let a = Some(1u8).map(|a| foo_ptr(a)); + let a = Some(1u8).map(|a| foo_ptr(a)); //~ redundant_closure } fn test_redundant_closure_with_another_closure() { let closure = |a| println!("{}", a); - let a = Some(1u8).map(|a| closure(a)); + let a = Some(1u8).map(|a| closure(a)); //~ redundant_closure } fn make_lazy(f: impl Fn() -> fn(u8) -> u8) -> impl Fn(u8) -> u8 { @@ -208,20 +220,20 @@ fn test_deref_with_trait_method() { fn mutable_closure_used_again(x: Vec, y: Vec, z: Vec) { let mut res = Vec::new(); let mut add_to_res = |n| res.push(n); - x.into_iter().for_each(|x| add_to_res(x)); - y.into_iter().for_each(|x| add_to_res(x)); - z.into_iter().for_each(|x| add_to_res(x)); + x.into_iter().for_each(|x| add_to_res(x)); //~ redundant_closure + y.into_iter().for_each(|x| add_to_res(x)); //~ redundant_closure + z.into_iter().for_each(|x| add_to_res(x)); //~ redundant_closure } fn mutable_closure_in_loop() { let mut value = 0; let mut closure = |n| value += n; for _ in 0..5 { - Some(1).map(|n| closure(n)); + Some(1).map(|n| closure(n)); //~ redundant_closure let mut value = 0; let mut in_loop = |n| value += n; - Some(1).map(|n| in_loop(n)); + Some(1).map(|n| in_loop(n)); //~ redundant_closure } } @@ -314,14 +326,14 @@ fn not_general_enough() { // https://github.com/rust-lang/rust-clippy/issues/9369 pub fn mutable_impl_fn_mut(mut f: impl FnMut(), mut f_used_once: impl FnMut()) -> impl FnMut() { fn takes_fn_mut(_: impl FnMut()) {} - takes_fn_mut(|| f()); + takes_fn_mut(|| f()); //~ redundant_closure fn takes_fn_once(_: impl FnOnce()) {} - takes_fn_once(|| f()); + takes_fn_once(|| f()); //~ redundant_closure f(); - move || takes_fn_mut(|| f_used_once()) + move || takes_fn_mut(|| f_used_once()) //~ redundant_closure } impl dyn TestTrait + '_ { @@ -334,16 +346,20 @@ impl dyn TestTrait + '_ { fn angle_brackets_and_args() { let array_opt: Option<&[u8; 3]> = Some(&[4, 8, 7]); array_opt.map(|a| a.as_slice()); + //~^ redundant_closure_for_method_calls let slice_opt: Option<&[u8]> = Some(b"slice"); slice_opt.map(|s| s.len()); + //~^ redundant_closure_for_method_calls let ptr_opt: Option<*const usize> = Some(&487); ptr_opt.map(|p| p.is_null()); + //~^ redundant_closure_for_method_calls let test_struct = TestStruct { some_ref: &487 }; let dyn_opt: Option<&dyn TestTrait> = Some(&test_struct); dyn_opt.map(|d| d.method_on_dyn()); + //~^ redundant_closure_for_method_calls } // https://github.com/rust-lang/rust-clippy/issues/12199 @@ -403,7 +419,7 @@ fn _mixed_late_bound_and_early_bound_regions() { fn f2<'a, T: 'a>(_: &'a T, y: &u32) -> u32 { *y } - let _ = f(&0, |x, y| f2(x, y)); + let _ = f(&0, |x, y| f2(x, y)); //~ redundant_closure } fn _closure_with_types() { @@ -432,10 +448,12 @@ mod issue_10854 { pub fn calls_test(test: Option) -> Option { test.map(|t| t.method()) + //~^ redundant_closure_for_method_calls } pub fn calls_outer(test: Option) -> Option { test.map(|t| t.method()) + //~^ redundant_closure_for_method_calls } } @@ -449,6 +467,7 @@ mod issue_10854 { pub fn calls_into_mod(test: Option) -> Option { test.map(|t| t.method()) + //~^ redundant_closure_for_method_calls } mod a { @@ -456,6 +475,7 @@ mod issue_10854 { pub mod c { pub fn extreme_nesting(test: Option) -> Option { test.map(|t| t.method()) + //~^ redundant_closure_for_method_calls } } } diff --git a/tests/ui/eta.stderr b/tests/ui/eta.stderr index 945de466d832..f3a851360f7a 100644 --- a/tests/ui/eta.stderr +++ b/tests/ui/eta.stderr @@ -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 - --> $DIR/eta.rs:33:40 + --> $DIR/eta.rs:35:40 | LL | let _: Option> = true.then(|| vec![]); // special case vec! | ^^^^^^^^^ help: replace the closure with `Vec::new`: `std::vec::Vec::new` error: redundant closure - --> $DIR/eta.rs:34:35 + --> $DIR/eta.rs:38: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 - --> $DIR/eta.rs:35:26 + --> $DIR/eta.rs:41: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 - --> $DIR/eta.rs:42:27 + --> $DIR/eta.rs:48:27 | LL | let e = Some(1u8).map(|a| generic(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `generic` error: redundant closure - --> $DIR/eta.rs:94:51 + --> $DIR/eta.rs:100:51 | LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); | ^^^^^^^^^^^ help: replace the closure with the method itself: `TestStruct::foo` @@ -41,151 +41,151 @@ 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 - --> $DIR/eta.rs:95:51 + --> $DIR/eta.rs:102: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 - --> $DIR/eta.rs:97:42 + --> $DIR/eta.rs:105: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 - --> $DIR/eta.rs:101:29 + --> $DIR/eta.rs:110: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 - --> $DIR/eta.rs:102:27 + --> $DIR/eta.rs:112: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 - --> $DIR/eta.rs:104:65 + --> $DIR/eta.rs:115:65 | LL | let e: std::vec::Vec = 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 - --> $DIR/eta.rs:167:22 + --> $DIR/eta.rs:179:22 | LL | requires_fn_once(|| x()); | ^^^^^^ help: replace the closure with the function itself: `x` error: redundant closure - --> $DIR/eta.rs:174:27 + --> $DIR/eta.rs:186:27 | LL | let a = Some(1u8).map(|a| foo_ptr(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo_ptr` error: redundant closure - --> $DIR/eta.rs:179:27 + --> $DIR/eta.rs:191:27 | LL | let a = Some(1u8).map(|a| closure(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `closure` error: redundant closure - --> $DIR/eta.rs:211:28 + --> $DIR/eta.rs:223: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 - --> $DIR/eta.rs:212:28 + --> $DIR/eta.rs:224: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 - --> $DIR/eta.rs:213:28 + --> $DIR/eta.rs:225: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 - --> $DIR/eta.rs:220:21 + --> $DIR/eta.rs:232:21 | LL | Some(1).map(|n| closure(n)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut closure` error: redundant closure - --> $DIR/eta.rs:224:21 + --> $DIR/eta.rs:236:21 | LL | Some(1).map(|n| in_loop(n)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `in_loop` error: redundant closure - --> $DIR/eta.rs:317:18 + --> $DIR/eta.rs:329:18 | LL | takes_fn_mut(|| f()); | ^^^^^^ help: replace the closure with the function itself: `&mut f` error: redundant closure - --> $DIR/eta.rs:320:19 + --> $DIR/eta.rs:332:19 | LL | takes_fn_once(|| f()); | ^^^^^^ help: replace the closure with the function itself: `&mut f` error: redundant closure - --> $DIR/eta.rs:324:26 + --> $DIR/eta.rs:336:26 | LL | move || takes_fn_mut(|| f_used_once()) | ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut f_used_once` error: redundant closure - --> $DIR/eta.rs:336:19 + --> $DIR/eta.rs:348:19 | LL | array_opt.map(|a| a.as_slice()); | ^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8; 3]>::as_slice` error: redundant closure - --> $DIR/eta.rs:339:19 + --> $DIR/eta.rs:352:19 | LL | slice_opt.map(|s| s.len()); | ^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8]>::len` error: redundant closure - --> $DIR/eta.rs:342:17 + --> $DIR/eta.rs:356:17 | LL | ptr_opt.map(|p| p.is_null()); | ^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<*const usize>::is_null` error: redundant closure - --> $DIR/eta.rs:346:17 + --> $DIR/eta.rs:361:17 | LL | dyn_opt.map(|d| d.method_on_dyn()); | ^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `::method_on_dyn` error: redundant closure - --> $DIR/eta.rs:406:19 + --> $DIR/eta.rs:422:19 | LL | let _ = f(&0, |x, y| f2(x, y)); | ^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `f2` error: redundant closure - --> $DIR/eta.rs:434:22 + --> $DIR/eta.rs:450:22 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `Test::method` error: redundant closure - --> $DIR/eta.rs:438:22 + --> $DIR/eta.rs:455:22 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `super::Outer::method` error: redundant closure - --> $DIR/eta.rs:451:18 + --> $DIR/eta.rs:469:18 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `test_mod::Test::method` error: redundant closure - --> $DIR/eta.rs:458:30 + --> $DIR/eta.rs:477:30 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `crate::issue_10854::d::Test::method` diff --git a/tests/ui/excessive_precision.fixed b/tests/ui/excessive_precision.fixed index cc5531035309..fa6084993558 100644 --- a/tests/ui/excessive_precision.fixed +++ b/tests/ui/excessive_precision.fixed @@ -17,17 +17,20 @@ fn main() { const GOOD64_SM: f32 = 0.000_000_000_000_000_1; const GOOD64_DOT: f32 = 10_000_000_000_000_000.0; - const BAD32_1: f32 = 0.123_456_79_f32; - const BAD32_2: f32 = 0.123_456_79; + const BAD32_1: f32 = 0.123_456_79_f32; //~ excessive_precision + const BAD32_2: f32 = 0.123_456_79; //~ excessive_precision const BAD32_3: f32 = 0.1; - const BAD32_EDGE: f32 = 1.000_001; + //~^ excessive_precision + const BAD32_EDGE: f32 = 1.000_001; //~ excessive_precision const BAD64_1: f64 = 0.123_456_789_012_345_67f64; const BAD64_2: f64 = 0.123_456_789_012_345_67; const BAD64_3: f64 = 0.1; + //~^ excessive_precision // Literal as param println!("{:?}", 8.888_888_888_888_89); + //~^ excessive_precision // // TODO add inferred type tests for f32 // Locals @@ -38,9 +41,9 @@ fn main() { let good64_suf: f64 = 0.123_456_789_012f64; let good64_inf = 0.123_456_789_012; - let bad32: f32 = 1.123_456_8; - let bad32_suf: f32 = 1.123_456_8_f32; - let bad32_inf = 1.123_456_8_f32; + let bad32: f32 = 1.123_456_8; //~ excessive_precision + let bad32_suf: f32 = 1.123_456_8_f32; //~ excessive_precision + let bad32_inf = 1.123_456_8_f32; //~ excessive_precision let bad64: f64 = 0.123_456_789_012_345_67; let bad64_suf: f64 = 0.123_456_789_012_345_67f64; @@ -51,14 +54,18 @@ fn main() { let good_vec64: Vec = vec![0.123_456_789]; let bad_vec32: Vec = vec![0.123_456_79]; + //~^ excessive_precision let bad_vec64: Vec = vec![0.123_456_789_123_456_78]; + //~^ excessive_precision // Exponential float notation let good_e32: f32 = 1e-10; let bad_e32: f32 = 1.123_456_8e-10; + //~^ excessive_precision let good_bige32: f32 = 1E-10; let bad_bige32: f32 = 1.123_456_8E-10; + //~^ excessive_precision // Inferred type let good_inferred: f32 = 1f32 * 1_000_000_000.; @@ -68,9 +75,10 @@ fn main() { // issue #7744 let _ = 2.225_073_858_507_201e-308_f64; + //~^ excessive_precision // issue #7745 - let _ = 0_f64; + let _ = 0_f64; //~ excessive_precision // issue #9910 const INF1: f32 = 1.0e+33f32; diff --git a/tests/ui/excessive_precision.rs b/tests/ui/excessive_precision.rs index fff986a8296c..3d1f906b2bcd 100644 --- a/tests/ui/excessive_precision.rs +++ b/tests/ui/excessive_precision.rs @@ -17,17 +17,20 @@ fn main() { const GOOD64_SM: f32 = 0.000_000_000_000_000_1; const GOOD64_DOT: f32 = 10_000_000_000_000_000.0; - const BAD32_1: f32 = 0.123_456_789_f32; - const BAD32_2: f32 = 0.123_456_789; + const BAD32_1: f32 = 0.123_456_789_f32; //~ excessive_precision + const BAD32_2: f32 = 0.123_456_789; //~ excessive_precision const BAD32_3: f32 = 0.100_000_000_000_1; - const BAD32_EDGE: f32 = 1.000_000_9; + //~^ excessive_precision + const BAD32_EDGE: f32 = 1.000_000_9; //~ excessive_precision const BAD64_1: f64 = 0.123_456_789_012_345_67f64; const BAD64_2: f64 = 0.123_456_789_012_345_67; const BAD64_3: f64 = 0.100_000_000_000_000_000_1; + //~^ excessive_precision // Literal as param println!("{:?}", 8.888_888_888_888_888_888_888); + //~^ excessive_precision // // TODO add inferred type tests for f32 // Locals @@ -38,9 +41,9 @@ fn main() { let good64_suf: f64 = 0.123_456_789_012f64; let good64_inf = 0.123_456_789_012; - let bad32: f32 = 1.123_456_789; - let bad32_suf: f32 = 1.123_456_789_f32; - let bad32_inf = 1.123_456_789_f32; + let bad32: f32 = 1.123_456_789; //~ excessive_precision + let bad32_suf: f32 = 1.123_456_789_f32; //~ excessive_precision + let bad32_inf = 1.123_456_789_f32; //~ excessive_precision let bad64: f64 = 0.123_456_789_012_345_67; let bad64_suf: f64 = 0.123_456_789_012_345_67f64; @@ -51,14 +54,18 @@ fn main() { let good_vec64: Vec = vec![0.123_456_789]; let bad_vec32: Vec = vec![0.123_456_789]; + //~^ excessive_precision let bad_vec64: Vec = vec![0.123_456_789_123_456_789]; + //~^ excessive_precision // Exponential float notation let good_e32: f32 = 1e-10; let bad_e32: f32 = 1.123_456_788_888e-10; + //~^ excessive_precision let good_bige32: f32 = 1E-10; let bad_bige32: f32 = 1.123_456_788_888E-10; + //~^ excessive_precision // Inferred type let good_inferred: f32 = 1f32 * 1_000_000_000.; @@ -68,9 +75,10 @@ fn main() { // issue #7744 let _ = 2.225_073_858_507_201_1e-308_f64; + //~^ excessive_precision // issue #7745 - let _ = 1.000_000_000_000_001e-324_f64; + let _ = 1.000_000_000_000_001e-324_f64; //~ excessive_precision // issue #9910 const INF1: f32 = 1.0e+33f32; diff --git a/tests/ui/excessive_precision.stderr b/tests/ui/excessive_precision.stderr index 5e7672e185af..da9452f9175c 100644 --- a/tests/ui/excessive_precision.stderr +++ b/tests/ui/excessive_precision.stderr @@ -20,73 +20,73 @@ LL | const BAD32_3: f32 = 0.100_000_000_000_1; | ^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.1` error: float has excessive precision - --> $DIR/excessive_precision.rs:23:29 + --> $DIR/excessive_precision.rs:24:29 | LL | const BAD32_EDGE: f32 = 1.000_000_9; | ^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.000_001` error: float has excessive precision - --> $DIR/excessive_precision.rs:27:26 + --> $DIR/excessive_precision.rs:28: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` error: float has excessive precision - --> $DIR/excessive_precision.rs:30:22 + --> $DIR/excessive_precision.rs:32: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` error: float has excessive precision - --> $DIR/excessive_precision.rs:41:22 + --> $DIR/excessive_precision.rs:44:22 | LL | let bad32: f32 = 1.123_456_789; | ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8` error: float has excessive precision - --> $DIR/excessive_precision.rs:42:26 + --> $DIR/excessive_precision.rs:45: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` error: float has excessive precision - --> $DIR/excessive_precision.rs:43:21 + --> $DIR/excessive_precision.rs:46:21 | LL | let bad32_inf = 1.123_456_789_f32; | ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8_f32` error: float has excessive precision - --> $DIR/excessive_precision.rs:53:36 + --> $DIR/excessive_precision.rs:56:36 | LL | let bad_vec32: Vec = vec![0.123_456_789]; | ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79` error: float has excessive precision - --> $DIR/excessive_precision.rs:54:36 + --> $DIR/excessive_precision.rs:58:36 | LL | let bad_vec64: Vec = vec![0.123_456_789_123_456_789]; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_123_456_78` error: float has excessive precision - --> $DIR/excessive_precision.rs:58:24 + --> $DIR/excessive_precision.rs:63: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` error: float has excessive precision - --> $DIR/excessive_precision.rs:61:27 + --> $DIR/excessive_precision.rs:67: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` error: float has excessive precision - --> $DIR/excessive_precision.rs:70:13 + --> $DIR/excessive_precision.rs:77: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` error: float has excessive precision - --> $DIR/excessive_precision.rs:73:13 + --> $DIR/excessive_precision.rs:81:13 | LL | let _ = 1.000_000_000_000_001e-324_f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0_f64` diff --git a/tests/ui/exhaustive_items.fixed b/tests/ui/exhaustive_items.fixed index 1bf33a5f2f13..960c12224ceb 100644 --- a/tests/ui/exhaustive_items.fixed +++ b/tests/ui/exhaustive_items.fixed @@ -6,6 +6,7 @@ fn main() { } pub mod enums { + //~v exhaustive_enums #[non_exhaustive] pub enum Exhaustive { Foo, @@ -16,6 +17,7 @@ pub mod enums { /// Some docs #[repr(C)] + //~v exhaustive_enums #[non_exhaustive] pub enum ExhaustiveWithAttrs { Foo, @@ -52,6 +54,7 @@ pub mod enums { } pub mod structs { + //~v exhaustive_structs #[non_exhaustive] pub struct Exhaustive { pub foo: u8, diff --git a/tests/ui/exhaustive_items.rs b/tests/ui/exhaustive_items.rs index 1328791e186d..22b405241780 100644 --- a/tests/ui/exhaustive_items.rs +++ b/tests/ui/exhaustive_items.rs @@ -6,6 +6,7 @@ fn main() { } pub mod enums { + //~v exhaustive_enums pub enum Exhaustive { Foo, Bar, @@ -15,6 +16,7 @@ pub mod enums { /// Some docs #[repr(C)] + //~v exhaustive_enums pub enum ExhaustiveWithAttrs { Foo, Bar, @@ -50,6 +52,7 @@ pub mod enums { } pub mod structs { + //~v exhaustive_structs pub struct Exhaustive { pub foo: u8, pub bar: String, diff --git a/tests/ui/exhaustive_items.stderr b/tests/ui/exhaustive_items.stderr index ae43e81c0d31..6ceb5a85396b 100644 --- a/tests/ui/exhaustive_items.stderr +++ b/tests/ui/exhaustive_items.stderr @@ -1,5 +1,5 @@ error: exported enums should not be exhaustive - --> $DIR/exhaustive_items.rs:9:5 + --> $DIR/exhaustive_items.rs:10:5 | LL | / pub enum Exhaustive { LL | | Foo, @@ -21,7 +21,7 @@ LL ~ pub enum Exhaustive { | error: exported enums should not be exhaustive - --> $DIR/exhaustive_items.rs:18:5 + --> $DIR/exhaustive_items.rs:20:5 | LL | / pub enum ExhaustiveWithAttrs { LL | | Foo, @@ -38,7 +38,7 @@ LL ~ pub enum ExhaustiveWithAttrs { | error: exported structs should not be exhaustive - --> $DIR/exhaustive_items.rs:53:5 + --> $DIR/exhaustive_items.rs:56:5 | LL | / pub struct Exhaustive { LL | | pub foo: u8, diff --git a/tests/ui/expect_fun_call.fixed b/tests/ui/expect_fun_call.fixed index 6ac3c43ad298..03cad90f6aa4 100644 --- a/tests/ui/expect_fun_call.fixed +++ b/tests/ui/expect_fun_call.fixed @@ -35,12 +35,15 @@ fn main() { let error_code = 123_i32; let with_none_and_format: Option = None; with_none_and_format.unwrap_or_else(|| panic!("Error {}: fake error", error_code)); + //~^ expect_fun_call let with_none_and_as_str: Option = None; with_none_and_as_str.unwrap_or_else(|| panic!("Error {}: fake error", error_code)); + //~^ expect_fun_call let with_none_and_format_with_macro: Option = None; with_none_and_format_with_macro.unwrap_or_else(|| panic!("Error {}: fake error", one!())); + //~^ expect_fun_call let with_ok: Result<(), ()> = Ok(()); with_ok.expect("error"); @@ -51,9 +54,11 @@ fn main() { let error_code = 123_i32; let with_err_and_format: Result<(), ()> = Err(()); with_err_and_format.unwrap_or_else(|_| panic!("Error {}: fake error", error_code)); + //~^ expect_fun_call let with_err_and_as_str: Result<(), ()> = Err(()); with_err_and_as_str.unwrap_or_else(|_| panic!("Error {}: fake error", error_code)); + //~^ expect_fun_call let with_dummy_type = Foo::new(); with_dummy_type.expect("another test string"); @@ -66,6 +71,7 @@ fn main() { //Issue #2937 Some("foo").unwrap_or_else(|| panic!("{} {}", 1, 2)); + //~^ expect_fun_call //Issue #2979 - this should not lint { @@ -86,27 +92,34 @@ fn main() { "foo" } + Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) }); //~ expect_fun_call Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) }); + //~^ expect_fun_call Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) }); - Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) }); + //~^ expect_fun_call - Some("foo").unwrap_or_else(|| { panic!("{}", get_static_str()) }); + Some("foo").unwrap_or_else(|| { panic!("{}", get_static_str()) }); //~ expect_fun_call Some("foo").unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) }); + //~^ expect_fun_call } //Issue #3839 Some(true).unwrap_or_else(|| panic!("key {}, {}", 1, 2)); + //~^ expect_fun_call //Issue #4912 - the receiver is a &Option { let opt = Some(1); let opt_ref = &opt; opt_ref.unwrap_or_else(|| panic!("{:?}", opt_ref)); + //~^ expect_fun_call } let format_capture: Option = None; format_capture.unwrap_or_else(|| panic!("{error_code}")); + //~^ expect_fun_call let format_capture_and_value: Option = None; format_capture_and_value.unwrap_or_else(|| panic!("{error_code}, {}", 1)); + //~^ expect_fun_call } diff --git a/tests/ui/expect_fun_call.rs b/tests/ui/expect_fun_call.rs index 22ea2db504fa..a2a968683077 100644 --- a/tests/ui/expect_fun_call.rs +++ b/tests/ui/expect_fun_call.rs @@ -35,12 +35,15 @@ fn main() { let error_code = 123_i32; let with_none_and_format: Option = None; with_none_and_format.expect(&format!("Error {}: fake error", error_code)); + //~^ expect_fun_call let with_none_and_as_str: Option = None; with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); + //~^ expect_fun_call let with_none_and_format_with_macro: Option = None; with_none_and_format_with_macro.expect(format!("Error {}: fake error", one!()).as_str()); + //~^ expect_fun_call let with_ok: Result<(), ()> = Ok(()); with_ok.expect("error"); @@ -51,9 +54,11 @@ fn main() { let error_code = 123_i32; let with_err_and_format: Result<(), ()> = Err(()); with_err_and_format.expect(&format!("Error {}: fake error", error_code)); + //~^ expect_fun_call let with_err_and_as_str: Result<(), ()> = Err(()); with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); + //~^ expect_fun_call let with_dummy_type = Foo::new(); with_dummy_type.expect("another test string"); @@ -66,6 +71,7 @@ fn main() { //Issue #2937 Some("foo").expect(format!("{} {}", 1, 2).as_ref()); + //~^ expect_fun_call //Issue #2979 - this should not lint { @@ -86,27 +92,34 @@ fn main() { "foo" } - Some("foo").expect(&get_string()); + Some("foo").expect(&get_string()); //~ expect_fun_call Some("foo").expect(get_string().as_ref()); + //~^ expect_fun_call Some("foo").expect(get_string().as_str()); + //~^ expect_fun_call - Some("foo").expect(get_static_str()); + Some("foo").expect(get_static_str()); //~ expect_fun_call Some("foo").expect(get_non_static_str(&0)); + //~^ expect_fun_call } //Issue #3839 Some(true).expect(&format!("key {}, {}", 1, 2)); + //~^ expect_fun_call //Issue #4912 - the receiver is a &Option { let opt = Some(1); let opt_ref = &opt; opt_ref.expect(&format!("{:?}", opt_ref)); + //~^ expect_fun_call } let format_capture: Option = None; format_capture.expect(&format!("{error_code}")); + //~^ expect_fun_call let format_capture_and_value: Option = None; format_capture_and_value.expect(&format!("{error_code}, {}", 1)); + //~^ expect_fun_call } diff --git a/tests/ui/expect_fun_call.stderr b/tests/ui/expect_fun_call.stderr index dd3976f3624c..d751c055d5c8 100644 --- a/tests/ui/expect_fun_call.stderr +++ b/tests/ui/expect_fun_call.stderr @@ -8,85 +8,85 @@ LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code = help: to override `-D warnings` add `#[allow(clippy::expect_fun_call)]` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:40:26 + --> $DIR/expect_fun_call.rs:41:26 | LL | with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:43:37 + --> $DIR/expect_fun_call.rs:45:37 | LL | with_none_and_format_with_macro.expect(format!("Error {}: fake error", one!()).as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("Error {}: fake error", one!()))` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:53:25 + --> $DIR/expect_fun_call.rs:56:25 | LL | with_err_and_format.expect(&format!("Error {}: fake error", error_code)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:56:25 + --> $DIR/expect_fun_call.rs:60:25 | LL | with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:68:17 + --> $DIR/expect_fun_call.rs:73:17 | LL | Some("foo").expect(format!("{} {}", 1, 2).as_ref()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{} {}", 1, 2))` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:89:21 + --> $DIR/expect_fun_call.rs:95:21 | LL | Some("foo").expect(&get_string()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:90:21 + --> $DIR/expect_fun_call.rs:96:21 | LL | Some("foo").expect(get_string().as_ref()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:91:21 + --> $DIR/expect_fun_call.rs:98:21 | LL | Some("foo").expect(get_string().as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:93:21 + --> $DIR/expect_fun_call.rs:101:21 | LL | Some("foo").expect(get_static_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_static_str()) })` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:94:21 + --> $DIR/expect_fun_call.rs:102:21 | LL | Some("foo").expect(get_non_static_str(&0)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) })` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:98:16 + --> $DIR/expect_fun_call.rs:107:16 | LL | Some(true).expect(&format!("key {}, {}", 1, 2)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("key {}, {}", 1, 2))` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:104:17 + --> $DIR/expect_fun_call.rs:114:17 | LL | opt_ref.expect(&format!("{:?}", opt_ref)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{:?}", opt_ref))` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:108:20 + --> $DIR/expect_fun_call.rs:119:20 | LL | format_capture.expect(&format!("{error_code}")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{error_code}"))` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:111:30 + --> $DIR/expect_fun_call.rs:123:30 | LL | format_capture_and_value.expect(&format!("{error_code}, {}", 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{error_code}, {}", 1))` diff --git a/tests/ui/explicit_auto_deref.fixed b/tests/ui/explicit_auto_deref.fixed index e6ca4bb66ccd..fe8f4a74c09f 100644 --- a/tests/ui/explicit_auto_deref.fixed +++ b/tests/ui/explicit_auto_deref.fixed @@ -65,44 +65,45 @@ extern "C" { fn main() { let s = String::new(); - let _: &str = &s; - let _: &str = &{ String::new() }; - let _: &str = &mut { String::new() }; + let _: &str = &s; //~ explicit_auto_deref + let _: &str = &{ String::new() }; //~ explicit_auto_deref + let _: &str = &mut { String::new() }; //~ explicit_auto_deref let _ = &*s; // Don't lint. Inferred type would change. let _: &_ = &*s; // Don't lint. Inferred type would change. - f_str(&s); + f_str(&s); //~ explicit_auto_deref f_t(&*s); // Don't lint. Inferred type would change. f_ref_t(&*s); // Don't lint. Inferred type would change. + //~v explicit_auto_deref f_str_t(&s, &*s); // Don't lint second param. let b = Box::new(Box::new(Box::new(5))); - let _: &Box = &b; + let _: &Box = &b; //~ explicit_auto_deref let _: &Box<_> = &**b; // Don't lint. Inferred type would change. f_box_t(&**b); // Don't lint. Inferred type would change. let c = |_x: &str| (); - c(&s); + c(&s); //~ explicit_auto_deref let c = |_x| (); c(&*s); // Don't lint. Inferred type would change. fn _f(x: &String) -> &str { - x + x //~ explicit_auto_deref } fn _f1(x: &String) -> &str { - { x } + { x } //~ explicit_auto_deref } fn _f2(x: &String) -> &str { - { x } + { x } //~ explicit_auto_deref } fn _f3(x: &Box>>) -> &Box { - x + x //~ explicit_auto_deref } fn _f4( @@ -119,26 +120,26 @@ fn main() { f10: >::T, f11: &dyn CallableT, ) { - f1(&x); - f2(&x); - f3(&x); - f4.callable_str()(&x); - f5(&x); - f6(&x); - f7.callable_str()(&x); - f8.callable_t()(&x); - f9(&x); - f10(&x); - f11.callable_t()(&x); + f1(&x); //~ explicit_auto_deref + f2(&x); //~ explicit_auto_deref + f3(&x); //~ explicit_auto_deref + f4.callable_str()(&x); //~ explicit_auto_deref + f5(&x); //~ explicit_auto_deref + f6(&x); //~ explicit_auto_deref + f7.callable_str()(&x); //~ explicit_auto_deref + f8.callable_t()(&x); //~ explicit_auto_deref + f9(&x); //~ explicit_auto_deref + f10(&x); //~ explicit_auto_deref + f11.callable_t()(&x); //~ explicit_auto_deref } struct S1<'a>(&'a str); - let _ = S1(&s); + let _ = S1(&s); //~ explicit_auto_deref struct S2<'a> { s: &'a str, } - let _ = S2 { s: &s }; + let _ = S2 { s: &s }; //~ explicit_auto_deref struct S3<'a, T: ?Sized>(&'a T); let _ = S3(&*s); // Don't lint. Inferred type would change. @@ -154,12 +155,12 @@ fn main() { } impl<'a> E1<'a> { fn m1(s: &'a String) { - let _ = Self::S1(s); - let _ = Self::S2 { s: s }; + let _ = Self::S1(s); //~ explicit_auto_deref + let _ = Self::S2 { s: s }; //~ explicit_auto_deref } } - let _ = E1::S1(&s); - let _ = E1::S2 { s: &s }; + let _ = E1::S1(&s); //~ explicit_auto_deref + let _ = E1::S2 { s: &s }; //~ explicit_auto_deref enum E2<'a, T: ?Sized> { S1(&'a T), @@ -177,8 +178,8 @@ fn main() { } let b = Box::new(Box::new(S5 { foo: 5 })); let _ = b.foo; - let _ = b.foo; - let _ = b.foo; + let _ = b.foo; //~ explicit_auto_deref + let _ = b.foo; //~ explicit_auto_deref struct S6 { foo: S5, @@ -193,9 +194,9 @@ fn main() { let _ = (*s6).foo; // Don't lint. `S6` also has a field named `foo` let ref_str = &"foo"; - let _ = f_str(ref_str); + let _ = f_str(ref_str); //~ explicit_auto_deref let ref_ref_str = &ref_str; - let _ = f_str(ref_ref_str); + let _ = f_str(ref_ref_str); //~ explicit_auto_deref fn _f5(x: &u32) -> u32 { if true { @@ -205,7 +206,10 @@ fn main() { } } + //~v explicit_auto_deref f_str(&ref_str); // `needless_borrow` will suggest removing both references + + //~v explicit_auto_deref f_str(&ref_str); // `needless_borrow` will suggest removing only one reference let x = &&40; @@ -216,6 +220,7 @@ fn main() { let s = &"str"; let _ = || return *s; let _ = || -> &'static str { return s }; + //~^ explicit_auto_deref struct X; struct Y(X); @@ -234,7 +239,7 @@ fn main() { let _: &X = &*if true { Y(X) } else { panic!() }; fn deref_to_u>(x: &T) -> &U { - x + x //~ explicit_auto_deref } let _ = |x: &'static Box>| -> &'static dyn Iterator { &**x }; @@ -257,12 +262,12 @@ fn main() { let c1 = |_: &Vec<&u32>| {}; let x = &&vec![&1u32]; - c1(x); + c1(x); //~ explicit_auto_deref let _ = for<'a, 'b> |x: &'a &'a Vec<&'b u32>, b: bool| -> &'a Vec<&'b u32> { if b { - return x; + return x; //~ explicit_auto_deref } - x + x //~ explicit_auto_deref }; trait WithAssoc { @@ -296,7 +301,7 @@ fn main() { // Issue #11366 let _: &mut u32 = match &mut Some(&mut 0u32) { - Some(x) => x, + Some(x) => x, //~ explicit_auto_deref None => panic!(), }; @@ -329,19 +334,19 @@ fn main() { u: core::mem::ManuallyDrop::new(S8 { x: "" }), }; let _ = &mut (*x.u).x; - let _ = &mut { x.u }.x; + let _ = &mut { x.u }.x; //~ explicit_auto_deref let _ = &mut ({ *x.u }).x; let mut x = U { u: Wrap(core::mem::ManuallyDrop::new(S8 { x: "" })), }; - let _ = &mut (*x.u).x; - let _ = &mut { x.u }.x; + let _ = &mut (*x.u).x; //~ explicit_auto_deref + let _ = &mut { x.u }.x; //~ explicit_auto_deref let _ = &mut ({ **x.u }).x; let mut x = U { u: Wrap(S8 { x: "" }) }; - let _ = &mut x.u.x; - let _ = &mut { x.u }.x; + let _ = &mut x.u.x; //~ explicit_auto_deref + let _ = &mut { x.u }.x; //~ explicit_auto_deref let _ = &mut ({ *x.u }).x; } } diff --git a/tests/ui/explicit_auto_deref.rs b/tests/ui/explicit_auto_deref.rs index 7531e1f87b71..59263d88c840 100644 --- a/tests/ui/explicit_auto_deref.rs +++ b/tests/ui/explicit_auto_deref.rs @@ -65,44 +65,45 @@ extern "C" { fn main() { let s = String::new(); - let _: &str = &*s; - let _: &str = &*{ String::new() }; - let _: &str = &mut *{ String::new() }; + let _: &str = &*s; //~ explicit_auto_deref + let _: &str = &*{ String::new() }; //~ explicit_auto_deref + let _: &str = &mut *{ String::new() }; //~ explicit_auto_deref let _ = &*s; // Don't lint. Inferred type would change. let _: &_ = &*s; // Don't lint. Inferred type would change. - f_str(&*s); + f_str(&*s); //~ explicit_auto_deref f_t(&*s); // Don't lint. Inferred type would change. f_ref_t(&*s); // Don't lint. Inferred type would change. + //~v explicit_auto_deref f_str_t(&*s, &*s); // Don't lint second param. let b = Box::new(Box::new(Box::new(5))); - let _: &Box = &**b; + let _: &Box = &**b; //~ explicit_auto_deref let _: &Box<_> = &**b; // Don't lint. Inferred type would change. f_box_t(&**b); // Don't lint. Inferred type would change. let c = |_x: &str| (); - c(&*s); + c(&*s); //~ explicit_auto_deref let c = |_x| (); c(&*s); // Don't lint. Inferred type would change. fn _f(x: &String) -> &str { - &**x + &**x //~ explicit_auto_deref } fn _f1(x: &String) -> &str { - { &**x } + { &**x } //~ explicit_auto_deref } fn _f2(x: &String) -> &str { - &**{ x } + &**{ x } //~ explicit_auto_deref } fn _f3(x: &Box>>) -> &Box { - &***x + &***x //~ explicit_auto_deref } fn _f4( @@ -119,26 +120,26 @@ fn main() { f10: >::T, f11: &dyn CallableT, ) { - f1(&*x); - f2(&*x); - f3(&*x); - f4.callable_str()(&*x); - f5(&*x); - f6(&*x); - f7.callable_str()(&*x); - f8.callable_t()(&*x); - f9(&*x); - f10(&*x); - f11.callable_t()(&*x); + f1(&*x); //~ explicit_auto_deref + f2(&*x); //~ explicit_auto_deref + f3(&*x); //~ explicit_auto_deref + f4.callable_str()(&*x); //~ explicit_auto_deref + f5(&*x); //~ explicit_auto_deref + f6(&*x); //~ explicit_auto_deref + f7.callable_str()(&*x); //~ explicit_auto_deref + f8.callable_t()(&*x); //~ explicit_auto_deref + f9(&*x); //~ explicit_auto_deref + f10(&*x); //~ explicit_auto_deref + f11.callable_t()(&*x); //~ explicit_auto_deref } struct S1<'a>(&'a str); - let _ = S1(&*s); + let _ = S1(&*s); //~ explicit_auto_deref struct S2<'a> { s: &'a str, } - let _ = S2 { s: &*s }; + let _ = S2 { s: &*s }; //~ explicit_auto_deref struct S3<'a, T: ?Sized>(&'a T); let _ = S3(&*s); // Don't lint. Inferred type would change. @@ -154,12 +155,12 @@ fn main() { } impl<'a> E1<'a> { fn m1(s: &'a String) { - let _ = Self::S1(&**s); - let _ = Self::S2 { s: &**s }; + let _ = Self::S1(&**s); //~ explicit_auto_deref + let _ = Self::S2 { s: &**s }; //~ explicit_auto_deref } } - let _ = E1::S1(&*s); - let _ = E1::S2 { s: &*s }; + let _ = E1::S1(&*s); //~ explicit_auto_deref + let _ = E1::S2 { s: &*s }; //~ explicit_auto_deref enum E2<'a, T: ?Sized> { S1(&'a T), @@ -177,8 +178,8 @@ fn main() { } let b = Box::new(Box::new(S5 { foo: 5 })); let _ = b.foo; - let _ = (*b).foo; - let _ = (**b).foo; + let _ = (*b).foo; //~ explicit_auto_deref + let _ = (**b).foo; //~ explicit_auto_deref struct S6 { foo: S5, @@ -193,9 +194,9 @@ fn main() { let _ = (*s6).foo; // Don't lint. `S6` also has a field named `foo` let ref_str = &"foo"; - let _ = f_str(*ref_str); + let _ = f_str(*ref_str); //~ explicit_auto_deref let ref_ref_str = &ref_str; - let _ = f_str(**ref_ref_str); + let _ = f_str(**ref_ref_str); //~ explicit_auto_deref fn _f5(x: &u32) -> u32 { if true { @@ -205,7 +206,10 @@ fn main() { } } + //~v explicit_auto_deref f_str(&&*ref_str); // `needless_borrow` will suggest removing both references + + //~v explicit_auto_deref f_str(&&**ref_str); // `needless_borrow` will suggest removing only one reference let x = &&40; @@ -216,6 +220,7 @@ fn main() { let s = &"str"; let _ = || return *s; let _ = || -> &'static str { return *s }; + //~^ explicit_auto_deref struct X; struct Y(X); @@ -234,7 +239,7 @@ fn main() { let _: &X = &*if true { Y(X) } else { panic!() }; fn deref_to_u>(x: &T) -> &U { - &**x + &**x //~ explicit_auto_deref } let _ = |x: &'static Box>| -> &'static dyn Iterator { &**x }; @@ -257,12 +262,12 @@ fn main() { let c1 = |_: &Vec<&u32>| {}; let x = &&vec![&1u32]; - c1(*x); + c1(*x); //~ explicit_auto_deref let _ = for<'a, 'b> |x: &'a &'a Vec<&'b u32>, b: bool| -> &'a Vec<&'b u32> { if b { - return *x; + return *x; //~ explicit_auto_deref } - *x + *x //~ explicit_auto_deref }; trait WithAssoc { @@ -296,7 +301,7 @@ fn main() { // Issue #11366 let _: &mut u32 = match &mut Some(&mut 0u32) { - Some(x) => &mut *x, + Some(x) => &mut *x, //~ explicit_auto_deref None => panic!(), }; @@ -329,19 +334,19 @@ fn main() { u: core::mem::ManuallyDrop::new(S8 { x: "" }), }; let _ = &mut (*x.u).x; - let _ = &mut (*{ x.u }).x; + let _ = &mut (*{ x.u }).x; //~ explicit_auto_deref let _ = &mut ({ *x.u }).x; let mut x = U { u: Wrap(core::mem::ManuallyDrop::new(S8 { x: "" })), }; - let _ = &mut (**x.u).x; - let _ = &mut (**{ x.u }).x; + let _ = &mut (**x.u).x; //~ explicit_auto_deref + let _ = &mut (**{ x.u }).x; //~ explicit_auto_deref let _ = &mut ({ **x.u }).x; let mut x = U { u: Wrap(S8 { x: "" }) }; - let _ = &mut (*x.u).x; - let _ = &mut (*{ x.u }).x; + let _ = &mut (*x.u).x; //~ explicit_auto_deref + let _ = &mut (*{ x.u }).x; //~ explicit_auto_deref let _ = &mut ({ *x.u }).x; } } diff --git a/tests/ui/explicit_auto_deref.stderr b/tests/ui/explicit_auto_deref.stderr index cc9eeeb50429..863e8cce1d78 100644 --- a/tests/ui/explicit_auto_deref.stderr +++ b/tests/ui/explicit_auto_deref.stderr @@ -26,247 +26,247 @@ LL | f_str(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:78:13 + --> $DIR/explicit_auto_deref.rs:79:13 | LL | f_str_t(&*s, &*s); // Don't lint second param. | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:81:24 + --> $DIR/explicit_auto_deref.rs:82:24 | LL | let _: &Box = &**b; | ^^^^ help: try: `&b` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:87:7 + --> $DIR/explicit_auto_deref.rs:88:7 | LL | c(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:93:9 + --> $DIR/explicit_auto_deref.rs:94:9 | LL | &**x | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:97:11 + --> $DIR/explicit_auto_deref.rs:98:11 | LL | { &**x } | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:101:9 + --> $DIR/explicit_auto_deref.rs:102:9 | LL | &**{ x } | ^^^^^^^^ help: try: `{ x }` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:105:9 + --> $DIR/explicit_auto_deref.rs:106:9 | LL | &***x | ^^^^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:122:12 + --> $DIR/explicit_auto_deref.rs:123:12 | LL | f1(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:123:12 + --> $DIR/explicit_auto_deref.rs:124:12 | LL | f2(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:124:12 + --> $DIR/explicit_auto_deref.rs:125:12 | LL | f3(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:125:27 + --> $DIR/explicit_auto_deref.rs:126:27 | LL | f4.callable_str()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:126:12 + --> $DIR/explicit_auto_deref.rs:127:12 | LL | f5(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:127:12 + --> $DIR/explicit_auto_deref.rs:128:12 | LL | f6(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:128:27 + --> $DIR/explicit_auto_deref.rs:129:27 | LL | f7.callable_str()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:129:25 + --> $DIR/explicit_auto_deref.rs:130:25 | LL | f8.callable_t()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:130:12 + --> $DIR/explicit_auto_deref.rs:131:12 | LL | f9(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:131:13 + --> $DIR/explicit_auto_deref.rs:132:13 | LL | f10(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:132:26 + --> $DIR/explicit_auto_deref.rs:133:26 | LL | f11.callable_t()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:136:16 + --> $DIR/explicit_auto_deref.rs:137:16 | LL | let _ = S1(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:141:21 + --> $DIR/explicit_auto_deref.rs:142:21 | LL | let _ = S2 { s: &*s }; | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:157:30 + --> $DIR/explicit_auto_deref.rs:158:30 | LL | let _ = Self::S1(&**s); | ^^^^ help: try: `s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:158:35 + --> $DIR/explicit_auto_deref.rs:159:35 | LL | let _ = Self::S2 { s: &**s }; | ^^^^ help: try: `s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:161:20 + --> $DIR/explicit_auto_deref.rs:162:20 | LL | let _ = E1::S1(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:162:25 + --> $DIR/explicit_auto_deref.rs:163:25 | LL | let _ = E1::S2 { s: &*s }; | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:180:13 + --> $DIR/explicit_auto_deref.rs:181:13 | LL | let _ = (*b).foo; | ^^^^ help: try: `b` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:181:13 + --> $DIR/explicit_auto_deref.rs:182:13 | LL | let _ = (**b).foo; | ^^^^^ help: try: `b` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:196:19 + --> $DIR/explicit_auto_deref.rs:197:19 | LL | let _ = f_str(*ref_str); | ^^^^^^^^ help: try: `ref_str` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:198:19 + --> $DIR/explicit_auto_deref.rs:199:19 | LL | let _ = f_str(**ref_ref_str); | ^^^^^^^^^^^^^ help: try: `ref_ref_str` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:208:12 + --> $DIR/explicit_auto_deref.rs:210:12 | LL | f_str(&&*ref_str); // `needless_borrow` will suggest removing both references | ^^^^^^^^^ help: try: `ref_str` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:209:12 + --> $DIR/explicit_auto_deref.rs:213:12 | LL | f_str(&&**ref_str); // `needless_borrow` will suggest removing only one reference | ^^^^^^^^^^ help: try: `ref_str` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:218:41 + --> $DIR/explicit_auto_deref.rs:222:41 | LL | let _ = || -> &'static str { return *s }; | ^^ help: try: `s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:237:9 + --> $DIR/explicit_auto_deref.rs:242:9 | LL | &**x | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:260:8 + --> $DIR/explicit_auto_deref.rs:265:8 | LL | c1(*x); | ^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:263:20 + --> $DIR/explicit_auto_deref.rs:268:20 | LL | return *x; | ^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:265:9 + --> $DIR/explicit_auto_deref.rs:270:9 | LL | *x | ^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:299:20 + --> $DIR/explicit_auto_deref.rs:304:20 | LL | Some(x) => &mut *x, | ^^^^^^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:332:22 + --> $DIR/explicit_auto_deref.rs:337:22 | LL | let _ = &mut (*{ x.u }).x; | ^^^^^^^^^^ help: try: `{ x.u }` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:338:22 + --> $DIR/explicit_auto_deref.rs:343:22 | LL | let _ = &mut (**x.u).x; | ^^^^^^^ help: try: `(*x.u)` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:339:22 + --> $DIR/explicit_auto_deref.rs:344:22 | LL | let _ = &mut (**{ x.u }).x; | ^^^^^^^^^^^ help: try: `{ x.u }` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:343:22 + --> $DIR/explicit_auto_deref.rs:348:22 | LL | let _ = &mut (*x.u).x; | ^^^^^^ help: try: `x.u` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:344:22 + --> $DIR/explicit_auto_deref.rs:349:22 | LL | let _ = &mut (*{ x.u }).x; | ^^^^^^^^^^ help: try: `{ x.u }` diff --git a/tests/ui/explicit_deref_methods.fixed b/tests/ui/explicit_deref_methods.fixed index 7b2dd2fe6eb8..eb959b467939 100644 --- a/tests/ui/explicit_deref_methods.fixed +++ b/tests/ui/explicit_deref_methods.fixed @@ -51,30 +51,34 @@ fn main() { // these should require linting - let b: &str = &*a; + let b: &str = &*a; //~ explicit_deref_methods - let b: &mut str = &mut **a; + let b: &mut str = &mut **a; //~ explicit_deref_methods // both derefs should get linted here let b: String = format!("{}, {}", &*a, &*a); + //~^ explicit_deref_methods + //~| explicit_deref_methods - println!("{}", &*a); + println!("{}", &*a); //~ explicit_deref_methods #[allow(clippy::match_single_binding)] + //~v explicit_deref_methods match &*a { _ => (), } - let b: String = concat(&*a); + let b: String = concat(&*a); //~ explicit_deref_methods - let b = just_return(a); + let b = just_return(a); //~ explicit_deref_methods let b: String = concat(just_return(a)); + //~^ explicit_deref_methods - let b: &str = &**a; + let b: &str = &**a; //~ explicit_deref_methods let opt_a = Some(a.clone()); - let b = &*opt_a.unwrap(); + let b = &*opt_a.unwrap(); //~ explicit_deref_methods // make sure `Aaa::deref` instead of `aaa.deref()` is not linted, as well as fully qualified // syntax @@ -111,7 +115,7 @@ fn main() { } let b: &str = expr_deref!(a); - let b: &str = expr_deref!(&*a); + let b: &str = expr_deref!(&*a); //~ explicit_deref_methods // The struct does not implement Deref trait #[derive(Copy, Clone)] diff --git a/tests/ui/explicit_deref_methods.rs b/tests/ui/explicit_deref_methods.rs index eb52cfb0d857..c12a90587ac7 100644 --- a/tests/ui/explicit_deref_methods.rs +++ b/tests/ui/explicit_deref_methods.rs @@ -51,30 +51,34 @@ fn main() { // these should require linting - let b: &str = a.deref(); + let b: &str = a.deref(); //~ explicit_deref_methods - let b: &mut str = a.deref_mut(); + let b: &mut str = a.deref_mut(); //~ explicit_deref_methods // both derefs should get linted here let b: String = format!("{}, {}", a.deref(), a.deref()); + //~^ explicit_deref_methods + //~| explicit_deref_methods - println!("{}", a.deref()); + println!("{}", a.deref()); //~ explicit_deref_methods #[allow(clippy::match_single_binding)] + //~v explicit_deref_methods match a.deref() { _ => (), } - let b: String = concat(a.deref()); + let b: String = concat(a.deref()); //~ explicit_deref_methods - let b = just_return(a).deref(); + let b = just_return(a).deref(); //~ explicit_deref_methods let b: String = concat(just_return(a).deref()); + //~^ explicit_deref_methods - let b: &str = a.deref().deref(); + let b: &str = a.deref().deref(); //~ explicit_deref_methods let opt_a = Some(a.clone()); - let b = opt_a.unwrap().deref(); + let b = opt_a.unwrap().deref(); //~ explicit_deref_methods // make sure `Aaa::deref` instead of `aaa.deref()` is not linted, as well as fully qualified // syntax @@ -111,7 +115,7 @@ fn main() { } let b: &str = expr_deref!(a); - let b: &str = expr_deref!(a.deref()); + let b: &str = expr_deref!(a.deref()); //~ explicit_deref_methods // The struct does not implement Deref trait #[derive(Copy, Clone)] diff --git a/tests/ui/explicit_deref_methods.stderr b/tests/ui/explicit_deref_methods.stderr index eb7059367a20..d88d8d822b8f 100644 --- a/tests/ui/explicit_deref_methods.stderr +++ b/tests/ui/explicit_deref_methods.stderr @@ -26,49 +26,49 @@ LL | let b: String = format!("{}, {}", a.deref(), a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:61:20 + --> $DIR/explicit_deref_methods.rs:63:20 | LL | println!("{}", a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:64:11 + --> $DIR/explicit_deref_methods.rs:67:11 | LL | match a.deref() { | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:68:28 + --> $DIR/explicit_deref_methods.rs:71:28 | LL | let b: String = concat(a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:70:13 + --> $DIR/explicit_deref_methods.rs:73:13 | LL | let b = just_return(a).deref(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `just_return(a)` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:72:28 + --> $DIR/explicit_deref_methods.rs:75:28 | LL | let b: String = concat(just_return(a).deref()); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `just_return(a)` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:74:19 + --> $DIR/explicit_deref_methods.rs:78:19 | LL | let b: &str = a.deref().deref(); | ^^^^^^^^^^^^^^^^^ help: try: `&**a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:77:13 + --> $DIR/explicit_deref_methods.rs:81:13 | LL | let b = opt_a.unwrap().deref(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*opt_a.unwrap()` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:114:31 + --> $DIR/explicit_deref_methods.rs:118:31 | LL | let b: &str = expr_deref!(a.deref()); | ^^^^^^^^^ help: try: `&*a` diff --git a/tests/ui/explicit_into_iter_loop.fixed b/tests/ui/explicit_into_iter_loop.fixed index 2521bce6a58e..7664f9639510 100644 --- a/tests/ui/explicit_into_iter_loop.fixed +++ b/tests/ui/explicit_into_iter_loop.fixed @@ -6,7 +6,7 @@ fn main() { where for<'a> &'a T: IntoIterator, { - for _ in iterator {} + for _ in iterator {} //~ explicit_into_iter_loop } struct T; @@ -19,10 +19,10 @@ fn main() { } let mut t = T; - for _ in &t {} + for _ in &t {} //~ explicit_into_iter_loop let r = &t; - for _ in r {} + for _ in r {} //~ explicit_into_iter_loop // No suggestion for this. // We'd have to suggest `for _ in *rr {}` which is less clear. @@ -30,7 +30,7 @@ fn main() { for _ in rr.into_iter() {} let mr = &mut t; - for _ in &*mr {} + for _ in &*mr {} //~ explicit_into_iter_loop struct U; impl IntoIterator for &mut U { @@ -42,10 +42,10 @@ fn main() { } let mut u = U; - for _ in &mut u {} + for _ in &mut u {} //~ explicit_into_iter_loop let mr = &mut u; - for _ in &mut *mr {} + for _ in &mut *mr {} //~ explicit_into_iter_loop // Issue #6900 struct S; diff --git a/tests/ui/explicit_into_iter_loop.rs b/tests/ui/explicit_into_iter_loop.rs index 9eac96d182b9..5b683b778596 100644 --- a/tests/ui/explicit_into_iter_loop.rs +++ b/tests/ui/explicit_into_iter_loop.rs @@ -6,7 +6,7 @@ fn main() { where for<'a> &'a T: IntoIterator, { - for _ in iterator.into_iter() {} + for _ in iterator.into_iter() {} //~ explicit_into_iter_loop } struct T; @@ -19,10 +19,10 @@ fn main() { } let mut t = T; - for _ in t.into_iter() {} + for _ in t.into_iter() {} //~ explicit_into_iter_loop let r = &t; - for _ in r.into_iter() {} + for _ in r.into_iter() {} //~ explicit_into_iter_loop // No suggestion for this. // We'd have to suggest `for _ in *rr {}` which is less clear. @@ -30,7 +30,7 @@ fn main() { for _ in rr.into_iter() {} let mr = &mut t; - for _ in mr.into_iter() {} + for _ in mr.into_iter() {} //~ explicit_into_iter_loop struct U; impl IntoIterator for &mut U { @@ -42,10 +42,10 @@ fn main() { } let mut u = U; - for _ in u.into_iter() {} + for _ in u.into_iter() {} //~ explicit_into_iter_loop let mr = &mut u; - for _ in mr.into_iter() {} + for _ in mr.into_iter() {} //~ explicit_into_iter_loop // Issue #6900 struct S; diff --git a/tests/ui/explicit_iter_loop.fixed b/tests/ui/explicit_iter_loop.fixed index f08397defa53..92532a2a055e 100644 --- a/tests/ui/explicit_iter_loop.fixed +++ b/tests/ui/explicit_iter_loop.fixed @@ -14,11 +14,11 @@ use std::collections::*; fn main() { let mut vec = vec![1, 2, 3, 4]; - for _ in &vec {} - for _ in &mut vec {} + for _ in &vec {} //~ explicit_iter_loop + for _ in &mut vec {} //~ explicit_iter_loop let rvec = &vec; - for _ in rvec {} + for _ in rvec {} //~ explicit_iter_loop let rmvec = &mut vec; for _ in rmvec.iter() {} @@ -27,37 +27,37 @@ fn main() { for _ in &vec {} // these are fine for _ in &mut vec {} // these are fine - for _ in &[1, 2, 3] {} + for _ in &[1, 2, 3] {} //~ explicit_iter_loop for _ in (&mut [1, 2, 3]).iter() {} - for _ in &[0; 32] {} - for _ in &[0; 33] {} + for _ in &[0; 32] {} //~ explicit_iter_loop + for _ in &[0; 33] {} //~ explicit_iter_loop let ll: LinkedList<()> = LinkedList::new(); - for _ in &ll {} + for _ in &ll {} //~ explicit_iter_loop let rll = ≪ - for _ in rll {} + for _ in rll {} //~ explicit_iter_loop let vd: VecDeque<()> = VecDeque::new(); - for _ in &vd {} + for _ in &vd {} //~ explicit_iter_loop let rvd = &vd; - for _ in rvd {} + for _ in rvd {} //~ explicit_iter_loop let bh: BinaryHeap<()> = BinaryHeap::new(); - for _ in &bh {} + for _ in &bh {} //~ explicit_iter_loop let hm: HashMap<(), ()> = HashMap::new(); - for _ in &hm {} + for _ in &hm {} //~ explicit_iter_loop let bt: BTreeMap<(), ()> = BTreeMap::new(); - for _ in &bt {} + for _ in &bt {} //~ explicit_iter_loop let hs: HashSet<()> = HashSet::new(); - for _ in &hs {} + for _ in &hs {} //~ explicit_iter_loop let bs: BTreeSet<()> = BTreeSet::new(); - for _ in &bs {} + for _ in &bs {} //~ explicit_iter_loop struct NoIntoIter(); impl NoIntoIter { @@ -146,9 +146,9 @@ fn main() { } } let mut x = CustomType; - for _ in &x {} - for _ in &mut x {} + for _ in &x {} //~ explicit_iter_loop + for _ in &mut x {} //~ explicit_iter_loop let r = &x; - for _ in r {} + for _ in r {} //~ explicit_iter_loop } diff --git a/tests/ui/explicit_iter_loop.rs b/tests/ui/explicit_iter_loop.rs index 2ee6825d445c..607dd550a2a1 100644 --- a/tests/ui/explicit_iter_loop.rs +++ b/tests/ui/explicit_iter_loop.rs @@ -14,11 +14,11 @@ use std::collections::*; fn main() { let mut vec = vec![1, 2, 3, 4]; - for _ in vec.iter() {} - for _ in vec.iter_mut() {} + for _ in vec.iter() {} //~ explicit_iter_loop + for _ in vec.iter_mut() {} //~ explicit_iter_loop let rvec = &vec; - for _ in rvec.iter() {} + for _ in rvec.iter() {} //~ explicit_iter_loop let rmvec = &mut vec; for _ in rmvec.iter() {} @@ -27,37 +27,37 @@ fn main() { for _ in &vec {} // these are fine for _ in &mut vec {} // these are fine - for _ in [1, 2, 3].iter() {} + for _ in [1, 2, 3].iter() {} //~ explicit_iter_loop for _ in (&mut [1, 2, 3]).iter() {} - for _ in [0; 32].iter() {} - for _ in [0; 33].iter() {} + for _ in [0; 32].iter() {} //~ explicit_iter_loop + for _ in [0; 33].iter() {} //~ explicit_iter_loop let ll: LinkedList<()> = LinkedList::new(); - for _ in ll.iter() {} + for _ in ll.iter() {} //~ explicit_iter_loop let rll = ≪ - for _ in rll.iter() {} + for _ in rll.iter() {} //~ explicit_iter_loop let vd: VecDeque<()> = VecDeque::new(); - for _ in vd.iter() {} + for _ in vd.iter() {} //~ explicit_iter_loop let rvd = &vd; - for _ in rvd.iter() {} + for _ in rvd.iter() {} //~ explicit_iter_loop let bh: BinaryHeap<()> = BinaryHeap::new(); - for _ in bh.iter() {} + for _ in bh.iter() {} //~ explicit_iter_loop let hm: HashMap<(), ()> = HashMap::new(); - for _ in hm.iter() {} + for _ in hm.iter() {} //~ explicit_iter_loop let bt: BTreeMap<(), ()> = BTreeMap::new(); - for _ in bt.iter() {} + for _ in bt.iter() {} //~ explicit_iter_loop let hs: HashSet<()> = HashSet::new(); - for _ in hs.iter() {} + for _ in hs.iter() {} //~ explicit_iter_loop let bs: BTreeSet<()> = BTreeSet::new(); - for _ in bs.iter() {} + for _ in bs.iter() {} //~ explicit_iter_loop struct NoIntoIter(); impl NoIntoIter { @@ -146,9 +146,9 @@ fn main() { } } let mut x = CustomType; - for _ in x.iter() {} - for _ in x.iter_mut() {} + for _ in x.iter() {} //~ explicit_iter_loop + for _ in x.iter_mut() {} //~ explicit_iter_loop let r = &x; - for _ in r.iter() {} + for _ in r.iter() {} //~ explicit_iter_loop } diff --git a/tests/ui/explicit_write.fixed b/tests/ui/explicit_write.fixed index 77a910dc1963..024999fc609e 100644 --- a/tests/ui/explicit_write.fixed +++ b/tests/ui/explicit_write.fixed @@ -21,23 +21,36 @@ fn main() { { use std::io::Write; print!("test"); + //~^ explicit_write eprint!("test"); + //~^ explicit_write println!("test"); + //~^ explicit_write eprintln!("test"); + //~^ explicit_write print!("test"); + //~^ explicit_write eprint!("test"); + //~^ explicit_write // including newlines println!("test\ntest"); + //~^ explicit_write eprintln!("test\ntest"); + //~^ explicit_write let value = 1; eprintln!("with {}", value); + //~^ explicit_write eprintln!("with {} {}", 2, value); + //~^ explicit_write eprintln!("with {value}"); + //~^ explicit_write eprintln!("macro arg {}", one!()); + //~^ explicit_write let width = 2; eprintln!("{:w$}", value, w = width); + //~^ explicit_write } // these should not warn, different destination { diff --git a/tests/ui/explicit_write.rs b/tests/ui/explicit_write.rs index c77956264f6d..c83c760d48c8 100644 --- a/tests/ui/explicit_write.rs +++ b/tests/ui/explicit_write.rs @@ -21,23 +21,36 @@ fn main() { { use std::io::Write; write!(std::io::stdout(), "test").unwrap(); + //~^ explicit_write write!(std::io::stderr(), "test").unwrap(); + //~^ explicit_write writeln!(std::io::stdout(), "test").unwrap(); + //~^ explicit_write writeln!(std::io::stderr(), "test").unwrap(); + //~^ explicit_write std::io::stdout().write_fmt(format_args!("test")).unwrap(); + //~^ explicit_write std::io::stderr().write_fmt(format_args!("test")).unwrap(); + //~^ explicit_write // including newlines writeln!(std::io::stdout(), "test\ntest").unwrap(); + //~^ explicit_write writeln!(std::io::stderr(), "test\ntest").unwrap(); + //~^ explicit_write let value = 1; writeln!(std::io::stderr(), "with {}", value).unwrap(); + //~^ explicit_write writeln!(std::io::stderr(), "with {} {}", 2, value).unwrap(); + //~^ explicit_write writeln!(std::io::stderr(), "with {value}").unwrap(); + //~^ explicit_write writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap(); + //~^ explicit_write let width = 2; writeln!(std::io::stderr(), "{:w$}", value, w = width).unwrap(); + //~^ explicit_write } // these should not warn, different destination { diff --git a/tests/ui/explicit_write.stderr b/tests/ui/explicit_write.stderr index 26aad266bbfc..d4287c0e80aa 100644 --- a/tests/ui/explicit_write.stderr +++ b/tests/ui/explicit_write.stderr @@ -8,73 +8,73 @@ LL | write!(std::io::stdout(), "test").unwrap(); = help: to override `-D warnings` add `#[allow(clippy::explicit_write)]` error: use of `write!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:24:9 + --> $DIR/explicit_write.rs:25:9 | LL | write!(std::io::stderr(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprint!("test")` error: use of `writeln!(stdout(), ...).unwrap()` - --> $DIR/explicit_write.rs:25:9 + --> $DIR/explicit_write.rs:27:9 | LL | writeln!(std::io::stdout(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `println!("test")` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:26:9 + --> $DIR/explicit_write.rs:29:9 | LL | writeln!(std::io::stderr(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("test")` error: use of `stdout().write_fmt(...).unwrap()` - --> $DIR/explicit_write.rs:27:9 + --> $DIR/explicit_write.rs:31:9 | LL | std::io::stdout().write_fmt(format_args!("test")).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `print!("test")` error: use of `stderr().write_fmt(...).unwrap()` - --> $DIR/explicit_write.rs:28:9 + --> $DIR/explicit_write.rs:33:9 | LL | std::io::stderr().write_fmt(format_args!("test")).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprint!("test")` error: use of `writeln!(stdout(), ...).unwrap()` - --> $DIR/explicit_write.rs:31:9 + --> $DIR/explicit_write.rs:37:9 | LL | writeln!(std::io::stdout(), "test\ntest").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `println!("test\ntest")` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:32:9 + --> $DIR/explicit_write.rs:39:9 | LL | writeln!(std::io::stderr(), "test\ntest").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("test\ntest")` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:35:9 + --> $DIR/explicit_write.rs:43:9 | LL | writeln!(std::io::stderr(), "with {}", value).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("with {}", value)` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:36:9 + --> $DIR/explicit_write.rs:45:9 | LL | writeln!(std::io::stderr(), "with {} {}", 2, value).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("with {} {}", 2, value)` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:37:9 + --> $DIR/explicit_write.rs:47:9 | LL | writeln!(std::io::stderr(), "with {value}").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("with {value}")` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:38:9 + --> $DIR/explicit_write.rs:49:9 | LL | writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("macro arg {}", one!())` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:40:9 + --> $DIR/explicit_write.rs:52:9 | LL | writeln!(std::io::stderr(), "{:w$}", value, w = width).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("{:w$}", value, w = width)` diff --git a/tests/ui/extend_with_drain.fixed b/tests/ui/extend_with_drain.fixed index 856c1a42dafc..c1137e6a6801 100644 --- a/tests/ui/extend_with_drain.fixed +++ b/tests/ui/extend_with_drain.fixed @@ -5,16 +5,16 @@ fn main() { //gets linted let mut vec1 = vec![0u8; 1024]; let mut vec2: std::vec::Vec = Vec::new(); - vec2.append(&mut vec1); + vec2.append(&mut vec1); //~ extend_with_drain let mut vec3 = vec![0u8; 1024]; let mut vec4: std::vec::Vec = Vec::new(); - vec4.append(&mut vec3); + vec4.append(&mut vec3); //~ extend_with_drain let mut vec11: std::vec::Vec = Vec::new(); - vec11.append(&mut return_vector()); + vec11.append(&mut return_vector()); //~ extend_with_drain //won't get linted it doesn't move the entire content of a vec into another let mut test1 = vec![0u8, 10]; @@ -45,7 +45,7 @@ fn main() { let mut x = vec![0, 1, 2, 3, 5]; let ref_x = &mut x; let mut y = Vec::new(); - y.append(ref_x); + y.append(ref_x); //~ extend_with_drain } fn return_vector() -> Vec { diff --git a/tests/ui/extend_with_drain.rs b/tests/ui/extend_with_drain.rs index 7d538097639f..d7be4a0cac68 100644 --- a/tests/ui/extend_with_drain.rs +++ b/tests/ui/extend_with_drain.rs @@ -5,16 +5,16 @@ fn main() { //gets linted let mut vec1 = vec![0u8; 1024]; let mut vec2: std::vec::Vec = Vec::new(); - vec2.extend(vec1.drain(..)); + vec2.extend(vec1.drain(..)); //~ extend_with_drain let mut vec3 = vec![0u8; 1024]; let mut vec4: std::vec::Vec = Vec::new(); - vec4.extend(vec3.drain(..)); + vec4.extend(vec3.drain(..)); //~ extend_with_drain let mut vec11: std::vec::Vec = Vec::new(); - vec11.extend(return_vector().drain(..)); + vec11.extend(return_vector().drain(..)); //~ extend_with_drain //won't get linted it doesn't move the entire content of a vec into another let mut test1 = vec![0u8, 10]; @@ -45,7 +45,7 @@ fn main() { let mut x = vec![0, 1, 2, 3, 5]; let ref_x = &mut x; let mut y = Vec::new(); - y.extend(ref_x.drain(..)); + y.extend(ref_x.drain(..)); //~ extend_with_drain } fn return_vector() -> Vec { diff --git a/tests/ui/extra_unused_lifetimes.rs b/tests/ui/extra_unused_lifetimes.rs index cdfaf8d3afea..8be5b818e7f7 100644 --- a/tests/ui/extra_unused_lifetimes.rs +++ b/tests/ui/extra_unused_lifetimes.rs @@ -16,7 +16,7 @@ fn empty() {} fn used_lt<'a>(x: &'a u8) {} -fn unused_lt<'a>(x: u8) {} +fn unused_lt<'a>(x: u8) {} //~ extra_unused_lifetimes fn unused_lt_transitive<'a, 'b: 'a>(x: &'b u8) { // 'a is useless here since it's not directly bound @@ -43,7 +43,7 @@ impl<'a> Foo<'a> for u8 { struct Bar; impl Bar { - fn x<'a>(&self) {} + fn x<'a>(&self) {} //~ extra_unused_lifetimes } // test for #489 (used lifetimes in bounds) @@ -69,7 +69,7 @@ impl X { // Methods implementing traits must have matching lifetimes mod issue4291 { trait BadTrait { - fn unused_lt<'a>(x: u8) {} + fn unused_lt<'a>(x: u8) {} //~ extra_unused_lifetimes } impl BadTrait for () { @@ -80,13 +80,16 @@ mod issue4291 { mod issue6437 { pub struct Scalar; + //~v extra_unused_lifetimes impl<'a> std::ops::AddAssign<&Scalar> for &mut Scalar { fn add_assign(&mut self, _rhs: &Scalar) { unimplemented!(); } } + //~v extra_unused_lifetimes impl<'b> Scalar { + //~v extra_unused_lifetimes pub fn something<'c>() -> Self { Self } diff --git a/tests/ui/extra_unused_lifetimes.stderr b/tests/ui/extra_unused_lifetimes.stderr index 8790fe5a5b1a..63e834e3d41f 100644 --- a/tests/ui/extra_unused_lifetimes.stderr +++ b/tests/ui/extra_unused_lifetimes.stderr @@ -20,19 +20,19 @@ LL | fn unused_lt<'a>(x: u8) {} | ^^ error: this lifetime isn't used in the impl - --> $DIR/extra_unused_lifetimes.rs:83:10 + --> $DIR/extra_unused_lifetimes.rs:84:10 | LL | impl<'a> std::ops::AddAssign<&Scalar> for &mut Scalar { | ^^ error: this lifetime isn't used in the impl - --> $DIR/extra_unused_lifetimes.rs:89:10 + --> $DIR/extra_unused_lifetimes.rs:91:10 | LL | impl<'b> Scalar { | ^^ error: this lifetime isn't used in the function definition - --> $DIR/extra_unused_lifetimes.rs:90:26 + --> $DIR/extra_unused_lifetimes.rs:93:26 | LL | pub fn something<'c>() -> Self { | ^^ diff --git a/tests/ui/extra_unused_type_parameters.fixed b/tests/ui/extra_unused_type_parameters.fixed index c9bebabdf17a..aeeed48a9f0c 100644 --- a/tests/ui/extra_unused_type_parameters.fixed +++ b/tests/ui/extra_unused_type_parameters.fixed @@ -6,14 +6,17 @@ extern crate proc_macros; use proc_macros::with_span; +//~v extra_unused_type_parameters fn unused_ty(x: u8) { unimplemented!() } +//~v extra_unused_type_parameters fn unused_multi(x: u8) { unimplemented!() } +//~v extra_unused_type_parameters fn unused_with_lt<'a>(x: &'a u8) { unimplemented!() } @@ -26,10 +29,12 @@ fn used_ret(x: u8) -> T { T::default() } +//~v extra_unused_type_parameters fn unused_bounded(x: U) { unimplemented!(); } +//~v extra_unused_type_parameters fn some_unused(b: B, c: C) { unimplemented!(); } @@ -55,6 +60,7 @@ fn used_closure() -> impl Fn() { struct S; impl S { + //~v extra_unused_type_parameters fn unused_ty_impl(&self) { unimplemented!() } @@ -77,6 +83,7 @@ where .filter_map(move |(i, a)| if i == index { None } else { Some(a) }) } +//~v extra_unused_type_parameters fn unused_opaque(dummy: impl Default) { unimplemented!() } @@ -90,6 +97,7 @@ mod unexported_trait_bounds { unimplemented!(); } + //~v extra_unused_type_parameters fn unused_with_priv_trait_bound() { unimplemented!(); } diff --git a/tests/ui/extra_unused_type_parameters.rs b/tests/ui/extra_unused_type_parameters.rs index 1bc0047adf01..92b0bfbe7b4d 100644 --- a/tests/ui/extra_unused_type_parameters.rs +++ b/tests/ui/extra_unused_type_parameters.rs @@ -6,14 +6,17 @@ extern crate proc_macros; use proc_macros::with_span; +//~v extra_unused_type_parameters fn unused_ty(x: u8) { unimplemented!() } +//~v extra_unused_type_parameters fn unused_multi(x: u8) { unimplemented!() } +//~v extra_unused_type_parameters fn unused_with_lt<'a, T>(x: &'a u8) { unimplemented!() } @@ -26,10 +29,12 @@ fn used_ret(x: u8) -> T { T::default() } +//~v extra_unused_type_parameters fn unused_bounded(x: U) { unimplemented!(); } +//~v extra_unused_type_parameters fn some_unused, E>(b: B, c: C) { unimplemented!(); } @@ -55,6 +60,7 @@ fn used_closure() -> impl Fn() { struct S; impl S { + //~v extra_unused_type_parameters fn unused_ty_impl(&self) { unimplemented!() } @@ -77,6 +83,7 @@ where .filter_map(move |(i, a)| if i == index { None } else { Some(a) }) } +//~v extra_unused_type_parameters fn unused_opaque(dummy: impl Default) { unimplemented!() } @@ -90,6 +97,7 @@ mod unexported_trait_bounds { unimplemented!(); } + //~v extra_unused_type_parameters fn unused_with_priv_trait_bound() { unimplemented!(); } diff --git a/tests/ui/extra_unused_type_parameters.stderr b/tests/ui/extra_unused_type_parameters.stderr index 9a179076c482..d81500c1d53b 100644 --- a/tests/ui/extra_unused_type_parameters.stderr +++ b/tests/ui/extra_unused_type_parameters.stderr @@ -1,5 +1,5 @@ error: type parameter `T` goes unused in function definition - --> $DIR/extra_unused_type_parameters.rs:9:13 + --> $DIR/extra_unused_type_parameters.rs:10:13 | LL | fn unused_ty(x: u8) { | ^^^ help: consider removing the parameter @@ -8,19 +8,19 @@ LL | fn unused_ty(x: u8) { = help: to override `-D warnings` add `#[allow(clippy::extra_unused_type_parameters)]` error: type parameters go unused in function definition: T, U - --> $DIR/extra_unused_type_parameters.rs:13:16 + --> $DIR/extra_unused_type_parameters.rs:15:16 | LL | fn unused_multi(x: u8) { | ^^^^^^ help: consider removing the parameters error: type parameter `T` goes unused in function definition - --> $DIR/extra_unused_type_parameters.rs:17:21 + --> $DIR/extra_unused_type_parameters.rs:20:21 | LL | fn unused_with_lt<'a, T>(x: &'a u8) { | ^^^ help: consider removing the parameter error: type parameters go unused in function definition: T, V - --> $DIR/extra_unused_type_parameters.rs:29:19 + --> $DIR/extra_unused_type_parameters.rs:33:19 | LL | fn unused_bounded(x: U) { | ^^^^^^^^^^^^ ^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL + fn unused_bounded(x: U) { | error: type parameters go unused in function definition: A, D, E - --> $DIR/extra_unused_type_parameters.rs:33:16 + --> $DIR/extra_unused_type_parameters.rs:38:16 | LL | fn some_unused, E>(b: B, c: C) { | ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,19 +44,19 @@ LL + fn some_unused(b: B, c: C) { | error: type parameter `T` goes unused in function definition - --> $DIR/extra_unused_type_parameters.rs:58:22 + --> $DIR/extra_unused_type_parameters.rs:64:22 | LL | fn unused_ty_impl(&self) { | ^^^ help: consider removing the parameter error: type parameters go unused in function definition: A, B - --> $DIR/extra_unused_type_parameters.rs:80:17 + --> $DIR/extra_unused_type_parameters.rs:87:17 | LL | fn unused_opaque(dummy: impl Default) { | ^^^^^^ help: consider removing the parameters error: type parameter `U` goes unused in function definition - --> $DIR/extra_unused_type_parameters.rs:93:56 + --> $DIR/extra_unused_type_parameters.rs:101:56 | LL | fn unused_with_priv_trait_bound() { | ^^^ help: consider removing the parameter diff --git a/tests/ui/field_reassign_with_default.rs b/tests/ui/field_reassign_with_default.rs index 2045b1eebcd7..dc2d33e811e1 100644 --- a/tests/ui/field_reassign_with_default.rs +++ b/tests/ui/field_reassign_with_default.rs @@ -53,7 +53,7 @@ impl SideEffect { fn main() { // wrong, produces first error in stderr let mut a: A = Default::default(); - a.i = 42; + a.i = 42; //~ field_reassign_with_default // right let mut a: A = Default::default(); @@ -93,18 +93,18 @@ fn main() { // wrong, produces second error in stderr let mut a: A = Default::default(); - a.j = 43; + a.j = 43; //~ field_reassign_with_default a.i = 42; // wrong, produces third error in stderr let mut a: A = Default::default(); - a.i = 42; + a.i = 42; //~ field_reassign_with_default a.j = 43; a.j = 44; // wrong, produces fourth error in stderr let mut a = A::default(); - a.i = 42; + a.i = 42; //~ field_reassign_with_default // wrong, but does not produce an error in stderr, because we can't produce a correct kind of // suggestion with current implementation @@ -114,11 +114,11 @@ fn main() { // wrong, produces the fifth error in stderr let mut a: A = Default::default(); - a.i = Default::default(); + a.i = Default::default(); //~ field_reassign_with_default // wrong, produces the sixth error in stderr let mut a: A = Default::default(); - a.i = Default::default(); + a.i = Default::default(); //~ field_reassign_with_default a.j = 45; // right, because an assignment refers to another field @@ -140,7 +140,7 @@ fn main() { // don't expand macros in the suggestion (#6522) let mut a: C = C::default(); - a.i = vec![1]; + a.i = vec![1]; //~ field_reassign_with_default // Don't lint in external macros external! { @@ -158,10 +158,10 @@ fn main() { // be sure suggestion is correct with generics let mut a: Wrapper = Default::default(); - a.i = true; + a.i = true; //~ field_reassign_with_default let mut a: WrapperMulti = Default::default(); - a.i = 42; + a.i = 42; //~ field_reassign_with_default // Don't lint in macros inline!( @@ -232,7 +232,7 @@ mod issue6312 { impl ImplDropAllCopy { fn new(name: &str) -> Self { let mut f = ImplDropAllCopy::default(); - f.name = name.len(); + f.name = name.len(); //~ field_reassign_with_default f } fn close(&self) {} @@ -248,7 +248,7 @@ mod issue6312 { impl NoDropAllCopy { fn new(name: &str) -> Self { let mut f = NoDropAllCopy::default(); - f.name = name.len(); + f.name = name.len(); //~ field_reassign_with_default f } } diff --git a/tests/ui/filter_map_bool_then.fixed b/tests/ui/filter_map_bool_then.fixed index 6a1b81fdbcbe..b3e112f19eb4 100644 --- a/tests/ui/filter_map_bool_then.fixed +++ b/tests/ui/filter_map_bool_then.fixed @@ -17,24 +17,30 @@ struct NonCopy; fn main() { let v = vec![1, 2, 3, 4, 5, 6]; v.clone().iter().filter(|&i| (i % 2 == 0)).map(|i| i + 1); + //~^ filter_map_bool_then v.clone().into_iter().filter(|&i| (i % 2 == 0)).map(|i| i + 1); + //~^ filter_map_bool_then v.clone() .into_iter() .filter(|&i| (i % 2 == 0)).map(|i| i + 1); + //~^ filter_map_bool_then v.clone() .into_iter() .filter(|&i| i != 1000) .filter(|&i| (i % 2 == 0)).map(|i| i + 1); + //~^ filter_map_bool_then v.iter() .copied() .filter(|&i| i != 1000) .filter(|&i| (i.clone() % 2 == 0)).map(|i| i + 1); + //~^ filter_map_bool_then // Despite this is non-copy, `is_copy` still returns true (at least now) because it's `&NonCopy`, // and any `&` is `Copy`. So since we can dereference it in `filter` (since it's then `&&NonCopy`), // we can lint this and still get the same input type. // See: let v = vec![NonCopy, NonCopy]; v.clone().iter().filter(|&i| (i == &NonCopy)).map(|i| i); + //~^ filter_map_bool_then // Do not lint let v = vec![NonCopy, NonCopy]; v.clone().into_iter().filter_map(|i| (i == NonCopy).then(|| i)); @@ -59,14 +65,17 @@ fn issue11309<'a>(iter: impl Iterator) -> Vec<&'a str fn issue11503() { let bools: &[bool] = &[true, false, false, true]; let _: Vec = bools.iter().enumerate().filter(|&(i, b)| *b).map(|(i, b)| i).collect(); + //~^ filter_map_bool_then // Need to insert multiple derefs if there is more than one layer of references let bools: &[&&bool] = &[&&true, &&false, &&false, &&true]; let _: Vec = bools.iter().enumerate().filter(|&(i, b)| ***b).map(|(i, b)| i).collect(); + //~^ filter_map_bool_then // Should also suggest derefs when going through a mutable reference let bools: &[&mut bool] = &[&mut true]; let _: Vec = bools.iter().enumerate().filter(|&(i, b)| **b).map(|(i, b)| i).collect(); + //~^ filter_map_bool_then // Should also suggest derefs when going through a custom deref struct DerefToBool; @@ -78,4 +87,5 @@ fn issue11503() { } let bools: &[&&DerefToBool] = &[&&DerefToBool]; let _: Vec = bools.iter().enumerate().filter(|&(i, b)| ****b).map(|(i, b)| i).collect(); + //~^ filter_map_bool_then } diff --git a/tests/ui/filter_map_bool_then.rs b/tests/ui/filter_map_bool_then.rs index a41e88f8805d..d996b3cb3c52 100644 --- a/tests/ui/filter_map_bool_then.rs +++ b/tests/ui/filter_map_bool_then.rs @@ -17,24 +17,30 @@ struct NonCopy; fn main() { let v = vec![1, 2, 3, 4, 5, 6]; v.clone().iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); + //~^ filter_map_bool_then v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); + //~^ filter_map_bool_then v.clone() .into_iter() .filter_map(|i| -> Option<_> { (i % 2 == 0).then(|| i + 1) }); + //~^ filter_map_bool_then v.clone() .into_iter() .filter(|&i| i != 1000) .filter_map(|i| (i % 2 == 0).then(|| i + 1)); + //~^ filter_map_bool_then v.iter() .copied() .filter(|&i| i != 1000) .filter_map(|i| (i.clone() % 2 == 0).then(|| i + 1)); + //~^ filter_map_bool_then // Despite this is non-copy, `is_copy` still returns true (at least now) because it's `&NonCopy`, // and any `&` is `Copy`. So since we can dereference it in `filter` (since it's then `&&NonCopy`), // we can lint this and still get the same input type. // See: let v = vec![NonCopy, NonCopy]; v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i)); + //~^ filter_map_bool_then // Do not lint let v = vec![NonCopy, NonCopy]; v.clone().into_iter().filter_map(|i| (i == NonCopy).then(|| i)); @@ -59,14 +65,17 @@ fn issue11309<'a>(iter: impl Iterator) -> Vec<&'a str fn issue11503() { let bools: &[bool] = &[true, false, false, true]; let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); + //~^ filter_map_bool_then // Need to insert multiple derefs if there is more than one layer of references let bools: &[&&bool] = &[&&true, &&false, &&false, &&true]; let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); + //~^ filter_map_bool_then // Should also suggest derefs when going through a mutable reference let bools: &[&mut bool] = &[&mut true]; let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); + //~^ filter_map_bool_then // Should also suggest derefs when going through a custom deref struct DerefToBool; @@ -78,4 +87,5 @@ fn issue11503() { } let bools: &[&&DerefToBool] = &[&&DerefToBool]; let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); + //~^ filter_map_bool_then } diff --git a/tests/ui/filter_map_bool_then.stderr b/tests/ui/filter_map_bool_then.stderr index fab6987913a1..54223b58eb48 100644 --- a/tests/ui/filter_map_bool_then.stderr +++ b/tests/ui/filter_map_bool_then.stderr @@ -8,55 +8,55 @@ LL | v.clone().iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); = help: to override `-D warnings` add `#[allow(clippy::filter_map_bool_then)]` error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:20:27 + --> $DIR/filter_map_bool_then.rs:21:27 | LL | v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:23:10 + --> $DIR/filter_map_bool_then.rs:25:10 | LL | .filter_map(|i| -> Option<_> { (i % 2 == 0).then(|| i + 1) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:27:10 + --> $DIR/filter_map_bool_then.rs:30:10 | LL | .filter_map(|i| (i % 2 == 0).then(|| i + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:31:10 + --> $DIR/filter_map_bool_then.rs:35:10 | LL | .filter_map(|i| (i.clone() % 2 == 0).then(|| i + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i.clone() % 2 == 0)).map(|i| i + 1)` error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:37:22 + --> $DIR/filter_map_bool_then.rs:42:22 | LL | v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i == &NonCopy)).map(|i| i)` error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:61:50 + --> $DIR/filter_map_bool_then.rs:67:50 | LL | let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&(i, b)| *b).map(|(i, b)| i)` error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:65:50 + --> $DIR/filter_map_bool_then.rs:72:50 | LL | let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&(i, b)| ***b).map(|(i, b)| i)` error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:69:50 + --> $DIR/filter_map_bool_then.rs:77:50 | LL | let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&(i, b)| **b).map(|(i, b)| i)` error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:80:50 + --> $DIR/filter_map_bool_then.rs:89:50 | LL | let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&(i, b)| ****b).map(|(i, b)| i)` diff --git a/tests/ui/filter_map_identity.fixed b/tests/ui/filter_map_identity.fixed index ad438afaca77..b19d657e32ce 100644 --- a/tests/ui/filter_map_identity.fixed +++ b/tests/ui/filter_map_identity.fixed @@ -3,15 +3,17 @@ fn main() { let iterator = vec![Some(1), None, Some(2)].into_iter(); - let _ = iterator.flatten(); + let _ = iterator.flatten(); //~ filter_map_identity let iterator = vec![Some(1), None, Some(2)].into_iter(); let _ = iterator.flatten(); + //~^ filter_map_identity use std::convert::identity; let iterator = vec![Some(1), None, Some(2)].into_iter(); - let _ = iterator.flatten(); + let _ = iterator.flatten(); //~ filter_map_identity let iterator = vec![Some(1), None, Some(2)].into_iter(); let _ = iterator.flatten(); + //~^ filter_map_identity } diff --git a/tests/ui/filter_map_identity.rs b/tests/ui/filter_map_identity.rs index d7423276872a..92e5aaf8942f 100644 --- a/tests/ui/filter_map_identity.rs +++ b/tests/ui/filter_map_identity.rs @@ -3,15 +3,17 @@ fn main() { let iterator = vec![Some(1), None, Some(2)].into_iter(); - let _ = iterator.filter_map(|x| x); + let _ = iterator.filter_map(|x| x); //~ filter_map_identity let iterator = vec![Some(1), None, Some(2)].into_iter(); let _ = iterator.filter_map(std::convert::identity); + //~^ filter_map_identity use std::convert::identity; let iterator = vec![Some(1), None, Some(2)].into_iter(); - let _ = iterator.filter_map(identity); + let _ = iterator.filter_map(identity); //~ filter_map_identity let iterator = vec![Some(1), None, Some(2)].into_iter(); let _ = iterator.filter_map(|x| return x); + //~^ filter_map_identity } diff --git a/tests/ui/filter_map_identity.stderr b/tests/ui/filter_map_identity.stderr index a08477695c93..f45046e9eda8 100644 --- a/tests/ui/filter_map_identity.stderr +++ b/tests/ui/filter_map_identity.stderr @@ -14,13 +14,13 @@ LL | let _ = iterator.filter_map(std::convert::identity); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> $DIR/filter_map_identity.rs:13:22 + --> $DIR/filter_map_identity.rs:14:22 | LL | let _ = iterator.filter_map(identity); | ^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> $DIR/filter_map_identity.rs:16:22 + --> $DIR/filter_map_identity.rs:17:22 | LL | let _ = iterator.filter_map(|x| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` diff --git a/tests/ui/filter_map_next_fixable.fixed b/tests/ui/filter_map_next_fixable.fixed index 193ac3aea433..285863ef340d 100644 --- a/tests/ui/filter_map_next_fixable.fixed +++ b/tests/ui/filter_map_next_fixable.fixed @@ -5,6 +5,7 @@ fn main() { let a = ["1", "lol", "3", "NaN", "5"]; let element: Option = a.iter().find_map(|s| s.parse().ok()); + //~^ filter_map_next assert_eq!(element, Some(1)); } @@ -18,4 +19,5 @@ fn msrv_1_29() { fn msrv_1_30() { let a = ["1", "lol", "3", "NaN", "5"]; let _: Option = a.iter().find_map(|s| s.parse().ok()); + //~^ filter_map_next } diff --git a/tests/ui/filter_map_next_fixable.rs b/tests/ui/filter_map_next_fixable.rs index dab8d289817e..af911689b7c7 100644 --- a/tests/ui/filter_map_next_fixable.rs +++ b/tests/ui/filter_map_next_fixable.rs @@ -5,6 +5,7 @@ fn main() { let a = ["1", "lol", "3", "NaN", "5"]; let element: Option = a.iter().filter_map(|s| s.parse().ok()).next(); + //~^ filter_map_next assert_eq!(element, Some(1)); } @@ -18,4 +19,5 @@ fn msrv_1_29() { fn msrv_1_30() { let a = ["1", "lol", "3", "NaN", "5"]; let _: Option = a.iter().filter_map(|s| s.parse().ok()).next(); + //~^ filter_map_next } diff --git a/tests/ui/filter_map_next_fixable.stderr b/tests/ui/filter_map_next_fixable.stderr index 0edf4e6e07d4..d5496817ac37 100644 --- a/tests/ui/filter_map_next_fixable.stderr +++ b/tests/ui/filter_map_next_fixable.stderr @@ -8,7 +8,7 @@ LL | let element: Option = a.iter().filter_map(|s| s.parse().ok()).next = help: to override `-D warnings` add `#[allow(clippy::filter_map_next)]` error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead - --> $DIR/filter_map_next_fixable.rs:20:26 + --> $DIR/filter_map_next_fixable.rs:21:26 | LL | let _: Option = a.iter().filter_map(|s| s.parse().ok()).next(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.iter().find_map(|s| s.parse().ok())` diff --git a/tests/ui/flat_map_identity.fixed b/tests/ui/flat_map_identity.fixed index c142cf719808..8719cfbe0a96 100644 --- a/tests/ui/flat_map_identity.fixed +++ b/tests/ui/flat_map_identity.fixed @@ -5,11 +5,12 @@ use std::convert; fn main() { let iterator = [[0, 1], [2, 3], [4, 5]].iter(); - let _ = iterator.flatten(); + let _ = iterator.flatten(); //~ flat_map_identity let iterator = [[0, 1], [2, 3], [4, 5]].iter(); let _ = iterator.flatten(); + //~^ flat_map_identity let iterator = [[0, 1], [2, 3], [4, 5]].iter(); - let _ = iterator.flatten(); + let _ = iterator.flatten(); //~ flat_map_identity } diff --git a/tests/ui/flat_map_identity.rs b/tests/ui/flat_map_identity.rs index 8505ba9005d3..36beee685ed0 100644 --- a/tests/ui/flat_map_identity.rs +++ b/tests/ui/flat_map_identity.rs @@ -5,11 +5,12 @@ use std::convert; fn main() { let iterator = [[0, 1], [2, 3], [4, 5]].iter(); - let _ = iterator.flat_map(|x| x); + let _ = iterator.flat_map(|x| x); //~ flat_map_identity let iterator = [[0, 1], [2, 3], [4, 5]].iter(); let _ = iterator.flat_map(convert::identity); + //~^ flat_map_identity let iterator = [[0, 1], [2, 3], [4, 5]].iter(); - let _ = iterator.flat_map(|x| return x); + let _ = iterator.flat_map(|x| return x); //~ flat_map_identity } diff --git a/tests/ui/flat_map_identity.stderr b/tests/ui/flat_map_identity.stderr index d6fcc14fc563..c25e81964f1f 100644 --- a/tests/ui/flat_map_identity.stderr +++ b/tests/ui/flat_map_identity.stderr @@ -14,7 +14,7 @@ LL | let _ = iterator.flat_map(convert::identity); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `flat_map` with an identity function - --> $DIR/flat_map_identity.rs:14:22 + --> $DIR/flat_map_identity.rs:15:22 | LL | let _ = iterator.flat_map(|x| return x); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` diff --git a/tests/ui/flat_map_option.fixed b/tests/ui/flat_map_option.fixed index e08d9a14533b..bb1e9f3f4f36 100644 --- a/tests/ui/flat_map_option.fixed +++ b/tests/ui/flat_map_option.fixed @@ -4,8 +4,8 @@ fn main() { // yay let c = |x| Some(x); - let _ = [1].iter().filter_map(c); - let _ = [1].iter().filter_map(Some); + let _ = [1].iter().filter_map(c); //~ flat_map_option + let _ = [1].iter().filter_map(Some); //~ flat_map_option // nay let _ = [1].iter().flat_map(|_| &Some(1)); diff --git a/tests/ui/flat_map_option.rs b/tests/ui/flat_map_option.rs index 4d0f32ac0fda..30a9ad3328c5 100644 --- a/tests/ui/flat_map_option.rs +++ b/tests/ui/flat_map_option.rs @@ -4,8 +4,8 @@ fn main() { // yay let c = |x| Some(x); - let _ = [1].iter().flat_map(c); - let _ = [1].iter().flat_map(Some); + let _ = [1].iter().flat_map(c); //~ flat_map_option + let _ = [1].iter().flat_map(Some); //~ flat_map_option // nay let _ = [1].iter().flat_map(|_| &Some(1)); diff --git a/tests/ui/floating_point_abs.fixed b/tests/ui/floating_point_abs.fixed index 5312a8b29c67..dbada96715e2 100644 --- a/tests/ui/floating_point_abs.fixed +++ b/tests/ui/floating_point_abs.fixed @@ -12,36 +12,36 @@ struct A { } fn fake_abs1(num: f64) -> f64 { - num.abs() + num.abs() //~ suboptimal_flops } fn fake_abs2(num: f64) -> f64 { - num.abs() + num.abs() //~ suboptimal_flops } fn fake_abs3(a: A) -> f64 { - a.a.abs() + a.a.abs() //~ suboptimal_flops } fn fake_abs4(num: f64) -> f64 { - num.abs() + num.abs() //~ suboptimal_flops } fn fake_abs5(a: A) -> f64 { - a.a.abs() + a.a.abs() //~ suboptimal_flops } fn fake_nabs1(num: f64) -> f64 { - -num.abs() + -num.abs() //~ suboptimal_flops } fn fake_nabs2(num: f64) -> f64 { - -num.abs() + -num.abs() //~ suboptimal_flops } fn fake_nabs3(a: A) -> A { A { - a: -a.a.abs(), + a: -a.a.abs(), //~ suboptimal_flops b: a.b, } } diff --git a/tests/ui/floating_point_abs.rs b/tests/ui/floating_point_abs.rs index 8619177130c9..92598c82d444 100644 --- a/tests/ui/floating_point_abs.rs +++ b/tests/ui/floating_point_abs.rs @@ -12,36 +12,36 @@ struct A { } fn fake_abs1(num: f64) -> f64 { - if num >= 0.0 { num } else { -num } + if num >= 0.0 { num } else { -num } //~ suboptimal_flops } fn fake_abs2(num: f64) -> f64 { - if 0.0 < num { num } else { -num } + if 0.0 < num { num } else { -num } //~ suboptimal_flops } fn fake_abs3(a: A) -> f64 { - if a.a > 0.0 { a.a } else { -a.a } + if a.a > 0.0 { a.a } else { -a.a } //~ suboptimal_flops } fn fake_abs4(num: f64) -> f64 { - if 0.0 >= num { -num } else { num } + if 0.0 >= num { -num } else { num } //~ suboptimal_flops } fn fake_abs5(a: A) -> f64 { - if a.a < 0.0 { -a.a } else { a.a } + if a.a < 0.0 { -a.a } else { a.a } //~ suboptimal_flops } fn fake_nabs1(num: f64) -> f64 { - if num < 0.0 { num } else { -num } + if num < 0.0 { num } else { -num } //~ suboptimal_flops } fn fake_nabs2(num: f64) -> f64 { - if 0.0 >= num { num } else { -num } + if 0.0 >= num { num } else { -num } //~ suboptimal_flops } fn fake_nabs3(a: A) -> A { A { - a: if a.a >= 0.0 { -a.a } else { a.a }, + a: if a.a >= 0.0 { -a.a } else { a.a }, //~ suboptimal_flops b: a.b, } } diff --git a/tests/ui/floating_point_exp.fixed b/tests/ui/floating_point_exp.fixed index 15072bb1ee9a..e7db87b2455e 100644 --- a/tests/ui/floating_point_exp.fixed +++ b/tests/ui/floating_point_exp.fixed @@ -3,16 +3,16 @@ fn main() { let x = 2f32; - let _ = x.exp_m1(); - let _ = x.exp_m1() + 2.0; - let _ = (x as f32).exp_m1() + 2.0; + let _ = x.exp_m1(); //~ imprecise_flops + let _ = x.exp_m1() + 2.0; //~ imprecise_flops + let _ = (x as f32).exp_m1() + 2.0; //~ imprecise_flops // Cases where the lint shouldn't be applied let _ = x.exp() - 2.0; let _ = x.exp() - 1.0 * 2.0; let x = 2f64; - let _ = x.exp_m1(); - let _ = x.exp_m1() + 2.0; + let _ = x.exp_m1(); //~ imprecise_flops + let _ = x.exp_m1() + 2.0; //~ imprecise_flops // Cases where the lint shouldn't be applied let _ = x.exp() - 2.0; let _ = x.exp() - 1.0 * 2.0; diff --git a/tests/ui/floating_point_exp.rs b/tests/ui/floating_point_exp.rs index 7d8b17946d0a..818aca133bbf 100644 --- a/tests/ui/floating_point_exp.rs +++ b/tests/ui/floating_point_exp.rs @@ -3,16 +3,16 @@ fn main() { let x = 2f32; - let _ = x.exp() - 1.0; - let _ = x.exp() - 1.0 + 2.0; - let _ = (x as f32).exp() - 1.0 + 2.0; + let _ = x.exp() - 1.0; //~ imprecise_flops + let _ = x.exp() - 1.0 + 2.0; //~ imprecise_flops + let _ = (x as f32).exp() - 1.0 + 2.0; //~ imprecise_flops // Cases where the lint shouldn't be applied let _ = x.exp() - 2.0; let _ = x.exp() - 1.0 * 2.0; let x = 2f64; - let _ = x.exp() - 1.0; - let _ = x.exp() - 1.0 + 2.0; + let _ = x.exp() - 1.0; //~ imprecise_flops + let _ = x.exp() - 1.0 + 2.0; //~ imprecise_flops // Cases where the lint shouldn't be applied let _ = x.exp() - 2.0; let _ = x.exp() - 1.0 * 2.0; diff --git a/tests/ui/floating_point_hypot.fixed b/tests/ui/floating_point_hypot.fixed index 75a224440b0d..f6a4f6cd7d76 100644 --- a/tests/ui/floating_point_hypot.fixed +++ b/tests/ui/floating_point_hypot.fixed @@ -3,9 +3,10 @@ fn main() { let x = 3f32; let y = 4f32; - let _ = x.hypot(y); + let _ = x.hypot(y); //~ imprecise_flops let _ = (x + 1f32).hypot(y); - let _ = x.hypot(y); + //~^ imprecise_flops + let _ = x.hypot(y); //~ imprecise_flops // Cases where the lint shouldn't be applied // TODO: linting this adds some complexity, but could be done let _ = x.mul_add(x, y * y).sqrt(); diff --git a/tests/ui/floating_point_hypot.rs b/tests/ui/floating_point_hypot.rs index ed4dbf6382e7..5a0ef2c427e7 100644 --- a/tests/ui/floating_point_hypot.rs +++ b/tests/ui/floating_point_hypot.rs @@ -3,9 +3,10 @@ fn main() { let x = 3f32; let y = 4f32; - let _ = (x * x + y * y).sqrt(); + let _ = (x * x + y * y).sqrt(); //~ imprecise_flops let _ = ((x + 1f32) * (x + 1f32) + y * y).sqrt(); - let _ = (x.powi(2) + y.powi(2)).sqrt(); + //~^ imprecise_flops + let _ = (x.powi(2) + y.powi(2)).sqrt(); //~ imprecise_flops // Cases where the lint shouldn't be applied // TODO: linting this adds some complexity, but could be done let _ = x.mul_add(x, y * y).sqrt(); diff --git a/tests/ui/floating_point_hypot.stderr b/tests/ui/floating_point_hypot.stderr index 21e0bd8b5810..60c17862a796 100644 --- a/tests/ui/floating_point_hypot.stderr +++ b/tests/ui/floating_point_hypot.stderr @@ -14,7 +14,7 @@ LL | let _ = ((x + 1f32) * (x + 1f32) + y * y).sqrt(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x + 1f32).hypot(y)` error: hypotenuse can be computed more accurately - --> $DIR/floating_point_hypot.rs:8:13 + --> $DIR/floating_point_hypot.rs:9:13 | LL | let _ = (x.powi(2) + y.powi(2)).sqrt(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.hypot(y)` diff --git a/tests/ui/floating_point_log.fixed b/tests/ui/floating_point_log.fixed index 01f0fc5c671a..24570a131cc8 100644 --- a/tests/ui/floating_point_log.fixed +++ b/tests/ui/floating_point_log.fixed @@ -6,32 +6,33 @@ const E: f32 = std::f32::consts::E; fn check_log_base() { let x = 1f32; - let _ = x.log2(); - let _ = x.log10(); - let _ = x.ln(); - let _ = x.log2(); - let _ = x.ln(); - let _ = (x as f32).log2(); + let _ = x.log2(); //~ suboptimal_flops + let _ = x.log10(); //~ suboptimal_flops + let _ = x.ln(); //~ suboptimal_flops + let _ = x.log2(); //~ suboptimal_flops + let _ = x.ln(); //~ suboptimal_flops + let _ = (x as f32).log2(); //~ suboptimal_flops let x = 1f64; - let _ = x.log2(); - let _ = x.log10(); - let _ = x.ln(); + let _ = x.log2(); //~ suboptimal_flops + let _ = x.log10(); //~ suboptimal_flops + let _ = x.ln(); //~ suboptimal_flops } fn check_ln1p() { let x = 1f32; - let _ = 2.0f32.ln_1p(); - let _ = 2.0f32.ln_1p(); - let _ = x.ln_1p(); - let _ = (x / 2.0).ln_1p(); - let _ = x.powi(3).ln_1p(); - let _ = (x.powi(3) / 2.0).ln_1p(); + let _ = 2.0f32.ln_1p(); //~ imprecise_flops + let _ = 2.0f32.ln_1p(); //~ imprecise_flops + let _ = x.ln_1p(); //~ imprecise_flops + let _ = (x / 2.0).ln_1p(); //~ imprecise_flops + let _ = x.powi(3).ln_1p(); //~ imprecise_flops + let _ = (x.powi(3) / 2.0).ln_1p(); //~ imprecise_flops let _ = (std::f32::consts::E - 1.0).ln_1p(); - let _ = x.ln_1p(); - let _ = x.powi(3).ln_1p(); - let _ = (x + 2.0).ln_1p(); - let _ = (x / 2.0).ln_1p(); + //~^ imprecise_flops + let _ = x.ln_1p(); //~ imprecise_flops + let _ = x.powi(3).ln_1p(); //~ imprecise_flops + let _ = (x + 2.0).ln_1p(); //~ imprecise_flops + let _ = (x / 2.0).ln_1p(); //~ imprecise_flops // Cases where the lint shouldn't be applied let _ = (1.0 + x + 2.0).ln(); let _ = (x + 1.0 + 2.0).ln(); @@ -39,15 +40,15 @@ fn check_ln1p() { let _ = (1.0 + x - 2.0).ln(); let x = 1f64; - let _ = 2.0f64.ln_1p(); - let _ = 2.0f64.ln_1p(); - let _ = x.ln_1p(); - let _ = (x / 2.0).ln_1p(); - let _ = x.powi(3).ln_1p(); - let _ = x.ln_1p(); - let _ = x.powi(3).ln_1p(); - let _ = (x + 2.0).ln_1p(); - let _ = (x / 2.0).ln_1p(); + let _ = 2.0f64.ln_1p(); //~ imprecise_flops + let _ = 2.0f64.ln_1p(); //~ imprecise_flops + let _ = x.ln_1p(); //~ imprecise_flops + let _ = (x / 2.0).ln_1p(); //~ imprecise_flops + let _ = x.powi(3).ln_1p(); //~ imprecise_flops + let _ = x.ln_1p(); //~ imprecise_flops + let _ = x.powi(3).ln_1p(); //~ imprecise_flops + let _ = (x + 2.0).ln_1p(); //~ imprecise_flops + let _ = (x / 2.0).ln_1p(); //~ imprecise_flops // Cases where the lint shouldn't be applied let _ = (1.0 + x + 2.0).ln(); let _ = (x + 1.0 + 2.0).ln(); diff --git a/tests/ui/floating_point_log.rs b/tests/ui/floating_point_log.rs index 197e3e1ff909..de6e4102d9ca 100644 --- a/tests/ui/floating_point_log.rs +++ b/tests/ui/floating_point_log.rs @@ -6,32 +6,33 @@ const E: f32 = std::f32::consts::E; fn check_log_base() { let x = 1f32; - let _ = x.log(2f32); - let _ = x.log(10f32); - let _ = x.log(std::f32::consts::E); - let _ = x.log(TWO); - let _ = x.log(E); - let _ = (x as f32).log(2f32); + let _ = x.log(2f32); //~ suboptimal_flops + let _ = x.log(10f32); //~ suboptimal_flops + let _ = x.log(std::f32::consts::E); //~ suboptimal_flops + let _ = x.log(TWO); //~ suboptimal_flops + let _ = x.log(E); //~ suboptimal_flops + let _ = (x as f32).log(2f32); //~ suboptimal_flops let x = 1f64; - let _ = x.log(2f64); - let _ = x.log(10f64); - let _ = x.log(std::f64::consts::E); + let _ = x.log(2f64); //~ suboptimal_flops + let _ = x.log(10f64); //~ suboptimal_flops + let _ = x.log(std::f64::consts::E); //~ suboptimal_flops } fn check_ln1p() { let x = 1f32; - let _ = (1f32 + 2.).ln(); - let _ = (1f32 + 2.0).ln(); - let _ = (1.0 + x).ln(); - let _ = (1.0 + x / 2.0).ln(); - let _ = (1.0 + x.powi(3)).ln(); - let _ = (1.0 + x.powi(3) / 2.0).ln(); + let _ = (1f32 + 2.).ln(); //~ imprecise_flops + let _ = (1f32 + 2.0).ln(); //~ imprecise_flops + let _ = (1.0 + x).ln(); //~ imprecise_flops + let _ = (1.0 + x / 2.0).ln(); //~ imprecise_flops + let _ = (1.0 + x.powi(3)).ln(); //~ imprecise_flops + let _ = (1.0 + x.powi(3) / 2.0).ln(); //~ imprecise_flops let _ = (1.0 + (std::f32::consts::E - 1.0)).ln(); - let _ = (x + 1.0).ln(); - let _ = (x.powi(3) + 1.0).ln(); - let _ = (x + 2.0 + 1.0).ln(); - let _ = (x / 2.0 + 1.0).ln(); + //~^ imprecise_flops + let _ = (x + 1.0).ln(); //~ imprecise_flops + let _ = (x.powi(3) + 1.0).ln(); //~ imprecise_flops + let _ = (x + 2.0 + 1.0).ln(); //~ imprecise_flops + let _ = (x / 2.0 + 1.0).ln(); //~ imprecise_flops // Cases where the lint shouldn't be applied let _ = (1.0 + x + 2.0).ln(); let _ = (x + 1.0 + 2.0).ln(); @@ -39,15 +40,15 @@ fn check_ln1p() { let _ = (1.0 + x - 2.0).ln(); let x = 1f64; - let _ = (1f64 + 2.).ln(); - let _ = (1f64 + 2.0).ln(); - let _ = (1.0 + x).ln(); - let _ = (1.0 + x / 2.0).ln(); - let _ = (1.0 + x.powi(3)).ln(); - let _ = (x + 1.0).ln(); - let _ = (x.powi(3) + 1.0).ln(); - let _ = (x + 2.0 + 1.0).ln(); - let _ = (x / 2.0 + 1.0).ln(); + let _ = (1f64 + 2.).ln(); //~ imprecise_flops + let _ = (1f64 + 2.0).ln(); //~ imprecise_flops + let _ = (1.0 + x).ln(); //~ imprecise_flops + let _ = (1.0 + x / 2.0).ln(); //~ imprecise_flops + let _ = (1.0 + x.powi(3)).ln(); //~ imprecise_flops + let _ = (x + 1.0).ln(); //~ imprecise_flops + let _ = (x.powi(3) + 1.0).ln(); //~ imprecise_flops + let _ = (x + 2.0 + 1.0).ln(); //~ imprecise_flops + let _ = (x / 2.0 + 1.0).ln(); //~ imprecise_flops // Cases where the lint shouldn't be applied let _ = (1.0 + x + 2.0).ln(); let _ = (x + 1.0 + 2.0).ln(); diff --git a/tests/ui/floating_point_log.stderr b/tests/ui/floating_point_log.stderr index a426f4c3dde8..1d4a6baa399b 100644 --- a/tests/ui/floating_point_log.stderr +++ b/tests/ui/floating_point_log.stderr @@ -101,79 +101,79 @@ LL | let _ = (1.0 + (std::f32::consts::E - 1.0)).ln(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(std::f32::consts::E - 1.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:31:13 + --> $DIR/floating_point_log.rs:32:13 | LL | let _ = (x + 1.0).ln(); | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:32:13 + --> $DIR/floating_point_log.rs:33:13 | LL | let _ = (x.powi(3) + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(3).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:33:13 + --> $DIR/floating_point_log.rs:34:13 | LL | let _ = (x + 2.0 + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x + 2.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:34:13 + --> $DIR/floating_point_log.rs:35:13 | LL | let _ = (x / 2.0 + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x / 2.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:42:13 + --> $DIR/floating_point_log.rs:43:13 | LL | let _ = (1f64 + 2.).ln(); | ^^^^^^^^^^^^^^^^ help: consider using: `2.0f64.ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:43:13 + --> $DIR/floating_point_log.rs:44:13 | LL | let _ = (1f64 + 2.0).ln(); | ^^^^^^^^^^^^^^^^^ help: consider using: `2.0f64.ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:44:13 + --> $DIR/floating_point_log.rs:45:13 | LL | let _ = (1.0 + x).ln(); | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:45:13 + --> $DIR/floating_point_log.rs:46:13 | LL | let _ = (1.0 + x / 2.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x / 2.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:46:13 + --> $DIR/floating_point_log.rs:47:13 | LL | let _ = (1.0 + x.powi(3)).ln(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(3).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:47:13 + --> $DIR/floating_point_log.rs:48:13 | LL | let _ = (x + 1.0).ln(); | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:48:13 + --> $DIR/floating_point_log.rs:49:13 | LL | let _ = (x.powi(3) + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(3).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:49:13 + --> $DIR/floating_point_log.rs:50:13 | LL | let _ = (x + 2.0 + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x + 2.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:50:13 + --> $DIR/floating_point_log.rs:51:13 | LL | let _ = (x / 2.0 + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x / 2.0).ln_1p()` diff --git a/tests/ui/floating_point_logbase.fixed b/tests/ui/floating_point_logbase.fixed index 451673d109c6..ab938b76321d 100644 --- a/tests/ui/floating_point_logbase.fixed +++ b/tests/ui/floating_point_logbase.fixed @@ -4,11 +4,11 @@ fn main() { let x = 3f32; let y = 5f32; - let _ = x.log(y); - let _ = (x as f32).log(y); - let _ = x.log(y); - let _ = x.log(y); - let _ = x.log(y); + let _ = x.log(y); //~ suboptimal_flops + let _ = (x as f32).log(y); //~ suboptimal_flops + let _ = x.log(y); //~ suboptimal_flops + let _ = x.log(y); //~ suboptimal_flops + let _ = x.log(y); //~ suboptimal_flops // Cases where the lint shouldn't be applied let _ = x.ln() / y.powf(3.2); let _ = x.powf(3.2) / y.powf(3.2); diff --git a/tests/ui/floating_point_logbase.rs b/tests/ui/floating_point_logbase.rs index c309114599d9..fc0f321dfbbd 100644 --- a/tests/ui/floating_point_logbase.rs +++ b/tests/ui/floating_point_logbase.rs @@ -4,11 +4,11 @@ fn main() { let x = 3f32; let y = 5f32; - let _ = x.ln() / y.ln(); - let _ = (x as f32).ln() / y.ln(); - let _ = x.log2() / y.log2(); - let _ = x.log10() / y.log10(); - let _ = x.log(5f32) / y.log(5f32); + let _ = x.ln() / y.ln(); //~ suboptimal_flops + let _ = (x as f32).ln() / y.ln(); //~ suboptimal_flops + let _ = x.log2() / y.log2(); //~ suboptimal_flops + let _ = x.log10() / y.log10(); //~ suboptimal_flops + let _ = x.log(5f32) / y.log(5f32); //~ suboptimal_flops // Cases where the lint shouldn't be applied let _ = x.ln() / y.powf(3.2); let _ = x.powf(3.2) / y.powf(3.2); diff --git a/tests/ui/floating_point_mul_add.fixed b/tests/ui/floating_point_mul_add.fixed index 3ce2edf2c71f..1bb211fd22e8 100644 --- a/tests/ui/floating_point_mul_add.fixed +++ b/tests/ui/floating_point_mul_add.fixed @@ -17,24 +17,26 @@ fn main() { let c: f64 = 0.0004; let d: f64 = 0.0001; - let _ = a.mul_add(b, c); - let _ = a.mul_add(b, -c); - let _ = a.mul_add(b, c); - let _ = a.mul_add(-b, c); - let _ = 2.0f64.mul_add(4.0, a); - let _ = 2.0f64.mul_add(4., a); + let _ = a.mul_add(b, c); //~ suboptimal_flops + let _ = a.mul_add(b, -c); //~ suboptimal_flops + let _ = a.mul_add(b, c); //~ suboptimal_flops + let _ = a.mul_add(-b, c); //~ suboptimal_flops + let _ = 2.0f64.mul_add(4.0, a); //~ suboptimal_flops + let _ = 2.0f64.mul_add(4., a); //~ suboptimal_flops - let _ = a.mul_add(b, c); - let _ = a.mul_add(b, c); - let _ = (a * b).mul_add(c, d); + let _ = a.mul_add(b, c); //~ suboptimal_flops + let _ = a.mul_add(b, c); //~ suboptimal_flops + let _ = (a * b).mul_add(c, d); //~ suboptimal_flops let _ = a.mul_add(b, c).mul_add(a.mul_add(b, c), a.mul_add(b, c)) + c; + //~^ suboptimal_flops let _ = 1234.567_f64.mul_add(45.67834_f64, 0.0004_f64); + //~^ suboptimal_flops - let _ = a.mul_add(a, b).sqrt(); + let _ = a.mul_add(a, b).sqrt(); //~ suboptimal_flops let u = 1usize; - let _ = b.mul_add(-(u as f64), a); + let _ = b.mul_add(-(u as f64), a); //~ suboptimal_flops // Cases where the lint shouldn't be applied let _ = (a * a + b * b).sqrt(); diff --git a/tests/ui/floating_point_mul_add.rs b/tests/ui/floating_point_mul_add.rs index b5e4a8db4db2..5be050eb4495 100644 --- a/tests/ui/floating_point_mul_add.rs +++ b/tests/ui/floating_point_mul_add.rs @@ -17,24 +17,26 @@ fn main() { let c: f64 = 0.0004; let d: f64 = 0.0001; - let _ = a * b + c; - let _ = a * b - c; - let _ = c + a * b; - let _ = c - a * b; - let _ = a + 2.0 * 4.0; - let _ = a + 2. * 4.; + let _ = a * b + c; //~ suboptimal_flops + let _ = a * b - c; //~ suboptimal_flops + let _ = c + a * b; //~ suboptimal_flops + let _ = c - a * b; //~ suboptimal_flops + let _ = a + 2.0 * 4.0; //~ suboptimal_flops + let _ = a + 2. * 4.; //~ suboptimal_flops - let _ = (a * b) + c; - let _ = c + (a * b); - let _ = a * b * c + d; + let _ = (a * b) + c; //~ suboptimal_flops + let _ = c + (a * b); //~ suboptimal_flops + let _ = a * b * c + d; //~ suboptimal_flops let _ = a.mul_add(b, c) * a.mul_add(b, c) + a.mul_add(b, c) + c; + //~^ suboptimal_flops let _ = 1234.567_f64 * 45.67834_f64 + 0.0004_f64; + //~^ suboptimal_flops - let _ = (a * a + b).sqrt(); + let _ = (a * a + b).sqrt(); //~ suboptimal_flops let u = 1usize; - let _ = a - (b * u as f64); + let _ = a - (b * u as f64); //~ suboptimal_flops // Cases where the lint shouldn't be applied let _ = (a * a + b * b).sqrt(); diff --git a/tests/ui/floating_point_mul_add.stderr b/tests/ui/floating_point_mul_add.stderr index 38dbefbe14c6..4ab378dc1f9d 100644 --- a/tests/ui/floating_point_mul_add.stderr +++ b/tests/ui/floating_point_mul_add.stderr @@ -62,19 +62,19 @@ LL | let _ = a.mul_add(b, c) * a.mul_add(b, c) + a.mul_add(b, c) + c; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `a.mul_add(b, c).mul_add(a.mul_add(b, c), a.mul_add(b, c))` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:32:13 + --> $DIR/floating_point_mul_add.rs:33:13 | LL | let _ = 1234.567_f64 * 45.67834_f64 + 0.0004_f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1234.567_f64.mul_add(45.67834_f64, 0.0004_f64)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:34:13 + --> $DIR/floating_point_mul_add.rs:36:13 | LL | let _ = (a * a + b).sqrt(); | ^^^^^^^^^^^ help: consider using: `a.mul_add(a, b)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:37:13 + --> $DIR/floating_point_mul_add.rs:39:13 | LL | let _ = a - (b * u as f64); | ^^^^^^^^^^^^^^^^^^ help: consider using: `b.mul_add(-(u as f64), a)` diff --git a/tests/ui/floating_point_powf.fixed b/tests/ui/floating_point_powf.fixed index c2884ca318c6..62f9531832af 100644 --- a/tests/ui/floating_point_powf.fixed +++ b/tests/ui/floating_point_powf.fixed @@ -3,25 +3,25 @@ fn main() { let x = 3f32; - let _ = x.exp2(); - let _ = 3.1f32.exp2(); - let _ = (-3.1f32).exp2(); - let _ = x.exp(); - let _ = 3.1f32.exp(); - let _ = (-3.1f32).exp(); - let _ = x.sqrt(); - let _ = x.cbrt(); - let _ = (x as f32).cbrt(); - let _ = x.powi(3); - let _ = x.powi(-2); - let _ = x.powi(16_777_215); - let _ = x.powi(-16_777_215); - let _ = (x as f32).powi(-16_777_215); - let _ = (x as f32).powi(3); - let _ = (1.5_f32 + 1.0).cbrt(); - let _ = 1.5_f64.cbrt(); - let _ = 1.5_f64.sqrt(); - let _ = 1.5_f64.powi(3); + let _ = x.exp2(); //~ suboptimal_flops + let _ = 3.1f32.exp2(); //~ suboptimal_flops + let _ = (-3.1f32).exp2(); //~ suboptimal_flops + let _ = x.exp(); //~ suboptimal_flops + let _ = 3.1f32.exp(); //~ suboptimal_flops + let _ = (-3.1f32).exp(); //~ suboptimal_flops + let _ = x.sqrt(); //~ suboptimal_flops + let _ = x.cbrt(); //~ imprecise_flops + let _ = (x as f32).cbrt(); //~ imprecise_flops + let _ = x.powi(3); //~ suboptimal_flops + let _ = x.powi(-2); //~ suboptimal_flops + let _ = x.powi(16_777_215); //~ suboptimal_flops + let _ = x.powi(-16_777_215); //~ suboptimal_flops + let _ = (x as f32).powi(-16_777_215); //~ suboptimal_flops + let _ = (x as f32).powi(3); //~ suboptimal_flops + let _ = (1.5_f32 + 1.0).cbrt(); //~ imprecise_flops + let _ = 1.5_f64.cbrt(); //~ imprecise_flops + let _ = 1.5_f64.sqrt(); //~ suboptimal_flops + let _ = 1.5_f64.powi(3); //~ suboptimal_flops // Cases where the lint shouldn't be applied let _ = x.powf(2.1); @@ -30,18 +30,18 @@ fn main() { let _ = x.powf(-16_777_216.0); let x = 3f64; - let _ = x.exp2(); - let _ = 3.1f64.exp2(); - let _ = (-3.1f64).exp2(); - let _ = x.exp(); - let _ = 3.1f64.exp(); - let _ = (-3.1f64).exp(); - let _ = x.sqrt(); - let _ = x.cbrt(); - let _ = x.powi(3); - let _ = x.powi(-2); - let _ = x.powi(-2_147_483_648); - let _ = x.powi(2_147_483_647); + let _ = x.exp2(); //~ suboptimal_flops + let _ = 3.1f64.exp2(); //~ suboptimal_flops + let _ = (-3.1f64).exp2(); //~ suboptimal_flops + let _ = x.exp(); //~ suboptimal_flops + let _ = 3.1f64.exp(); //~ suboptimal_flops + let _ = (-3.1f64).exp(); //~ suboptimal_flops + let _ = x.sqrt(); //~ suboptimal_flops + let _ = x.cbrt(); //~ imprecise_flops + let _ = x.powi(3); //~ suboptimal_flops + let _ = x.powi(-2); //~ suboptimal_flops + let _ = x.powi(-2_147_483_648); //~ suboptimal_flops + let _ = x.powi(2_147_483_647); //~ suboptimal_flops // Cases where the lint shouldn't be applied let _ = x.powf(2.1); let _ = x.powf(-2.1); diff --git a/tests/ui/floating_point_powf.rs b/tests/ui/floating_point_powf.rs index 37d58af05513..237adf323ce0 100644 --- a/tests/ui/floating_point_powf.rs +++ b/tests/ui/floating_point_powf.rs @@ -3,25 +3,25 @@ fn main() { let x = 3f32; - let _ = 2f32.powf(x); - let _ = 2f32.powf(3.1); - let _ = 2f32.powf(-3.1); - let _ = std::f32::consts::E.powf(x); - let _ = std::f32::consts::E.powf(3.1); - let _ = std::f32::consts::E.powf(-3.1); - let _ = x.powf(1.0 / 2.0); - let _ = x.powf(1.0 / 3.0); - let _ = (x as f32).powf(1.0 / 3.0); - let _ = x.powf(3.0); - let _ = x.powf(-2.0); - let _ = x.powf(16_777_215.0); - let _ = x.powf(-16_777_215.0); - let _ = (x as f32).powf(-16_777_215.0); - let _ = (x as f32).powf(3.0); - let _ = (1.5_f32 + 1.0).powf(1.0 / 3.0); - let _ = 1.5_f64.powf(1.0 / 3.0); - let _ = 1.5_f64.powf(1.0 / 2.0); - let _ = 1.5_f64.powf(3.0); + let _ = 2f32.powf(x); //~ suboptimal_flops + let _ = 2f32.powf(3.1); //~ suboptimal_flops + let _ = 2f32.powf(-3.1); //~ suboptimal_flops + let _ = std::f32::consts::E.powf(x); //~ suboptimal_flops + let _ = std::f32::consts::E.powf(3.1); //~ suboptimal_flops + let _ = std::f32::consts::E.powf(-3.1); //~ suboptimal_flops + let _ = x.powf(1.0 / 2.0); //~ suboptimal_flops + let _ = x.powf(1.0 / 3.0); //~ imprecise_flops + let _ = (x as f32).powf(1.0 / 3.0); //~ imprecise_flops + let _ = x.powf(3.0); //~ suboptimal_flops + let _ = x.powf(-2.0); //~ suboptimal_flops + let _ = x.powf(16_777_215.0); //~ suboptimal_flops + let _ = x.powf(-16_777_215.0); //~ suboptimal_flops + let _ = (x as f32).powf(-16_777_215.0); //~ suboptimal_flops + let _ = (x as f32).powf(3.0); //~ suboptimal_flops + let _ = (1.5_f32 + 1.0).powf(1.0 / 3.0); //~ imprecise_flops + let _ = 1.5_f64.powf(1.0 / 3.0); //~ imprecise_flops + let _ = 1.5_f64.powf(1.0 / 2.0); //~ suboptimal_flops + let _ = 1.5_f64.powf(3.0); //~ suboptimal_flops // Cases where the lint shouldn't be applied let _ = x.powf(2.1); @@ -30,18 +30,18 @@ fn main() { let _ = x.powf(-16_777_216.0); let x = 3f64; - let _ = 2f64.powf(x); - let _ = 2f64.powf(3.1); - let _ = 2f64.powf(-3.1); - let _ = std::f64::consts::E.powf(x); - let _ = std::f64::consts::E.powf(3.1); - let _ = std::f64::consts::E.powf(-3.1); - let _ = x.powf(1.0 / 2.0); - let _ = x.powf(1.0 / 3.0); - let _ = x.powf(3.0); - let _ = x.powf(-2.0); - let _ = x.powf(-2_147_483_648.0); - let _ = x.powf(2_147_483_647.0); + let _ = 2f64.powf(x); //~ suboptimal_flops + let _ = 2f64.powf(3.1); //~ suboptimal_flops + let _ = 2f64.powf(-3.1); //~ suboptimal_flops + let _ = std::f64::consts::E.powf(x); //~ suboptimal_flops + let _ = std::f64::consts::E.powf(3.1); //~ suboptimal_flops + let _ = std::f64::consts::E.powf(-3.1); //~ suboptimal_flops + let _ = x.powf(1.0 / 2.0); //~ suboptimal_flops + let _ = x.powf(1.0 / 3.0); //~ imprecise_flops + let _ = x.powf(3.0); //~ suboptimal_flops + let _ = x.powf(-2.0); //~ suboptimal_flops + let _ = x.powf(-2_147_483_648.0); //~ suboptimal_flops + let _ = x.powf(2_147_483_647.0); //~ suboptimal_flops // Cases where the lint shouldn't be applied let _ = x.powf(2.1); let _ = x.powf(-2.1); diff --git a/tests/ui/floating_point_powi.fixed b/tests/ui/floating_point_powi.fixed index cb033c899f31..1197aecfbe41 100644 --- a/tests/ui/floating_point_powi.fixed +++ b/tests/ui/floating_point_powi.fixed @@ -6,21 +6,21 @@ fn main() { let x = 3f32; let y = 4f32; - let _ = x.mul_add(x, y); - let _ = x.mul_add(x, -y); - let _ = y.mul_add(y, x); - let _ = y.mul_add(-y, x); - let _ = (y as f32).mul_add(y as f32, x); - let _ = x.mul_add(x, y).sqrt(); - let _ = y.mul_add(y, x).sqrt(); + let _ = x.mul_add(x, y); //~ suboptimal_flops + let _ = x.mul_add(x, -y); //~ suboptimal_flops + let _ = y.mul_add(y, x); //~ suboptimal_flops + let _ = y.mul_add(-y, x); //~ suboptimal_flops + let _ = (y as f32).mul_add(y as f32, x); //~ suboptimal_flops + let _ = x.mul_add(x, y).sqrt(); //~ suboptimal_flops + let _ = y.mul_add(y, x).sqrt(); //~ suboptimal_flops - let _ = (x - 1.0).mul_add(x - 1.0, -y); - let _ = (x - 1.0).mul_add(x - 1.0, -y) + 3.0; - let _ = (x - 1.0).mul_add(x - 1.0, -(y + 3.0)); - let _ = (y + 1.0).mul_add(-(y + 1.0), x); - let _ = (3.0 * y).mul_add(-(3.0 * y), x); - let _ = (y + 1.0 + x).mul_add(-(y + 1.0 + x), x); - let _ = (y + 1.0 + 2.0).mul_add(-(y + 1.0 + 2.0), x); + let _ = (x - 1.0).mul_add(x - 1.0, -y); //~ suboptimal_flops + let _ = (x - 1.0).mul_add(x - 1.0, -y) + 3.0; //~ suboptimal_flops + let _ = (x - 1.0).mul_add(x - 1.0, -(y + 3.0)); //~ suboptimal_flops + let _ = (y + 1.0).mul_add(-(y + 1.0), x); //~ suboptimal_flops + let _ = (3.0 * y).mul_add(-(3.0 * y), x); //~ suboptimal_flops + let _ = (y + 1.0 + x).mul_add(-(y + 1.0 + x), x); //~ suboptimal_flops + let _ = (y + 1.0 + 2.0).mul_add(-(y + 1.0 + 2.0), x); //~ suboptimal_flops // Cases where the lint shouldn't be applied let _ = x.powi(2); diff --git a/tests/ui/floating_point_powi.rs b/tests/ui/floating_point_powi.rs index f02e0e8ddb36..dbd2bf3f68b1 100644 --- a/tests/ui/floating_point_powi.rs +++ b/tests/ui/floating_point_powi.rs @@ -6,21 +6,21 @@ fn main() { let x = 3f32; let y = 4f32; - let _ = x.powi(2) + y; - let _ = x.powi(2) - y; - let _ = x + y.powi(2); - let _ = x - y.powi(2); - let _ = x + (y as f32).powi(2); - let _ = (x.powi(2) + y).sqrt(); - let _ = (x + y.powi(2)).sqrt(); + let _ = x.powi(2) + y; //~ suboptimal_flops + let _ = x.powi(2) - y; //~ suboptimal_flops + let _ = x + y.powi(2); //~ suboptimal_flops + let _ = x - y.powi(2); //~ suboptimal_flops + let _ = x + (y as f32).powi(2); //~ suboptimal_flops + let _ = (x.powi(2) + y).sqrt(); //~ suboptimal_flops + let _ = (x + y.powi(2)).sqrt(); //~ suboptimal_flops - let _ = (x - 1.0).powi(2) - y; - let _ = (x - 1.0).powi(2) - y + 3.0; - let _ = (x - 1.0).powi(2) - (y + 3.0); - let _ = x - (y + 1.0).powi(2); - let _ = x - (3.0 * y).powi(2); - let _ = x - (y + 1.0 + x).powi(2); - let _ = x - (y + 1.0 + 2.0).powi(2); + let _ = (x - 1.0).powi(2) - y; //~ suboptimal_flops + let _ = (x - 1.0).powi(2) - y + 3.0; //~ suboptimal_flops + let _ = (x - 1.0).powi(2) - (y + 3.0); //~ suboptimal_flops + let _ = x - (y + 1.0).powi(2); //~ suboptimal_flops + let _ = x - (3.0 * y).powi(2); //~ suboptimal_flops + let _ = x - (y + 1.0 + x).powi(2); //~ suboptimal_flops + let _ = x - (y + 1.0 + 2.0).powi(2); //~ suboptimal_flops // Cases where the lint shouldn't be applied let _ = x.powi(2); diff --git a/tests/ui/floating_point_rad.fixed b/tests/ui/floating_point_rad.fixed index a710bd9bd607..124d895994b4 100644 --- a/tests/ui/floating_point_rad.fixed +++ b/tests/ui/floating_point_rad.fixed @@ -9,17 +9,23 @@ pub const fn const_context() { pub fn issue9391(degrees: i64) { let _ = (degrees as f64).to_radians(); + //~^ suboptimal_flops let _ = (degrees as f64).to_degrees(); + //~^ suboptimal_flops } fn main() { let x = 3f32; - let _ = x.to_degrees(); + let _ = x.to_degrees(); //~ suboptimal_flops let _ = 90.0_f64.to_degrees(); + //~^ suboptimal_flops let _ = 90.5_f64.to_degrees(); - let _ = x.to_radians(); + //~^ suboptimal_flops + let _ = x.to_radians(); //~ suboptimal_flops let _ = 90.0_f64.to_radians(); + //~^ suboptimal_flops let _ = 90.5_f64.to_radians(); + //~^ suboptimal_flops // let _ = 90.5 * 80. * std::f32::consts::PI / 180f32; // Cases where the lint shouldn't be applied let _ = x * 90f32 / std::f32::consts::PI; diff --git a/tests/ui/floating_point_rad.rs b/tests/ui/floating_point_rad.rs index 14656f021df4..c48dece6ffdd 100644 --- a/tests/ui/floating_point_rad.rs +++ b/tests/ui/floating_point_rad.rs @@ -9,17 +9,23 @@ pub const fn const_context() { pub fn issue9391(degrees: i64) { let _ = degrees as f64 * std::f64::consts::PI / 180.0; + //~^ suboptimal_flops let _ = degrees as f64 * 180.0 / std::f64::consts::PI; + //~^ suboptimal_flops } fn main() { let x = 3f32; - let _ = x * 180f32 / std::f32::consts::PI; + let _ = x * 180f32 / std::f32::consts::PI; //~ suboptimal_flops let _ = 90. * 180f64 / std::f64::consts::PI; + //~^ suboptimal_flops let _ = 90.5 * 180f64 / std::f64::consts::PI; - let _ = x * std::f32::consts::PI / 180f32; + //~^ suboptimal_flops + let _ = x * std::f32::consts::PI / 180f32; //~ suboptimal_flops let _ = 90. * std::f32::consts::PI / 180f32; + //~^ suboptimal_flops let _ = 90.5 * std::f32::consts::PI / 180f32; + //~^ suboptimal_flops // let _ = 90.5 * 80. * std::f32::consts::PI / 180f32; // Cases where the lint shouldn't be applied let _ = x * 90f32 / std::f32::consts::PI; diff --git a/tests/ui/floating_point_rad.stderr b/tests/ui/floating_point_rad.stderr index e7b42de04bdf..d55a3989c074 100644 --- a/tests/ui/floating_point_rad.stderr +++ b/tests/ui/floating_point_rad.stderr @@ -8,43 +8,43 @@ LL | let _ = degrees as f64 * std::f64::consts::PI / 180.0; = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: conversion to degrees can be done more accurately - --> $DIR/floating_point_rad.rs:12:13 + --> $DIR/floating_point_rad.rs:13:13 | LL | let _ = degrees as f64 * 180.0 / std::f64::consts::PI; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(degrees as f64).to_degrees()` error: conversion to degrees can be done more accurately - --> $DIR/floating_point_rad.rs:17:13 + --> $DIR/floating_point_rad.rs:19:13 | LL | let _ = x * 180f32 / std::f32::consts::PI; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_degrees()` error: conversion to degrees can be done more accurately - --> $DIR/floating_point_rad.rs:18:13 + --> $DIR/floating_point_rad.rs:20:13 | LL | let _ = 90. * 180f64 / std::f64::consts::PI; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.0_f64.to_degrees()` error: conversion to degrees can be done more accurately - --> $DIR/floating_point_rad.rs:19:13 + --> $DIR/floating_point_rad.rs:22:13 | LL | let _ = 90.5 * 180f64 / std::f64::consts::PI; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.5_f64.to_degrees()` error: conversion to radians can be done more accurately - --> $DIR/floating_point_rad.rs:20:13 + --> $DIR/floating_point_rad.rs:24:13 | LL | let _ = x * std::f32::consts::PI / 180f32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_radians()` error: conversion to radians can be done more accurately - --> $DIR/floating_point_rad.rs:21:13 + --> $DIR/floating_point_rad.rs:25:13 | LL | let _ = 90. * std::f32::consts::PI / 180f32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.0_f64.to_radians()` error: conversion to radians can be done more accurately - --> $DIR/floating_point_rad.rs:22:13 + --> $DIR/floating_point_rad.rs:27:13 | LL | let _ = 90.5 * std::f32::consts::PI / 180f32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.5_f64.to_radians()` diff --git a/tests/ui/fn_to_numeric_cast.rs b/tests/ui/fn_to_numeric_cast.rs index 9501eb5da4b2..d32eef753fd1 100644 --- a/tests/ui/fn_to_numeric_cast.rs +++ b/tests/ui/fn_to_numeric_cast.rs @@ -7,18 +7,18 @@ fn foo() -> String { } fn test_function_to_numeric_cast() { - let _ = foo as i8; - let _ = foo as i16; - let _ = foo as i32; - let _ = foo as i64; - let _ = foo as i128; - let _ = foo as isize; - - let _ = foo as u8; - let _ = foo as u16; - let _ = foo as u32; - let _ = foo as u64; - let _ = foo as u128; + let _ = foo as i8; //~ fn_to_numeric_cast_with_truncation + let _ = foo as i16; //~ fn_to_numeric_cast_with_truncation + let _ = foo as i32; //~ fn_to_numeric_cast_with_truncation + let _ = foo as i64; //~ fn_to_numeric_cast + let _ = foo as i128; //~ fn_to_numeric_cast + let _ = foo as isize; //~ fn_to_numeric_cast + + let _ = foo as u8; //~ fn_to_numeric_cast_with_truncation + let _ = foo as u16; //~ fn_to_numeric_cast_with_truncation + let _ = foo as u32; //~ fn_to_numeric_cast_with_truncation + let _ = foo as u64; //~ fn_to_numeric_cast + let _ = foo as u128; //~ fn_to_numeric_cast // Casting to usize is OK and should not warn let _ = foo as usize; @@ -31,25 +31,25 @@ fn test_function_to_numeric_cast() { fn test_function_var_to_numeric_cast() { let abc: fn() -> String = foo; - let _ = abc as i8; - let _ = abc as i16; - let _ = abc as i32; - let _ = abc as i64; - let _ = abc as i128; - let _ = abc as isize; + let _ = abc as i8; //~ fn_to_numeric_cast_with_truncation + let _ = abc as i16; //~ fn_to_numeric_cast_with_truncation + let _ = abc as i32; //~ fn_to_numeric_cast_with_truncation + let _ = abc as i64; //~ fn_to_numeric_cast + let _ = abc as i128; //~ fn_to_numeric_cast + let _ = abc as isize; //~ fn_to_numeric_cast - let _ = abc as u8; - let _ = abc as u16; - let _ = abc as u32; - let _ = abc as u64; - let _ = abc as u128; + let _ = abc as u8; //~ fn_to_numeric_cast_with_truncation + let _ = abc as u16; //~ fn_to_numeric_cast_with_truncation + let _ = abc as u32; //~ fn_to_numeric_cast_with_truncation + let _ = abc as u64; //~ fn_to_numeric_cast + let _ = abc as u128; //~ fn_to_numeric_cast // Casting to usize is OK and should not warn let _ = abc as usize; } fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 { - f as i32 + f as i32 //~ fn_to_numeric_cast_with_truncation } fn main() {} diff --git a/tests/ui/format.fixed b/tests/ui/format.fixed index 2b32fdeae2b5..7e6b25eb993f 100644 --- a/tests/ui/format.fixed +++ b/tests/ui/format.fixed @@ -16,15 +16,17 @@ macro_rules! foo { } fn main() { - "foo".to_string(); - "{}".to_string(); - "{} abc {}".to_string(); + "foo".to_string(); //~ useless_format + "{}".to_string(); //~ useless_format + "{} abc {}".to_string(); //~ useless_format + + //~v useless_format r##"foo {} " bar"##.to_string(); - let _ = String::new(); + let _ = String::new(); //~ useless_format - "foo".to_string(); + "foo".to_string(); //~ useless_format format!("{:?}", "foo"); // Don't warn about `Debug`. format!("{:8}", "foo"); format!("{:width$}", "foo", width = 8); @@ -32,7 +34,7 @@ fn main() { format!("{} bar", "foo"); let arg = String::new(); - arg.to_string(); + arg.to_string(); //~ useless_format format!("{:?}", arg); // Don't warn about debug. format!("{:8}", arg); format!("{:width$}", arg, width = 8); @@ -62,29 +64,30 @@ fn main() { format!("{:.prec$}", "foo", prec = 1); format!("{:.prec$}", "foo", prec = 10); - 42.to_string(); + 42.to_string(); //~ useless_format let x = std::path::PathBuf::from("/bar/foo/qux"); - x.display().to_string(); + x.display().to_string(); //~ useless_format // False positive let a = "foo".to_string(); - let _ = Some(a + "bar"); + let _ = Some(a + "bar"); //~ useless_format // Wrap it with braces let v: Vec = vec!["foo".to_string(), "bar".to_string()]; let _s: String = (&*v.join("\n")).to_string(); + //~^ useless_format format!("prepend {:+}", "s"); // Issue #8290 let x = "foo"; - let _ = x.to_string(); + let _ = x.to_string(); //~ useless_format let _ = format!("{x:?}"); // Don't lint on debug - let _ = x.to_string(); + let _ = x.to_string(); //~ useless_format // Issue #9234 let abc = "abc"; - let _ = abc.to_string(); + let _ = abc.to_string(); //~ useless_format let xx = "xx"; - let _ = xx.to_string(); + let _ = xx.to_string(); //~ useless_format } diff --git a/tests/ui/format.rs b/tests/ui/format.rs index bad192067e93..e77481eac441 100644 --- a/tests/ui/format.rs +++ b/tests/ui/format.rs @@ -16,17 +16,19 @@ macro_rules! foo { } fn main() { - format!("foo"); - format!("{{}}"); - format!("{{}} abc {{}}"); + format!("foo"); //~ useless_format + format!("{{}}"); //~ useless_format + format!("{{}} abc {{}}"); //~ useless_format + + //~v useless_format format!( r##"foo {{}} " bar"## ); - let _ = format!(""); + let _ = format!(""); //~ useless_format - format!("{}", "foo"); + format!("{}", "foo"); //~ useless_format format!("{:?}", "foo"); // Don't warn about `Debug`. format!("{:8}", "foo"); format!("{:width$}", "foo", width = 8); @@ -34,7 +36,7 @@ fn main() { format!("{} bar", "foo"); let arg = String::new(); - format!("{}", arg); + format!("{}", arg); //~ useless_format format!("{:?}", arg); // Don't warn about debug. format!("{:8}", arg); format!("{:width$}", arg, width = 8); @@ -64,29 +66,30 @@ fn main() { format!("{:.prec$}", "foo", prec = 1); format!("{:.prec$}", "foo", prec = 10); - format!("{}", 42.to_string()); + format!("{}", 42.to_string()); //~ useless_format let x = std::path::PathBuf::from("/bar/foo/qux"); - format!("{}", x.display().to_string()); + format!("{}", x.display().to_string()); //~ useless_format // False positive let a = "foo".to_string(); - let _ = Some(format!("{}", a + "bar")); + let _ = Some(format!("{}", a + "bar")); //~ useless_format // Wrap it with braces let v: Vec = vec!["foo".to_string(), "bar".to_string()]; let _s: String = format!("{}", &*v.join("\n")); + //~^ useless_format format!("prepend {:+}", "s"); // Issue #8290 let x = "foo"; - let _ = format!("{x}"); + let _ = format!("{x}"); //~ useless_format let _ = format!("{x:?}"); // Don't lint on debug - let _ = format!("{y}", y = x); + let _ = format!("{y}", y = x); //~ useless_format // Issue #9234 let abc = "abc"; - let _ = format!("{abc}"); + let _ = format!("{abc}"); //~ useless_format let xx = "xx"; - let _ = format!("{xx}"); + let _ = format!("{xx}"); //~ useless_format } diff --git a/tests/ui/format.stderr b/tests/ui/format.stderr index e02fdb1e4151..8e55ea3619da 100644 --- a/tests/ui/format.stderr +++ b/tests/ui/format.stderr @@ -20,7 +20,7 @@ LL | format!("{{}} abc {{}}"); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{} abc {}".to_string()` error: useless use of `format!` - --> $DIR/format.rs:22:5 + --> $DIR/format.rs:24:5 | LL | / format!( LL | | r##"foo {{}} @@ -35,67 +35,67 @@ LL ~ " bar"##.to_string(); | error: useless use of `format!` - --> $DIR/format.rs:27:13 + --> $DIR/format.rs:29:13 | LL | let _ = format!(""); | ^^^^^^^^^^^ help: consider using `String::new()`: `String::new()` error: useless use of `format!` - --> $DIR/format.rs:29:5 + --> $DIR/format.rs:31:5 | LL | format!("{}", "foo"); | ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` error: useless use of `format!` - --> $DIR/format.rs:37:5 + --> $DIR/format.rs:39:5 | LL | format!("{}", arg); | ^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()` error: useless use of `format!` - --> $DIR/format.rs:67:5 + --> $DIR/format.rs:69:5 | LL | format!("{}", 42.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string()` error: useless use of `format!` - --> $DIR/format.rs:69:5 + --> $DIR/format.rs:71:5 | LL | format!("{}", x.display().to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string()` error: useless use of `format!` - --> $DIR/format.rs:73:18 + --> $DIR/format.rs:75:18 | LL | let _ = Some(format!("{}", a + "bar")); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `a + "bar"` error: useless use of `format!` - --> $DIR/format.rs:77:22 + --> $DIR/format.rs:79:22 | LL | let _s: String = format!("{}", &*v.join("\n")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `(&*v.join("\n")).to_string()` error: useless use of `format!` - --> $DIR/format.rs:83:13 + --> $DIR/format.rs:86:13 | LL | let _ = format!("{x}"); | ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()` error: useless use of `format!` - --> $DIR/format.rs:85:13 + --> $DIR/format.rs:88:13 | LL | let _ = format!("{y}", y = x); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()` error: useless use of `format!` - --> $DIR/format.rs:89:13 + --> $DIR/format.rs:92:13 | LL | let _ = format!("{abc}"); | ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `abc.to_string()` error: useless use of `format!` - --> $DIR/format.rs:91:13 + --> $DIR/format.rs:94:13 | LL | let _ = format!("{xx}"); | ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `xx.to_string()` diff --git a/tests/ui/format_args.fixed b/tests/ui/format_args.fixed index cab20b11e073..07660d867503 100644 --- a/tests/ui/format_args.fixed +++ b/tests/ui/format_args.fixed @@ -75,35 +75,50 @@ fn main() { let x_ref = &x; let _ = format!("error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args let _ = write!( stdout(), "error: something failed at {}", - Location::caller() + Location::caller() //~ to_string_in_format_args ); let _ = writeln!( stdout(), "error: something failed at {}", - Location::caller() + Location::caller() //~ to_string_in_format_args ); print!("error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args println!("error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args eprint!("error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args eprintln!("error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args let _ = format_args!("error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args assert!(true, "error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args assert_eq!(0, 0, "error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args assert_ne!(0, 0, "error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args panic!("error: something failed at {}", Location::caller()); - println!("{}", *X(1)); + //~^ to_string_in_format_args + println!("{}", *X(1)); //~ to_string_in_format_args println!("{}", ***Y(&X(1))); - println!("{}", Z(1)); - println!("{}", **x); - println!("{}", ***x_ref); + //~^ to_string_in_format_args + println!("{}", Z(1)); //~ to_string_in_format_args + println!("{}", **x); //~ to_string_in_format_args + println!("{}", ***x_ref); //~ to_string_in_format_args // https://github.com/rust-lang/rust-clippy/issues/7903 println!("{foo}{bar}", foo = "foo", bar = "bar"); + //~^ to_string_in_format_args println!("{foo}{bar}", foo = "foo", bar = "bar"); + //~^ to_string_in_format_args println!("{foo}{bar}", bar = "bar", foo = "foo"); + //~^ to_string_in_format_args println!("{foo}{bar}", bar = "bar", foo = "foo"); + //~^ to_string_in_format_args // negative tests println!("error: something failed at {}", Somewhere.to_string()); @@ -116,7 +131,9 @@ fn main() { // https://github.com/rust-lang/rust-clippy/issues/7903 println!("{foo}{foo:?}", foo = "foo".to_string()); print!("{}", (Location::caller())); + //~^ to_string_in_format_args print!("{}", ((Location::caller()))); + //~^ to_string_in_format_args } fn issue8643(vendor_id: usize, product_id: usize, name: &str) { @@ -145,6 +162,7 @@ mod issue_8855 { let b = A {}; let x = format!("{} {}", a, b); + //~^ to_string_in_format_args dbg!(x); let x = format!("{:>6} {:>6}", a, b.to_string()); @@ -159,6 +177,7 @@ mod issue_9256 { fn print_substring(original: &str) { assert!(original.len() > 10); println!("{}", &original[..10]); + //~^ to_string_in_format_args } fn main() { diff --git a/tests/ui/format_args.rs b/tests/ui/format_args.rs index bc3645cb2c2b..01d6c16a1d19 100644 --- a/tests/ui/format_args.rs +++ b/tests/ui/format_args.rs @@ -75,35 +75,50 @@ fn main() { let x_ref = &x; let _ = format!("error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args let _ = write!( stdout(), "error: something failed at {}", - Location::caller().to_string() + Location::caller().to_string() //~ to_string_in_format_args ); let _ = writeln!( stdout(), "error: something failed at {}", - Location::caller().to_string() + Location::caller().to_string() //~ to_string_in_format_args ); print!("error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args println!("error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args eprint!("error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args eprintln!("error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args let _ = format_args!("error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args assert!(true, "error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args assert_eq!(0, 0, "error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args assert_ne!(0, 0, "error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args panic!("error: something failed at {}", Location::caller().to_string()); - println!("{}", X(1).to_string()); + //~^ to_string_in_format_args + println!("{}", X(1).to_string()); //~ to_string_in_format_args println!("{}", Y(&X(1)).to_string()); - println!("{}", Z(1).to_string()); - println!("{}", x.to_string()); - println!("{}", x_ref.to_string()); + //~^ to_string_in_format_args + println!("{}", Z(1).to_string()); //~ to_string_in_format_args + println!("{}", x.to_string()); //~ to_string_in_format_args + println!("{}", x_ref.to_string()); //~ to_string_in_format_args // https://github.com/rust-lang/rust-clippy/issues/7903 println!("{foo}{bar}", foo = "foo".to_string(), bar = "bar"); + //~^ to_string_in_format_args println!("{foo}{bar}", foo = "foo", bar = "bar".to_string()); + //~^ to_string_in_format_args println!("{foo}{bar}", bar = "bar".to_string(), foo = "foo"); + //~^ to_string_in_format_args println!("{foo}{bar}", bar = "bar", foo = "foo".to_string()); + //~^ to_string_in_format_args // negative tests println!("error: something failed at {}", Somewhere.to_string()); @@ -116,7 +131,9 @@ fn main() { // https://github.com/rust-lang/rust-clippy/issues/7903 println!("{foo}{foo:?}", foo = "foo".to_string()); print!("{}", (Location::caller().to_string())); + //~^ to_string_in_format_args print!("{}", ((Location::caller()).to_string())); + //~^ to_string_in_format_args } fn issue8643(vendor_id: usize, product_id: usize, name: &str) { @@ -145,6 +162,7 @@ mod issue_8855 { let b = A {}; let x = format!("{} {}", a, b.to_string()); + //~^ to_string_in_format_args dbg!(x); let x = format!("{:>6} {:>6}", a, b.to_string()); @@ -159,6 +177,7 @@ mod issue_9256 { fn print_substring(original: &str) { assert!(original.len() > 10); println!("{}", original[..10].to_string()); + //~^ to_string_in_format_args } fn main() { diff --git a/tests/ui/format_args.stderr b/tests/ui/format_args.stderr index 2f1714296d6c..a2eceb819900 100644 --- a/tests/ui/format_args.stderr +++ b/tests/ui/format_args.stderr @@ -8,145 +8,145 @@ LL | let _ = format!("error: something failed at {}", Location::caller().to_ = help: to override `-D warnings` add `#[allow(clippy::to_string_in_format_args)]` error: `to_string` applied to a type that implements `Display` in `write!` args - --> $DIR/format_args.rs:81:27 + --> $DIR/format_args.rs:82:27 | LL | Location::caller().to_string() | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `writeln!` args - --> $DIR/format_args.rs:86:27 + --> $DIR/format_args.rs:87:27 | LL | Location::caller().to_string() | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `print!` args - --> $DIR/format_args.rs:88:63 + --> $DIR/format_args.rs:89:63 | LL | print!("error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:89:65 + --> $DIR/format_args.rs:91:65 | LL | println!("error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `eprint!` args - --> $DIR/format_args.rs:90:64 + --> $DIR/format_args.rs:93:64 | LL | eprint!("error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `eprintln!` args - --> $DIR/format_args.rs:91:66 + --> $DIR/format_args.rs:95:66 | LL | eprintln!("error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `format_args!` args - --> $DIR/format_args.rs:92:77 + --> $DIR/format_args.rs:97:77 | LL | let _ = format_args!("error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `assert!` args - --> $DIR/format_args.rs:93:70 + --> $DIR/format_args.rs:99:70 | LL | assert!(true, "error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `assert_eq!` args - --> $DIR/format_args.rs:94:73 + --> $DIR/format_args.rs:101:73 | LL | assert_eq!(0, 0, "error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `assert_ne!` args - --> $DIR/format_args.rs:95:73 + --> $DIR/format_args.rs:103:73 | LL | assert_ne!(0, 0, "error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `panic!` args - --> $DIR/format_args.rs:96:63 + --> $DIR/format_args.rs:105:63 | LL | panic!("error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:97:20 + --> $DIR/format_args.rs:107:20 | LL | println!("{}", X(1).to_string()); | ^^^^^^^^^^^^^^^^ help: use this: `*X(1)` error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:98:20 + --> $DIR/format_args.rs:108:20 | LL | println!("{}", Y(&X(1)).to_string()); | ^^^^^^^^^^^^^^^^^^^^ help: use this: `***Y(&X(1))` error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:99:24 + --> $DIR/format_args.rs:110:24 | LL | println!("{}", Z(1).to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:100:20 + --> $DIR/format_args.rs:111:20 | LL | println!("{}", x.to_string()); | ^^^^^^^^^^^^^ help: use this: `**x` error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:101:20 + --> $DIR/format_args.rs:112:20 | LL | println!("{}", x_ref.to_string()); | ^^^^^^^^^^^^^^^^^ help: use this: `***x_ref` error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:103:39 + --> $DIR/format_args.rs:114:39 | LL | println!("{foo}{bar}", foo = "foo".to_string(), bar = "bar"); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:104:52 + --> $DIR/format_args.rs:116:52 | LL | println!("{foo}{bar}", foo = "foo", bar = "bar".to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:105:39 + --> $DIR/format_args.rs:118:39 | LL | println!("{foo}{bar}", bar = "bar".to_string(), foo = "foo"); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:106:52 + --> $DIR/format_args.rs:120:52 | LL | println!("{foo}{bar}", bar = "bar", foo = "foo".to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `print!` args - --> $DIR/format_args.rs:118:37 + --> $DIR/format_args.rs:133:37 | LL | print!("{}", (Location::caller().to_string())); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `print!` args - --> $DIR/format_args.rs:119:39 + --> $DIR/format_args.rs:135:39 | LL | print!("{}", ((Location::caller()).to_string())); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `format!` args - --> $DIR/format_args.rs:147:38 + --> $DIR/format_args.rs:164:38 | LL | let x = format!("{} {}", a, b.to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:161:24 + --> $DIR/format_args.rs:179:24 | LL | println!("{}", original[..10].to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use this: `&original[..10]` diff --git a/tests/ui/four_forward_slashes.fixed b/tests/ui/four_forward_slashes.fixed index 6d31c543d727..98b08828e58f 100644 --- a/tests/ui/four_forward_slashes.fixed +++ b/tests/ui/four_forward_slashes.fixed @@ -9,13 +9,16 @@ #[macro_use] extern crate proc_macros; +//~v four_forward_slashes /// whoops fn a() {} +//~v four_forward_slashes /// whoops #[allow(dead_code)] fn b() {} +//~v four_forward_slashes /// whoops /// two borked comments! #[track_caller] @@ -24,10 +27,12 @@ fn c() {} fn d() {} #[test] +//~v four_forward_slashes /// between attributes #[allow(dead_code)] fn g() {} + //~v four_forward_slashes /// not very start of contents fn h() {} diff --git a/tests/ui/four_forward_slashes.rs b/tests/ui/four_forward_slashes.rs index 458b8de53e15..b2a2b87a4961 100644 --- a/tests/ui/four_forward_slashes.rs +++ b/tests/ui/four_forward_slashes.rs @@ -9,13 +9,16 @@ #[macro_use] extern crate proc_macros; +//~v four_forward_slashes //// whoops fn a() {} +//~v four_forward_slashes //// whoops #[allow(dead_code)] fn b() {} +//~v four_forward_slashes //// whoops //// two borked comments! #[track_caller] @@ -24,10 +27,12 @@ fn c() {} fn d() {} #[test] +//~v four_forward_slashes //// between attributes #[allow(dead_code)] fn g() {} + //~v four_forward_slashes //// not very start of contents fn h() {} diff --git a/tests/ui/four_forward_slashes.stderr b/tests/ui/four_forward_slashes.stderr index 6450c5f94601..1883c4af9037 100644 --- a/tests/ui/four_forward_slashes.stderr +++ b/tests/ui/four_forward_slashes.stderr @@ -1,5 +1,5 @@ error: this item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't - --> $DIR/four_forward_slashes.rs:12:1 + --> $DIR/four_forward_slashes.rs:13:1 | LL | / //// whoops LL | | fn a() {} @@ -13,7 +13,7 @@ LL + /// whoops | error: this item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't - --> $DIR/four_forward_slashes.rs:15:1 + --> $DIR/four_forward_slashes.rs:17:1 | LL | / //// whoops LL | | #[allow(dead_code)] @@ -26,7 +26,7 @@ LL + /// whoops | error: this item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't - --> $DIR/four_forward_slashes.rs:19:1 + --> $DIR/four_forward_slashes.rs:22:1 | LL | / //// whoops LL | | //// two borked comments! @@ -41,7 +41,7 @@ LL ~ /// two borked comments! | error: this item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't - --> $DIR/four_forward_slashes.rs:27:1 + --> $DIR/four_forward_slashes.rs:31:1 | LL | / //// between attributes LL | | #[allow(dead_code)] @@ -54,7 +54,7 @@ LL + /// between attributes | error: this item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't - --> $DIR/four_forward_slashes.rs:31:1 + --> $DIR/four_forward_slashes.rs:36:1 | LL | / //// not very start of contents LL | | fn h() {} diff --git a/tests/ui/four_forward_slashes_first_line.fixed b/tests/ui/four_forward_slashes_first_line.fixed index 5ef40015d88b..f0b96d96441f 100644 --- a/tests/ui/four_forward_slashes_first_line.fixed +++ b/tests/ui/four_forward_slashes_first_line.fixed @@ -1,3 +1,4 @@ +//~v four_forward_slashes /// borked doc comment on the first line. doesn't combust! fn a() {} diff --git a/tests/ui/four_forward_slashes_first_line.rs b/tests/ui/four_forward_slashes_first_line.rs index 9c835e745f65..4c01aac3d304 100644 --- a/tests/ui/four_forward_slashes_first_line.rs +++ b/tests/ui/four_forward_slashes_first_line.rs @@ -1,3 +1,4 @@ +//~v four_forward_slashes //// borked doc comment on the first line. doesn't combust! fn a() {} diff --git a/tests/ui/four_forward_slashes_first_line.stderr b/tests/ui/four_forward_slashes_first_line.stderr index f49b7a0977fe..80606ce19dd6 100644 --- a/tests/ui/four_forward_slashes_first_line.stderr +++ b/tests/ui/four_forward_slashes_first_line.stderr @@ -1,5 +1,5 @@ error: this item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't - --> $DIR/four_forward_slashes_first_line.rs:1:1 + --> $DIR/four_forward_slashes_first_line.rs:2:1 | LL | / //// borked doc comment on the first line. doesn't combust! LL | | fn a() {} diff --git a/tests/ui/from_iter_instead_of_collect.fixed b/tests/ui/from_iter_instead_of_collect.fixed index c250162dfb8c..8a1023c254a8 100644 --- a/tests/ui/from_iter_instead_of_collect.fixed +++ b/tests/ui/from_iter_instead_of_collect.fixed @@ -15,46 +15,61 @@ impl FromIterator for Foo { impl<'a> FromIterator<&'a bool> for Foo { fn from_iter>(iter: T) -> Self { iter.into_iter().copied().collect::() + //~^ from_iter_instead_of_collect } } fn main() { let iter_expr = std::iter::repeat(5).take(5); let _ = iter_expr.collect::>(); + //~^ from_iter_instead_of_collect let _ = vec![5, 5, 5, 5].iter().enumerate().collect::>(); + //~^ from_iter_instead_of_collect Vec::from_iter(vec![42u32]); let a = vec![0, 1, 2]; assert_eq!(a, (0..3).collect::>()); + //~^ from_iter_instead_of_collect assert_eq!(a, (0..3).collect::>()); + //~^ from_iter_instead_of_collect let mut b = (0..3).collect::>(); + //~^ from_iter_instead_of_collect b.push_back(4); let mut b = (0..3).collect::>(); + //~^ from_iter_instead_of_collect b.push_back(4); { use std::collections; let mut b = (0..3).collect::>(); + //~^ from_iter_instead_of_collect b.push_back(4); } let values = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd')]; let bm = values.iter().cloned().collect::>(); + //~^ from_iter_instead_of_collect let mut bar = bm.range(0..2).collect::>(); + //~^ from_iter_instead_of_collect bar.insert(&4, &'e'); let mut bts = (0..3).collect::>(); + //~^ from_iter_instead_of_collect bts.insert(2); { use std::collections; let _ = (0..3).collect::>(); + //~^ from_iter_instead_of_collect let _ = (0..3).collect::>(); + //~^ from_iter_instead_of_collect } for _i in [1, 2, 3].iter().collect::>() {} + //~^ from_iter_instead_of_collect for _i in [1, 2, 3].iter().collect::>() {} + //~^ from_iter_instead_of_collect } diff --git a/tests/ui/from_iter_instead_of_collect.rs b/tests/ui/from_iter_instead_of_collect.rs index 8adbb841c8ba..000f15b2f048 100644 --- a/tests/ui/from_iter_instead_of_collect.rs +++ b/tests/ui/from_iter_instead_of_collect.rs @@ -15,46 +15,61 @@ impl FromIterator for Foo { impl<'a> FromIterator<&'a bool> for Foo { fn from_iter>(iter: T) -> Self { >::from_iter(iter.into_iter().copied()) + //~^ from_iter_instead_of_collect } } fn main() { let iter_expr = std::iter::repeat(5).take(5); let _ = Vec::from_iter(iter_expr); + //~^ from_iter_instead_of_collect let _ = HashMap::::from_iter(vec![5, 5, 5, 5].iter().enumerate()); + //~^ from_iter_instead_of_collect Vec::from_iter(vec![42u32]); let a = vec![0, 1, 2]; assert_eq!(a, Vec::from_iter(0..3)); + //~^ from_iter_instead_of_collect assert_eq!(a, Vec::::from_iter(0..3)); + //~^ from_iter_instead_of_collect let mut b = VecDeque::from_iter(0..3); + //~^ from_iter_instead_of_collect b.push_back(4); let mut b = VecDeque::::from_iter(0..3); + //~^ from_iter_instead_of_collect b.push_back(4); { use std::collections; let mut b = collections::VecDeque::::from_iter(0..3); + //~^ from_iter_instead_of_collect b.push_back(4); } let values = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd')]; let bm = BTreeMap::from_iter(values.iter().cloned()); + //~^ from_iter_instead_of_collect let mut bar = BTreeMap::from_iter(bm.range(0..2)); + //~^ from_iter_instead_of_collect bar.insert(&4, &'e'); let mut bts = BTreeSet::from_iter(0..3); + //~^ from_iter_instead_of_collect bts.insert(2); { use std::collections; let _ = collections::BTreeSet::from_iter(0..3); + //~^ from_iter_instead_of_collect let _ = collections::BTreeSet::::from_iter(0..3); + //~^ from_iter_instead_of_collect } for _i in Vec::from_iter([1, 2, 3].iter()) {} + //~^ from_iter_instead_of_collect for _i in Vec::<&i32>::from_iter([1, 2, 3].iter()) {} + //~^ from_iter_instead_of_collect } diff --git a/tests/ui/from_iter_instead_of_collect.stderr b/tests/ui/from_iter_instead_of_collect.stderr index 6e86341d1574..30080eb599c2 100644 --- a/tests/ui/from_iter_instead_of_collect.stderr +++ b/tests/ui/from_iter_instead_of_collect.stderr @@ -8,85 +8,85 @@ LL | >::from_iter(iter.into_iter().copied()) = help: to override `-D warnings` add `#[allow(clippy::from_iter_instead_of_collect)]` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:23:13 + --> $DIR/from_iter_instead_of_collect.rs:24:13 | LL | let _ = Vec::from_iter(iter_expr); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `iter_expr.collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:25:13 + --> $DIR/from_iter_instead_of_collect.rs:27:13 | LL | let _ = HashMap::::from_iter(vec![5, 5, 5, 5].iter().enumerate()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `vec![5, 5, 5, 5].iter().enumerate().collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:30:19 + --> $DIR/from_iter_instead_of_collect.rs:33:19 | LL | assert_eq!(a, Vec::from_iter(0..3)); | ^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:31:19 + --> $DIR/from_iter_instead_of_collect.rs:35:19 | LL | assert_eq!(a, Vec::::from_iter(0..3)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:33:17 + --> $DIR/from_iter_instead_of_collect.rs:38:17 | LL | let mut b = VecDeque::from_iter(0..3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:36:17 + --> $DIR/from_iter_instead_of_collect.rs:42:17 | LL | let mut b = VecDeque::::from_iter(0..3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:41:21 + --> $DIR/from_iter_instead_of_collect.rs:48:21 | LL | let mut b = collections::VecDeque::::from_iter(0..3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:46:14 + --> $DIR/from_iter_instead_of_collect.rs:54:14 | LL | let bm = BTreeMap::from_iter(values.iter().cloned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `values.iter().cloned().collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:47:19 + --> $DIR/from_iter_instead_of_collect.rs:56:19 | LL | let mut bar = BTreeMap::from_iter(bm.range(0..2)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `bm.range(0..2).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:50:19 + --> $DIR/from_iter_instead_of_collect.rs:60:19 | LL | let mut bts = BTreeSet::from_iter(0..3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:54:17 + --> $DIR/from_iter_instead_of_collect.rs:65:17 | LL | let _ = collections::BTreeSet::from_iter(0..3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:55:17 + --> $DIR/from_iter_instead_of_collect.rs:67:17 | LL | let _ = collections::BTreeSet::::from_iter(0..3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:58:15 + --> $DIR/from_iter_instead_of_collect.rs:71:15 | LL | for _i in Vec::from_iter([1, 2, 3].iter()) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `[1, 2, 3].iter().collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:59:15 + --> $DIR/from_iter_instead_of_collect.rs:73:15 | LL | for _i in Vec::<&i32>::from_iter([1, 2, 3].iter()) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `[1, 2, 3].iter().collect::>()` diff --git a/tests/ui/from_over_into.fixed b/tests/ui/from_over_into.fixed index 4a68505ee0b1..98db53b101a2 100644 --- a/tests/ui/from_over_into.fixed +++ b/tests/ui/from_over_into.fixed @@ -5,6 +5,7 @@ // this should throw an error struct StringWrapper(String); +//~v from_over_into impl From for StringWrapper { fn from(val: String) -> Self { StringWrapper(val) @@ -13,6 +14,7 @@ impl From for StringWrapper { struct SelfType(String); +//~v from_over_into impl From for SelfType { fn from(val: String) -> Self { SelfType(String::new()) @@ -28,6 +30,7 @@ impl X { struct SelfKeywords; +//~v from_over_into impl From for SelfKeywords { fn from(val: X) -> Self { let _ = X; @@ -40,6 +43,7 @@ impl From for SelfKeywords { struct ExplicitPaths(bool); +//~v from_over_into impl core::convert::From for bool { fn from(mut val: crate::ExplicitPaths) -> Self { let in_closure = || val.0; @@ -60,6 +64,7 @@ impl From for A { struct PathInExpansion; +//~v from_over_into impl From for String { fn from(val: PathInExpansion) -> Self { // non self/Self paths in expansions are fine @@ -82,6 +87,7 @@ fn msrv_1_40() { fn msrv_1_41() { struct FromOverInto(Vec); + //~v from_over_into impl From> for FromOverInto { fn from(val: Vec) -> Self { FromOverInto(val) @@ -92,6 +98,7 @@ fn msrv_1_41() { fn issue_12138() { struct Hello; + //~v from_over_into impl From for () { fn from(val: Hello) {} } diff --git a/tests/ui/from_over_into.rs b/tests/ui/from_over_into.rs index bf3ed0c2b642..d72c5da135ab 100644 --- a/tests/ui/from_over_into.rs +++ b/tests/ui/from_over_into.rs @@ -5,6 +5,7 @@ // this should throw an error struct StringWrapper(String); +//~v from_over_into impl Into for String { fn into(self) -> StringWrapper { StringWrapper(self) @@ -13,6 +14,7 @@ impl Into for String { struct SelfType(String); +//~v from_over_into impl Into for String { fn into(self) -> SelfType { SelfType(Self::new()) @@ -28,6 +30,7 @@ impl X { struct SelfKeywords; +//~v from_over_into impl Into for X { fn into(self) -> SelfKeywords { let _ = Self; @@ -40,6 +43,7 @@ impl Into for X { struct ExplicitPaths(bool); +//~v from_over_into impl core::convert::Into for crate::ExplicitPaths { fn into(mut self) -> bool { let in_closure = || self.0; @@ -60,6 +64,7 @@ impl From for A { struct PathInExpansion; +//~v from_over_into impl Into for PathInExpansion { fn into(self) -> String { // non self/Self paths in expansions are fine @@ -82,6 +87,7 @@ fn msrv_1_40() { fn msrv_1_41() { struct FromOverInto(Vec); + //~v from_over_into impl Into> for Vec { fn into(self) -> FromOverInto { FromOverInto(self) @@ -92,6 +98,7 @@ fn msrv_1_41() { fn issue_12138() { struct Hello; + //~v from_over_into impl Into<()> for Hello { fn into(self) {} } diff --git a/tests/ui/from_over_into.stderr b/tests/ui/from_over_into.stderr index f1370ed844fa..ac72d012b9a5 100644 --- a/tests/ui/from_over_into.stderr +++ b/tests/ui/from_over_into.stderr @@ -1,5 +1,5 @@ error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:8:1 + --> $DIR/from_over_into.rs:9:1 | LL | impl Into for String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -14,7 +14,7 @@ LL ~ StringWrapper(val) | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:16:1 + --> $DIR/from_over_into.rs:18:1 | LL | impl Into for String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL ~ SelfType(String::new()) | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:31:1 + --> $DIR/from_over_into.rs:34:1 | LL | impl Into for X { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -42,7 +42,7 @@ LL ~ let _: X = val; | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:43:1 + --> $DIR/from_over_into.rs:47:1 | LL | impl core::convert::Into for crate::ExplicitPaths { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL ~ val.0 | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:63:1 + --> $DIR/from_over_into.rs:68:1 | LL | impl Into for PathInExpansion { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -74,7 +74,7 @@ LL ~ fn from(val: PathInExpansion) -> Self { | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:85:5 + --> $DIR/from_over_into.rs:91:5 | LL | impl Into> for Vec { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -87,7 +87,7 @@ LL ~ FromOverInto(val) | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:95:5 + --> $DIR/from_over_into.rs:102:5 | LL | impl Into<()> for Hello { | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/get_last_with_len.fixed b/tests/ui/get_last_with_len.fixed index 377906cb2448..669e23dae364 100644 --- a/tests/ui/get_last_with_len.fixed +++ b/tests/ui/get_last_with_len.fixed @@ -5,7 +5,7 @@ use std::collections::VecDeque; fn dont_use_last() { let x = vec![2, 3, 5]; - let _ = x.last(); + let _ = x.last(); //~ get_last_with_len } fn indexing_two_from_end() { @@ -29,19 +29,20 @@ struct S { } fn in_field(s: &S) { - let _ = s.field.last(); + let _ = s.field.last(); //~ get_last_with_len } fn main() { let slice = &[1, 2, 3]; - let _ = slice.last(); + let _ = slice.last(); //~ get_last_with_len let array = [4, 5, 6]; - let _ = array.last(); + let _ = array.last(); //~ get_last_with_len let deq = VecDeque::from([7, 8, 9]); - let _ = deq.back(); + let _ = deq.back(); //~ get_last_with_len let nested = [[1]]; let _ = nested[0].last(); + //~^ get_last_with_len } diff --git a/tests/ui/get_last_with_len.rs b/tests/ui/get_last_with_len.rs index 2735932043a3..399b4b9d3b8c 100644 --- a/tests/ui/get_last_with_len.rs +++ b/tests/ui/get_last_with_len.rs @@ -5,7 +5,7 @@ use std::collections::VecDeque; fn dont_use_last() { let x = vec![2, 3, 5]; - let _ = x.get(x.len() - 1); + let _ = x.get(x.len() - 1); //~ get_last_with_len } fn indexing_two_from_end() { @@ -29,19 +29,20 @@ struct S { } fn in_field(s: &S) { - let _ = s.field.get(s.field.len() - 1); + let _ = s.field.get(s.field.len() - 1); //~ get_last_with_len } fn main() { let slice = &[1, 2, 3]; - let _ = slice.get(slice.len() - 1); + let _ = slice.get(slice.len() - 1); //~ get_last_with_len let array = [4, 5, 6]; - let _ = array.get(array.len() - 1); + let _ = array.get(array.len() - 1); //~ get_last_with_len let deq = VecDeque::from([7, 8, 9]); - let _ = deq.get(deq.len() - 1); + let _ = deq.get(deq.len() - 1); //~ get_last_with_len let nested = [[1]]; let _ = nested[0].get(nested[0].len() - 1); + //~^ get_last_with_len } diff --git a/tests/ui/get_unwrap.fixed b/tests/ui/get_unwrap.fixed index 62beb195939c..a84a1784cd2f 100644 --- a/tests/ui/get_unwrap.fixed +++ b/tests/ui/get_unwrap.fixed @@ -35,23 +35,45 @@ fn main() { { // Test `get().unwrap()` let _ = &boxed_slice[1]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_slice[0]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_vec[0]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_vecdeque[0]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_hashmap[&1]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_btreemap[&1]; + //~^ get_unwrap + //~| unwrap_used #[allow(clippy::unwrap_used)] let _ = false_positive.get(0).unwrap(); // Test with deref let _: u8 = boxed_slice[1]; + //~^ get_unwrap + //~| unwrap_used } { // Test `get_mut().unwrap()` boxed_slice[0] = 1; + //~^ get_unwrap + //~| unwrap_used some_slice[0] = 1; + //~^ get_unwrap + //~| unwrap_used some_vec[0] = 1; + //~^ get_unwrap + //~| unwrap_used some_vecdeque[0] = 1; + //~^ get_unwrap + //~| unwrap_used // Check false positives #[allow(clippy::unwrap_used)] { @@ -64,7 +86,11 @@ fn main() { { // Test `get().unwrap().foo()` and `get_mut().unwrap().bar()` let _ = some_vec[0..1].to_vec(); + //~^ get_unwrap + //~| unwrap_used let _ = some_vec[0..1].to_vec(); + //~^ get_unwrap + //~| unwrap_used } } mod issue9909 { @@ -74,13 +100,13 @@ mod issue9909 { let f = &[1, 2, 3]; // include a borrow in the suggestion, even if the argument is not just a numeric literal - let _x: &i32 = &f[1 + 2]; + let _x: &i32 = &f[1 + 2]; //~ get_unwrap // don't include a borrow here - let _x = f[1 + 2].to_string(); + let _x = f[1 + 2].to_string(); //~ get_unwrap // don't include a borrow here - let _x = f[1 + 2].abs(); + let _x = f[1 + 2].abs(); //~ get_unwrap } // original code: @@ -98,6 +124,7 @@ mod issue9909 { let (x, rest) = mat.split_at_mut(linidx(i, k) + 1); let a = x.last_mut().unwrap(); let b = &mut rest[linidx(j, k) - linidx(i, k) - 1]; + //~^ get_unwrap ::std::mem::swap(a, b); } } diff --git a/tests/ui/get_unwrap.rs b/tests/ui/get_unwrap.rs index 1e09ff5c67e5..8b6a2d42f617 100644 --- a/tests/ui/get_unwrap.rs +++ b/tests/ui/get_unwrap.rs @@ -35,23 +35,45 @@ fn main() { { // Test `get().unwrap()` let _ = boxed_slice.get(1).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_slice.get(0).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_vec.get(0).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_vecdeque.get(0).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_hashmap.get(&1).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_btreemap.get(&1).unwrap(); + //~^ get_unwrap + //~| unwrap_used #[allow(clippy::unwrap_used)] let _ = false_positive.get(0).unwrap(); // Test with deref let _: u8 = *boxed_slice.get(1).unwrap(); + //~^ get_unwrap + //~| unwrap_used } { // Test `get_mut().unwrap()` *boxed_slice.get_mut(0).unwrap() = 1; + //~^ get_unwrap + //~| unwrap_used *some_slice.get_mut(0).unwrap() = 1; + //~^ get_unwrap + //~| unwrap_used *some_vec.get_mut(0).unwrap() = 1; + //~^ get_unwrap + //~| unwrap_used *some_vecdeque.get_mut(0).unwrap() = 1; + //~^ get_unwrap + //~| unwrap_used // Check false positives #[allow(clippy::unwrap_used)] { @@ -64,7 +86,11 @@ fn main() { { // Test `get().unwrap().foo()` and `get_mut().unwrap().bar()` let _ = some_vec.get(0..1).unwrap().to_vec(); + //~^ get_unwrap + //~| unwrap_used let _ = some_vec.get_mut(0..1).unwrap().to_vec(); + //~^ get_unwrap + //~| unwrap_used } } mod issue9909 { @@ -74,13 +100,13 @@ mod issue9909 { let f = &[1, 2, 3]; // include a borrow in the suggestion, even if the argument is not just a numeric literal - let _x: &i32 = f.get(1 + 2).unwrap(); + let _x: &i32 = f.get(1 + 2).unwrap(); //~ get_unwrap // don't include a borrow here - let _x = f.get(1 + 2).unwrap().to_string(); + let _x = f.get(1 + 2).unwrap().to_string(); //~ get_unwrap // don't include a borrow here - let _x = f.get(1 + 2).unwrap().abs(); + let _x = f.get(1 + 2).unwrap().abs(); //~ get_unwrap } // original code: @@ -98,6 +124,7 @@ mod issue9909 { let (x, rest) = mat.split_at_mut(linidx(i, k) + 1); let a = x.last_mut().unwrap(); let b = rest.get_mut(linidx(j, k) - linidx(i, k) - 1).unwrap(); + //~^ get_unwrap ::std::mem::swap(a, b); } } diff --git a/tests/ui/get_unwrap.stderr b/tests/ui/get_unwrap.stderr index 700f3cfec4e0..64468509b8fb 100644 --- a/tests/ui/get_unwrap.stderr +++ b/tests/ui/get_unwrap.stderr @@ -22,13 +22,13 @@ LL | let _ = boxed_slice.get(1).unwrap(); = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:38:17 + --> $DIR/get_unwrap.rs:40:17 | LL | let _ = some_slice.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_slice[0]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:38:17 + --> $DIR/get_unwrap.rs:40:17 | LL | let _ = some_slice.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,13 +37,13 @@ LL | let _ = some_slice.get(0).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:39:17 + --> $DIR/get_unwrap.rs:43:17 | LL | let _ = some_vec.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_vec[0]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:39:17 + --> $DIR/get_unwrap.rs:43:17 | LL | let _ = some_vec.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,13 +52,13 @@ LL | let _ = some_vec.get(0).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:40:17 + --> $DIR/get_unwrap.rs:46:17 | LL | let _ = some_vecdeque.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_vecdeque[0]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:40:17 + --> $DIR/get_unwrap.rs:46:17 | LL | let _ = some_vecdeque.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,13 +67,13 @@ LL | let _ = some_vecdeque.get(0).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:41:17 + --> $DIR/get_unwrap.rs:49:17 | LL | let _ = some_hashmap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_hashmap[&1]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:41:17 + --> $DIR/get_unwrap.rs:49:17 | LL | let _ = some_hashmap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -82,13 +82,13 @@ LL | let _ = some_hashmap.get(&1).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:42:17 + --> $DIR/get_unwrap.rs:52:17 | LL | let _ = some_btreemap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_btreemap[&1]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:42:17 + --> $DIR/get_unwrap.rs:52:17 | LL | let _ = some_btreemap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,13 +97,13 @@ LL | let _ = some_btreemap.get(&1).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:46:21 + --> $DIR/get_unwrap.rs:58:21 | LL | let _: u8 = *boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice[1]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:46:22 + --> $DIR/get_unwrap.rs:58:22 | LL | let _: u8 = *boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,13 +112,13 @@ LL | let _: u8 = *boxed_slice.get(1).unwrap(); = 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 - --> $DIR/get_unwrap.rs:51:9 + --> $DIR/get_unwrap.rs:65:9 | LL | *boxed_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice[0]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:51:10 + --> $DIR/get_unwrap.rs:65:10 | LL | *boxed_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -127,13 +127,13 @@ LL | *boxed_slice.get_mut(0).unwrap() = 1; = 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 - --> $DIR/get_unwrap.rs:52:9 + --> $DIR/get_unwrap.rs:68:9 | LL | *some_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_slice[0]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:52:10 + --> $DIR/get_unwrap.rs:68:10 | LL | *some_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -142,13 +142,13 @@ LL | *some_slice.get_mut(0).unwrap() = 1; = 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 - --> $DIR/get_unwrap.rs:53:9 + --> $DIR/get_unwrap.rs:71:9 | LL | *some_vec.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:53:10 + --> $DIR/get_unwrap.rs:71:10 | LL | *some_vec.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,13 +157,13 @@ LL | *some_vec.get_mut(0).unwrap() = 1; = 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 - --> $DIR/get_unwrap.rs:54:9 + --> $DIR/get_unwrap.rs:74:9 | LL | *some_vecdeque.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vecdeque[0]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:54:10 + --> $DIR/get_unwrap.rs:74:10 | LL | *some_vecdeque.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -172,13 +172,13 @@ LL | *some_vecdeque.get_mut(0).unwrap() = 1; = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:66:17 + --> $DIR/get_unwrap.rs:88:17 | LL | let _ = some_vec.get(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0..1]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:66:17 + --> $DIR/get_unwrap.rs:88:17 | LL | let _ = some_vec.get(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -187,13 +187,13 @@ LL | let _ = some_vec.get(0..1).unwrap().to_vec(); = 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 - --> $DIR/get_unwrap.rs:67:17 + --> $DIR/get_unwrap.rs:91:17 | LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0..1]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:67:17 + --> $DIR/get_unwrap.rs:91:17 | LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -202,25 +202,25 @@ LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:77:24 + --> $DIR/get_unwrap.rs:103:24 | LL | let _x: &i32 = f.get(1 + 2).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `&f[1 + 2]` error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:80:18 + --> $DIR/get_unwrap.rs:106:18 | LL | let _x = f.get(1 + 2).unwrap().to_string(); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `f[1 + 2]` error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:83:18 + --> $DIR/get_unwrap.rs:109:18 | LL | let _x = f.get(1 + 2).unwrap().abs(); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `f[1 + 2]` error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:100:33 + --> $DIR/get_unwrap.rs:126: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]` diff --git a/tests/ui/identity_op.fixed b/tests/ui/identity_op.fixed index 660e9a21b181..8a4b242cdbd1 100644 --- a/tests/ui/identity_op.fixed +++ b/tests/ui/identity_op.fixed @@ -162,6 +162,7 @@ fn main() { pub fn decide(a: bool, b: bool) -> u32 { (if a { 1 } else { 2 }) + if b { 3 } else { 5 } + //~^ identity_op } /// The following tests are from / for issue #12050 diff --git a/tests/ui/identity_op.rs b/tests/ui/identity_op.rs index bbef531e9dc0..105be7e4f833 100644 --- a/tests/ui/identity_op.rs +++ b/tests/ui/identity_op.rs @@ -162,6 +162,7 @@ fn main() { pub fn decide(a: bool, b: bool) -> u32 { 0 + if a { 1 } else { 2 } + if b { 3 } else { 5 } + //~^ identity_op } /// The following tests are from / for issue #12050 diff --git a/tests/ui/identity_op.stderr b/tests/ui/identity_op.stderr index 6bb980035c1a..2827c2967ad7 100644 --- a/tests/ui/identity_op.stderr +++ b/tests/ui/identity_op.stderr @@ -242,73 +242,73 @@ LL | 0 + if a { 1 } else { 2 } + if b { 3 } else { 5 } | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(if a { 1 } else { 2 })` error: this operation has no effect - --> $DIR/identity_op.rs:175:22 + --> $DIR/identity_op.rs:176:22 | LL | let _: i32 = *x + 0; | ^^^^^^ help: consider reducing it to: `*x` error: this operation has no effect - --> $DIR/identity_op.rs:177:22 + --> $DIR/identity_op.rs:178:22 | LL | let _: i32 = x + 0; | ^^^^^ help: consider reducing it to: `*x` error: this operation has no effect - --> $DIR/identity_op.rs:182:22 + --> $DIR/identity_op.rs:183:22 | LL | let _: i32 = **x + 0; | ^^^^^^^ help: consider reducing it to: `**x` error: this operation has no effect - --> $DIR/identity_op.rs:185:22 + --> $DIR/identity_op.rs:186:22 | LL | let _: i32 = *x + 0; | ^^^^^^ help: consider reducing it to: `**x` error: this operation has no effect - --> $DIR/identity_op.rs:191:22 + --> $DIR/identity_op.rs:192:22 | LL | let _: i32 = ***x + 0; | ^^^^^^^^ help: consider reducing it to: `***x` error: this operation has no effect - --> $DIR/identity_op.rs:193:22 + --> $DIR/identity_op.rs:194:22 | LL | let _: i32 = **x + 0; | ^^^^^^^ help: consider reducing it to: `***x` error: this operation has no effect - --> $DIR/identity_op.rs:196:22 + --> $DIR/identity_op.rs:197:22 | LL | let _: i32 = *&x + 0; | ^^^^^^^ help: consider reducing it to: `*&x` error: this operation has no effect - --> $DIR/identity_op.rs:198:22 + --> $DIR/identity_op.rs:199:22 | LL | let _: i32 = **&&x + 0; | ^^^^^^^^^ help: consider reducing it to: `**&&x` error: this operation has no effect - --> $DIR/identity_op.rs:200:22 + --> $DIR/identity_op.rs:201:22 | LL | let _: i32 = *&*&x + 0; | ^^^^^^^^^ help: consider reducing it to: `*&*&x` error: this operation has no effect - --> $DIR/identity_op.rs:202:22 + --> $DIR/identity_op.rs:203:22 | LL | let _: i32 = **&&*&x + 0; | ^^^^^^^^^^^ help: consider reducing it to: `**&&*&x` error: this operation has no effect - --> $DIR/identity_op.rs:209:22 + --> $DIR/identity_op.rs:210:22 | LL | let _: i32 = **&&*&x + 0; | ^^^^^^^^^^^ help: consider reducing it to: `***&&*&x` error: this operation has no effect - --> $DIR/identity_op.rs:211:22 + --> $DIR/identity_op.rs:212:22 | LL | let _: i32 = **&&*&x + 0; | ^^^^^^^^^^^ help: consider reducing it to: `***&&*&x` diff --git a/tests/ui/if_same_then_else.rs b/tests/ui/if_same_then_else.rs index d53e1383d845..17f97c3dd536 100644 --- a/tests/ui/if_same_then_else.rs +++ b/tests/ui/if_same_then_else.rs @@ -235,6 +235,7 @@ mod issue_11213 { fn do_lint(x: bool) -> bool { // but do lint if the type of the literal is the same + //~v if_same_then_else if x { 0_u8.is_power_of_two() } else { diff --git a/tests/ui/if_same_then_else.stderr b/tests/ui/if_same_then_else.stderr index 281f30f88b46..569125d39f8a 100644 --- a/tests/ui/if_same_then_else.stderr +++ b/tests/ui/if_same_then_else.stderr @@ -89,7 +89,7 @@ LL | | } | |_____^ error: this `if` has identical blocks - --> $DIR/if_same_then_else.rs:238:14 + --> $DIR/if_same_then_else.rs:239:14 | LL | if x { | ______________^ @@ -98,7 +98,7 @@ LL | | } else { | |_________^ | note: same as this - --> $DIR/if_same_then_else.rs:240:16 + --> $DIR/if_same_then_else.rs:241:16 | LL | } else { | ________________^ diff --git a/tests/ui/implicit_clone.fixed b/tests/ui/implicit_clone.fixed index 98556b4dd303..41a3043800e0 100644 --- a/tests/ui/implicit_clone.fixed +++ b/tests/ui/implicit_clone.fixed @@ -62,13 +62,13 @@ mod weird { fn main() { let vec = vec![5]; let _ = return_owned_from_slice(&vec); - let _ = vec.clone(); - let _ = vec.clone(); + let _ = vec.clone(); //~ implicit_clone + let _ = vec.clone(); //~ implicit_clone let vec_ref = &vec; let _ = return_owned_from_slice(vec_ref); let _ = vec_ref.to_owned(); - let _ = vec_ref.clone(); + let _ = vec_ref.clone(); //~ implicit_clone // we expect no lint for this let _ = weird::to_vec(&vec); @@ -80,11 +80,11 @@ fn main() { let _ = slice.to_vec(); let str = "hello world".to_string(); - let _ = str.clone(); + let _ = str.clone(); //~ implicit_clone // testing w/ an arbitrary type let kitten = Kitten {}; - let _ = kitten.clone(); + let _ = kitten.clone(); //~ implicit_clone let _ = own_same_from_ref(&kitten); // this shouldn't lint let _ = kitten.to_vec(); @@ -94,12 +94,12 @@ fn main() { let _ = borrowed.to_owned(); let pathbuf = PathBuf::new(); - let _ = pathbuf.clone(); - let _ = pathbuf.clone(); + let _ = pathbuf.clone(); //~ implicit_clone + let _ = pathbuf.clone(); //~ implicit_clone let os_string = OsString::from("foo"); - let _ = os_string.clone(); - let _ = os_string.clone(); + let _ = os_string.clone(); //~ implicit_clone + let _ = os_string.clone(); //~ implicit_clone // we expect no lints for this let os_str = OsStr::new("foo"); @@ -110,10 +110,10 @@ fn main() { let pathbuf_ref = &pathbuf; let pathbuf_ref = &pathbuf_ref; let _ = pathbuf_ref.to_owned(); // Don't lint. Returns `&PathBuf` - let _ = (*pathbuf_ref).clone(); + let _ = (*pathbuf_ref).clone(); //~ implicit_clone let pathbuf_ref = &pathbuf_ref; let _ = pathbuf_ref.to_owned(); // Don't lint. Returns `&&PathBuf` - let _ = (**pathbuf_ref).clone(); + let _ = (**pathbuf_ref).clone(); //~ implicit_clone struct NoClone; impl ToOwned for NoClone { diff --git a/tests/ui/implicit_clone.rs b/tests/ui/implicit_clone.rs index a064bd23a338..17c85fab006b 100644 --- a/tests/ui/implicit_clone.rs +++ b/tests/ui/implicit_clone.rs @@ -62,13 +62,13 @@ mod weird { fn main() { let vec = vec![5]; let _ = return_owned_from_slice(&vec); - let _ = vec.to_owned(); - let _ = vec.to_vec(); + let _ = vec.to_owned(); //~ implicit_clone + let _ = vec.to_vec(); //~ implicit_clone let vec_ref = &vec; let _ = return_owned_from_slice(vec_ref); let _ = vec_ref.to_owned(); - let _ = vec_ref.to_vec(); + let _ = vec_ref.to_vec(); //~ implicit_clone // we expect no lint for this let _ = weird::to_vec(&vec); @@ -80,11 +80,11 @@ fn main() { let _ = slice.to_vec(); let str = "hello world".to_string(); - let _ = str.to_owned(); + let _ = str.to_owned(); //~ implicit_clone // testing w/ an arbitrary type let kitten = Kitten {}; - let _ = kitten.to_owned(); + let _ = kitten.to_owned(); //~ implicit_clone let _ = own_same_from_ref(&kitten); // this shouldn't lint let _ = kitten.to_vec(); @@ -94,12 +94,12 @@ fn main() { let _ = borrowed.to_owned(); let pathbuf = PathBuf::new(); - let _ = pathbuf.to_owned(); - let _ = pathbuf.to_path_buf(); + let _ = pathbuf.to_owned(); //~ implicit_clone + let _ = pathbuf.to_path_buf(); //~ implicit_clone let os_string = OsString::from("foo"); - let _ = os_string.to_owned(); - let _ = os_string.to_os_string(); + let _ = os_string.to_owned(); //~ implicit_clone + let _ = os_string.to_os_string(); //~ implicit_clone // we expect no lints for this let os_str = OsStr::new("foo"); @@ -110,10 +110,10 @@ fn main() { let pathbuf_ref = &pathbuf; let pathbuf_ref = &pathbuf_ref; let _ = pathbuf_ref.to_owned(); // Don't lint. Returns `&PathBuf` - let _ = pathbuf_ref.to_path_buf(); + let _ = pathbuf_ref.to_path_buf(); //~ implicit_clone let pathbuf_ref = &pathbuf_ref; let _ = pathbuf_ref.to_owned(); // Don't lint. Returns `&&PathBuf` - let _ = pathbuf_ref.to_path_buf(); + let _ = pathbuf_ref.to_path_buf(); //~ implicit_clone struct NoClone; impl ToOwned for NoClone { diff --git a/tests/ui/implicit_return.fixed b/tests/ui/implicit_return.fixed index 897f1b766163..7719984ef552 100644 --- a/tests/ui/implicit_return.fixed +++ b/tests/ui/implicit_return.fixed @@ -8,18 +8,20 @@ fn test_end_of_fn() -> bool { return true; } - return true + return true //~ implicit_return } fn test_if_block() -> bool { if true { return true } else { return false } + //~^ implicit_return + //~| implicit_return } #[rustfmt::skip] fn test_match(x: bool) -> bool { match x { - true => return false, - false => { return true }, + true => return false, //~ implicit_return + false => { return true }, //~ implicit_return } } @@ -32,14 +34,14 @@ fn test_match_with_unreachable(x: bool) -> bool { fn test_loop() -> bool { loop { - return true; + return true; //~ implicit_return } } fn test_loop_with_block() -> bool { loop { { - return true; + return true; //~ implicit_return } } } @@ -47,7 +49,7 @@ fn test_loop_with_block() -> bool { fn test_loop_with_nests() -> bool { loop { if true { - return true; + return true; //~ implicit_return } else { let _ = true; } @@ -65,8 +67,8 @@ fn test_loop_with_if_let() -> bool { fn test_closure() { #[rustfmt::skip] - let _ = || { return true }; - let _ = || return true; + let _ = || { return true }; //~ implicit_return + let _ = || return true; //~ implicit_return } fn test_panic() -> bool { @@ -74,7 +76,7 @@ fn test_panic() -> bool { } fn test_return_macro() -> String { - return format!("test {}", "test") + return format!("test {}", "test") //~ implicit_return } fn macro_branch_test() -> bool { @@ -83,18 +85,18 @@ fn macro_branch_test() -> bool { if true { $t } else { $f } }; } - return m!(true, false) + return m!(true, false) //~ implicit_return } fn loop_test() -> bool { 'outer: loop { if true { - return true; + return true; //~ implicit_return } let _ = loop { if false { - return false; + return false; //~ implicit_return } if true { break true; @@ -109,6 +111,7 @@ fn loop_macro_test() -> bool { break $e }; } + //~v implicit_return return loop { m!(true); } @@ -123,7 +126,7 @@ fn divergent_test() -> bool { // issue #6940 async fn foo() -> bool { - return true + return true //~ implicit_return } fn main() {} diff --git a/tests/ui/implicit_return.rs b/tests/ui/implicit_return.rs index fcff67b58071..bd02ffcc0f87 100644 --- a/tests/ui/implicit_return.rs +++ b/tests/ui/implicit_return.rs @@ -8,18 +8,20 @@ fn test_end_of_fn() -> bool { return true; } - true + true //~ implicit_return } fn test_if_block() -> bool { if true { true } else { false } + //~^ implicit_return + //~| implicit_return } #[rustfmt::skip] fn test_match(x: bool) -> bool { match x { - true => false, - false => { true }, + true => false, //~ implicit_return + false => { true }, //~ implicit_return } } @@ -32,14 +34,14 @@ fn test_match_with_unreachable(x: bool) -> bool { fn test_loop() -> bool { loop { - break true; + break true; //~ implicit_return } } fn test_loop_with_block() -> bool { loop { { - break true; + break true; //~ implicit_return } } } @@ -47,7 +49,7 @@ fn test_loop_with_block() -> bool { fn test_loop_with_nests() -> bool { loop { if true { - break true; + break true; //~ implicit_return } else { let _ = true; } @@ -65,8 +67,8 @@ fn test_loop_with_if_let() -> bool { fn test_closure() { #[rustfmt::skip] - let _ = || { true }; - let _ = || true; + let _ = || { true }; //~ implicit_return + let _ = || true; //~ implicit_return } fn test_panic() -> bool { @@ -74,7 +76,7 @@ fn test_panic() -> bool { } fn test_return_macro() -> String { - format!("test {}", "test") + format!("test {}", "test") //~ implicit_return } fn macro_branch_test() -> bool { @@ -83,18 +85,18 @@ fn macro_branch_test() -> bool { if true { $t } else { $f } }; } - m!(true, false) + m!(true, false) //~ implicit_return } fn loop_test() -> bool { 'outer: loop { if true { - break true; + break true; //~ implicit_return } let _ = loop { if false { - break 'outer false; + break 'outer false; //~ implicit_return } if true { break true; @@ -109,6 +111,7 @@ fn loop_macro_test() -> bool { break $e }; } + //~v implicit_return loop { m!(true); } @@ -123,7 +126,7 @@ fn divergent_test() -> bool { // issue #6940 async fn foo() -> bool { - true + true //~ implicit_return } fn main() {} diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr index 1edc6cc6f778..fd265feec727 100644 --- a/tests/ui/implicit_return.stderr +++ b/tests/ui/implicit_return.stderr @@ -20,73 +20,73 @@ LL | if true { true } else { false } | ^^^^^ help: add `return` as shown: `return false` error: missing `return` statement - --> $DIR/implicit_return.rs:21:17 + --> $DIR/implicit_return.rs:23:17 | LL | true => false, | ^^^^^ help: add `return` as shown: `return false` error: missing `return` statement - --> $DIR/implicit_return.rs:22:20 + --> $DIR/implicit_return.rs:24:20 | LL | false => { true }, | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:35:9 + --> $DIR/implicit_return.rs:37:9 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:42:13 + --> $DIR/implicit_return.rs:44:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:50:13 + --> $DIR/implicit_return.rs:52:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:68:18 + --> $DIR/implicit_return.rs:70:18 | LL | let _ = || { true }; | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:69:16 + --> $DIR/implicit_return.rs:71:16 | LL | let _ = || true; | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:77:5 + --> $DIR/implicit_return.rs:79:5 | LL | format!("test {}", "test") | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")` error: missing `return` statement - --> $DIR/implicit_return.rs:86:5 + --> $DIR/implicit_return.rs:88:5 | LL | m!(true, false) | ^^^^^^^^^^^^^^^ help: add `return` as shown: `return m!(true, false)` error: missing `return` statement - --> $DIR/implicit_return.rs:92:13 + --> $DIR/implicit_return.rs:94:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:97:17 + --> $DIR/implicit_return.rs:99:17 | LL | break 'outer false; | ^^^^^^^^^^^^^^^^^^ help: change `break` to `return` as shown: `return false` error: missing `return` statement - --> $DIR/implicit_return.rs:112:5 + --> $DIR/implicit_return.rs:115:5 | LL | / loop { LL | | m!(true); @@ -101,7 +101,7 @@ LL + } | error: missing `return` statement - --> $DIR/implicit_return.rs:126:5 + --> $DIR/implicit_return.rs:129:5 | LL | true | ^^^^ help: add `return` as shown: `return true` diff --git a/tests/ui/implicit_saturating_add.fixed b/tests/ui/implicit_saturating_add.fixed index 4cf8e3587b61..1640bd4dfb1e 100644 --- a/tests/ui/implicit_saturating_add.fixed +++ b/tests/ui/implicit_saturating_add.fixed @@ -18,54 +18,77 @@ fn main() { i_8 += 1; } + //~v implicit_saturating_add u_8 = u_8.saturating_add(1); + //~v implicit_saturating_add u_8 = u_8.saturating_add(1); if u_8 < 15 { u_8 += 1; } + //~v implicit_saturating_add u_16 = u_16.saturating_add(1); + //~v implicit_saturating_add u_16 = u_16.saturating_add(1); + //~v implicit_saturating_add u_16 = u_16.saturating_add(1); + //~v implicit_saturating_add u_32 = u_32.saturating_add(1); + //~v implicit_saturating_add u_32 = u_32.saturating_add(1); + //~v implicit_saturating_add u_32 = u_32.saturating_add(1); + //~v implicit_saturating_add u_64 = u_64.saturating_add(1); + //~v implicit_saturating_add u_64 = u_64.saturating_add(1); + //~v implicit_saturating_add u_64 = u_64.saturating_add(1); + //~v implicit_saturating_add i_8 = i_8.saturating_add(1); + //~v implicit_saturating_add i_8 = i_8.saturating_add(1); + //~v implicit_saturating_add i_8 = i_8.saturating_add(1); + //~v implicit_saturating_add i_16 = i_16.saturating_add(1); + //~v implicit_saturating_add i_16 = i_16.saturating_add(1); + //~v implicit_saturating_add i_16 = i_16.saturating_add(1); + //~v implicit_saturating_add i_32 = i_32.saturating_add(1); + //~v implicit_saturating_add i_32 = i_32.saturating_add(1); + //~v implicit_saturating_add i_32 = i_32.saturating_add(1); + //~v implicit_saturating_add i_64 = i_64.saturating_add(1); + //~v implicit_saturating_add i_64 = i_64.saturating_add(1); + //~v implicit_saturating_add i_64 = i_64.saturating_add(1); if i_64 < 42 { @@ -100,5 +123,6 @@ fn main() { if u_32 < 42 { println!("brace yourself!"); + //~v implicit_saturating_add } else {u_32 = u_32.saturating_add(1); } } diff --git a/tests/ui/implicit_saturating_add.rs b/tests/ui/implicit_saturating_add.rs index 94513f34c262..062017171c14 100644 --- a/tests/ui/implicit_saturating_add.rs +++ b/tests/ui/implicit_saturating_add.rs @@ -18,10 +18,12 @@ fn main() { i_8 += 1; } + //~v implicit_saturating_add if u_8 != u8::MAX { u_8 += 1; } + //~v implicit_saturating_add if u_8 < u8::MAX { u_8 += 1; } @@ -30,86 +32,107 @@ fn main() { u_8 += 1; } + //~v implicit_saturating_add if u_16 != u16::MAX { u_16 += 1; } + //~v implicit_saturating_add if u_16 < u16::MAX { u_16 += 1; } + //~v implicit_saturating_add if u16::MAX > u_16 { u_16 += 1; } + //~v implicit_saturating_add if u_32 != u32::MAX { u_32 += 1; } + //~v implicit_saturating_add if u_32 < u32::MAX { u_32 += 1; } + //~v implicit_saturating_add if u32::MAX > u_32 { u_32 += 1; } + //~v implicit_saturating_add if u_64 != u64::MAX { u_64 += 1; } + //~v implicit_saturating_add if u_64 < u64::MAX { u_64 += 1; } + //~v implicit_saturating_add if u64::MAX > u_64 { u_64 += 1; } + //~v implicit_saturating_add if i_8 != i8::MAX { i_8 += 1; } + //~v implicit_saturating_add if i_8 < i8::MAX { i_8 += 1; } + //~v implicit_saturating_add if i8::MAX > i_8 { i_8 += 1; } + //~v implicit_saturating_add if i_16 != i16::MAX { i_16 += 1; } + //~v implicit_saturating_add if i_16 < i16::MAX { i_16 += 1; } + //~v implicit_saturating_add if i16::MAX > i_16 { i_16 += 1; } + //~v implicit_saturating_add if i_32 != i32::MAX { i_32 += 1; } + //~v implicit_saturating_add if i_32 < i32::MAX { i_32 += 1; } + //~v implicit_saturating_add if i32::MAX > i_32 { i_32 += 1; } + //~v implicit_saturating_add if i_64 != i64::MAX { i_64 += 1; } + //~v implicit_saturating_add if i_64 < i64::MAX { i_64 += 1; } + //~v implicit_saturating_add if i64::MAX > i_64 { i_64 += 1; } @@ -146,6 +169,7 @@ fn main() { if u_32 < 42 { println!("brace yourself!"); + //~v implicit_saturating_add } else if u_32 < u32::MAX { u_32 += 1; } diff --git a/tests/ui/implicit_saturating_add.stderr b/tests/ui/implicit_saturating_add.stderr index 7119c8bf6fad..1ceb4552d2f7 100644 --- a/tests/ui/implicit_saturating_add.stderr +++ b/tests/ui/implicit_saturating_add.stderr @@ -1,5 +1,5 @@ error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:21:5 + --> $DIR/implicit_saturating_add.rs:22:5 | LL | / if u_8 != u8::MAX { LL | | u_8 += 1; @@ -10,7 +10,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::implicit_saturating_add)]` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:25:5 + --> $DIR/implicit_saturating_add.rs:27:5 | LL | / if u_8 < u8::MAX { LL | | u_8 += 1; @@ -18,7 +18,7 @@ LL | | } | |_____^ help: use instead: `u_8 = u_8.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:33:5 + --> $DIR/implicit_saturating_add.rs:36:5 | LL | / if u_16 != u16::MAX { LL | | u_16 += 1; @@ -26,7 +26,7 @@ LL | | } | |_____^ help: use instead: `u_16 = u_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:37:5 + --> $DIR/implicit_saturating_add.rs:41:5 | LL | / if u_16 < u16::MAX { LL | | u_16 += 1; @@ -34,7 +34,7 @@ LL | | } | |_____^ help: use instead: `u_16 = u_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:41:5 + --> $DIR/implicit_saturating_add.rs:46:5 | LL | / if u16::MAX > u_16 { LL | | u_16 += 1; @@ -42,7 +42,7 @@ LL | | } | |_____^ help: use instead: `u_16 = u_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:45:5 + --> $DIR/implicit_saturating_add.rs:51:5 | LL | / if u_32 != u32::MAX { LL | | u_32 += 1; @@ -50,7 +50,7 @@ LL | | } | |_____^ help: use instead: `u_32 = u_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:49:5 + --> $DIR/implicit_saturating_add.rs:56:5 | LL | / if u_32 < u32::MAX { LL | | u_32 += 1; @@ -58,7 +58,7 @@ LL | | } | |_____^ help: use instead: `u_32 = u_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:53:5 + --> $DIR/implicit_saturating_add.rs:61:5 | LL | / if u32::MAX > u_32 { LL | | u_32 += 1; @@ -66,7 +66,7 @@ LL | | } | |_____^ help: use instead: `u_32 = u_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:57:5 + --> $DIR/implicit_saturating_add.rs:66:5 | LL | / if u_64 != u64::MAX { LL | | u_64 += 1; @@ -74,7 +74,7 @@ LL | | } | |_____^ help: use instead: `u_64 = u_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:61:5 + --> $DIR/implicit_saturating_add.rs:71:5 | LL | / if u_64 < u64::MAX { LL | | u_64 += 1; @@ -82,7 +82,7 @@ LL | | } | |_____^ help: use instead: `u_64 = u_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:65:5 + --> $DIR/implicit_saturating_add.rs:76:5 | LL | / if u64::MAX > u_64 { LL | | u_64 += 1; @@ -90,7 +90,7 @@ LL | | } | |_____^ help: use instead: `u_64 = u_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:69:5 + --> $DIR/implicit_saturating_add.rs:81:5 | LL | / if i_8 != i8::MAX { LL | | i_8 += 1; @@ -98,7 +98,7 @@ LL | | } | |_____^ help: use instead: `i_8 = i_8.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:73:5 + --> $DIR/implicit_saturating_add.rs:86:5 | LL | / if i_8 < i8::MAX { LL | | i_8 += 1; @@ -106,7 +106,7 @@ LL | | } | |_____^ help: use instead: `i_8 = i_8.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:77:5 + --> $DIR/implicit_saturating_add.rs:91:5 | LL | / if i8::MAX > i_8 { LL | | i_8 += 1; @@ -114,7 +114,7 @@ LL | | } | |_____^ help: use instead: `i_8 = i_8.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:81:5 + --> $DIR/implicit_saturating_add.rs:96:5 | LL | / if i_16 != i16::MAX { LL | | i_16 += 1; @@ -122,7 +122,7 @@ LL | | } | |_____^ help: use instead: `i_16 = i_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:85:5 + --> $DIR/implicit_saturating_add.rs:101:5 | LL | / if i_16 < i16::MAX { LL | | i_16 += 1; @@ -130,7 +130,7 @@ LL | | } | |_____^ help: use instead: `i_16 = i_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:89:5 + --> $DIR/implicit_saturating_add.rs:106:5 | LL | / if i16::MAX > i_16 { LL | | i_16 += 1; @@ -138,7 +138,7 @@ LL | | } | |_____^ help: use instead: `i_16 = i_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:93:5 + --> $DIR/implicit_saturating_add.rs:111:5 | LL | / if i_32 != i32::MAX { LL | | i_32 += 1; @@ -146,7 +146,7 @@ LL | | } | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:97:5 + --> $DIR/implicit_saturating_add.rs:116:5 | LL | / if i_32 < i32::MAX { LL | | i_32 += 1; @@ -154,7 +154,7 @@ LL | | } | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:101:5 + --> $DIR/implicit_saturating_add.rs:121:5 | LL | / if i32::MAX > i_32 { LL | | i_32 += 1; @@ -162,7 +162,7 @@ LL | | } | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:105:5 + --> $DIR/implicit_saturating_add.rs:126:5 | LL | / if i_64 != i64::MAX { LL | | i_64 += 1; @@ -170,7 +170,7 @@ LL | | } | |_____^ help: use instead: `i_64 = i_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:109:5 + --> $DIR/implicit_saturating_add.rs:131:5 | LL | / if i_64 < i64::MAX { LL | | i_64 += 1; @@ -178,7 +178,7 @@ LL | | } | |_____^ help: use instead: `i_64 = i_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:113:5 + --> $DIR/implicit_saturating_add.rs:136:5 | LL | / if i64::MAX > i_64 { LL | | i_64 += 1; @@ -186,7 +186,7 @@ LL | | } | |_____^ help: use instead: `i_64 = i_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:149:12 + --> $DIR/implicit_saturating_add.rs:173:12 | LL | } else if u_32 < u32::MAX { | ____________^ diff --git a/tests/ui/implicit_saturating_sub.fixed b/tests/ui/implicit_saturating_sub.fixed index 27f679797dd9..e63bf1346466 100644 --- a/tests/ui/implicit_saturating_sub.fixed +++ b/tests/ui/implicit_saturating_sub.fixed @@ -24,11 +24,13 @@ fn main() { let mut u_8: u8 = end_8 - start_8; // Lint + //~v implicit_saturating_sub u_8 = u_8.saturating_sub(1); match end_8 { 10 => { // Lint + //~v implicit_saturating_sub u_8 = u_8.saturating_sub(1); }, 11 => u_8 += 1, @@ -41,6 +43,7 @@ fn main() { let mut u_16: u16 = end_16 - start_16; // Lint + //~v implicit_saturating_sub u_16 = u_16.saturating_sub(1); let mut end_32: u32 = 7010; @@ -49,6 +52,7 @@ fn main() { let mut u_32: u32 = end_32 - start_32; // Lint + //~v implicit_saturating_sub u_32 = u_32.saturating_sub(1); // No Lint @@ -68,12 +72,15 @@ fn main() { let mut u_64: u64 = end_64 - start_64; // Lint + //~v implicit_saturating_sub u_64 = u_64.saturating_sub(1); // Lint + //~v implicit_saturating_sub u_64 = u_64.saturating_sub(1); // Lint + //~v implicit_saturating_sub u_64 = u_64.saturating_sub(1); // No Lint @@ -93,6 +100,7 @@ fn main() { let mut u_usize: usize = end_usize - start_usize; // Lint + //~v implicit_saturating_sub u_usize = u_usize.saturating_sub(1); // Tests for signed integers @@ -103,15 +111,19 @@ fn main() { let mut i_8: i8 = endi_8 - starti_8; // Lint + //~v implicit_saturating_sub i_8 = i_8.saturating_sub(1); // Lint + //~v implicit_saturating_sub i_8 = i_8.saturating_sub(1); // Lint + //~v implicit_saturating_sub i_8 = i_8.saturating_sub(1); // Lint + //~v implicit_saturating_sub i_8 = i_8.saturating_sub(1); let endi_16: i16 = 45; @@ -120,15 +132,19 @@ fn main() { let mut i_16: i16 = endi_16 - starti_16; // Lint + //~v implicit_saturating_sub i_16 = i_16.saturating_sub(1); // Lint + //~v implicit_saturating_sub i_16 = i_16.saturating_sub(1); // Lint + //~v implicit_saturating_sub i_16 = i_16.saturating_sub(1); // Lint + //~v implicit_saturating_sub i_16 = i_16.saturating_sub(1); let endi_32: i32 = 45; @@ -137,15 +153,19 @@ fn main() { let mut i_32: i32 = endi_32 - starti_32; // Lint + //~v implicit_saturating_sub i_32 = i_32.saturating_sub(1); // Lint + //~v implicit_saturating_sub i_32 = i_32.saturating_sub(1); // Lint + //~v implicit_saturating_sub i_32 = i_32.saturating_sub(1); // Lint + //~v implicit_saturating_sub i_32 = i_32.saturating_sub(1); let endi_64: i64 = 45; @@ -154,12 +174,15 @@ fn main() { let mut i_64: i64 = endi_64 - starti_64; // Lint + //~v implicit_saturating_sub i_64 = i_64.saturating_sub(1); // Lint + //~v implicit_saturating_sub i_64 = i_64.saturating_sub(1); // Lint + //~v implicit_saturating_sub i_64 = i_64.saturating_sub(1); // No Lint diff --git a/tests/ui/implicit_saturating_sub.rs b/tests/ui/implicit_saturating_sub.rs index 5d7b95d2c652..c888cd625dcb 100644 --- a/tests/ui/implicit_saturating_sub.rs +++ b/tests/ui/implicit_saturating_sub.rs @@ -24,6 +24,7 @@ fn main() { let mut u_8: u8 = end_8 - start_8; // Lint + //~v implicit_saturating_sub if u_8 > 0 { u_8 = u_8 - 1; } @@ -31,6 +32,7 @@ fn main() { match end_8 { 10 => { // Lint + //~v implicit_saturating_sub if u_8 > 0 { u_8 -= 1; } @@ -45,6 +47,7 @@ fn main() { let mut u_16: u16 = end_16 - start_16; // Lint + //~v implicit_saturating_sub if u_16 > 0 { u_16 -= 1; } @@ -55,6 +58,7 @@ fn main() { let mut u_32: u32 = end_32 - start_32; // Lint + //~v implicit_saturating_sub if u_32 != 0 { u_32 -= 1; } @@ -76,16 +80,19 @@ fn main() { let mut u_64: u64 = end_64 - start_64; // Lint + //~v implicit_saturating_sub if u_64 > 0 { u_64 -= 1; } // Lint + //~v implicit_saturating_sub if 0 < u_64 { u_64 -= 1; } // Lint + //~v implicit_saturating_sub if 0 != u_64 { u_64 -= 1; } @@ -107,6 +114,7 @@ fn main() { let mut u_usize: usize = end_usize - start_usize; // Lint + //~v implicit_saturating_sub if u_usize > 0 { u_usize -= 1; } @@ -119,21 +127,25 @@ fn main() { let mut i_8: i8 = endi_8 - starti_8; // Lint + //~v implicit_saturating_sub if i_8 > i8::MIN { i_8 -= 1; } // Lint + //~v implicit_saturating_sub if i_8 > i8::MIN { i_8 -= 1; } // Lint + //~v implicit_saturating_sub if i_8 != i8::MIN { i_8 -= 1; } // Lint + //~v implicit_saturating_sub if i_8 != i8::MIN { i_8 -= 1; } @@ -144,21 +156,25 @@ fn main() { let mut i_16: i16 = endi_16 - starti_16; // Lint + //~v implicit_saturating_sub if i_16 > i16::MIN { i_16 -= 1; } // Lint + //~v implicit_saturating_sub if i_16 > i16::MIN { i_16 -= 1; } // Lint + //~v implicit_saturating_sub if i_16 != i16::MIN { i_16 -= 1; } // Lint + //~v implicit_saturating_sub if i_16 != i16::MIN { i_16 -= 1; } @@ -169,21 +185,25 @@ fn main() { let mut i_32: i32 = endi_32 - starti_32; // Lint + //~v implicit_saturating_sub if i_32 > i32::MIN { i_32 -= 1; } // Lint + //~v implicit_saturating_sub if i_32 > i32::MIN { i_32 -= 1; } // Lint + //~v implicit_saturating_sub if i_32 != i32::MIN { i_32 -= 1; } // Lint + //~v implicit_saturating_sub if i_32 != i32::MIN { i_32 -= 1; } @@ -194,16 +214,19 @@ fn main() { let mut i_64: i64 = endi_64 - starti_64; // Lint + //~v implicit_saturating_sub if i64::MIN < i_64 { i_64 -= 1; } // Lint + //~v implicit_saturating_sub if i64::MIN != i_64 { i_64 -= 1; } // Lint + //~v implicit_saturating_sub if i64::MIN < i_64 { i_64 -= 1; } diff --git a/tests/ui/implicit_saturating_sub.stderr b/tests/ui/implicit_saturating_sub.stderr index 6e026d1a6987..feeee0adb510 100644 --- a/tests/ui/implicit_saturating_sub.stderr +++ b/tests/ui/implicit_saturating_sub.stderr @@ -1,5 +1,5 @@ error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:27:5 + --> $DIR/implicit_saturating_sub.rs:28:5 | LL | / if u_8 > 0 { LL | | u_8 = u_8 - 1; @@ -10,7 +10,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::implicit_saturating_sub)]` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:34:13 + --> $DIR/implicit_saturating_sub.rs:36:13 | LL | / if u_8 > 0 { LL | | u_8 -= 1; @@ -18,7 +18,7 @@ LL | | } | |_____________^ help: try: `u_8 = u_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:48:5 + --> $DIR/implicit_saturating_sub.rs:51:5 | LL | / if u_16 > 0 { LL | | u_16 -= 1; @@ -26,7 +26,7 @@ LL | | } | |_____^ help: try: `u_16 = u_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:58:5 + --> $DIR/implicit_saturating_sub.rs:62:5 | LL | / if u_32 != 0 { LL | | u_32 -= 1; @@ -34,7 +34,7 @@ LL | | } | |_____^ help: try: `u_32 = u_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:79:5 + --> $DIR/implicit_saturating_sub.rs:84:5 | LL | / if u_64 > 0 { LL | | u_64 -= 1; @@ -42,7 +42,7 @@ LL | | } | |_____^ help: try: `u_64 = u_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:84:5 + --> $DIR/implicit_saturating_sub.rs:90:5 | LL | / if 0 < u_64 { LL | | u_64 -= 1; @@ -50,7 +50,7 @@ LL | | } | |_____^ help: try: `u_64 = u_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:89:5 + --> $DIR/implicit_saturating_sub.rs:96:5 | LL | / if 0 != u_64 { LL | | u_64 -= 1; @@ -58,7 +58,7 @@ LL | | } | |_____^ help: try: `u_64 = u_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:110:5 + --> $DIR/implicit_saturating_sub.rs:118:5 | LL | / if u_usize > 0 { LL | | u_usize -= 1; @@ -66,7 +66,7 @@ LL | | } | |_____^ help: try: `u_usize = u_usize.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:122:5 + --> $DIR/implicit_saturating_sub.rs:131:5 | LL | / if i_8 > i8::MIN { LL | | i_8 -= 1; @@ -74,7 +74,7 @@ LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:127:5 + --> $DIR/implicit_saturating_sub.rs:137:5 | LL | / if i_8 > i8::MIN { LL | | i_8 -= 1; @@ -82,7 +82,7 @@ LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:132:5 + --> $DIR/implicit_saturating_sub.rs:143:5 | LL | / if i_8 != i8::MIN { LL | | i_8 -= 1; @@ -90,7 +90,7 @@ LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:137:5 + --> $DIR/implicit_saturating_sub.rs:149:5 | LL | / if i_8 != i8::MIN { LL | | i_8 -= 1; @@ -98,7 +98,7 @@ LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:147:5 + --> $DIR/implicit_saturating_sub.rs:160:5 | LL | / if i_16 > i16::MIN { LL | | i_16 -= 1; @@ -106,7 +106,7 @@ LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:152:5 + --> $DIR/implicit_saturating_sub.rs:166:5 | LL | / if i_16 > i16::MIN { LL | | i_16 -= 1; @@ -114,7 +114,7 @@ LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:157:5 + --> $DIR/implicit_saturating_sub.rs:172:5 | LL | / if i_16 != i16::MIN { LL | | i_16 -= 1; @@ -122,7 +122,7 @@ LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:162:5 + --> $DIR/implicit_saturating_sub.rs:178:5 | LL | / if i_16 != i16::MIN { LL | | i_16 -= 1; @@ -130,7 +130,7 @@ LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:172:5 + --> $DIR/implicit_saturating_sub.rs:189:5 | LL | / if i_32 > i32::MIN { LL | | i_32 -= 1; @@ -138,7 +138,7 @@ LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:177:5 + --> $DIR/implicit_saturating_sub.rs:195:5 | LL | / if i_32 > i32::MIN { LL | | i_32 -= 1; @@ -146,7 +146,7 @@ LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:182:5 + --> $DIR/implicit_saturating_sub.rs:201:5 | LL | / if i_32 != i32::MIN { LL | | i_32 -= 1; @@ -154,7 +154,7 @@ LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:187:5 + --> $DIR/implicit_saturating_sub.rs:207:5 | LL | / if i_32 != i32::MIN { LL | | i_32 -= 1; @@ -162,7 +162,7 @@ LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:197:5 + --> $DIR/implicit_saturating_sub.rs:218:5 | LL | / if i64::MIN < i_64 { LL | | i_64 -= 1; @@ -170,7 +170,7 @@ LL | | } | |_____^ help: try: `i_64 = i_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:202:5 + --> $DIR/implicit_saturating_sub.rs:224:5 | LL | / if i64::MIN != i_64 { LL | | i_64 -= 1; @@ -178,7 +178,7 @@ LL | | } | |_____^ help: try: `i_64 = i_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:207:5 + --> $DIR/implicit_saturating_sub.rs:230:5 | LL | / if i64::MIN < i_64 { LL | | i_64 -= 1; diff --git a/tests/ui/implied_bounds_in_impls.fixed b/tests/ui/implied_bounds_in_impls.fixed index 18f29e900c15..406d0b4da44f 100644 --- a/tests/ui/implied_bounds_in_impls.fixed +++ b/tests/ui/implied_bounds_in_impls.fixed @@ -9,6 +9,7 @@ fn normal_deref(x: T) -> impl Deref { } // Deref implied by DerefMut +//~v implied_bounds_in_impls fn deref_derefmut(x: T) -> impl DerefMut { Box::new(x) } @@ -27,14 +28,19 @@ impl GenericSubtrait<(), i32, V> for () {} impl GenericSubtrait<(), i64, V> for () {} fn generics_implied() -> impl GenericSubtrait +//~^ implied_bounds_in_impls where (): GenericSubtrait, { } fn generics_implied_multi() -> impl GenericSubtrait<(), i32, V> {} +//~^ implied_bounds_in_impls +//~| implied_bounds_in_impls fn generics_implied_multi2() -> impl GenericSubtrait<(), T, V> +//~^ implied_bounds_in_impls +//~| implied_bounds_in_impls where (): GenericSubtrait<(), T, V> + GenericTrait, { @@ -45,20 +51,24 @@ fn generics_different() -> impl GenericTrait + GenericSubtrait<(), i64, ()> // i32 == i32, GenericSubtrait<_, i32, _> does imply GenericTrait, lint fn generics_same() -> impl GenericSubtrait<(), i32, ()> {} +//~^ implied_bounds_in_impls trait SomeTrait { // Check that it works in trait declarations. fn f() -> impl DerefMut; + //~^ implied_bounds_in_impls } struct SomeStruct; impl SomeStruct { // Check that it works in inherent impl blocks. + //~v implied_bounds_in_impls fn f() -> impl DerefMut { Box::new(123) } } impl SomeTrait for SomeStruct { // Check that it works in trait impls. + //~v implied_bounds_in_impls fn f() -> impl DerefMut { Box::new(42) } @@ -71,7 +81,9 @@ mod issue11422 { // `PartialOrd` has a default generic parameter and does not need to be explicitly specified. // This needs special handling. fn default_generic_param1() -> impl PartialOrd + Debug {} + //~^ implied_bounds_in_impls fn default_generic_param2() -> impl PartialOrd + Debug {} + //~^ implied_bounds_in_impls // Referring to `Self` in the supertrait clause needs special handling. trait Trait1 {} @@ -84,11 +96,13 @@ mod issue11422 { mod issue11435 { // Associated type needs to be included on DoubleEndedIterator in the suggestion + //~v implied_bounds_in_impls fn my_iter() -> impl DoubleEndedIterator { 0..5 } // Removing the `Clone` bound should include the `+` behind it in its remove suggestion + //~v implied_bounds_in_impls fn f() -> impl Copy { 1 } @@ -104,6 +118,7 @@ mod issue11435 { // When the other trait has generics, it shouldn't add another pair of `<>` fn f2() -> impl Trait2 {} + //~^ implied_bounds_in_impls trait Trait3 { type X; @@ -119,6 +134,7 @@ mod issue11435 { // Associated type `X` is specified, but `Y` is not, so only that associated type should be moved // over fn f3() -> impl Trait4 {} + //~^ implied_bounds_in_impls } fn issue11880() { @@ -145,9 +161,10 @@ fn issue11880() { // X::T is never constrained in the first place, so it can be omitted // and left unconstrained - fn f3() -> impl Y {} - fn f4() -> impl Y {} + fn f3() -> impl Y {} //~ implied_bounds_in_impls + fn f4() -> impl Y {} //~ implied_bounds_in_impls fn f5() -> impl Y {} + //~^ implied_bounds_in_impls } fn main() {} diff --git a/tests/ui/implied_bounds_in_impls.rs b/tests/ui/implied_bounds_in_impls.rs index b7951e7dfba8..9640fd6c45ea 100644 --- a/tests/ui/implied_bounds_in_impls.rs +++ b/tests/ui/implied_bounds_in_impls.rs @@ -9,6 +9,7 @@ fn normal_deref(x: T) -> impl Deref { } // Deref implied by DerefMut +//~v implied_bounds_in_impls fn deref_derefmut(x: T) -> impl Deref + DerefMut { Box::new(x) } @@ -27,14 +28,19 @@ impl GenericSubtrait<(), i32, V> for () {} impl GenericSubtrait<(), i64, V> for () {} fn generics_implied() -> impl GenericTrait + GenericSubtrait +//~^ implied_bounds_in_impls where (): GenericSubtrait, { } fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} +//~^ implied_bounds_in_impls +//~| implied_bounds_in_impls fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> +//~^ implied_bounds_in_impls +//~| implied_bounds_in_impls where (): GenericSubtrait<(), T, V> + GenericTrait, { @@ -45,20 +51,24 @@ fn generics_different() -> impl GenericTrait + GenericSubtrait<(), i64, ()> // i32 == i32, GenericSubtrait<_, i32, _> does imply GenericTrait, lint fn generics_same() -> impl GenericTrait + GenericSubtrait<(), i32, ()> {} +//~^ implied_bounds_in_impls trait SomeTrait { // Check that it works in trait declarations. fn f() -> impl Deref + DerefMut; + //~^ implied_bounds_in_impls } struct SomeStruct; impl SomeStruct { // Check that it works in inherent impl blocks. + //~v implied_bounds_in_impls fn f() -> impl Deref + DerefMut { Box::new(123) } } impl SomeTrait for SomeStruct { // Check that it works in trait impls. + //~v implied_bounds_in_impls fn f() -> impl Deref + DerefMut { Box::new(42) } @@ -71,7 +81,9 @@ mod issue11422 { // `PartialOrd` has a default generic parameter and does not need to be explicitly specified. // This needs special handling. fn default_generic_param1() -> impl PartialEq + PartialOrd + Debug {} + //~^ implied_bounds_in_impls fn default_generic_param2() -> impl PartialOrd + PartialEq + Debug {} + //~^ implied_bounds_in_impls // Referring to `Self` in the supertrait clause needs special handling. trait Trait1 {} @@ -84,11 +96,13 @@ mod issue11422 { mod issue11435 { // Associated type needs to be included on DoubleEndedIterator in the suggestion + //~v implied_bounds_in_impls fn my_iter() -> impl Iterator + DoubleEndedIterator { 0..5 } // Removing the `Clone` bound should include the `+` behind it in its remove suggestion + //~v implied_bounds_in_impls fn f() -> impl Copy + Clone { 1 } @@ -104,6 +118,7 @@ mod issue11435 { // When the other trait has generics, it shouldn't add another pair of `<>` fn f2() -> impl Trait1 + Trait2 {} + //~^ implied_bounds_in_impls trait Trait3 { type X; @@ -119,6 +134,7 @@ mod issue11435 { // Associated type `X` is specified, but `Y` is not, so only that associated type should be moved // over fn f3() -> impl Trait3 + Trait4 {} + //~^ implied_bounds_in_impls } fn issue11880() { @@ -145,9 +161,10 @@ fn issue11880() { // X::T is never constrained in the first place, so it can be omitted // and left unconstrained - fn f3() -> impl X + Y {} - fn f4() -> impl X + Y {} + fn f3() -> impl X + Y {} //~ implied_bounds_in_impls + fn f4() -> impl X + Y {} //~ implied_bounds_in_impls fn f5() -> impl X + Y {} + //~^ implied_bounds_in_impls } fn main() {} diff --git a/tests/ui/implied_bounds_in_impls.stderr b/tests/ui/implied_bounds_in_impls.stderr index 3b09e4582e30..bf0344d2b128 100644 --- a/tests/ui/implied_bounds_in_impls.stderr +++ b/tests/ui/implied_bounds_in_impls.stderr @@ -1,5 +1,5 @@ error: this bound is already specified as the supertrait of `DerefMut` - --> $DIR/implied_bounds_in_impls.rs:12:36 + --> $DIR/implied_bounds_in_impls.rs:13:36 | LL | fn deref_derefmut(x: T) -> impl Deref + DerefMut { | ^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + fn deref_derefmut(x: T) -> impl DerefMut { | error: this bound is already specified as the supertrait of `GenericSubtrait` - --> $DIR/implied_bounds_in_impls.rs:29:37 + --> $DIR/implied_bounds_in_impls.rs:30:37 | LL | fn generics_implied() -> impl GenericTrait + GenericSubtrait | ^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + fn generics_implied() -> impl GenericSubtrait | error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, V>` - --> $DIR/implied_bounds_in_impls.rs:35:40 + --> $DIR/implied_bounds_in_impls.rs:37:40 | LL | fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} | ^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + fn generics_implied_multi() -> impl GenericTrait2 + GenericSubtrait<( | error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, V>` - --> $DIR/implied_bounds_in_impls.rs:35:60 + --> $DIR/implied_bounds_in_impls.rs:37:60 | LL | fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} | ^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + fn generics_implied_multi() -> impl GenericTrait + GenericSubtrait< | error: this bound is already specified as the supertrait of `GenericSubtrait<(), T, V>` - --> $DIR/implied_bounds_in_impls.rs:37:44 + --> $DIR/implied_bounds_in_impls.rs:41:44 | LL | fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> | ^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + fn generics_implied_multi2() -> impl GenericTrait2 + GenericSubtra | error: this bound is already specified as the supertrait of `GenericSubtrait<(), T, V>` - --> $DIR/implied_bounds_in_impls.rs:37:62 + --> $DIR/implied_bounds_in_impls.rs:41:62 | LL | fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> | ^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + fn generics_implied_multi2() -> impl GenericTrait + GenericSubtrai | error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, ()>` - --> $DIR/implied_bounds_in_impls.rs:47:28 + --> $DIR/implied_bounds_in_impls.rs:53:28 | LL | fn generics_same() -> impl GenericTrait + GenericSubtrait<(), i32, ()> {} | ^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + fn generics_same() -> impl GenericSubtrait<(), i32, ()> {} | error: this bound is already specified as the supertrait of `DerefMut` - --> $DIR/implied_bounds_in_impls.rs:51:20 + --> $DIR/implied_bounds_in_impls.rs:58:20 | LL | fn f() -> impl Deref + DerefMut; | ^^^^^ @@ -97,7 +97,7 @@ LL + fn f() -> impl DerefMut; | error: this bound is already specified as the supertrait of `DerefMut` - --> $DIR/implied_bounds_in_impls.rs:56:20 + --> $DIR/implied_bounds_in_impls.rs:65:20 | LL | fn f() -> impl Deref + DerefMut { | ^^^^^ @@ -109,7 +109,7 @@ LL + fn f() -> impl DerefMut { | error: this bound is already specified as the supertrait of `DerefMut` - --> $DIR/implied_bounds_in_impls.rs:62:20 + --> $DIR/implied_bounds_in_impls.rs:72:20 | LL | fn f() -> impl Deref + DerefMut { | ^^^^^ @@ -121,7 +121,7 @@ LL + fn f() -> impl DerefMut { | error: this bound is already specified as the supertrait of `PartialOrd` - --> $DIR/implied_bounds_in_impls.rs:73:41 + --> $DIR/implied_bounds_in_impls.rs:83:41 | LL | fn default_generic_param1() -> impl PartialEq + PartialOrd + Debug {} | ^^^^^^^^^ @@ -133,7 +133,7 @@ LL + fn default_generic_param1() -> impl PartialOrd + Debug {} | error: this bound is already specified as the supertrait of `PartialOrd` - --> $DIR/implied_bounds_in_impls.rs:74:54 + --> $DIR/implied_bounds_in_impls.rs:85:54 | LL | fn default_generic_param2() -> impl PartialOrd + PartialEq + Debug {} | ^^^^^^^^^ @@ -145,7 +145,7 @@ LL + fn default_generic_param2() -> impl PartialOrd + Debug {} | error: this bound is already specified as the supertrait of `DoubleEndedIterator` - --> $DIR/implied_bounds_in_impls.rs:87:26 + --> $DIR/implied_bounds_in_impls.rs:100:26 | LL | fn my_iter() -> impl Iterator + DoubleEndedIterator { | ^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + fn my_iter() -> impl DoubleEndedIterator { | error: this bound is already specified as the supertrait of `Copy` - --> $DIR/implied_bounds_in_impls.rs:92:27 + --> $DIR/implied_bounds_in_impls.rs:106:27 | LL | fn f() -> impl Copy + Clone { | ^^^^^ @@ -169,7 +169,7 @@ LL + fn f() -> impl Copy { | error: this bound is already specified as the supertrait of `Trait2` - --> $DIR/implied_bounds_in_impls.rs:106:21 + --> $DIR/implied_bounds_in_impls.rs:120:21 | LL | fn f2() -> impl Trait1 + Trait2 {} | ^^^^^^^^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + fn f2() -> impl Trait2 {} | error: this bound is already specified as the supertrait of `Trait4` - --> $DIR/implied_bounds_in_impls.rs:121:21 + --> $DIR/implied_bounds_in_impls.rs:136:21 | LL | fn f3() -> impl Trait3 + Trait4 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL + fn f3() -> impl Trait4 {} | error: this bound is already specified as the supertrait of `Y` - --> $DIR/implied_bounds_in_impls.rs:148:21 + --> $DIR/implied_bounds_in_impls.rs:164:21 | LL | fn f3() -> impl X + Y {} | ^ @@ -205,7 +205,7 @@ LL + fn f3() -> impl Y {} | error: this bound is already specified as the supertrait of `Y` - --> $DIR/implied_bounds_in_impls.rs:149:21 + --> $DIR/implied_bounds_in_impls.rs:165:21 | LL | fn f4() -> impl X + Y {} | ^ @@ -217,7 +217,7 @@ LL + fn f4() -> impl Y {} | error: this bound is already specified as the supertrait of `Y` - --> $DIR/implied_bounds_in_impls.rs:150:21 + --> $DIR/implied_bounds_in_impls.rs:166:21 | LL | fn f5() -> impl X + Y {} | ^^^^^^^^^^^^^ diff --git a/tests/ui/inconsistent_digit_grouping.fixed b/tests/ui/inconsistent_digit_grouping.fixed index 3f1dfbbae97b..24e162540c22 100644 --- a/tests/ui/inconsistent_digit_grouping.fixed +++ b/tests/ui/inconsistent_digit_grouping.fixed @@ -23,15 +23,20 @@ fn main() { 1.123_456_7_f32, ); let bad = (123_456, 12_345_678, 1_234_567, 1_234.567_8_f32, 1.234_567_8_f32); + //~^ inconsistent_digit_grouping + //~| inconsistent_digit_grouping + //~| inconsistent_digit_grouping + //~| inconsistent_digit_grouping + //~| inconsistent_digit_grouping // Test padding - let _ = 0x0010_0000; - let _ = 0x0100_0000; - let _ = 0x1000_0000; - let _ = 0x0001_0000_0000_u64; + let _ = 0x0010_0000; //~ unreadable_literal + let _ = 0x0100_0000; //~ unreadable_literal + let _ = 0x1000_0000; //~ unreadable_literal + let _ = 0x0001_0000_0000_u64; //~ unreadable_literal // Test suggestion when fraction has no digits - let _: f32 = 123_456.; + let _: f32 = 123_456.; //~ inconsistent_digit_grouping // Test UUID formatted literal let _: u128 = 0x12345678_1234_1234_1234_123456789012; diff --git a/tests/ui/inconsistent_digit_grouping.rs b/tests/ui/inconsistent_digit_grouping.rs index ac47ae175948..0eb9a5021976 100644 --- a/tests/ui/inconsistent_digit_grouping.rs +++ b/tests/ui/inconsistent_digit_grouping.rs @@ -23,15 +23,20 @@ fn main() { 1.123_456_7_f32, ); let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); + //~^ inconsistent_digit_grouping + //~| inconsistent_digit_grouping + //~| inconsistent_digit_grouping + //~| inconsistent_digit_grouping + //~| inconsistent_digit_grouping // Test padding - let _ = 0x100000; - let _ = 0x1000000; - let _ = 0x10000000; - let _ = 0x100000000_u64; + let _ = 0x100000; //~ unreadable_literal + let _ = 0x1000000; //~ unreadable_literal + let _ = 0x10000000; //~ unreadable_literal + let _ = 0x100000000_u64; //~ unreadable_literal // Test suggestion when fraction has no digits - let _: f32 = 1_23_456.; + let _: f32 = 1_23_456.; //~ inconsistent_digit_grouping // Test UUID formatted literal let _: u128 = 0x12345678_1234_1234_1234_123456789012; diff --git a/tests/ui/inconsistent_digit_grouping.stderr b/tests/ui/inconsistent_digit_grouping.stderr index 6aeb33edafd3..62b7288bf80d 100644 --- a/tests/ui/inconsistent_digit_grouping.stderr +++ b/tests/ui/inconsistent_digit_grouping.stderr @@ -32,7 +32,7 @@ LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f | ^^^^^^^^^^^^^^ help: consider: `1.234_567_8_f32` error: long literal lacking separators - --> $DIR/inconsistent_digit_grouping.rs:28:13 + --> $DIR/inconsistent_digit_grouping.rs:33:13 | LL | let _ = 0x100000; | ^^^^^^^^ help: consider: `0x0010_0000` @@ -44,25 +44,25 @@ LL | #[deny(clippy::unreadable_literal)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: long literal lacking separators - --> $DIR/inconsistent_digit_grouping.rs:29:13 + --> $DIR/inconsistent_digit_grouping.rs:34:13 | LL | let _ = 0x1000000; | ^^^^^^^^^ help: consider: `0x0100_0000` error: long literal lacking separators - --> $DIR/inconsistent_digit_grouping.rs:30:13 + --> $DIR/inconsistent_digit_grouping.rs:35:13 | LL | let _ = 0x10000000; | ^^^^^^^^^^ help: consider: `0x1000_0000` error: long literal lacking separators - --> $DIR/inconsistent_digit_grouping.rs:31:13 + --> $DIR/inconsistent_digit_grouping.rs:36:13 | LL | let _ = 0x100000000_u64; | ^^^^^^^^^^^^^^^ help: consider: `0x0001_0000_0000_u64` error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:34:18 + --> $DIR/inconsistent_digit_grouping.rs:39:18 | LL | let _: f32 = 1_23_456.; | ^^^^^^^^^ help: consider: `123_456.` diff --git a/tests/ui/inconsistent_struct_constructor.fixed b/tests/ui/inconsistent_struct_constructor.fixed index 5778f8f526f8..ed25517fd525 100644 --- a/tests/ui/inconsistent_struct_constructor.fixed +++ b/tests/ui/inconsistent_struct_constructor.fixed @@ -25,7 +25,7 @@ mod without_base { let z = 1; // Should lint. - Foo { x, y, z }; + Foo { x, y, z }; //~ inconsistent_struct_constructor // Should NOT lint. // issue #7069. @@ -52,6 +52,7 @@ mod with_base { let z = 1; // Should lint. + //~v inconsistent_struct_constructor Foo { x, z, ..Default::default() }; // Should NOT lint because the order is consistent with the definition. diff --git a/tests/ui/inconsistent_struct_constructor.rs b/tests/ui/inconsistent_struct_constructor.rs index 9efaf0689342..4a60598ec0a9 100644 --- a/tests/ui/inconsistent_struct_constructor.rs +++ b/tests/ui/inconsistent_struct_constructor.rs @@ -25,7 +25,7 @@ mod without_base { let z = 1; // Should lint. - Foo { y, x, z }; + Foo { y, x, z }; //~ inconsistent_struct_constructor // Should NOT lint. // issue #7069. @@ -52,6 +52,7 @@ mod with_base { let z = 1; // Should lint. + //~v inconsistent_struct_constructor Foo { z, x, diff --git a/tests/ui/inconsistent_struct_constructor.stderr b/tests/ui/inconsistent_struct_constructor.stderr index fc080d7ec057..2289dc462386 100644 --- a/tests/ui/inconsistent_struct_constructor.stderr +++ b/tests/ui/inconsistent_struct_constructor.stderr @@ -8,7 +8,7 @@ LL | Foo { y, x, z }; = help: to override `-D warnings` add `#[allow(clippy::inconsistent_struct_constructor)]` error: struct constructor field order is inconsistent with struct definition field order - --> $DIR/inconsistent_struct_constructor.rs:55:9 + --> $DIR/inconsistent_struct_constructor.rs:56:9 | LL | / Foo { LL | | z, diff --git a/tests/ui/indexing_slicing_index.rs b/tests/ui/indexing_slicing_index.rs index 1ac0bb11014a..41a5f998e0a5 100644 --- a/tests/ui/indexing_slicing_index.rs +++ b/tests/ui/indexing_slicing_index.rs @@ -29,9 +29,9 @@ fn main() { x[index]; //~^ ERROR: indexing may panic // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. - x[4]; + x[4]; //~ out_of_bounds_indexing // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. - x[1 << 3]; + x[1 << 3]; //~ out_of_bounds_indexing // Ok, should not produce stderr. x[0]; @@ -52,7 +52,7 @@ fn main() { // Ok, referencing shouldn't affect this lint. See the issue 6021 y[0]; // Ok, rustc will handle references too. - y[4]; + y[4]; //~ out_of_bounds_indexing let v = vec![0; 5]; v[0]; @@ -67,7 +67,7 @@ fn main() { // In bounds const M: usize = 3; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. - x[N]; + x[N]; //~ out_of_bounds_indexing // Ok, should not produce stderr. x[M]; v[N]; @@ -76,5 +76,5 @@ fn main() { //~^ ERROR: indexing may panic let slice = &x; - let _ = x[4]; + let _ = x[4]; //~ out_of_bounds_indexing } diff --git a/tests/ui/inefficient_to_string.fixed b/tests/ui/inefficient_to_string.fixed index 1e19323113c5..9e0e29844a9e 100644 --- a/tests/ui/inefficient_to_string.fixed +++ b/tests/ui/inefficient_to_string.fixed @@ -7,8 +7,8 @@ fn main() { let rrstr: &&str = &rstr; let rrrstr: &&&str = &rrstr; let _: String = rstr.to_string(); - let _: String = (*rrstr).to_string(); - let _: String = (**rrrstr).to_string(); + let _: String = (*rrstr).to_string(); //~ inefficient_to_string + let _: String = (**rrrstr).to_string(); //~ inefficient_to_string let string: String = String::from("hello"); let rstring: &String = &string; @@ -16,8 +16,8 @@ fn main() { let rrrstring: &&&String = &rrstring; let _: String = string.to_string(); let _: String = rstring.to_string(); - let _: String = (*rrstring).to_string(); - let _: String = (**rrrstring).to_string(); + let _: String = (*rrstring).to_string(); //~ inefficient_to_string + let _: String = (**rrrstring).to_string(); //~ inefficient_to_string let cow: Cow<'_, str> = Cow::Borrowed("hello"); let rcow: &Cow<'_, str> = &cow; @@ -25,6 +25,6 @@ fn main() { let rrrcow: &&&Cow<'_, str> = &rrcow; let _: String = cow.to_string(); let _: String = rcow.to_string(); - let _: String = (*rrcow).to_string(); - let _: String = (**rrrcow).to_string(); + let _: String = (*rrcow).to_string(); //~ inefficient_to_string + let _: String = (**rrrcow).to_string(); //~ inefficient_to_string } diff --git a/tests/ui/inefficient_to_string.rs b/tests/ui/inefficient_to_string.rs index f027bae6fe34..332079678ab9 100644 --- a/tests/ui/inefficient_to_string.rs +++ b/tests/ui/inefficient_to_string.rs @@ -7,8 +7,8 @@ fn main() { let rrstr: &&str = &rstr; let rrrstr: &&&str = &rrstr; let _: String = rstr.to_string(); - let _: String = rrstr.to_string(); - let _: String = rrrstr.to_string(); + let _: String = rrstr.to_string(); //~ inefficient_to_string + let _: String = rrrstr.to_string(); //~ inefficient_to_string let string: String = String::from("hello"); let rstring: &String = &string; @@ -16,8 +16,8 @@ fn main() { let rrrstring: &&&String = &rrstring; let _: String = string.to_string(); let _: String = rstring.to_string(); - let _: String = rrstring.to_string(); - let _: String = rrrstring.to_string(); + let _: String = rrstring.to_string(); //~ inefficient_to_string + let _: String = rrrstring.to_string(); //~ inefficient_to_string let cow: Cow<'_, str> = Cow::Borrowed("hello"); let rcow: &Cow<'_, str> = &cow; @@ -25,6 +25,6 @@ fn main() { let rrrcow: &&&Cow<'_, str> = &rrcow; let _: String = cow.to_string(); let _: String = rcow.to_string(); - let _: String = rrcow.to_string(); - let _: String = rrrcow.to_string(); + let _: String = rrcow.to_string(); //~ inefficient_to_string + let _: String = rrrcow.to_string(); //~ inefficient_to_string } diff --git a/tests/ui/infallible_destructuring_match.fixed b/tests/ui/infallible_destructuring_match.fixed index ecf1b14e5b62..922706e1703a 100644 --- a/tests/ui/infallible_destructuring_match.fixed +++ b/tests/ui/infallible_destructuring_match.fixed @@ -25,6 +25,7 @@ fn infallible_destructuring_match_enum() { let wrapper = SingleVariantEnum::Variant(0); // This should lint! + //~v infallible_destructuring_match let SingleVariantEnum::Variant(data) = wrapper; // This shouldn't (inside macro) @@ -55,6 +56,7 @@ fn infallible_destructuring_match_struct() { let wrapper = TupleStruct(0); // This should lint! + //~v infallible_destructuring_match let TupleStruct(data) = wrapper; // This shouldn't (inside macro) @@ -77,6 +79,7 @@ fn infallible_destructuring_match_struct_with_noncopy() { let wrapper = TupleStructWithNonCopy(NonCopy); // This should lint! (keeping `ref` in the suggestion) + //~v infallible_destructuring_match let TupleStructWithNonCopy(ref data) = wrapper; let TupleStructWithNonCopy(ref data) = wrapper; @@ -94,6 +97,7 @@ fn never_enum() { let wrapper: Result = Ok(23); // This should lint! + //~v infallible_destructuring_match let Ok(data) = wrapper; // This shouldn't (inside macro) diff --git a/tests/ui/infallible_destructuring_match.rs b/tests/ui/infallible_destructuring_match.rs index 7cc7cb9d6878..dfd24b161b24 100644 --- a/tests/ui/infallible_destructuring_match.rs +++ b/tests/ui/infallible_destructuring_match.rs @@ -25,6 +25,7 @@ fn infallible_destructuring_match_enum() { let wrapper = SingleVariantEnum::Variant(0); // This should lint! + //~v infallible_destructuring_match let data = match wrapper { SingleVariantEnum::Variant(i) => i, }; @@ -57,6 +58,7 @@ fn infallible_destructuring_match_struct() { let wrapper = TupleStruct(0); // This should lint! + //~v infallible_destructuring_match let data = match wrapper { TupleStruct(i) => i, }; @@ -81,6 +83,7 @@ fn infallible_destructuring_match_struct_with_noncopy() { let wrapper = TupleStructWithNonCopy(NonCopy); // This should lint! (keeping `ref` in the suggestion) + //~v infallible_destructuring_match let data = match wrapper { TupleStructWithNonCopy(ref n) => n, }; @@ -100,6 +103,7 @@ fn never_enum() { let wrapper: Result = Ok(23); // This should lint! + //~v infallible_destructuring_match let data = match wrapper { Ok(i) => i, }; diff --git a/tests/ui/infallible_destructuring_match.stderr b/tests/ui/infallible_destructuring_match.stderr index 93851aae82bd..5d1b7945388a 100644 --- a/tests/ui/infallible_destructuring_match.stderr +++ b/tests/ui/infallible_destructuring_match.stderr @@ -1,5 +1,5 @@ error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let` - --> $DIR/infallible_destructuring_match.rs:28:5 + --> $DIR/infallible_destructuring_match.rs:29:5 | LL | / let data = match wrapper { LL | | SingleVariantEnum::Variant(i) => i, @@ -10,7 +10,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::infallible_destructuring_match)]` error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let` - --> $DIR/infallible_destructuring_match.rs:60:5 + --> $DIR/infallible_destructuring_match.rs:62:5 | LL | / let data = match wrapper { LL | | TupleStruct(i) => i, @@ -18,7 +18,7 @@ LL | | }; | |______^ help: try: `let TupleStruct(data) = wrapper;` error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let` - --> $DIR/infallible_destructuring_match.rs:84:5 + --> $DIR/infallible_destructuring_match.rs:87:5 | LL | / let data = match wrapper { LL | | TupleStructWithNonCopy(ref n) => n, @@ -26,7 +26,7 @@ LL | | }; | |______^ help: try: `let TupleStructWithNonCopy(ref data) = wrapper;` error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let` - --> $DIR/infallible_destructuring_match.rs:103:5 + --> $DIR/infallible_destructuring_match.rs:107:5 | LL | / let data = match wrapper { LL | | Ok(i) => i, diff --git a/tests/ui/infinite_loops.rs b/tests/ui/infinite_loops.rs index 646f1eca56d0..11d0b0124b71 100644 --- a/tests/ui/infinite_loops.rs +++ b/tests/ui/infinite_loops.rs @@ -43,6 +43,7 @@ fn no_break_never_ret() -> ! { } fn no_break_never_ret_noise() { + //~v infinite_loop loop { fn inner_fn() -> ! { std::process::exit(0); @@ -358,6 +359,7 @@ fn inf_loop_in_closure() { } fn inf_loop_in_res() -> Result<(), i32> { + //~v infinite_loop Ok(loop { do_something() }) diff --git a/tests/ui/infinite_loops.stderr b/tests/ui/infinite_loops.stderr index 771fbfa44ee9..50a6e0c39c73 100644 --- a/tests/ui/infinite_loops.stderr +++ b/tests/ui/infinite_loops.stderr @@ -74,7 +74,7 @@ LL | | } = help: if this is not intended, try adding a `break` or `return` condition in the loop error: infinite loop detected - --> $DIR/infinite_loops.rs:46:5 + --> $DIR/infinite_loops.rs:47:5 | LL | / loop { LL | | fn inner_fn() -> ! { @@ -90,7 +90,7 @@ LL | fn no_break_never_ret_noise() -> ! { | ++++ error: infinite loop detected - --> $DIR/infinite_loops.rs:89:5 + --> $DIR/infinite_loops.rs:90:5 | LL | / loop { LL | | @@ -107,7 +107,7 @@ LL | fn break_inner_but_not_outer_1(cond: bool) -> ! { | ++++ error: infinite loop detected - --> $DIR/infinite_loops.rs:100:5 + --> $DIR/infinite_loops.rs:101:5 | LL | / loop { LL | | @@ -124,7 +124,7 @@ LL | fn break_inner_but_not_outer_2(cond: bool) -> ! { | ++++ error: infinite loop detected - --> $DIR/infinite_loops.rs:114:9 + --> $DIR/infinite_loops.rs:115:9 | LL | / loop { LL | | @@ -138,7 +138,7 @@ LL | fn break_outer_but_not_inner() -> ! { | ++++ error: infinite loop detected - --> $DIR/infinite_loops.rs:137:9 + --> $DIR/infinite_loops.rs:138:9 | LL | / loop { LL | | @@ -155,7 +155,7 @@ LL | fn break_wrong_loop(cond: bool) -> ! { | ++++ error: infinite loop detected - --> $DIR/infinite_loops.rs:177:5 + --> $DIR/infinite_loops.rs:178:5 | LL | / loop { LL | | @@ -172,7 +172,7 @@ LL | fn match_like() -> ! { | ++++ error: infinite loop detected - --> $DIR/infinite_loops.rs:218:5 + --> $DIR/infinite_loops.rs:219:5 | LL | / loop { LL | | @@ -186,7 +186,7 @@ LL | fn match_like() -> ! { | ++++ error: infinite loop detected - --> $DIR/infinite_loops.rs:223:5 + --> $DIR/infinite_loops.rs:224:5 | LL | / loop { LL | | @@ -203,7 +203,7 @@ LL | fn match_like() -> ! { | ++++ error: infinite loop detected - --> $DIR/infinite_loops.rs:328:9 + --> $DIR/infinite_loops.rs:329:9 | LL | / loop { LL | | @@ -217,7 +217,7 @@ LL | fn problematic_trait_method() -> ! { | ++++ error: infinite loop detected - --> $DIR/infinite_loops.rs:338:9 + --> $DIR/infinite_loops.rs:339:9 | LL | / loop { LL | | @@ -231,7 +231,7 @@ LL | fn could_be_problematic() -> ! { | ++++ error: infinite loop detected - --> $DIR/infinite_loops.rs:347:9 + --> $DIR/infinite_loops.rs:348:9 | LL | / loop { LL | | @@ -245,7 +245,7 @@ LL | let _loop_forever = || -> ! { | ++++ error: infinite loop detected - --> $DIR/infinite_loops.rs:361:8 + --> $DIR/infinite_loops.rs:363:8 | LL | Ok(loop { | ________^ diff --git a/tests/ui/inline_fn_without_body.fixed b/tests/ui/inline_fn_without_body.fixed index acd808ed49bb..0ff7589ec9c3 100644 --- a/tests/ui/inline_fn_without_body.fixed +++ b/tests/ui/inline_fn_without_body.fixed @@ -2,10 +2,13 @@ #![allow(clippy::inline_always)] trait Foo { + //~ inline_fn_without_body fn default_inline(); + //~ inline_fn_without_body fn always_inline(); + //~ inline_fn_without_body fn never_inline(); #[inline] diff --git a/tests/ui/inline_fn_without_body.rs b/tests/ui/inline_fn_without_body.rs index af81feaa374a..e1163177b0b8 100644 --- a/tests/ui/inline_fn_without_body.rs +++ b/tests/ui/inline_fn_without_body.rs @@ -2,13 +2,13 @@ #![allow(clippy::inline_always)] trait Foo { - #[inline] + #[inline] //~ inline_fn_without_body fn default_inline(); - #[inline(always)] + #[inline(always)] //~ inline_fn_without_body fn always_inline(); - #[inline(never)] + #[inline(never)] //~ inline_fn_without_body fn never_inline(); #[inline] diff --git a/tests/ui/inline_fn_without_body.stderr b/tests/ui/inline_fn_without_body.stderr index 60f6eb8dff08..db65aa07b095 100644 --- a/tests/ui/inline_fn_without_body.stderr +++ b/tests/ui/inline_fn_without_body.stderr @@ -1,10 +1,10 @@ error: use of `#[inline]` on trait method `default_inline` which has no body --> $DIR/inline_fn_without_body.rs:5:5 | -LL | #[inline] - | _____-^^^^^^^^ -LL | | fn default_inline(); - | |____- help: remove +LL | #[inline] + | ^^^^^^^^^- + | | + | help: remove | = note: `-D clippy::inline-fn-without-body` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::inline_fn_without_body)]` @@ -12,18 +12,18 @@ LL | | fn default_inline(); error: use of `#[inline]` on trait method `always_inline` which has no body --> $DIR/inline_fn_without_body.rs:8:5 | -LL | #[inline(always)] - | _____-^^^^^^^^^^^^^^^^ -LL | | fn always_inline(); - | |____- help: remove +LL | #[inline(always)] + | ^^^^^^^^^^^^^^^^^- + | | + | help: remove error: use of `#[inline]` on trait method `never_inline` which has no body --> $DIR/inline_fn_without_body.rs:11:5 | -LL | #[inline(never)] - | _____-^^^^^^^^^^^^^^^ -LL | | fn never_inline(); - | |____- help: remove +LL | #[inline(never)] + | ^^^^^^^^^^^^^^^^- + | | + | help: remove error: aborting due to 3 previous errors diff --git a/tests/ui/int_plus_one.fixed b/tests/ui/int_plus_one.fixed index 77d9cd3f773a..b66f9ffacfb9 100644 --- a/tests/ui/int_plus_one.fixed +++ b/tests/ui/int_plus_one.fixed @@ -4,11 +4,11 @@ fn main() { let x = 1i32; let y = 0i32; - let _ = x > y; - let _ = y < x; + let _ = x > y; //~ int_plus_one + let _ = y < x; //~ int_plus_one - let _ = x > y; - let _ = y < x; + let _ = x > y; //~ int_plus_one + let _ = y < x; //~ int_plus_one let _ = x > y; // should be ok let _ = y < x; // should be ok diff --git a/tests/ui/int_plus_one.rs b/tests/ui/int_plus_one.rs index 57c87819dbfe..2dee6c2c3dbf 100644 --- a/tests/ui/int_plus_one.rs +++ b/tests/ui/int_plus_one.rs @@ -4,11 +4,11 @@ fn main() { let x = 1i32; let y = 0i32; - let _ = x >= y + 1; - let _ = y + 1 <= x; + let _ = x >= y + 1; //~ int_plus_one + let _ = y + 1 <= x; //~ int_plus_one - let _ = x - 1 >= y; - let _ = y <= x - 1; + let _ = x - 1 >= y; //~ int_plus_one + let _ = y <= x - 1; //~ int_plus_one let _ = x > y; // should be ok let _ = y < x; // should be ok diff --git a/tests/ui/into_iter_without_iter.rs b/tests/ui/into_iter_without_iter.rs index c8b9076041a3..841152a8d312 100644 --- a/tests/ui/into_iter_without_iter.rs +++ b/tests/ui/into_iter_without_iter.rs @@ -117,6 +117,7 @@ impl IntoIterator for &Alias { pub struct Issue12037; macro_rules! generate_impl { () => { + //~v into_iter_without_iter impl<'a> IntoIterator for &'a Issue12037 { type IntoIter = std::slice::Iter<'a, u8>; type Item = &'a u8; diff --git a/tests/ui/into_iter_without_iter.stderr b/tests/ui/into_iter_without_iter.stderr index a232c7cecc57..1f9d2d74ccb2 100644 --- a/tests/ui/into_iter_without_iter.stderr +++ b/tests/ui/into_iter_without_iter.stderr @@ -111,7 +111,7 @@ LL + } | error: `IntoIterator` implemented for a reference type without an `iter` method - --> $DIR/into_iter_without_iter.rs:120:9 + --> $DIR/into_iter_without_iter.rs:121:9 | LL | / impl<'a> IntoIterator for &'a Issue12037 { LL | | type IntoIter = std::slice::Iter<'a, u8>; diff --git a/tests/ui/invalid_null_ptr_usage.fixed b/tests/ui/invalid_null_ptr_usage.fixed index eeddc2349a13..377fe6144133 100644 --- a/tests/ui/invalid_null_ptr_usage.fixed +++ b/tests/ui/invalid_null_ptr_usage.fixed @@ -1,47 +1,72 @@ fn main() { unsafe { let _slice: &[usize] = std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage let _slice: &[usize] = std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage let _slice: &[usize] = std::slice::from_raw_parts_mut(core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage std::ptr::copy::(core::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage std::ptr::copy::(std::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage std::ptr::copy_nonoverlapping::(core::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage std::ptr::copy_nonoverlapping::(std::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage struct A; // zero sized struct assert_eq!(std::mem::size_of::(), 0); let _a: A = std::ptr::read(core::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read(core::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read_unaligned(core::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read_unaligned(core::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read_volatile(core::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read_volatile(core::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::replace(core::ptr::NonNull::dangling().as_ptr(), A); + //~^ invalid_null_ptr_usage let _slice: *const [usize] = std::ptr::slice_from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage let _slice: *const [usize] = std::ptr::slice_from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage let _slice: *const [usize] = std::ptr::slice_from_raw_parts_mut(core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage std::ptr::swap::(core::ptr::NonNull::dangling().as_ptr(), &mut A); + //~^ invalid_null_ptr_usage std::ptr::swap::(&mut A, core::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage std::ptr::swap_nonoverlapping::(core::ptr::NonNull::dangling().as_ptr(), &mut A, 0); + //~^ invalid_null_ptr_usage std::ptr::swap_nonoverlapping::(&mut A, core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage std::ptr::write(core::ptr::NonNull::dangling().as_ptr(), A); + //~^ invalid_null_ptr_usage std::ptr::write_unaligned(core::ptr::NonNull::dangling().as_ptr(), A); + //~^ invalid_null_ptr_usage std::ptr::write_volatile(core::ptr::NonNull::dangling().as_ptr(), A); + //~^ invalid_null_ptr_usage std::ptr::write_bytes::(core::ptr::NonNull::dangling().as_ptr(), 42, 0); + //~^ invalid_null_ptr_usage } } diff --git a/tests/ui/invalid_null_ptr_usage.rs b/tests/ui/invalid_null_ptr_usage.rs index 8569b7740845..1f5c9595ad93 100644 --- a/tests/ui/invalid_null_ptr_usage.rs +++ b/tests/ui/invalid_null_ptr_usage.rs @@ -1,47 +1,72 @@ fn main() { unsafe { let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null(), 0); + //~^ invalid_null_ptr_usage let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null_mut(), 0); + //~^ invalid_null_ptr_usage let _slice: &[usize] = std::slice::from_raw_parts_mut(std::ptr::null_mut(), 0); + //~^ invalid_null_ptr_usage std::ptr::copy::(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage std::ptr::copy::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); + //~^ invalid_null_ptr_usage std::ptr::copy_nonoverlapping::(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage std::ptr::copy_nonoverlapping::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); + //~^ invalid_null_ptr_usage struct A; // zero sized struct assert_eq!(std::mem::size_of::(), 0); let _a: A = std::ptr::read(std::ptr::null()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read(std::ptr::null_mut()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read_unaligned(std::ptr::null()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read_unaligned(std::ptr::null_mut()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read_volatile(std::ptr::null()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read_volatile(std::ptr::null_mut()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::replace(std::ptr::null_mut(), A); + //~^ invalid_null_ptr_usage let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null(), 0); + //~^ invalid_null_ptr_usage let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null_mut(), 0); + //~^ invalid_null_ptr_usage let _slice: *const [usize] = std::ptr::slice_from_raw_parts_mut(std::ptr::null_mut(), 0); + //~^ invalid_null_ptr_usage std::ptr::swap::(std::ptr::null_mut(), &mut A); + //~^ invalid_null_ptr_usage std::ptr::swap::(&mut A, std::ptr::null_mut()); + //~^ invalid_null_ptr_usage std::ptr::swap_nonoverlapping::(std::ptr::null_mut(), &mut A, 0); + //~^ invalid_null_ptr_usage std::ptr::swap_nonoverlapping::(&mut A, std::ptr::null_mut(), 0); + //~^ invalid_null_ptr_usage std::ptr::write(std::ptr::null_mut(), A); + //~^ invalid_null_ptr_usage std::ptr::write_unaligned(std::ptr::null_mut(), A); + //~^ invalid_null_ptr_usage std::ptr::write_volatile(std::ptr::null_mut(), A); + //~^ invalid_null_ptr_usage std::ptr::write_bytes::(std::ptr::null_mut(), 42, 0); + //~^ invalid_null_ptr_usage } } diff --git a/tests/ui/invalid_null_ptr_usage.stderr b/tests/ui/invalid_null_ptr_usage.stderr index 22efa0d84ad4..a2d13daeebf0 100644 --- a/tests/ui/invalid_null_ptr_usage.stderr +++ b/tests/ui/invalid_null_ptr_usage.stderr @@ -7,145 +7,145 @@ LL | let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null(), = note: `#[deny(clippy::invalid_null_ptr_usage)]` on by default error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:4:59 + --> $DIR/invalid_null_ptr_usage.rs:5:59 | LL | let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:6:63 + --> $DIR/invalid_null_ptr_usage.rs:8:63 | LL | let _slice: &[usize] = std::slice::from_raw_parts_mut(std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:8:33 + --> $DIR/invalid_null_ptr_usage.rs:11:33 | LL | std::ptr::copy::(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:9:73 + --> $DIR/invalid_null_ptr_usage.rs:13:73 | LL | std::ptr::copy::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:11:48 + --> $DIR/invalid_null_ptr_usage.rs:16:48 | LL | std::ptr::copy_nonoverlapping::(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:12:88 + --> $DIR/invalid_null_ptr_usage.rs:18:88 | LL | std::ptr::copy_nonoverlapping::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:17:36 + --> $DIR/invalid_null_ptr_usage.rs:24:36 | LL | let _a: A = std::ptr::read(std::ptr::null()); | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:18:36 + --> $DIR/invalid_null_ptr_usage.rs:26:36 | LL | let _a: A = std::ptr::read(std::ptr::null_mut()); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:20:46 + --> $DIR/invalid_null_ptr_usage.rs:29:46 | LL | let _a: A = std::ptr::read_unaligned(std::ptr::null()); | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:21:46 + --> $DIR/invalid_null_ptr_usage.rs:31:46 | LL | let _a: A = std::ptr::read_unaligned(std::ptr::null_mut()); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:23:45 + --> $DIR/invalid_null_ptr_usage.rs:34:45 | LL | let _a: A = std::ptr::read_volatile(std::ptr::null()); | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:24:45 + --> $DIR/invalid_null_ptr_usage.rs:36:45 | LL | let _a: A = std::ptr::read_volatile(std::ptr::null_mut()); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:26:39 + --> $DIR/invalid_null_ptr_usage.rs:39:39 | LL | let _a: A = std::ptr::replace(std::ptr::null_mut(), A); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:28:69 + --> $DIR/invalid_null_ptr_usage.rs:42:69 | LL | let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null(), 0); | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:29:69 + --> $DIR/invalid_null_ptr_usage.rs:44:69 | LL | let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:31:73 + --> $DIR/invalid_null_ptr_usage.rs:47:73 | LL | let _slice: *const [usize] = std::ptr::slice_from_raw_parts_mut(std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:33:29 + --> $DIR/invalid_null_ptr_usage.rs:50:29 | LL | std::ptr::swap::(std::ptr::null_mut(), &mut A); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:34:37 + --> $DIR/invalid_null_ptr_usage.rs:52:37 | LL | std::ptr::swap::(&mut A, std::ptr::null_mut()); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:36:44 + --> $DIR/invalid_null_ptr_usage.rs:55:44 | LL | std::ptr::swap_nonoverlapping::(std::ptr::null_mut(), &mut A, 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:37:52 + --> $DIR/invalid_null_ptr_usage.rs:57:52 | LL | std::ptr::swap_nonoverlapping::(&mut A, std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:39:25 + --> $DIR/invalid_null_ptr_usage.rs:60:25 | LL | std::ptr::write(std::ptr::null_mut(), A); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:41:35 + --> $DIR/invalid_null_ptr_usage.rs:63:35 | LL | std::ptr::write_unaligned(std::ptr::null_mut(), A); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:43:34 + --> $DIR/invalid_null_ptr_usage.rs:66:34 | LL | std::ptr::write_volatile(std::ptr::null_mut(), A); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:45:40 + --> $DIR/invalid_null_ptr_usage.rs:69:40 | LL | std::ptr::write_bytes::(std::ptr::null_mut(), 42, 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` diff --git a/tests/ui/is_digit_ascii_radix.fixed b/tests/ui/is_digit_ascii_radix.fixed index 62953ff74cfc..1296ca0b8ab0 100644 --- a/tests/ui/is_digit_ascii_radix.fixed +++ b/tests/ui/is_digit_ascii_radix.fixed @@ -6,9 +6,9 @@ fn main() { let c: char = '6'; // Should trigger the lint. - let _ = c.is_ascii_digit(); - let _ = c.is_ascii_hexdigit(); - let _ = c.is_ascii_hexdigit(); + let _ = c.is_ascii_digit(); //~ is_digit_ascii_radix + let _ = c.is_ascii_hexdigit(); //~ is_digit_ascii_radix + let _ = c.is_ascii_hexdigit(); //~ is_digit_ascii_radix // Should not trigger the lint. let _ = c.is_digit(11); diff --git a/tests/ui/is_digit_ascii_radix.rs b/tests/ui/is_digit_ascii_radix.rs index 229f530f611d..1c5ca10175a7 100644 --- a/tests/ui/is_digit_ascii_radix.rs +++ b/tests/ui/is_digit_ascii_radix.rs @@ -6,9 +6,9 @@ fn main() { let c: char = '6'; // Should trigger the lint. - let _ = c.is_digit(10); - let _ = c.is_digit(16); - let _ = c.is_digit(0x10); + let _ = c.is_digit(10); //~ is_digit_ascii_radix + let _ = c.is_digit(16); //~ is_digit_ascii_radix + let _ = c.is_digit(0x10); //~ is_digit_ascii_radix // Should not trigger the lint. let _ = c.is_digit(11); diff --git a/tests/ui/issue_2356.fixed b/tests/ui/issue_2356.fixed index 892aa4e34216..bcd33f00546b 100644 --- a/tests/ui/issue_2356.fixed +++ b/tests/ui/issue_2356.fixed @@ -14,6 +14,7 @@ impl Foo { } fn foo2>(mut it: I) { + //~v while_let_on_iterator for e in it { println!("{:?}", e); } diff --git a/tests/ui/issue_2356.rs b/tests/ui/issue_2356.rs index da0eead15b39..95b41a280124 100644 --- a/tests/ui/issue_2356.rs +++ b/tests/ui/issue_2356.rs @@ -14,6 +14,7 @@ impl Foo { } fn foo2>(mut it: I) { + //~v while_let_on_iterator while let Some(e) = it.next() { println!("{:?}", e); } diff --git a/tests/ui/issue_2356.stderr b/tests/ui/issue_2356.stderr index 860c545c7b82..91aa29e56a00 100644 --- a/tests/ui/issue_2356.stderr +++ b/tests/ui/issue_2356.stderr @@ -1,5 +1,5 @@ error: this loop could be written as a `for` loop - --> $DIR/issue_2356.rs:17:9 + --> $DIR/issue_2356.rs:18:9 | LL | while let Some(e) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for e in it` diff --git a/tests/ui/items_after_statement.rs b/tests/ui/items_after_statement.rs index 943e7c116760..725f54ebf1e2 100644 --- a/tests/ui/items_after_statement.rs +++ b/tests/ui/items_after_statement.rs @@ -33,6 +33,7 @@ fn mac() { macro_rules! b { () => {{ a = 6; + //~v items_after_statements fn say_something() { println!("something"); } diff --git a/tests/ui/items_after_statement.stderr b/tests/ui/items_after_statement.stderr index fa494f217489..efee5dd5f182 100644 --- a/tests/ui/items_after_statement.stderr +++ b/tests/ui/items_after_statement.stderr @@ -21,7 +21,7 @@ LL | | } | |_____^ error: adding items after statements is confusing, since items exist from the start of the scope - --> $DIR/items_after_statement.rs:36:13 + --> $DIR/items_after_statement.rs:37:13 | LL | / fn say_something() { LL | | println!("something"); diff --git a/tests/ui/items_after_test_module/root_module.fixed b/tests/ui/items_after_test_module/root_module.fixed index d444100a76b9..adadb25a6e3b 100644 --- a/tests/ui/items_after_test_module/root_module.fixed +++ b/tests/ui/items_after_test_module/root_module.fixed @@ -16,6 +16,7 @@ macro_rules! should_lint { #[allow(unused)] // Some attributes to check that span replacement is good enough #[allow(clippy::allow_attributes)] #[cfg(test)] +//~v items_after_test_module mod tests { #[test] fn hi() {} diff --git a/tests/ui/items_after_test_module/root_module.rs b/tests/ui/items_after_test_module/root_module.rs index 57da01639cca..53944e6c90cb 100644 --- a/tests/ui/items_after_test_module/root_module.rs +++ b/tests/ui/items_after_test_module/root_module.rs @@ -9,6 +9,7 @@ fn should_not_lint() {} #[allow(unused)] // Some attributes to check that span replacement is good enough #[allow(clippy::allow_attributes)] #[cfg(test)] +//~v items_after_test_module mod tests { #[test] fn hi() {} diff --git a/tests/ui/items_after_test_module/root_module.stderr b/tests/ui/items_after_test_module/root_module.stderr index b736b166295d..9ed735265590 100644 --- a/tests/ui/items_after_test_module/root_module.stderr +++ b/tests/ui/items_after_test_module/root_module.stderr @@ -1,5 +1,5 @@ error: items after a test module - --> $DIR/items_after_test_module/root_module.rs:12:1 + --> $DIR/items_after_test_module/root_module.rs:13:1 | LL | mod tests { | ^^^^^^^^^ diff --git a/tests/ui/iter_cloned_collect.fixed b/tests/ui/iter_cloned_collect.fixed index 1d623642a713..b96ce859d63f 100644 --- a/tests/ui/iter_cloned_collect.fixed +++ b/tests/ui/iter_cloned_collect.fixed @@ -6,22 +6,27 @@ use std::collections::{HashSet, VecDeque}; fn main() { let v = [1, 2, 3, 4, 5]; let v2: Vec = v.to_vec(); + //~^ iter_cloned_collect let v3: HashSet = v.iter().cloned().collect(); let v4: VecDeque = v.iter().cloned().collect(); // Handle macro expansion in suggestion let _: Vec = vec![1, 2, 3].to_vec(); + //~^ iter_cloned_collect // Issue #3704 unsafe { let _: Vec = std::ffi::CStr::from_ptr(std::ptr::null()) + //~v iter_cloned_collect .to_bytes().to_vec(); } // Issue #6808 let arr: [u8; 64] = [0; 64]; let _: Vec<_> = arr.to_vec(); + //~^ iter_cloned_collect // Issue #6703 let _: Vec = v.to_vec(); + //~^ iter_cloned_collect } diff --git a/tests/ui/iter_cloned_collect.rs b/tests/ui/iter_cloned_collect.rs index 091bd9eaf081..75dda3f69948 100644 --- a/tests/ui/iter_cloned_collect.rs +++ b/tests/ui/iter_cloned_collect.rs @@ -6,15 +6,18 @@ use std::collections::{HashSet, VecDeque}; fn main() { let v = [1, 2, 3, 4, 5]; let v2: Vec = v.iter().cloned().collect(); + //~^ iter_cloned_collect let v3: HashSet = v.iter().cloned().collect(); let v4: VecDeque = v.iter().cloned().collect(); // Handle macro expansion in suggestion let _: Vec = vec![1, 2, 3].iter().cloned().collect(); + //~^ iter_cloned_collect // Issue #3704 unsafe { let _: Vec = std::ffi::CStr::from_ptr(std::ptr::null()) + //~v iter_cloned_collect .to_bytes() .iter() .cloned() @@ -24,7 +27,9 @@ fn main() { // Issue #6808 let arr: [u8; 64] = [0; 64]; let _: Vec<_> = arr.iter().cloned().collect(); + //~^ iter_cloned_collect // Issue #6703 let _: Vec = v.iter().copied().collect(); + //~^ iter_cloned_collect } diff --git a/tests/ui/iter_cloned_collect.stderr b/tests/ui/iter_cloned_collect.stderr index aa7fb98a7c8a..692c7f831144 100644 --- a/tests/ui/iter_cloned_collect.stderr +++ b/tests/ui/iter_cloned_collect.stderr @@ -8,13 +8,13 @@ LL | let v2: Vec = v.iter().cloned().collect(); = help: to override `-D warnings` add `#[allow(clippy::iter_cloned_collect)]` error: called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable - --> $DIR/iter_cloned_collect.rs:13:38 + --> $DIR/iter_cloned_collect.rs:14:38 | LL | let _: Vec = vec![1, 2, 3].iter().cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()` error: called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable - --> $DIR/iter_cloned_collect.rs:18:24 + --> $DIR/iter_cloned_collect.rs:21:24 | LL | .to_bytes() | ________________________^ @@ -24,13 +24,13 @@ LL | | .collect(); | |______________________^ help: try: `.to_vec()` error: called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable - --> $DIR/iter_cloned_collect.rs:26:24 + --> $DIR/iter_cloned_collect.rs:29:24 | LL | let _: Vec<_> = arr.iter().cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()` error: called `iter().copied().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable - --> $DIR/iter_cloned_collect.rs:29:26 + --> $DIR/iter_cloned_collect.rs:33:26 | LL | let _: Vec = v.iter().copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()` diff --git a/tests/ui/iter_count.fixed b/tests/ui/iter_count.fixed index 75c007bb0c99..f81b2309294e 100644 --- a/tests/ui/iter_count.fixed +++ b/tests/ui/iter_count.fixed @@ -51,33 +51,33 @@ fn main() { linked_list.push_back(1); binary_heap.push(1); - &vec[..].len(); - vec.len(); - boxed_slice.len(); - vec_deque.len(); - hash_set.len(); - hash_map.len(); - b_tree_map.len(); - b_tree_set.len(); - linked_list.len(); - binary_heap.len(); + &vec[..].len(); //~ iter_count + vec.len(); //~ iter_count + boxed_slice.len(); //~ iter_count + vec_deque.len(); //~ iter_count + hash_set.len(); //~ iter_count + hash_map.len(); //~ iter_count + b_tree_map.len(); //~ iter_count + b_tree_set.len(); //~ iter_count + linked_list.len(); //~ iter_count + binary_heap.len(); //~ iter_count - vec.len(); - &vec[..].len(); - vec_deque.len(); - hash_map.len(); - b_tree_map.len(); - linked_list.len(); + vec.len(); //~ iter_count + &vec[..].len(); //~ iter_count + vec_deque.len(); //~ iter_count + hash_map.len(); //~ iter_count + b_tree_map.len(); //~ iter_count + linked_list.len(); //~ iter_count - &vec[..].len(); - vec.len(); - vec_deque.len(); - hash_set.len(); - hash_map.len(); - b_tree_map.len(); - b_tree_set.len(); - linked_list.len(); - binary_heap.len(); + &vec[..].len(); //~ iter_count + vec.len(); //~ iter_count + vec_deque.len(); //~ iter_count + hash_set.len(); //~ iter_count + hash_map.len(); //~ iter_count + b_tree_map.len(); //~ iter_count + b_tree_set.len(); //~ iter_count + linked_list.len(); //~ iter_count + binary_heap.len(); //~ iter_count // Make sure we don't lint for non-relevant types. let false_positive = HasIter; diff --git a/tests/ui/iter_count.rs b/tests/ui/iter_count.rs index cd8207b2c5dc..dabdc9eca04d 100644 --- a/tests/ui/iter_count.rs +++ b/tests/ui/iter_count.rs @@ -51,33 +51,33 @@ fn main() { linked_list.push_back(1); binary_heap.push(1); - &vec[..].iter().count(); - vec.iter().count(); - boxed_slice.iter().count(); - vec_deque.iter().count(); - hash_set.iter().count(); - hash_map.iter().count(); - b_tree_map.iter().count(); - b_tree_set.iter().count(); - linked_list.iter().count(); - binary_heap.iter().count(); + &vec[..].iter().count(); //~ iter_count + vec.iter().count(); //~ iter_count + boxed_slice.iter().count(); //~ iter_count + vec_deque.iter().count(); //~ iter_count + hash_set.iter().count(); //~ iter_count + hash_map.iter().count(); //~ iter_count + b_tree_map.iter().count(); //~ iter_count + b_tree_set.iter().count(); //~ iter_count + linked_list.iter().count(); //~ iter_count + binary_heap.iter().count(); //~ iter_count - vec.iter_mut().count(); - &vec[..].iter_mut().count(); - vec_deque.iter_mut().count(); - hash_map.iter_mut().count(); - b_tree_map.iter_mut().count(); - linked_list.iter_mut().count(); + vec.iter_mut().count(); //~ iter_count + &vec[..].iter_mut().count(); //~ iter_count + vec_deque.iter_mut().count(); //~ iter_count + hash_map.iter_mut().count(); //~ iter_count + b_tree_map.iter_mut().count(); //~ iter_count + linked_list.iter_mut().count(); //~ iter_count - &vec[..].into_iter().count(); - vec.into_iter().count(); - vec_deque.into_iter().count(); - hash_set.into_iter().count(); - hash_map.into_iter().count(); - b_tree_map.into_iter().count(); - b_tree_set.into_iter().count(); - linked_list.into_iter().count(); - binary_heap.into_iter().count(); + &vec[..].into_iter().count(); //~ iter_count + vec.into_iter().count(); //~ iter_count + vec_deque.into_iter().count(); //~ iter_count + hash_set.into_iter().count(); //~ iter_count + hash_map.into_iter().count(); //~ iter_count + b_tree_map.into_iter().count(); //~ iter_count + b_tree_set.into_iter().count(); //~ iter_count + linked_list.into_iter().count(); //~ iter_count + binary_heap.into_iter().count(); //~ iter_count // Make sure we don't lint for non-relevant types. let false_positive = HasIter; diff --git a/tests/ui/iter_filter_is_ok.fixed b/tests/ui/iter_filter_is_ok.fixed index 80db8b29c18e..cffc1ccdc798 100644 --- a/tests/ui/iter_filter_is_ok.fixed +++ b/tests/ui/iter_filter_is_ok.fixed @@ -9,51 +9,51 @@ fn main() { { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok } { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok } { let _ = vec![Ok(1), Err(2), Ok(3)] .into_iter() .flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok let _ = vec![Ok(1), Err(2), Ok(3)] .into_iter() .flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok #[rustfmt::skip] let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok } { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok } } diff --git a/tests/ui/iter_filter_is_ok.rs b/tests/ui/iter_filter_is_ok.rs index b023bd50cc46..26c71b699539 100644 --- a/tests/ui/iter_filter_is_ok.rs +++ b/tests/ui/iter_filter_is_ok.rs @@ -9,39 +9,51 @@ fn main() { { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(Result::is_ok); + //~^ iter_filter_is_ok let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|a| a.is_ok()); + //~^ iter_filter_is_ok #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().filter(|o| { o.is_ok() }); + //~^ iter_filter_is_ok } { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|&a| a.is_ok()); + //~^ iter_filter_is_ok let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|&a| a.is_ok()); + //~^ iter_filter_is_ok #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().filter(|&o| { o.is_ok() }); + //~^ iter_filter_is_ok } { let _ = vec![Ok(1), Err(2), Ok(3)] .into_iter() .filter(std::result::Result::is_ok); + //~^ iter_filter_is_ok let _ = vec![Ok(1), Err(2), Ok(3)] .into_iter() .filter(|a| std::result::Result::is_ok(a)); + //~^ iter_filter_is_ok #[rustfmt::skip] let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|a| { std::result::Result::is_ok(a) }); + //~^ iter_filter_is_ok } { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|ref a| a.is_ok()); + //~^ iter_filter_is_ok let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|ref a| a.is_ok()); + //~^ iter_filter_is_ok #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().filter(|ref o| { o.is_ok() }); + //~^ iter_filter_is_ok } } diff --git a/tests/ui/iter_filter_is_some.fixed b/tests/ui/iter_filter_is_some.fixed index abc3a47fa46a..fb4a9a4faed1 100644 --- a/tests/ui/iter_filter_is_some.fixed +++ b/tests/ui/iter_filter_is_some.fixed @@ -12,45 +12,45 @@ use std::collections::HashMap; fn main() { { let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some } { let _ = vec![Some(1), None, Some(3)] .into_iter() .flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some let _ = vec![Some(1), None, Some(3)] .into_iter() .flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some } { let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some } { let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some } } diff --git a/tests/ui/iter_filter_is_some.rs b/tests/ui/iter_filter_is_some.rs index 35ae092d45af..999ea55c1607 100644 --- a/tests/ui/iter_filter_is_some.rs +++ b/tests/ui/iter_filter_is_some.rs @@ -12,35 +12,45 @@ use std::collections::HashMap; fn main() { { let _ = vec![Some(1), None, Some(3)].into_iter().filter(Option::is_some); + //~^ iter_filter_is_some let _ = vec![Some(1), None, Some(3)].into_iter().filter(|a| a.is_some()); + //~^ iter_filter_is_some #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().filter(|o| { o.is_some() }); + //~^ iter_filter_is_some } { let _ = vec![Some(1), None, Some(3)] .into_iter() .filter(std::option::Option::is_some); + //~^ iter_filter_is_some let _ = vec![Some(1), None, Some(3)] .into_iter() .filter(|a| std::option::Option::is_some(a)); + //~^ iter_filter_is_some #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().filter(|a| { std::option::Option::is_some(a) }); + //~^ iter_filter_is_some } { let _ = vec![Some(1), None, Some(3)].into_iter().filter(|&a| a.is_some()); + //~^ iter_filter_is_some #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().filter(|&o| { o.is_some() }); + //~^ iter_filter_is_some } { let _ = vec![Some(1), None, Some(3)].into_iter().filter(|ref a| a.is_some()); + //~^ iter_filter_is_some #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().filter(|ref o| { o.is_some() }); + //~^ iter_filter_is_some } } diff --git a/tests/ui/iter_kv_map.fixed b/tests/ui/iter_kv_map.fixed index 2cbf972fca5f..e98ef04322d6 100644 --- a/tests/ui/iter_kv_map.fixed +++ b/tests/ui/iter_kv_map.fixed @@ -12,17 +12,26 @@ fn main() { let map: HashMap = HashMap::new(); let _ = map.keys().collect::>(); + //~^ iter_kv_map let _ = map.values().collect::>(); + //~^ iter_kv_map let _ = map.values().map(|v| v + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_keys().collect::>(); + //~^ iter_kv_map let _ = map.clone().into_keys().map(|key| key + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_values().collect::>(); + //~^ iter_kv_map let _ = map.clone().into_values().map(|val| val + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().values().collect::>(); + //~^ iter_kv_map let _ = map.keys().filter(|x| *x % 2 == 0).count(); + //~^ iter_kv_map // Don't lint let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count(); @@ -33,12 +42,16 @@ fn main() { // Lint let _ = map.keys().map(|key| key * 9).count(); + //~^ iter_kv_map let _ = map.values().map(|value| value * 17).count(); + //~^ iter_kv_map // Preserve the ref in the fix. let _ = map.clone().into_values().map(|ref val| ref_acceptor(val)).count(); + //~^ iter_kv_map // Preserve the mut in the fix. + //~v iter_kv_map let _ = map .clone().into_values().map(|mut val| { val += 2; @@ -48,21 +61,31 @@ fn main() { // Don't let a mut interfere. let _ = map.clone().into_values().count(); + //~^ iter_kv_map let map: BTreeMap = BTreeMap::new(); let _ = map.keys().collect::>(); + //~^ iter_kv_map let _ = map.values().collect::>(); + //~^ iter_kv_map let _ = map.values().map(|v| v + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_keys().collect::>(); + //~^ iter_kv_map let _ = map.clone().into_keys().map(|key| key + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_values().collect::>(); + //~^ iter_kv_map let _ = map.clone().into_values().map(|val| val + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().values().collect::>(); + //~^ iter_kv_map let _ = map.keys().filter(|x| *x % 2 == 0).count(); + //~^ iter_kv_map // Don't lint let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count(); @@ -73,12 +96,16 @@ fn main() { // Lint let _ = map.keys().map(|key| key * 9).count(); + //~^ iter_kv_map let _ = map.values().map(|value| value * 17).count(); + //~^ iter_kv_map // Preserve the ref in the fix. let _ = map.clone().into_values().map(|ref val| ref_acceptor(val)).count(); + //~^ iter_kv_map // Preserve the mut in the fix. + //~v iter_kv_map let _ = map .clone().into_values().map(|mut val| { val += 2; @@ -88,6 +115,7 @@ fn main() { // Don't let a mut interfere. let _ = map.clone().into_values().count(); + //~^ iter_kv_map } #[clippy::msrv = "1.53"] diff --git a/tests/ui/iter_kv_map.rs b/tests/ui/iter_kv_map.rs index 6a9a4267a765..8f6ec11093ae 100644 --- a/tests/ui/iter_kv_map.rs +++ b/tests/ui/iter_kv_map.rs @@ -12,17 +12,26 @@ fn main() { let map: HashMap = HashMap::new(); let _ = map.iter().map(|(key, _)| key).collect::>(); + //~^ iter_kv_map let _ = map.iter().map(|(_, value)| value).collect::>(); + //~^ iter_kv_map let _ = map.iter().map(|(_, v)| v + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_iter().map(|(key, _)| key).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_iter().map(|(_, val)| val).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().iter().map(|(_, val)| val).collect::>(); + //~^ iter_kv_map let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count(); + //~^ iter_kv_map // Don't lint let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count(); @@ -33,12 +42,16 @@ fn main() { // Lint let _ = map.iter().map(|(key, _value)| key * 9).count(); + //~^ iter_kv_map let _ = map.iter().map(|(_key, value)| value * 17).count(); + //~^ iter_kv_map // Preserve the ref in the fix. let _ = map.clone().into_iter().map(|(_, ref val)| ref_acceptor(val)).count(); + //~^ iter_kv_map // Preserve the mut in the fix. + //~v iter_kv_map let _ = map .clone() .into_iter() @@ -50,21 +63,31 @@ fn main() { // Don't let a mut interfere. let _ = map.clone().into_iter().map(|(_, mut val)| val).count(); + //~^ iter_kv_map let map: BTreeMap = BTreeMap::new(); let _ = map.iter().map(|(key, _)| key).collect::>(); + //~^ iter_kv_map let _ = map.iter().map(|(_, value)| value).collect::>(); + //~^ iter_kv_map let _ = map.iter().map(|(_, v)| v + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_iter().map(|(key, _)| key).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_iter().map(|(_, val)| val).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().iter().map(|(_, val)| val).collect::>(); + //~^ iter_kv_map let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count(); + //~^ iter_kv_map // Don't lint let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count(); @@ -75,12 +98,16 @@ fn main() { // Lint let _ = map.iter().map(|(key, _value)| key * 9).count(); + //~^ iter_kv_map let _ = map.iter().map(|(_key, value)| value * 17).count(); + //~^ iter_kv_map // Preserve the ref in the fix. let _ = map.clone().into_iter().map(|(_, ref val)| ref_acceptor(val)).count(); + //~^ iter_kv_map // Preserve the mut in the fix. + //~v iter_kv_map let _ = map .clone() .into_iter() @@ -92,6 +119,7 @@ fn main() { // Don't let a mut interfere. let _ = map.clone().into_iter().map(|(_, mut val)| val).count(); + //~^ iter_kv_map } #[clippy::msrv = "1.53"] diff --git a/tests/ui/iter_kv_map.stderr b/tests/ui/iter_kv_map.stderr index 471615978e1e..8d78db9321f5 100644 --- a/tests/ui/iter_kv_map.stderr +++ b/tests/ui/iter_kv_map.stderr @@ -8,73 +8,73 @@ LL | let _ = map.iter().map(|(key, _)| key).collect::>(); = help: to override `-D warnings` add `#[allow(clippy::iter_kv_map)]` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:15:13 + --> $DIR/iter_kv_map.rs:16:13 | LL | let _ = map.iter().map(|(_, value)| value).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:16:13 + --> $DIR/iter_kv_map.rs:18:13 | LL | let _ = map.iter().map(|(_, v)| v + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:18:13 + --> $DIR/iter_kv_map.rs:21:13 | LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:19:13 + --> $DIR/iter_kv_map.rs:23:13 | LL | let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys().map(|key| key + 2)` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:21:13 + --> $DIR/iter_kv_map.rs:26:13 | LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:22:13 + --> $DIR/iter_kv_map.rs:28:13 | LL | let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|val| val + 2)` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:24:13 + --> $DIR/iter_kv_map.rs:31:13 | LL | let _ = map.clone().iter().map(|(_, val)| val).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:25:13 + --> $DIR/iter_kv_map.rs:33:13 | LL | let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:35:13 + --> $DIR/iter_kv_map.rs:44:13 | LL | let _ = map.iter().map(|(key, _value)| key * 9).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:36:13 + --> $DIR/iter_kv_map.rs:46:13 | LL | let _ = map.iter().map(|(_key, value)| value * 17).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:39:13 + --> $DIR/iter_kv_map.rs:50:13 | LL | let _ = map.clone().into_iter().map(|(_, ref val)| ref_acceptor(val)).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|ref val| ref_acceptor(val))` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:42:13 + --> $DIR/iter_kv_map.rs:55:13 | LL | let _ = map | _____________^ @@ -96,85 +96,85 @@ LL + }) | error: iterating on a map's values - --> $DIR/iter_kv_map.rs:52:13 + --> $DIR/iter_kv_map.rs:65:13 | LL | let _ = map.clone().into_iter().map(|(_, mut val)| val).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:56:13 + --> $DIR/iter_kv_map.rs:70:13 | LL | let _ = map.iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:57:13 + --> $DIR/iter_kv_map.rs:72:13 | LL | let _ = map.iter().map(|(_, value)| value).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:58:13 + --> $DIR/iter_kv_map.rs:74:13 | LL | let _ = map.iter().map(|(_, v)| v + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:60:13 + --> $DIR/iter_kv_map.rs:77:13 | LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:61:13 + --> $DIR/iter_kv_map.rs:79:13 | LL | let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys().map(|key| key + 2)` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:63:13 + --> $DIR/iter_kv_map.rs:82:13 | LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:64:13 + --> $DIR/iter_kv_map.rs:84:13 | LL | let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|val| val + 2)` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:66:13 + --> $DIR/iter_kv_map.rs:87:13 | LL | let _ = map.clone().iter().map(|(_, val)| val).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:67:13 + --> $DIR/iter_kv_map.rs:89:13 | LL | let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:77:13 + --> $DIR/iter_kv_map.rs:100:13 | LL | let _ = map.iter().map(|(key, _value)| key * 9).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:78:13 + --> $DIR/iter_kv_map.rs:102:13 | LL | let _ = map.iter().map(|(_key, value)| value * 17).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:81:13 + --> $DIR/iter_kv_map.rs:106:13 | LL | let _ = map.clone().into_iter().map(|(_, ref val)| ref_acceptor(val)).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|ref val| ref_acceptor(val))` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:84:13 + --> $DIR/iter_kv_map.rs:111:13 | LL | let _ = map | _____________^ @@ -196,67 +196,67 @@ LL + }) | error: iterating on a map's values - --> $DIR/iter_kv_map.rs:94:13 + --> $DIR/iter_kv_map.rs:121:13 | LL | let _ = map.clone().into_iter().map(|(_, mut val)| val).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:109:13 + --> $DIR/iter_kv_map.rs:137:13 | LL | let _ = map.iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:111:13 + --> $DIR/iter_kv_map.rs:139:13 | LL | let _ = map.iter().map(|(_, value)| value).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:113:13 + --> $DIR/iter_kv_map.rs:141:13 | LL | let _ = map.iter().map(|(_, v)| v + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:122:13 + --> $DIR/iter_kv_map.rs:150:13 | LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:124:13 + --> $DIR/iter_kv_map.rs:152:13 | LL | let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys().map(|key| key + 2)` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:127:13 + --> $DIR/iter_kv_map.rs:155:13 | LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:129:13 + --> $DIR/iter_kv_map.rs:157:13 | LL | let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|val| val + 2)` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:132:13 + --> $DIR/iter_kv_map.rs:160:13 | LL | let _ = map.iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:134:13 + --> $DIR/iter_kv_map.rs:162:13 | LL | let _ = map.iter().map(|(_, value)| value).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:136:13 + --> $DIR/iter_kv_map.rs:164:13 | LL | let _ = map.iter().map(|(_, v)| v + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)` diff --git a/tests/ui/iter_next_slice.fixed b/tests/ui/iter_next_slice.fixed index 83be12c4e254..26cee7c1064c 100644 --- a/tests/ui/iter_next_slice.fixed +++ b/tests/ui/iter_next_slice.fixed @@ -6,16 +6,16 @@ fn main() { let s = [1, 2, 3]; let v = vec![1, 2, 3]; - let _ = s.first(); + let _ = s.first(); //~ iter_next_slice // Should be replaced by s.first() - let _ = s.get(2); + let _ = s.get(2); //~ iter_next_slice // Should be replaced by s.get(2) - let _ = v.get(5); + let _ = v.get(5); //~ iter_next_slice // Should be replaced by v.get(5) - let _ = v.first(); + let _ = v.first(); //~ iter_next_slice // Should be replaced by v.first() let o = Some(5); diff --git a/tests/ui/iter_next_slice.rs b/tests/ui/iter_next_slice.rs index 1b257514d23e..016ebbc4cd2b 100644 --- a/tests/ui/iter_next_slice.rs +++ b/tests/ui/iter_next_slice.rs @@ -6,16 +6,16 @@ fn main() { let s = [1, 2, 3]; let v = vec![1, 2, 3]; - let _ = s.iter().next(); + let _ = s.iter().next(); //~ iter_next_slice // Should be replaced by s.first() - let _ = s[2..].iter().next(); + let _ = s[2..].iter().next(); //~ iter_next_slice // Should be replaced by s.get(2) - let _ = v[5..].iter().next(); + let _ = v[5..].iter().next(); //~ iter_next_slice // Should be replaced by v.get(5) - let _ = v.iter().next(); + let _ = v.iter().next(); //~ iter_next_slice // Should be replaced by v.first() let o = Some(5); diff --git a/tests/ui/iter_nth.rs b/tests/ui/iter_nth.rs index 7c567bb81d88..f605629b707d 100644 --- a/tests/ui/iter_nth.rs +++ b/tests/ui/iter_nth.rs @@ -31,21 +31,25 @@ fn iter_nth() { { // Make sure we lint `.iter()` for relevant types. - let bad_vec = some_vec.iter().nth(3); - let bad_slice = &some_vec[..].iter().nth(3); + let bad_vec = some_vec.iter().nth(3); //~ iter_nth + let bad_slice = &some_vec[..].iter().nth(3); //~ iter_nth let bad_boxed_slice = boxed_slice.iter().nth(3); + //~^ iter_nth let bad_vec_deque = some_vec_deque.iter().nth(3); + //~^ iter_nth } { // Make sure we lint `.iter_mut()` for relevant types. - let bad_vec = some_vec.iter_mut().nth(3); + let bad_vec = some_vec.iter_mut().nth(3); //~ iter_nth } { let bad_slice = &some_vec[..].iter_mut().nth(3); + //~^ iter_nth } { let bad_vec_deque = some_vec_deque.iter_mut().nth(3); + //~^ iter_nth } // Make sure we don't lint for non-relevant types. diff --git a/tests/ui/iter_nth.stderr b/tests/ui/iter_nth.stderr index 162e6c338494..47d8ba4d6a3c 100644 --- a/tests/ui/iter_nth.stderr +++ b/tests/ui/iter_nth.stderr @@ -25,7 +25,7 @@ LL | let bad_boxed_slice = boxed_slice.iter().nth(3); = help: calling `.get()` is both faster and more readable error: called `.iter().nth()` on a `VecDeque` - --> $DIR/iter_nth.rs:37:29 + --> $DIR/iter_nth.rs:38:29 | LL | let bad_vec_deque = some_vec_deque.iter().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | let bad_vec_deque = some_vec_deque.iter().nth(3); = help: calling `.get()` is both faster and more readable error: called `.iter_mut().nth()` on a `Vec` - --> $DIR/iter_nth.rs:42:23 + --> $DIR/iter_nth.rs:44:23 | LL | let bad_vec = some_vec.iter_mut().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | let bad_vec = some_vec.iter_mut().nth(3); = help: calling `.get_mut()` is both faster and more readable error: called `.iter_mut().nth()` on a slice - --> $DIR/iter_nth.rs:45:26 + --> $DIR/iter_nth.rs:47:26 | LL | let bad_slice = &some_vec[..].iter_mut().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let bad_slice = &some_vec[..].iter_mut().nth(3); = help: calling `.get_mut()` is both faster and more readable error: called `.iter_mut().nth()` on a `VecDeque` - --> $DIR/iter_nth.rs:48:29 + --> $DIR/iter_nth.rs:51:29 | LL | let bad_vec_deque = some_vec_deque.iter_mut().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/iter_nth_zero.fixed b/tests/ui/iter_nth_zero.fixed index a3cdb2e59bff..30f9ccf7df07 100644 --- a/tests/ui/iter_nth_zero.fixed +++ b/tests/ui/iter_nth_zero.fixed @@ -15,17 +15,17 @@ fn main() { let mut s = HashSet::new(); s.insert(1); - let _x = s.iter().next(); + let _x = s.iter().next(); //~ iter_nth_zero let mut s2 = HashSet::new(); s2.insert(2); let mut iter = s2.iter(); - let _y = iter.next(); + let _y = iter.next(); //~ iter_nth_zero let mut s3 = HashSet::new(); s3.insert(3); let mut iter2 = s3.iter(); - let _unwrapped = iter2.next().unwrap(); + let _unwrapped = iter2.next().unwrap(); //~ iter_nth_zero } struct Issue9820; diff --git a/tests/ui/iter_nth_zero.rs b/tests/ui/iter_nth_zero.rs index 64229b5128a3..22a99d2e33b2 100644 --- a/tests/ui/iter_nth_zero.rs +++ b/tests/ui/iter_nth_zero.rs @@ -15,17 +15,17 @@ fn main() { let mut s = HashSet::new(); s.insert(1); - let _x = s.iter().nth(0); + let _x = s.iter().nth(0); //~ iter_nth_zero let mut s2 = HashSet::new(); s2.insert(2); let mut iter = s2.iter(); - let _y = iter.nth(0); + let _y = iter.nth(0); //~ iter_nth_zero let mut s3 = HashSet::new(); s3.insert(3); let mut iter2 = s3.iter(); - let _unwrapped = iter2.nth(0).unwrap(); + let _unwrapped = iter2.nth(0).unwrap(); //~ iter_nth_zero } struct Issue9820; diff --git a/tests/ui/iter_on_empty_collections.fixed b/tests/ui/iter_on_empty_collections.fixed index 794629f240eb..daf9c27120d1 100644 --- a/tests/ui/iter_on_empty_collections.fixed +++ b/tests/ui/iter_on_empty_collections.fixed @@ -3,11 +3,17 @@ fn array() { assert_eq!(std::iter::empty().next(), Option::::None); + //~^ iter_on_empty_collections assert_eq!(std::iter::empty().next(), Option::<&mut i32>::None); + //~^ iter_on_empty_collections assert_eq!(std::iter::empty().next(), Option::<&i32>::None); + //~^ iter_on_empty_collections assert_eq!(std::iter::empty().next(), Option::::None); + //~^ iter_on_empty_collections assert_eq!(std::iter::empty().next(), Option::<&mut i32>::None); + //~^ iter_on_empty_collections assert_eq!(std::iter::empty().next(), Option::<&i32>::None); + //~^ iter_on_empty_collections // Don't trigger on non-iter methods let _: Option = None.clone(); diff --git a/tests/ui/iter_on_empty_collections.rs b/tests/ui/iter_on_empty_collections.rs index a6461a702eb2..fb1e10383f47 100644 --- a/tests/ui/iter_on_empty_collections.rs +++ b/tests/ui/iter_on_empty_collections.rs @@ -3,11 +3,17 @@ fn array() { assert_eq!([].into_iter().next(), Option::::None); + //~^ iter_on_empty_collections assert_eq!([].iter_mut().next(), Option::<&mut i32>::None); + //~^ iter_on_empty_collections assert_eq!([].iter().next(), Option::<&i32>::None); + //~^ iter_on_empty_collections assert_eq!(None.into_iter().next(), Option::::None); + //~^ iter_on_empty_collections assert_eq!(None.iter_mut().next(), Option::<&mut i32>::None); + //~^ iter_on_empty_collections assert_eq!(None.iter().next(), Option::<&i32>::None); + //~^ iter_on_empty_collections // Don't trigger on non-iter methods let _: Option = None.clone(); diff --git a/tests/ui/iter_on_empty_collections.stderr b/tests/ui/iter_on_empty_collections.stderr index 57a532019966..6de7c075abc7 100644 --- a/tests/ui/iter_on_empty_collections.stderr +++ b/tests/ui/iter_on_empty_collections.stderr @@ -8,31 +8,31 @@ LL | assert_eq!([].into_iter().next(), Option::::None); = help: to override `-D warnings` add `#[allow(clippy::iter_on_empty_collections)]` error: `iter_mut` call on an empty collection - --> $DIR/iter_on_empty_collections.rs:6:16 + --> $DIR/iter_on_empty_collections.rs:7:16 | LL | assert_eq!([].iter_mut().next(), Option::<&mut i32>::None); | ^^^^^^^^^^^^^ help: try: `std::iter::empty()` error: `iter` call on an empty collection - --> $DIR/iter_on_empty_collections.rs:7:16 + --> $DIR/iter_on_empty_collections.rs:9:16 | LL | assert_eq!([].iter().next(), Option::<&i32>::None); | ^^^^^^^^^ help: try: `std::iter::empty()` error: `into_iter` call on an empty collection - --> $DIR/iter_on_empty_collections.rs:8:16 + --> $DIR/iter_on_empty_collections.rs:11:16 | LL | assert_eq!(None.into_iter().next(), Option::::None); | ^^^^^^^^^^^^^^^^ help: try: `std::iter::empty()` error: `iter_mut` call on an empty collection - --> $DIR/iter_on_empty_collections.rs:9:16 + --> $DIR/iter_on_empty_collections.rs:13:16 | LL | assert_eq!(None.iter_mut().next(), Option::<&mut i32>::None); | ^^^^^^^^^^^^^^^ help: try: `std::iter::empty()` error: `iter` call on an empty collection - --> $DIR/iter_on_empty_collections.rs:10:16 + --> $DIR/iter_on_empty_collections.rs:15:16 | LL | assert_eq!(None.iter().next(), Option::<&i32>::None); | ^^^^^^^^^^^ help: try: `std::iter::empty()` diff --git a/tests/ui/iter_on_single_items.fixed b/tests/ui/iter_on_single_items.fixed index 117ec8429c37..b43fad6449c1 100644 --- a/tests/ui/iter_on_single_items.fixed +++ b/tests/ui/iter_on_single_items.fixed @@ -3,11 +3,17 @@ fn array() { assert_eq!(std::iter::once(123).next(), Some(123)); + //~^ iter_on_single_items assert_eq!(std::iter::once(&mut 123).next(), Some(&mut 123)); + //~^ iter_on_single_items assert_eq!(std::iter::once(&123).next(), Some(&123)); + //~^ iter_on_single_items assert_eq!(std::iter::once(123).next(), Some(123)); + //~^ iter_on_single_items assert_eq!(std::iter::once(&mut 123).next(), Some(&mut 123)); + //~^ iter_on_single_items assert_eq!(std::iter::once(&123).next(), Some(&123)); + //~^ iter_on_single_items // Don't trigger on non-iter methods let _: Option = Some("test".to_string()).clone(); diff --git a/tests/ui/iter_on_single_items.rs b/tests/ui/iter_on_single_items.rs index d059370d996c..625c96d3ef1f 100644 --- a/tests/ui/iter_on_single_items.rs +++ b/tests/ui/iter_on_single_items.rs @@ -3,11 +3,17 @@ fn array() { assert_eq!([123].into_iter().next(), Some(123)); + //~^ iter_on_single_items assert_eq!([123].iter_mut().next(), Some(&mut 123)); + //~^ iter_on_single_items assert_eq!([123].iter().next(), Some(&123)); + //~^ iter_on_single_items assert_eq!(Some(123).into_iter().next(), Some(123)); + //~^ iter_on_single_items assert_eq!(Some(123).iter_mut().next(), Some(&mut 123)); + //~^ iter_on_single_items assert_eq!(Some(123).iter().next(), Some(&123)); + //~^ iter_on_single_items // Don't trigger on non-iter methods let _: Option = Some("test".to_string()).clone(); diff --git a/tests/ui/iter_on_single_items.stderr b/tests/ui/iter_on_single_items.stderr index 00398f541e9a..2775267d4020 100644 --- a/tests/ui/iter_on_single_items.stderr +++ b/tests/ui/iter_on_single_items.stderr @@ -8,31 +8,31 @@ LL | assert_eq!([123].into_iter().next(), Some(123)); = help: to override `-D warnings` add `#[allow(clippy::iter_on_single_items)]` error: `iter_mut` call on a collection with only one item - --> $DIR/iter_on_single_items.rs:6:16 + --> $DIR/iter_on_single_items.rs:7:16 | LL | assert_eq!([123].iter_mut().next(), Some(&mut 123)); | ^^^^^^^^^^^^^^^^ help: try: `std::iter::once(&mut 123)` error: `iter` call on a collection with only one item - --> $DIR/iter_on_single_items.rs:7:16 + --> $DIR/iter_on_single_items.rs:9:16 | LL | assert_eq!([123].iter().next(), Some(&123)); | ^^^^^^^^^^^^ help: try: `std::iter::once(&123)` error: `into_iter` call on a collection with only one item - --> $DIR/iter_on_single_items.rs:8:16 + --> $DIR/iter_on_single_items.rs:11:16 | LL | assert_eq!(Some(123).into_iter().next(), Some(123)); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::once(123)` error: `iter_mut` call on a collection with only one item - --> $DIR/iter_on_single_items.rs:9:16 + --> $DIR/iter_on_single_items.rs:13:16 | LL | assert_eq!(Some(123).iter_mut().next(), Some(&mut 123)); | ^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::once(&mut 123)` error: `iter` call on a collection with only one item - --> $DIR/iter_on_single_items.rs:10:16 + --> $DIR/iter_on_single_items.rs:15:16 | LL | assert_eq!(Some(123).iter().next(), Some(&123)); | ^^^^^^^^^^^^^^^^ help: try: `std::iter::once(&123)` diff --git a/tests/ui/iter_over_hash_type.rs b/tests/ui/iter_over_hash_type.rs index 7000c8bf96f8..3b9569b1a5c6 100644 --- a/tests/ui/iter_over_hash_type.rs +++ b/tests/ui/iter_over_hash_type.rs @@ -15,46 +15,59 @@ fn main() { let vec = Vec::::new(); // test hashset + //~v iter_over_hash_type for x in &hash_set { let _ = x; } + //~v iter_over_hash_type for x in hash_set.iter() { let _ = x; } + //~v iter_over_hash_type for x in hash_set.clone() { let _ = x; } + //~v iter_over_hash_type for x in hash_set.drain() { let _ = x; } // test hashmap + //~v iter_over_hash_type for (x, y) in &hash_map { let _ = (x, y); } + //~v iter_over_hash_type for x in hash_map.keys() { let _ = x; } + //~v iter_over_hash_type for x in hash_map.values() { let _ = x; } + //~v iter_over_hash_type for x in hash_map.values_mut() { *x += 1; } + //~v iter_over_hash_type for x in hash_map.iter() { let _ = x; } + //~v iter_over_hash_type for x in hash_map.clone() { let _ = x; } + //~v iter_over_hash_type for x in hash_map.drain() { let _ = x; } // test type-aliased hashers + //~v iter_over_hash_type for x in fx_hash_set { let _ = x; } + //~v iter_over_hash_type for x in fx_hash_map { let _ = x; } diff --git a/tests/ui/iter_over_hash_type.stderr b/tests/ui/iter_over_hash_type.stderr index cf420fb8e996..fef46766b695 100644 --- a/tests/ui/iter_over_hash_type.stderr +++ b/tests/ui/iter_over_hash_type.stderr @@ -1,5 +1,5 @@ error: iteration over unordered hash-based type - --> $DIR/iter_over_hash_type.rs:18:5 + --> $DIR/iter_over_hash_type.rs:19:5 | LL | / for x in &hash_set { LL | | let _ = x; @@ -10,7 +10,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::iter_over_hash_type)]` error: iteration over unordered hash-based type - --> $DIR/iter_over_hash_type.rs:21:5 + --> $DIR/iter_over_hash_type.rs:23:5 | LL | / for x in hash_set.iter() { LL | | let _ = x; @@ -18,7 +18,7 @@ LL | | } | |_____^ error: iteration over unordered hash-based type - --> $DIR/iter_over_hash_type.rs:24:5 + --> $DIR/iter_over_hash_type.rs:27:5 | LL | / for x in hash_set.clone() { LL | | let _ = x; @@ -26,7 +26,7 @@ LL | | } | |_____^ error: iteration over unordered hash-based type - --> $DIR/iter_over_hash_type.rs:27:5 + --> $DIR/iter_over_hash_type.rs:31:5 | LL | / for x in hash_set.drain() { LL | | let _ = x; @@ -34,7 +34,7 @@ LL | | } | |_____^ error: iteration over unordered hash-based type - --> $DIR/iter_over_hash_type.rs:32:5 + --> $DIR/iter_over_hash_type.rs:37:5 | LL | / for (x, y) in &hash_map { LL | | let _ = (x, y); @@ -42,7 +42,7 @@ LL | | } | |_____^ error: iteration over unordered hash-based type - --> $DIR/iter_over_hash_type.rs:35:5 + --> $DIR/iter_over_hash_type.rs:41:5 | LL | / for x in hash_map.keys() { LL | | let _ = x; @@ -50,7 +50,7 @@ LL | | } | |_____^ error: iteration over unordered hash-based type - --> $DIR/iter_over_hash_type.rs:38:5 + --> $DIR/iter_over_hash_type.rs:45:5 | LL | / for x in hash_map.values() { LL | | let _ = x; @@ -58,7 +58,7 @@ LL | | } | |_____^ error: iteration over unordered hash-based type - --> $DIR/iter_over_hash_type.rs:41:5 + --> $DIR/iter_over_hash_type.rs:49:5 | LL | / for x in hash_map.values_mut() { LL | | *x += 1; @@ -66,7 +66,7 @@ LL | | } | |_____^ error: iteration over unordered hash-based type - --> $DIR/iter_over_hash_type.rs:44:5 + --> $DIR/iter_over_hash_type.rs:53:5 | LL | / for x in hash_map.iter() { LL | | let _ = x; @@ -74,7 +74,7 @@ LL | | } | |_____^ error: iteration over unordered hash-based type - --> $DIR/iter_over_hash_type.rs:47:5 + --> $DIR/iter_over_hash_type.rs:57:5 | LL | / for x in hash_map.clone() { LL | | let _ = x; @@ -82,7 +82,7 @@ LL | | } | |_____^ error: iteration over unordered hash-based type - --> $DIR/iter_over_hash_type.rs:50:5 + --> $DIR/iter_over_hash_type.rs:61:5 | LL | / for x in hash_map.drain() { LL | | let _ = x; @@ -90,7 +90,7 @@ LL | | } | |_____^ error: iteration over unordered hash-based type - --> $DIR/iter_over_hash_type.rs:55:5 + --> $DIR/iter_over_hash_type.rs:67:5 | LL | / for x in fx_hash_set { LL | | let _ = x; @@ -98,7 +98,7 @@ LL | | } | |_____^ error: iteration over unordered hash-based type - --> $DIR/iter_over_hash_type.rs:58:5 + --> $DIR/iter_over_hash_type.rs:71:5 | LL | / for x in fx_hash_map { LL | | let _ = x; diff --git a/tests/ui/iter_overeager_cloned.fixed b/tests/ui/iter_overeager_cloned.fixed index 7d8a584b0224..451e59c732f3 100644 --- a/tests/ui/iter_overeager_cloned.fixed +++ b/tests/ui/iter_overeager_cloned.fixed @@ -5,36 +5,49 @@ fn main() { let vec = vec!["1".to_string(), "2".to_string(), "3".to_string()]; let _: Option = vec.iter().last().cloned(); + //~^ iter_overeager_cloned let _: Option = vec.iter().chain(vec.iter()).next().cloned(); + //~^ iter_overeager_cloned let _: usize = vec.iter().filter(|x| x == &"2").count(); + //~^ redundant_clone let _: Vec<_> = vec.iter().take(2).cloned().collect(); + //~^ iter_overeager_cloned let _: Vec<_> = vec.iter().skip(2).cloned().collect(); + //~^ iter_overeager_cloned let _ = vec.iter().filter(|x| x == &"2").nth(2).cloned(); + //~^ iter_overeager_cloned + //~v iter_overeager_cloned let _ = [Some(Some("str".to_string())), Some(Some("str".to_string()))] .iter() .flatten().cloned(); let _ = vec.iter().filter(|&x| x.starts_with('2')).cloned(); + //~^ iter_overeager_cloned let _ = vec.iter().find(|&x| x == "2").cloned(); + //~^ iter_overeager_cloned { let f = |x: &String| x.starts_with('2'); let _ = vec.iter().filter(|&x| f(x)).cloned(); + //~^ iter_overeager_cloned let _ = vec.iter().find(|&x| f(x)).cloned(); + //~^ iter_overeager_cloned } { let vec: Vec<(String, String)> = vec![]; let f = move |x: &(String, String)| x.0.starts_with('2'); let _ = vec.iter().filter(|&x| f(x)).cloned(); + //~^ iter_overeager_cloned let _ = vec.iter().find(|&x| f(x)).cloned(); + //~^ iter_overeager_cloned } fn test_move<'a>( @@ -42,6 +55,7 @@ fn main() { target: String, ) -> impl Iterator + 'a { iter.filter(move |&(&a, b)| a == 1 && b == &target).cloned() + //~^ iter_overeager_cloned } { @@ -53,19 +67,24 @@ fn main() { fn bar<'a>(iter: impl Iterator> + 'a, target: String) -> impl Iterator> + 'a { iter.filter(move |&S { a, b }| **a == 1 && b == &target).cloned() + //~^ iter_overeager_cloned } } let _ = vec.iter().map(|x| x.len()); + //~^ redundant_clone // This would fail if changed. let _ = vec.iter().cloned().map(|x| x + "2"); let _ = vec.iter().for_each(|x| assert!(!x.is_empty())); + //~^ redundant_clone let _ = vec.iter().all(|x| x.len() == 1); + //~^ redundant_clone let _ = vec.iter().any(|x| x.len() == 1); + //~^ redundant_clone // Should probably stay as it is. let _ = [0, 1, 2, 3, 4].iter().cloned().take(10); diff --git a/tests/ui/iter_overeager_cloned.rs b/tests/ui/iter_overeager_cloned.rs index 58c374ab8cd1..44438dd3aff9 100644 --- a/tests/ui/iter_overeager_cloned.rs +++ b/tests/ui/iter_overeager_cloned.rs @@ -5,37 +5,50 @@ fn main() { let vec = vec!["1".to_string(), "2".to_string(), "3".to_string()]; let _: Option = vec.iter().cloned().last(); + //~^ iter_overeager_cloned let _: Option = vec.iter().chain(vec.iter()).cloned().next(); + //~^ iter_overeager_cloned let _: usize = vec.iter().filter(|x| x == &"2").cloned().count(); + //~^ redundant_clone let _: Vec<_> = vec.iter().cloned().take(2).collect(); + //~^ iter_overeager_cloned let _: Vec<_> = vec.iter().cloned().skip(2).collect(); + //~^ iter_overeager_cloned let _ = vec.iter().filter(|x| x == &"2").cloned().nth(2); + //~^ iter_overeager_cloned + //~v iter_overeager_cloned let _ = [Some(Some("str".to_string())), Some(Some("str".to_string()))] .iter() .cloned() .flatten(); let _ = vec.iter().cloned().filter(|x| x.starts_with('2')); + //~^ iter_overeager_cloned let _ = vec.iter().cloned().find(|x| x == "2"); + //~^ iter_overeager_cloned { let f = |x: &String| x.starts_with('2'); let _ = vec.iter().cloned().filter(f); + //~^ iter_overeager_cloned let _ = vec.iter().cloned().find(f); + //~^ iter_overeager_cloned } { let vec: Vec<(String, String)> = vec![]; let f = move |x: &(String, String)| x.0.starts_with('2'); let _ = vec.iter().cloned().filter(f); + //~^ iter_overeager_cloned let _ = vec.iter().cloned().find(f); + //~^ iter_overeager_cloned } fn test_move<'a>( @@ -43,6 +56,7 @@ fn main() { target: String, ) -> impl Iterator + 'a { iter.cloned().filter(move |(&a, b)| a == 1 && b == &target) + //~^ iter_overeager_cloned } { @@ -54,19 +68,24 @@ fn main() { fn bar<'a>(iter: impl Iterator> + 'a, target: String) -> impl Iterator> + 'a { iter.cloned().filter(move |S { a, b }| **a == 1 && b == &target) + //~^ iter_overeager_cloned } } let _ = vec.iter().cloned().map(|x| x.len()); + //~^ redundant_clone // This would fail if changed. let _ = vec.iter().cloned().map(|x| x + "2"); let _ = vec.iter().cloned().for_each(|x| assert!(!x.is_empty())); + //~^ redundant_clone let _ = vec.iter().cloned().all(|x| x.len() == 1); + //~^ redundant_clone let _ = vec.iter().cloned().any(|x| x.len() == 1); + //~^ redundant_clone // Should probably stay as it is. let _ = [0, 1, 2, 3, 4].iter().cloned().take(10); diff --git a/tests/ui/iter_overeager_cloned.stderr b/tests/ui/iter_overeager_cloned.stderr index a9a739688ebf..b4b5508b7ff1 100644 --- a/tests/ui/iter_overeager_cloned.stderr +++ b/tests/ui/iter_overeager_cloned.stderr @@ -10,7 +10,7 @@ LL | let _: Option = vec.iter().cloned().last(); = help: to override `-D warnings` add `#[allow(clippy::iter_overeager_cloned)]` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:9:29 + --> $DIR/iter_overeager_cloned.rs:10:29 | LL | let _: Option = vec.iter().chain(vec.iter()).cloned().next(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------- @@ -18,7 +18,7 @@ LL | let _: Option = vec.iter().chain(vec.iter()).cloned().next(); | help: try: `.next().cloned()` error: unneeded cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:11:20 + --> $DIR/iter_overeager_cloned.rs:13:20 | LL | let _: usize = vec.iter().filter(|x| x == &"2").cloned().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------- @@ -29,7 +29,7 @@ LL | let _: usize = vec.iter().filter(|x| x == &"2").cloned().count(); = help: to override `-D warnings` add `#[allow(clippy::redundant_clone)]` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:13:21 + --> $DIR/iter_overeager_cloned.rs:16:21 | LL | let _: Vec<_> = vec.iter().cloned().take(2).collect(); | ^^^^^^^^^^----------------- @@ -37,7 +37,7 @@ LL | let _: Vec<_> = vec.iter().cloned().take(2).collect(); | help: try: `.take(2).cloned()` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:15:21 + --> $DIR/iter_overeager_cloned.rs:19:21 | LL | let _: Vec<_> = vec.iter().cloned().skip(2).collect(); | ^^^^^^^^^^----------------- @@ -45,7 +45,7 @@ LL | let _: Vec<_> = vec.iter().cloned().skip(2).collect(); | help: try: `.skip(2).cloned()` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:17:13 + --> $DIR/iter_overeager_cloned.rs:22:13 | LL | let _ = vec.iter().filter(|x| x == &"2").cloned().nth(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------- @@ -53,7 +53,7 @@ LL | let _ = vec.iter().filter(|x| x == &"2").cloned().nth(2); | help: try: `.nth(2).cloned()` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:19:13 + --> $DIR/iter_overeager_cloned.rs:26:13 | LL | let _ = [Some(Some("str".to_string())), Some(Some("str".to_string()))] | _____________^ @@ -69,7 +69,7 @@ LL ~ .flatten().cloned(); | error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:24:13 + --> $DIR/iter_overeager_cloned.rs:31:13 | LL | let _ = vec.iter().cloned().filter(|x| x.starts_with('2')); | ^^^^^^^^^^---------------------------------------- @@ -77,7 +77,7 @@ LL | let _ = vec.iter().cloned().filter(|x| x.starts_with('2')); | help: try: `.filter(|&x| x.starts_with('2')).cloned()` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:26:13 + --> $DIR/iter_overeager_cloned.rs:34:13 | LL | let _ = vec.iter().cloned().find(|x| x == "2"); | ^^^^^^^^^^---------------------------- @@ -85,7 +85,7 @@ LL | let _ = vec.iter().cloned().find(|x| x == "2"); | help: try: `.find(|&x| x == "2").cloned()` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:30:17 + --> $DIR/iter_overeager_cloned.rs:39:17 | LL | let _ = vec.iter().cloned().filter(f); | ^^^^^^^^^^------------------- @@ -93,7 +93,7 @@ LL | let _ = vec.iter().cloned().filter(f); | help: try: `.filter(|&x| f(x)).cloned()` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:31:17 + --> $DIR/iter_overeager_cloned.rs:41:17 | LL | let _ = vec.iter().cloned().find(f); | ^^^^^^^^^^----------------- @@ -101,7 +101,7 @@ LL | let _ = vec.iter().cloned().find(f); | help: try: `.find(|&x| f(x)).cloned()` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:37:17 + --> $DIR/iter_overeager_cloned.rs:48:17 | LL | let _ = vec.iter().cloned().filter(f); | ^^^^^^^^^^------------------- @@ -109,7 +109,7 @@ LL | let _ = vec.iter().cloned().filter(f); | help: try: `.filter(|&x| f(x)).cloned()` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:38:17 + --> $DIR/iter_overeager_cloned.rs:50:17 | LL | let _ = vec.iter().cloned().find(f); | ^^^^^^^^^^----------------- @@ -117,7 +117,7 @@ LL | let _ = vec.iter().cloned().find(f); | help: try: `.find(|&x| f(x)).cloned()` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:45:9 + --> $DIR/iter_overeager_cloned.rs:58:9 | LL | iter.cloned().filter(move |(&a, b)| a == 1 && b == &target) | ^^^^------------------------------------------------------- @@ -125,7 +125,7 @@ LL | iter.cloned().filter(move |(&a, b)| a == 1 && b == &target) | help: try: `.filter(move |&(&a, b)| a == 1 && b == &target).cloned()` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:56:13 + --> $DIR/iter_overeager_cloned.rs:70:13 | LL | iter.cloned().filter(move |S { a, b }| **a == 1 && b == &target) | ^^^^------------------------------------------------------------ @@ -133,7 +133,7 @@ LL | iter.cloned().filter(move |S { a, b }| **a == 1 && b == &target | help: try: `.filter(move |&S { a, b }| **a == 1 && b == &target).cloned()` error: unneeded cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:60:13 + --> $DIR/iter_overeager_cloned.rs:75:13 | LL | let _ = vec.iter().cloned().map(|x| x.len()); | ^^^^^^^^^^-------------------------- @@ -141,7 +141,7 @@ LL | let _ = vec.iter().cloned().map(|x| x.len()); | help: try: `.map(|x| x.len())` error: unneeded cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:65:13 + --> $DIR/iter_overeager_cloned.rs:81:13 | LL | let _ = vec.iter().cloned().for_each(|x| assert!(!x.is_empty())); | ^^^^^^^^^^---------------------------------------------- @@ -149,7 +149,7 @@ LL | let _ = vec.iter().cloned().for_each(|x| assert!(!x.is_empty())); | help: try: `.for_each(|x| assert!(!x.is_empty()))` error: unneeded cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:67:13 + --> $DIR/iter_overeager_cloned.rs:84:13 | LL | let _ = vec.iter().cloned().all(|x| x.len() == 1); | ^^^^^^^^^^------------------------------- @@ -157,7 +157,7 @@ LL | let _ = vec.iter().cloned().all(|x| x.len() == 1); | help: try: `.all(|x| x.len() == 1)` error: unneeded cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:69:13 + --> $DIR/iter_overeager_cloned.rs:87:13 | LL | let _ = vec.iter().cloned().any(|x| x.len() == 1); | ^^^^^^^^^^------------------------------- diff --git a/tests/ui/iter_skip_next.fixed b/tests/ui/iter_skip_next.fixed index 3e41b3632490..e549d7e0ff02 100644 --- a/tests/ui/iter_skip_next.fixed +++ b/tests/ui/iter_skip_next.fixed @@ -14,10 +14,11 @@ use option_helpers::IteratorFalsePositives; /// Checks implementation of `ITER_SKIP_NEXT` lint fn main() { let some_vec = vec![0, 1, 2, 3]; - let _ = some_vec.iter().nth(42); + let _ = some_vec.iter().nth(42); //~ iter_skip_next let _ = some_vec.iter().cycle().nth(42); - let _ = (1..10).nth(10); - let _ = &some_vec[..].iter().nth(3); + //~^ iter_skip_next + let _ = (1..10).nth(10); //~ iter_skip_next + let _ = &some_vec[..].iter().nth(3); //~ iter_skip_next let foo = IteratorFalsePositives { foo: 0 }; let _ = foo.skip(42).next(); let _ = foo.filter().skip(42).next(); @@ -26,13 +27,16 @@ fn main() { let test_string = "1|1 2"; let mut sp = test_string.split('|').map(|s| s.trim()); let _: Vec<&str> = sp.nth(1).unwrap().split(' ').collect(); + //~^ iter_skip_next if let Some(mut s) = Some(test_string.split('|').map(|s| s.trim())) { let _: Vec<&str> = s.nth(1).unwrap().split(' ').collect(); + //~^ iter_skip_next }; fn check(mut s: T) where T: Iterator, { let _: Vec<&str> = s.nth(1).unwrap().split(' ').collect(); + //~^ iter_skip_next } } diff --git a/tests/ui/iter_skip_next.rs b/tests/ui/iter_skip_next.rs index 6d96441ca96f..e43c6015a80f 100644 --- a/tests/ui/iter_skip_next.rs +++ b/tests/ui/iter_skip_next.rs @@ -14,10 +14,11 @@ use option_helpers::IteratorFalsePositives; /// Checks implementation of `ITER_SKIP_NEXT` lint fn main() { let some_vec = vec![0, 1, 2, 3]; - let _ = some_vec.iter().skip(42).next(); + let _ = some_vec.iter().skip(42).next(); //~ iter_skip_next let _ = some_vec.iter().cycle().skip(42).next(); - let _ = (1..10).skip(10).next(); - let _ = &some_vec[..].iter().skip(3).next(); + //~^ iter_skip_next + let _ = (1..10).skip(10).next(); //~ iter_skip_next + let _ = &some_vec[..].iter().skip(3).next(); //~ iter_skip_next let foo = IteratorFalsePositives { foo: 0 }; let _ = foo.skip(42).next(); let _ = foo.filter().skip(42).next(); @@ -26,13 +27,16 @@ fn main() { let test_string = "1|1 2"; let mut sp = test_string.split('|').map(|s| s.trim()); let _: Vec<&str> = sp.skip(1).next().unwrap().split(' ').collect(); + //~^ iter_skip_next if let Some(mut s) = Some(test_string.split('|').map(|s| s.trim())) { let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); + //~^ iter_skip_next }; fn check(mut s: T) where T: Iterator, { let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); + //~^ iter_skip_next } } diff --git a/tests/ui/iter_skip_next.stderr b/tests/ui/iter_skip_next.stderr index 39b173e75869..8e091a953a8f 100644 --- a/tests/ui/iter_skip_next.stderr +++ b/tests/ui/iter_skip_next.stderr @@ -14,31 +14,31 @@ LL | let _ = some_vec.iter().cycle().skip(42).next(); | ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)` error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next.rs:19:20 + --> $DIR/iter_skip_next.rs:20:20 | LL | let _ = (1..10).skip(10).next(); | ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(10)` error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next.rs:20:33 + --> $DIR/iter_skip_next.rs:21:33 | LL | let _ = &some_vec[..].iter().skip(3).next(); | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(3)` error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next.rs:28:26 + --> $DIR/iter_skip_next.rs:29:26 | LL | let _: Vec<&str> = sp.skip(1).next().unwrap().split(' ').collect(); | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)` error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next.rs:30:29 + --> $DIR/iter_skip_next.rs:32:29 | LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)` error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next.rs:36:29 + --> $DIR/iter_skip_next.rs:39:29 | LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)` diff --git a/tests/ui/iter_skip_zero.fixed b/tests/ui/iter_skip_zero.fixed index 447d07100e95..fc3349306a60 100644 --- a/tests/ui/iter_skip_zero.fixed +++ b/tests/ui/iter_skip_zero.fixed @@ -8,10 +8,12 @@ extern crate proc_macros; use std::iter::once; fn main() { - let _ = [1, 2, 3].iter().skip(1); - let _ = vec![1, 2, 3].iter().skip(1); - let _ = once([1, 2, 3]).skip(1); + let _ = [1, 2, 3].iter().skip(1); //~ iter_skip_zero + let _ = vec![1, 2, 3].iter().skip(1); //~ iter_skip_zero + let _ = once([1, 2, 3]).skip(1); //~ iter_skip_zero let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(1)).skip(1); + //~^ iter_skip_zero + //~| iter_skip_zero // Don't lint let _ = [1, 2, 3].iter().skip(1); let _ = vec![1, 2, 3].iter().skip(1); diff --git a/tests/ui/iter_skip_zero.rs b/tests/ui/iter_skip_zero.rs index ba63c3981808..d0a5405c61cb 100644 --- a/tests/ui/iter_skip_zero.rs +++ b/tests/ui/iter_skip_zero.rs @@ -8,10 +8,12 @@ extern crate proc_macros; use std::iter::once; fn main() { - let _ = [1, 2, 3].iter().skip(0); - let _ = vec![1, 2, 3].iter().skip(0); - let _ = once([1, 2, 3]).skip(0); + let _ = [1, 2, 3].iter().skip(0); //~ iter_skip_zero + let _ = vec![1, 2, 3].iter().skip(0); //~ iter_skip_zero + let _ = once([1, 2, 3]).skip(0); //~ iter_skip_zero let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(0)).skip(0); + //~^ iter_skip_zero + //~| iter_skip_zero // Don't lint let _ = [1, 2, 3].iter().skip(1); let _ = vec![1, 2, 3].iter().skip(1); diff --git a/tests/ui/iter_with_drain.fixed b/tests/ui/iter_with_drain.fixed index a03efceed4ca..9a5b949631f6 100644 --- a/tests/ui/iter_with_drain.fixed +++ b/tests/ui/iter_with_drain.fixed @@ -8,20 +8,25 @@ use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque}; fn full() { let mut a = vec!["aaa".to_string(), "bbb".to_string()]; let mut a: BinaryHeap<_> = a.into_iter().collect(); + //~^ iter_with_drain let mut a: HashSet<_> = a.drain().collect(); let mut a: VecDeque<_> = a.drain().collect(); - let mut a: Vec<_> = a.into_iter().collect(); + let mut a: Vec<_> = a.into_iter().collect(); //~ iter_with_drain let mut a: HashMap<_, _> = a.into_iter().map(|x| (x.clone(), x)).collect(); + //~^ iter_with_drain let _: Vec<(String, String)> = a.drain().collect(); } fn closed() { let mut a = vec!["aaa".to_string(), "bbb".to_string()]; let mut a: BinaryHeap<_> = a.into_iter().collect(); + //~^ iter_with_drain let mut a: HashSet<_> = a.drain().collect(); let mut a: VecDeque<_> = a.drain().collect(); let mut a: Vec<_> = a.into_iter().collect(); + //~^ iter_with_drain let mut a: HashMap<_, _> = a.into_iter().map(|x| (x.clone(), x)).collect(); + //~^ iter_with_drain let _: Vec<(String, String)> = a.drain().collect(); } diff --git a/tests/ui/iter_with_drain.rs b/tests/ui/iter_with_drain.rs index a8cd47f83d04..e652f12678ac 100644 --- a/tests/ui/iter_with_drain.rs +++ b/tests/ui/iter_with_drain.rs @@ -8,20 +8,25 @@ use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque}; fn full() { let mut a = vec!["aaa".to_string(), "bbb".to_string()]; let mut a: BinaryHeap<_> = a.drain(..).collect(); + //~^ iter_with_drain let mut a: HashSet<_> = a.drain().collect(); let mut a: VecDeque<_> = a.drain().collect(); - let mut a: Vec<_> = a.drain(..).collect(); + let mut a: Vec<_> = a.drain(..).collect(); //~ iter_with_drain let mut a: HashMap<_, _> = a.drain(..).map(|x| (x.clone(), x)).collect(); + //~^ iter_with_drain let _: Vec<(String, String)> = a.drain().collect(); } fn closed() { let mut a = vec!["aaa".to_string(), "bbb".to_string()]; let mut a: BinaryHeap<_> = a.drain(0..).collect(); + //~^ iter_with_drain let mut a: HashSet<_> = a.drain().collect(); let mut a: VecDeque<_> = a.drain().collect(); let mut a: Vec<_> = a.drain(..a.len()).collect(); + //~^ iter_with_drain let mut a: HashMap<_, _> = a.drain(0..a.len()).map(|x| (x.clone(), x)).collect(); + //~^ iter_with_drain let _: Vec<(String, String)> = a.drain().collect(); } diff --git a/tests/ui/iter_with_drain.stderr b/tests/ui/iter_with_drain.stderr index ac04f9396f5d..bf70c9cc72ff 100644 --- a/tests/ui/iter_with_drain.stderr +++ b/tests/ui/iter_with_drain.stderr @@ -8,31 +8,31 @@ LL | let mut a: BinaryHeap<_> = a.drain(..).collect(); = help: to override `-D warnings` add `#[allow(clippy::iter_with_drain)]` error: `drain(..)` used on a `VecDeque` - --> $DIR/iter_with_drain.rs:13:27 + --> $DIR/iter_with_drain.rs:14:27 | LL | let mut a: Vec<_> = a.drain(..).collect(); | ^^^^^^^^^ help: try: `into_iter()` error: `drain(..)` used on a `Vec` - --> $DIR/iter_with_drain.rs:14:34 + --> $DIR/iter_with_drain.rs:15:34 | LL | let mut a: HashMap<_, _> = a.drain(..).map(|x| (x.clone(), x)).collect(); | ^^^^^^^^^ help: try: `into_iter()` error: `drain(..)` used on a `Vec` - --> $DIR/iter_with_drain.rs:20:34 + --> $DIR/iter_with_drain.rs:22:34 | LL | let mut a: BinaryHeap<_> = a.drain(0..).collect(); | ^^^^^^^^^^ help: try: `into_iter()` error: `drain(..)` used on a `VecDeque` - --> $DIR/iter_with_drain.rs:23:27 + --> $DIR/iter_with_drain.rs:26:27 | LL | let mut a: Vec<_> = a.drain(..a.len()).collect(); | ^^^^^^^^^^^^^^^^ help: try: `into_iter()` error: `drain(..)` used on a `Vec` - --> $DIR/iter_with_drain.rs:24:34 + --> $DIR/iter_with_drain.rs:28:34 | LL | let mut a: HashMap<_, _> = a.drain(0..a.len()).map(|x| (x.clone(), x)).collect(); | ^^^^^^^^^^^^^^^^^ help: try: `into_iter()` diff --git a/tests/ui/iter_without_into_iter.rs b/tests/ui/iter_without_into_iter.rs index 3054d848efb7..b93783d6138a 100644 --- a/tests/ui/iter_without_into_iter.rs +++ b/tests/ui/iter_without_into_iter.rs @@ -66,6 +66,7 @@ impl S7 { pub struct S8(T); impl S8 { + //~v iter_without_into_iter pub fn iter(&self) -> std::slice::Iter<'static, T> { todo!() } @@ -127,6 +128,7 @@ pub struct Issue12037; macro_rules! generate_impl { () => { impl Issue12037 { + //~v iter_without_into_iter fn iter(&self) -> std::slice::Iter<'_, u8> { todo!() } diff --git a/tests/ui/iter_without_into_iter.stderr b/tests/ui/iter_without_into_iter.stderr index 4cf20e2aa56c..003683bbefb7 100644 --- a/tests/ui/iter_without_into_iter.stderr +++ b/tests/ui/iter_without_into_iter.stderr @@ -85,7 +85,7 @@ LL + } | error: `iter` method without an `IntoIterator` impl for `&S8` - --> $DIR/iter_without_into_iter.rs:69:5 + --> $DIR/iter_without_into_iter.rs:70:5 | LL | / pub fn iter(&self) -> std::slice::Iter<'static, T> { LL | | todo!() @@ -105,7 +105,7 @@ LL + } | error: `iter` method without an `IntoIterator` impl for `&S9` - --> $DIR/iter_without_into_iter.rs:77:5 + --> $DIR/iter_without_into_iter.rs:78:5 | LL | / pub fn iter(&self) -> std::slice::Iter<'_, T> { LL | | @@ -126,7 +126,7 @@ LL + } | error: `iter_mut` method without an `IntoIterator` impl for `&mut S9` - --> $DIR/iter_without_into_iter.rs:81:5 + --> $DIR/iter_without_into_iter.rs:82:5 | LL | / pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, T> { LL | | @@ -147,7 +147,7 @@ LL + } | error: `iter` method without an `IntoIterator` impl for `&Issue12037` - --> $DIR/iter_without_into_iter.rs:130:13 + --> $DIR/iter_without_into_iter.rs:132:13 | LL | / fn iter(&self) -> std::slice::Iter<'_, u8> { LL | | todo!() diff --git a/tests/ui/large_const_arrays.fixed b/tests/ui/large_const_arrays.fixed index 6011bb99dec2..ec1e58391ee4 100644 --- a/tests/ui/large_const_arrays.fixed +++ b/tests/ui/large_const_arrays.fixed @@ -8,8 +8,11 @@ pub struct S { // Should lint pub(crate) static FOO_PUB_CRATE: [u32; 1_000_000] = [0u32; 1_000_000]; +//~^ large_const_arrays pub static FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; +//~^ large_const_arrays static FOO: [u32; 1_000_000] = [0u32; 1_000_000]; +//~^ large_const_arrays // Good pub(crate) const G_FOO_PUB_CRATE: [u32; 1_000] = [0u32; 1_000]; @@ -19,11 +22,17 @@ const G_FOO: [u32; 1_000] = [0u32; 1_000]; fn main() { // Should lint pub static BAR_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; + //~^ large_const_arrays static BAR: [u32; 1_000_000] = [0u32; 1_000_000]; + //~^ large_const_arrays pub static BAR_STRUCT_PUB: [S; 5_000] = [S { data: [0; 32] }; 5_000]; + //~^ large_const_arrays static BAR_STRUCT: [S; 5_000] = [S { data: [0; 32] }; 5_000]; + //~^ large_const_arrays pub static BAR_S_PUB: [Option<&str>; 200_000] = [Some("str"); 200_000]; + //~^ large_const_arrays static BAR_S: [Option<&str>; 200_000] = [Some("str"); 200_000]; + //~^ large_const_arrays // Good pub const G_BAR_PUB: [u32; 1_000] = [0u32; 1_000]; diff --git a/tests/ui/large_const_arrays.rs b/tests/ui/large_const_arrays.rs index a78425d7bc62..32568c3082f7 100644 --- a/tests/ui/large_const_arrays.rs +++ b/tests/ui/large_const_arrays.rs @@ -8,8 +8,11 @@ pub struct S { // Should lint pub(crate) const FOO_PUB_CRATE: [u32; 1_000_000] = [0u32; 1_000_000]; +//~^ large_const_arrays pub const FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; +//~^ large_const_arrays const FOO: [u32; 1_000_000] = [0u32; 1_000_000]; +//~^ large_const_arrays // Good pub(crate) const G_FOO_PUB_CRATE: [u32; 1_000] = [0u32; 1_000]; @@ -19,11 +22,17 @@ const G_FOO: [u32; 1_000] = [0u32; 1_000]; fn main() { // Should lint pub const BAR_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; + //~^ large_const_arrays const BAR: [u32; 1_000_000] = [0u32; 1_000_000]; + //~^ large_const_arrays pub const BAR_STRUCT_PUB: [S; 5_000] = [S { data: [0; 32] }; 5_000]; + //~^ large_const_arrays const BAR_STRUCT: [S; 5_000] = [S { data: [0; 32] }; 5_000]; + //~^ large_const_arrays pub const BAR_S_PUB: [Option<&str>; 200_000] = [Some("str"); 200_000]; + //~^ large_const_arrays const BAR_S: [Option<&str>; 200_000] = [Some("str"); 200_000]; + //~^ large_const_arrays // Good pub const G_BAR_PUB: [u32; 1_000] = [0u32; 1_000]; diff --git a/tests/ui/large_const_arrays.stderr b/tests/ui/large_const_arrays.stderr index e522550ffcbd..b1f76420169e 100644 --- a/tests/ui/large_const_arrays.stderr +++ b/tests/ui/large_const_arrays.stderr @@ -10,7 +10,7 @@ LL | pub(crate) const FOO_PUB_CRATE: [u32; 1_000_000] = [0u32; 1_000_000]; = help: to override `-D warnings` add `#[allow(clippy::large_const_arrays)]` error: large array defined as const - --> $DIR/large_const_arrays.rs:11:1 + --> $DIR/large_const_arrays.rs:12:1 | LL | pub const FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -18,7 +18,7 @@ LL | pub const FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; | help: make this a static item: `static` error: large array defined as const - --> $DIR/large_const_arrays.rs:12:1 + --> $DIR/large_const_arrays.rs:14:1 | LL | const FOO: [u32; 1_000_000] = [0u32; 1_000_000]; | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | const FOO: [u32; 1_000_000] = [0u32; 1_000_000]; | help: make this a static item: `static` error: large array defined as const - --> $DIR/large_const_arrays.rs:21:5 + --> $DIR/large_const_arrays.rs:24:5 | LL | pub const BAR_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | pub const BAR_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; | help: make this a static item: `static` error: large array defined as const - --> $DIR/large_const_arrays.rs:22:5 + --> $DIR/large_const_arrays.rs:26:5 | LL | const BAR: [u32; 1_000_000] = [0u32; 1_000_000]; | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -42,7 +42,7 @@ LL | const BAR: [u32; 1_000_000] = [0u32; 1_000_000]; | help: make this a static item: `static` error: large array defined as const - --> $DIR/large_const_arrays.rs:23:5 + --> $DIR/large_const_arrays.rs:28:5 | LL | pub const BAR_STRUCT_PUB: [S; 5_000] = [S { data: [0; 32] }; 5_000]; | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -50,7 +50,7 @@ LL | pub const BAR_STRUCT_PUB: [S; 5_000] = [S { data: [0; 32] }; 5_000]; | help: make this a static item: `static` error: large array defined as const - --> $DIR/large_const_arrays.rs:24:5 + --> $DIR/large_const_arrays.rs:30:5 | LL | const BAR_STRUCT: [S; 5_000] = [S { data: [0; 32] }; 5_000]; | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -58,7 +58,7 @@ LL | const BAR_STRUCT: [S; 5_000] = [S { data: [0; 32] }; 5_000]; | help: make this a static item: `static` error: large array defined as const - --> $DIR/large_const_arrays.rs:25:5 + --> $DIR/large_const_arrays.rs:32:5 | LL | pub const BAR_S_PUB: [Option<&str>; 200_000] = [Some("str"); 200_000]; | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -66,7 +66,7 @@ LL | pub const BAR_S_PUB: [Option<&str>; 200_000] = [Some("str"); 200_000]; | help: make this a static item: `static` error: large array defined as const - --> $DIR/large_const_arrays.rs:26:5 + --> $DIR/large_const_arrays.rs:34:5 | LL | const BAR_S: [Option<&str>; 200_000] = [Some("str"); 200_000]; | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/large_digit_groups.fixed b/tests/ui/large_digit_groups.fixed index cdb001e47e2b..404057ab2e17 100644 --- a/tests/ui/large_digit_groups.fixed +++ b/tests/ui/large_digit_groups.fixed @@ -19,11 +19,11 @@ fn main() { ); let _bad = ( 0b1_10110_i64, - 0xdead_beef_usize, - 123_456_f32, - 123_456.12_f32, - 123_456.123_45_f64, - 123_456.123_456_f64, + 0xdead_beef_usize, //~ unusual_byte_groupings + 123_456_f32, //~ large_digit_groups + 123_456.12_f32, //~ large_digit_groups + 123_456.123_45_f64, //~ large_digit_groups + 123_456.123_456_f64, //~ large_digit_groups ); // Ignore literals in macros let _ = mac!(); diff --git a/tests/ui/large_digit_groups.rs b/tests/ui/large_digit_groups.rs index 3c30c8670284..03008206ee65 100644 --- a/tests/ui/large_digit_groups.rs +++ b/tests/ui/large_digit_groups.rs @@ -19,11 +19,11 @@ fn main() { ); let _bad = ( 0b1_10110_i64, - 0xd_e_adbee_f_usize, - 1_23456_f32, - 1_23456.12_f32, - 1_23456.12345_f64, - 1_23456.12345_6_f64, + 0xd_e_adbee_f_usize, //~ unusual_byte_groupings + 1_23456_f32, //~ large_digit_groups + 1_23456.12_f32, //~ large_digit_groups + 1_23456.12345_f64, //~ large_digit_groups + 1_23456.12345_6_f64, //~ large_digit_groups ); // Ignore literals in macros let _ = mac!(); diff --git a/tests/ui/large_enum_variant.64bit.stderr b/tests/ui/large_enum_variant.64bit.stderr index 3eba43e05ece..5a584e401583 100644 --- a/tests/ui/large_enum_variant.64bit.stderr +++ b/tests/ui/large_enum_variant.64bit.stderr @@ -1,5 +1,5 @@ error: large size difference between variants - --> $DIR/large_enum_variant.rs:11:1 + --> $DIR/large_enum_variant.rs:12:1 | LL | / enum LargeEnum { LL | | A(i32), @@ -17,7 +17,7 @@ LL | B(Box<[i32; 8000]>), | ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> $DIR/large_enum_variant.rs:35:1 + --> $DIR/large_enum_variant.rs:37:1 | LL | / enum LargeEnum2 { LL | | VariantOk(i32, u32), @@ -33,7 +33,7 @@ LL | ContainingLargeEnum(Box), | ~~~~~~~~~~~~~~ error: large size difference between variants - --> $DIR/large_enum_variant.rs:40:1 + --> $DIR/large_enum_variant.rs:43:1 | LL | / enum LargeEnum3 { LL | | ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), @@ -50,7 +50,7 @@ LL | ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>), | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> $DIR/large_enum_variant.rs:46:1 + --> $DIR/large_enum_variant.rs:50:1 | LL | / enum LargeEnum4 { LL | | VariantOk(i32, u32), @@ -66,7 +66,7 @@ LL | StructLikeLarge { x: Box<[i32; 8000]>, y: i32 }, | ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> $DIR/large_enum_variant.rs:51:1 + --> $DIR/large_enum_variant.rs:56:1 | LL | / enum LargeEnum5 { LL | | VariantOk(i32, u32), @@ -82,7 +82,7 @@ LL | StructLikeLarge2 { x: Box<[i32; 8000]> }, | ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> $DIR/large_enum_variant.rs:67:1 + --> $DIR/large_enum_variant.rs:73:1 | LL | / enum LargeEnum7 { LL | | A, @@ -99,7 +99,7 @@ LL | B(Box<[u8; 1255]>), | ~~~~~~~~~~~~~~~ error: large size difference between variants - --> $DIR/large_enum_variant.rs:73:1 + --> $DIR/large_enum_variant.rs:80:1 | LL | / enum LargeEnum8 { LL | | VariantOk(i32, u32), @@ -115,7 +115,7 @@ LL | ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]> | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> $DIR/large_enum_variant.rs:78:1 + --> $DIR/large_enum_variant.rs:86:1 | LL | / enum LargeEnum9 { LL | | A(Struct<()>), @@ -131,7 +131,7 @@ LL | B(Box), | ~~~~~~~~~~~~ error: large size difference between variants - --> $DIR/large_enum_variant.rs:83:1 + --> $DIR/large_enum_variant.rs:92:1 | LL | / enum LargeEnumOk2 { LL | | A(T), @@ -147,7 +147,7 @@ LL | B(Box), | ~~~~~~~~~~~~ error: large size difference between variants - --> $DIR/large_enum_variant.rs:88:1 + --> $DIR/large_enum_variant.rs:98:1 | LL | / enum LargeEnumOk3 { LL | | A(Struct), @@ -163,7 +163,7 @@ LL | B(Box), | ~~~~~~~~~~~~ error: large size difference between variants - --> $DIR/large_enum_variant.rs:103:1 + --> $DIR/large_enum_variant.rs:114:1 | LL | / enum CopyableLargeEnum { LL | | A(bool), @@ -174,18 +174,18 @@ LL | | } | |_^ the entire enum is at least 64008 bytes | note: boxing a variant would require the type no longer be `Copy` - --> $DIR/large_enum_variant.rs:103:6 + --> $DIR/large_enum_variant.rs:114:6 | LL | enum CopyableLargeEnum { | ^^^^^^^^^^^^^^^^^ help: consider boxing the large fields to reduce the total size of the enum - --> $DIR/large_enum_variant.rs:105:5 + --> $DIR/large_enum_variant.rs:116:5 | LL | B([u64; 8000]), | ^^^^^^^^^^^^^^ error: large size difference between variants - --> $DIR/large_enum_variant.rs:108:1 + --> $DIR/large_enum_variant.rs:120:1 | LL | / enum ManuallyCopyLargeEnum { LL | | A(bool), @@ -196,18 +196,18 @@ LL | | } | |_^ the entire enum is at least 64008 bytes | note: boxing a variant would require the type no longer be `Copy` - --> $DIR/large_enum_variant.rs:108:6 + --> $DIR/large_enum_variant.rs:120:6 | LL | enum ManuallyCopyLargeEnum { | ^^^^^^^^^^^^^^^^^^^^^ help: consider boxing the large fields to reduce the total size of the enum - --> $DIR/large_enum_variant.rs:110:5 + --> $DIR/large_enum_variant.rs:122:5 | LL | B([u64; 8000]), | ^^^^^^^^^^^^^^ error: large size difference between variants - --> $DIR/large_enum_variant.rs:121:1 + --> $DIR/large_enum_variant.rs:134:1 | LL | / enum SomeGenericPossiblyCopyEnum { LL | | A(bool, std::marker::PhantomData), @@ -218,18 +218,18 @@ LL | | } | |_^ the entire enum is at least 32008 bytes | note: boxing a variant would require the type no longer be `Copy` - --> $DIR/large_enum_variant.rs:121:6 + --> $DIR/large_enum_variant.rs:134:6 | LL | enum SomeGenericPossiblyCopyEnum { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider boxing the large fields to reduce the total size of the enum - --> $DIR/large_enum_variant.rs:123:5 + --> $DIR/large_enum_variant.rs:136:5 | LL | B([u64; 4000]), | ^^^^^^^^^^^^^^ error: large size difference between variants - --> $DIR/large_enum_variant.rs:134:1 + --> $DIR/large_enum_variant.rs:148:1 | LL | / enum LargeEnumWithGenerics { LL | | Small, @@ -245,7 +245,7 @@ LL | Large(Box<(T, [u8; 512])>), | ~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> $DIR/large_enum_variant.rs:143:1 + --> $DIR/large_enum_variant.rs:158:1 | LL | / enum WithGenerics { LL | | Large([Foo; 64]), @@ -261,7 +261,7 @@ LL | Large(Box<[Foo; 64]>), | ~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> $DIR/large_enum_variant.rs:153:1 + --> $DIR/large_enum_variant.rs:169:1 | LL | / enum LargeEnumOfConst { LL | | Ok, diff --git a/tests/ui/large_enum_variant.rs b/tests/ui/large_enum_variant.rs index 3625c011dbfa..953887add028 100644 --- a/tests/ui/large_enum_variant.rs +++ b/tests/ui/large_enum_variant.rs @@ -8,6 +8,7 @@ extern crate proc_macros; use proc_macros::external; +//~v large_enum_variant enum LargeEnum { A(i32), B([i32; 8000]), @@ -32,22 +33,26 @@ enum LargeEnumGeneric { Var(A::Item), } +//~v large_enum_variant enum LargeEnum2 { VariantOk(i32, u32), ContainingLargeEnum(LargeEnum), } +//~v large_enum_variant enum LargeEnum3 { ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), VoidVariant, StructLikeLittle { x: i32, y: i32 }, } +//~v large_enum_variant enum LargeEnum4 { VariantOk(i32, u32), StructLikeLarge { x: [i32; 8000], y: i32 }, } +//~v large_enum_variant enum LargeEnum5 { VariantOk(i32, u32), StructLikeLarge2 { x: [i32; 8000] }, @@ -64,27 +69,32 @@ enum LargeEnum6 { C([u8; 200]), } +//~v large_enum_variant enum LargeEnum7 { A, B([u8; 1255]), C([u8; 200]), } +//~v large_enum_variant enum LargeEnum8 { VariantOk(i32, u32), ContainingMoreThanOneField([i32; 8000], [i32; 2], [i32; 9500], [i32; 30]), } +//~v large_enum_variant enum LargeEnum9 { A(Struct<()>), B(Struct2), } +//~v large_enum_variant enum LargeEnumOk2 { A(T), B(Struct2), } +//~v large_enum_variant enum LargeEnumOk3 { A(Struct), B(Struct2), @@ -100,11 +110,13 @@ struct Struct2 { } #[derive(Copy, Clone)] +//~v large_enum_variant enum CopyableLargeEnum { A(bool), B([u64; 8000]), } +//~v large_enum_variant enum ManuallyCopyLargeEnum { A(bool), B([u64; 8000]), @@ -118,6 +130,7 @@ impl Clone for ManuallyCopyLargeEnum { impl Copy for ManuallyCopyLargeEnum {} +//~v large_enum_variant enum SomeGenericPossiblyCopyEnum { A(bool, std::marker::PhantomData), B([u64; 4000]), @@ -131,6 +144,7 @@ impl Clone for SomeGenericPossiblyCopyEnum { impl Copy for SomeGenericPossiblyCopyEnum {} +//~v large_enum_variant enum LargeEnumWithGenerics { Small, Large((T, [u8; 512])), @@ -140,6 +154,7 @@ struct Foo { foo: T, } +//~v large_enum_variant enum WithGenerics { Large([Foo; 64]), Small(u8), @@ -150,6 +165,7 @@ enum PossiblyLargeEnumWithConst { MightyBuffer([u16; U]), } +//~v large_enum_variant enum LargeEnumOfConst { Ok, Error(PossiblyLargeEnumWithConst<256>), diff --git a/tests/ui/large_futures.fixed b/tests/ui/large_futures.fixed index aa8c3021b970..da75d837efd7 100644 --- a/tests/ui/large_futures.fixed +++ b/tests/ui/large_futures.fixed @@ -57,6 +57,7 @@ pub async fn lines() { pub async fn macro_expn() { macro_rules! macro_ { () => { + //~v large_futures Box::pin(async { let x = [0i32; 1024 * 16]; async {}.await; diff --git a/tests/ui/large_futures.rs b/tests/ui/large_futures.rs index fc6ea458d3db..58b4188636a6 100644 --- a/tests/ui/large_futures.rs +++ b/tests/ui/large_futures.rs @@ -57,6 +57,7 @@ pub async fn lines() { pub async fn macro_expn() { macro_rules! macro_ { () => { + //~v large_futures async { let x = [0i32; 1024 * 16]; async {}.await; diff --git a/tests/ui/large_futures.stderr b/tests/ui/large_futures.stderr index 861366dafac6..1834c03c538d 100644 --- a/tests/ui/large_futures.stderr +++ b/tests/ui/large_futures.stderr @@ -59,7 +59,7 @@ LL + }) | error: large future with a size of 65540 bytes - --> $DIR/large_futures.rs:60:13 + --> $DIR/large_futures.rs:61:13 | LL | / async { LL | | let x = [0i32; 1024 * 16]; diff --git a/tests/ui/large_types_passed_by_value.rs b/tests/ui/large_types_passed_by_value.rs index 78994a2988a2..8a90f9a4d000 100644 --- a/tests/ui/large_types_passed_by_value.rs +++ b/tests/ui/large_types_passed_by_value.rs @@ -17,20 +17,25 @@ fn small(a: Small, b: SmallAndCopy) {} fn not_copy(a: Large) {} fn by_ref(a: &Large, b: &LargeAndCopy) {} fn mutable(mut a: LargeAndCopy) {} -fn bad(a: LargeAndCopy) {} +fn bad(a: LargeAndCopy) {} //~ large_types_passed_by_value pub fn bad_but_pub(a: LargeAndCopy) {} impl LargeAndCopy { fn self_is_ok(self) {} fn other_is_not_ok(self, other: LargeAndCopy) {} + //~^ large_types_passed_by_value fn unless_other_can_change(self, mut other: LargeAndCopy) {} pub fn or_were_in_public(self, other: LargeAndCopy) {} } trait LargeTypeDevourer { fn devoure_array(&self, array: [u8; 6666]); + //~^ large_types_passed_by_value fn devoure_tuple(&self, tup: (LargeAndCopy, LargeAndCopy)); + //~^ large_types_passed_by_value fn devoure_array_and_tuple_wow(&self, array: [u8; 6666], tup: (LargeAndCopy, LargeAndCopy)); + //~^ large_types_passed_by_value + //~| large_types_passed_by_value } pub trait PubLargeTypeDevourer { @@ -55,10 +60,12 @@ fn foo_always(x: LargeAndCopy) { todo!(); } #[inline(never)] +//~v large_types_passed_by_value fn foo_never(x: LargeAndCopy) { todo!(); } #[inline] +//~v large_types_passed_by_value fn foo(x: LargeAndCopy) { todo!(); } diff --git a/tests/ui/large_types_passed_by_value.stderr b/tests/ui/large_types_passed_by_value.stderr index b3f102cc498d..70567c17bfea 100644 --- a/tests/ui/large_types_passed_by_value.stderr +++ b/tests/ui/large_types_passed_by_value.stderr @@ -14,37 +14,37 @@ LL | fn other_is_not_ok(self, other: LargeAndCopy) {} | ^^^^^^^^^^^^ help: consider passing by reference instead: `&LargeAndCopy` error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> $DIR/large_types_passed_by_value.rs:31:36 + --> $DIR/large_types_passed_by_value.rs:32:36 | LL | fn devoure_array(&self, array: [u8; 6666]); | ^^^^^^^^^^ help: consider passing by reference instead: `&[u8; 6666]` error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> $DIR/large_types_passed_by_value.rs:32:34 + --> $DIR/large_types_passed_by_value.rs:34:34 | LL | fn devoure_tuple(&self, tup: (LargeAndCopy, LargeAndCopy)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider passing by reference instead: `&(LargeAndCopy, LargeAndCopy)` error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> $DIR/large_types_passed_by_value.rs:33:50 + --> $DIR/large_types_passed_by_value.rs:36:50 | LL | fn devoure_array_and_tuple_wow(&self, array: [u8; 6666], tup: (LargeAndCopy, LargeAndCopy)); | ^^^^^^^^^^ help: consider passing by reference instead: `&[u8; 6666]` error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> $DIR/large_types_passed_by_value.rs:33:67 + --> $DIR/large_types_passed_by_value.rs:36:67 | LL | fn devoure_array_and_tuple_wow(&self, array: [u8; 6666], tup: (LargeAndCopy, LargeAndCopy)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider passing by reference instead: `&(LargeAndCopy, LargeAndCopy)` error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> $DIR/large_types_passed_by_value.rs:58:17 + --> $DIR/large_types_passed_by_value.rs:64:17 | LL | fn foo_never(x: LargeAndCopy) { | ^^^^^^^^^^^^ help: consider passing by reference instead: `&LargeAndCopy` error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> $DIR/large_types_passed_by_value.rs:62:11 + --> $DIR/large_types_passed_by_value.rs:69:11 | LL | fn foo(x: LargeAndCopy) { | ^^^^^^^^^^^^ help: consider passing by reference instead: `&LargeAndCopy` diff --git a/tests/ui/len_zero.fixed b/tests/ui/len_zero.fixed index 745fc7e1a8b3..a7e8adcd9f9f 100644 --- a/tests/ui/len_zero.fixed +++ b/tests/ui/len_zero.fixed @@ -79,11 +79,12 @@ impl Deref for DerefToString { fn main() { let x = [1, 2]; + //~v len_zero if x.is_empty() { println!("This should not happen!"); } - if "".is_empty() {} + if "".is_empty() {} //~ len_zero let s = "Hello, world!"; let s1 = &s; @@ -92,15 +93,15 @@ fn main() { let s4 = &s3; let s5 = &s4; let s6 = &s5; - println!("{}", s1.is_empty()); - println!("{}", s2.is_empty()); - println!("{}", s3.is_empty()); - println!("{}", s4.is_empty()); - println!("{}", s5.is_empty()); - println!("{}", (s6).is_empty()); + println!("{}", s1.is_empty()); //~ comparison_to_empty + println!("{}", s2.is_empty()); //~ comparison_to_empty + println!("{}", s3.is_empty()); //~ comparison_to_empty + println!("{}", s4.is_empty()); //~ comparison_to_empty + println!("{}", s5.is_empty()); //~ comparison_to_empty + println!("{}", (s6).is_empty()); //~ comparison_to_empty let d2s = DerefToDerefToString {}; - println!("{}", (**d2s).is_empty()); + println!("{}", (**d2s).is_empty()); //~ comparison_to_empty let y = One; if y.len() == 0 { @@ -115,18 +116,23 @@ fn main() { } let has_is_empty = HasIsEmpty; + //~v len_zero if has_is_empty.is_empty() { println!("Or this!"); } + //~v len_zero if !has_is_empty.is_empty() { println!("Or this!"); } + //~v len_zero if !has_is_empty.is_empty() { println!("Or this!"); } + //~v len_zero if has_is_empty.is_empty() { println!("Or this!"); } + //~v len_zero if !has_is_empty.is_empty() { println!("Or this!"); } @@ -138,18 +144,23 @@ fn main() { // No error. println!("This can happen."); } + //~v len_zero if has_is_empty.is_empty() { println!("Or this!"); } + //~v len_zero if !has_is_empty.is_empty() { println!("Or this!"); } + //~v len_zero if !has_is_empty.is_empty() { println!("Or this!"); } + //~v len_zero if !has_is_empty.is_empty() { println!("Or this!"); } + //~v len_zero if has_is_empty.is_empty() { println!("Or this!"); } @@ -164,6 +175,7 @@ fn main() { assert!(!has_is_empty.is_empty()); let with_is_empty: &dyn WithIsEmpty = &Wither; + //~v len_zero if with_is_empty.is_empty() { println!("Or this!"); } @@ -177,9 +189,11 @@ fn main() { // issue #10529 (!has_is_empty.is_empty()).then(|| println!("This can happen.")); + //~^ len_zero (has_is_empty.is_empty()).then(|| println!("Or this!")); + //~^ len_zero } fn test_slice(b: &[u8]) { - if !b.is_empty() {} + if !b.is_empty() {} //~ len_zero } diff --git a/tests/ui/len_zero.rs b/tests/ui/len_zero.rs index 048ad2f4fd34..1838cc7ca1a8 100644 --- a/tests/ui/len_zero.rs +++ b/tests/ui/len_zero.rs @@ -79,11 +79,12 @@ impl Deref for DerefToString { fn main() { let x = [1, 2]; + //~v len_zero if x.len() == 0 { println!("This should not happen!"); } - if "".len() == 0 {} + if "".len() == 0 {} //~ len_zero let s = "Hello, world!"; let s1 = &s; @@ -92,15 +93,15 @@ fn main() { let s4 = &s3; let s5 = &s4; let s6 = &s5; - println!("{}", *s1 == ""); - println!("{}", **s2 == ""); - println!("{}", ***s3 == ""); - println!("{}", ****s4 == ""); - println!("{}", *****s5 == ""); - println!("{}", ******(s6) == ""); + println!("{}", *s1 == ""); //~ comparison_to_empty + println!("{}", **s2 == ""); //~ comparison_to_empty + println!("{}", ***s3 == ""); //~ comparison_to_empty + println!("{}", ****s4 == ""); //~ comparison_to_empty + println!("{}", *****s5 == ""); //~ comparison_to_empty + println!("{}", ******(s6) == ""); //~ comparison_to_empty let d2s = DerefToDerefToString {}; - println!("{}", &**d2s == ""); + println!("{}", &**d2s == ""); //~ comparison_to_empty let y = One; if y.len() == 0 { @@ -115,18 +116,23 @@ fn main() { } let has_is_empty = HasIsEmpty; + //~v len_zero if has_is_empty.len() == 0 { println!("Or this!"); } + //~v len_zero if has_is_empty.len() != 0 { println!("Or this!"); } + //~v len_zero if has_is_empty.len() > 0 { println!("Or this!"); } + //~v len_zero if has_is_empty.len() < 1 { println!("Or this!"); } + //~v len_zero if has_is_empty.len() >= 1 { println!("Or this!"); } @@ -138,18 +144,23 @@ fn main() { // No error. println!("This can happen."); } + //~v len_zero if 0 == has_is_empty.len() { println!("Or this!"); } + //~v len_zero if 0 != has_is_empty.len() { println!("Or this!"); } + //~v len_zero if 0 < has_is_empty.len() { println!("Or this!"); } + //~v len_zero if 1 <= has_is_empty.len() { println!("Or this!"); } + //~v len_zero if 1 > has_is_empty.len() { println!("Or this!"); } @@ -164,6 +175,7 @@ fn main() { assert!(!has_is_empty.is_empty()); let with_is_empty: &dyn WithIsEmpty = &Wither; + //~v len_zero if with_is_empty.len() == 0 { println!("Or this!"); } @@ -177,9 +189,11 @@ fn main() { // issue #10529 (has_is_empty.len() > 0).then(|| println!("This can happen.")); + //~^ len_zero (has_is_empty.len() == 0).then(|| println!("Or this!")); + //~^ len_zero } fn test_slice(b: &[u8]) { - if b.len() != 0 {} + if b.len() != 0 {} //~ len_zero } diff --git a/tests/ui/len_zero.stderr b/tests/ui/len_zero.stderr index e1f2434415d0..7706398f4e05 100644 --- a/tests/ui/len_zero.stderr +++ b/tests/ui/len_zero.stderr @@ -1,5 +1,5 @@ error: length comparison to zero - --> $DIR/len_zero.rs:82:8 + --> $DIR/len_zero.rs:83:8 | LL | if x.len() == 0 { | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `x.is_empty()` @@ -8,13 +8,13 @@ LL | if x.len() == 0 { = help: to override `-D warnings` add `#[allow(clippy::len_zero)]` error: length comparison to zero - --> $DIR/len_zero.rs:86:8 + --> $DIR/len_zero.rs:87:8 | LL | if "".len() == 0 {} | ^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `"".is_empty()` error: comparison to empty slice - --> $DIR/len_zero.rs:95:20 + --> $DIR/len_zero.rs:96:20 | LL | println!("{}", *s1 == ""); | ^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s1.is_empty()` @@ -23,121 +23,121 @@ LL | println!("{}", *s1 == ""); = help: to override `-D warnings` add `#[allow(clippy::comparison_to_empty)]` error: comparison to empty slice - --> $DIR/len_zero.rs:96:20 + --> $DIR/len_zero.rs:97:20 | LL | println!("{}", **s2 == ""); | ^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s2.is_empty()` error: comparison to empty slice - --> $DIR/len_zero.rs:97:20 + --> $DIR/len_zero.rs:98:20 | LL | println!("{}", ***s3 == ""); | ^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s3.is_empty()` error: comparison to empty slice - --> $DIR/len_zero.rs:98:20 + --> $DIR/len_zero.rs:99:20 | LL | println!("{}", ****s4 == ""); | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s4.is_empty()` error: comparison to empty slice - --> $DIR/len_zero.rs:99:20 + --> $DIR/len_zero.rs:100:20 | LL | println!("{}", *****s5 == ""); | ^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s5.is_empty()` error: comparison to empty slice - --> $DIR/len_zero.rs:100:20 + --> $DIR/len_zero.rs:101:20 | LL | println!("{}", ******(s6) == ""); | ^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(s6).is_empty()` error: comparison to empty slice - --> $DIR/len_zero.rs:103:20 + --> $DIR/len_zero.rs:104:20 | LL | println!("{}", &**d2s == ""); | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(**d2s).is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:118:8 + --> $DIR/len_zero.rs:120:8 | LL | if has_is_empty.len() == 0 { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:121:8 + --> $DIR/len_zero.rs:124:8 | LL | if has_is_empty.len() != 0 { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:124:8 + --> $DIR/len_zero.rs:128:8 | LL | if has_is_empty.len() > 0 { | ^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to one - --> $DIR/len_zero.rs:127:8 + --> $DIR/len_zero.rs:132:8 | LL | if has_is_empty.len() < 1 { | ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` error: length comparison to one - --> $DIR/len_zero.rs:130:8 + --> $DIR/len_zero.rs:136:8 | LL | if has_is_empty.len() >= 1 { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:141:8 + --> $DIR/len_zero.rs:148:8 | LL | if 0 == has_is_empty.len() { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:144:8 + --> $DIR/len_zero.rs:152:8 | LL | if 0 != has_is_empty.len() { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:147:8 + --> $DIR/len_zero.rs:156:8 | LL | if 0 < has_is_empty.len() { | ^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to one - --> $DIR/len_zero.rs:150:8 + --> $DIR/len_zero.rs:160:8 | LL | if 1 <= has_is_empty.len() { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to one - --> $DIR/len_zero.rs:153:8 + --> $DIR/len_zero.rs:164:8 | LL | if 1 > has_is_empty.len() { | ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:167:8 + --> $DIR/len_zero.rs:179:8 | LL | if with_is_empty.len() == 0 { | ^^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `with_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:179:6 + --> $DIR/len_zero.rs:191:6 | LL | (has_is_empty.len() > 0).then(|| println!("This can happen.")); | ^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:180:6 + --> $DIR/len_zero.rs:193:6 | LL | (has_is_empty.len() == 0).then(|| println!("Or this!")); | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:184:8 + --> $DIR/len_zero.rs:198:8 | LL | if b.len() != 0 {} | ^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!b.is_empty()` diff --git a/tests/ui/len_zero_ranges.fixed b/tests/ui/len_zero_ranges.fixed index 1fdeb2c7a37b..8be2bc9a8eb4 100644 --- a/tests/ui/len_zero_ranges.fixed +++ b/tests/ui/len_zero_ranges.fixed @@ -4,11 +4,11 @@ // Now that `Range(Inclusive)::is_empty` is stable (1.47), we can always suggest this mod issue_3807 { fn suggestion_is_fine_range() { - let _ = (0..42).is_empty(); + let _ = (0..42).is_empty(); //~ len_zero } fn suggestion_is_fine_range_inclusive() { - let _ = (0_u8..=42).is_empty(); + let _ = (0_u8..=42).is_empty(); //~ len_zero } } diff --git a/tests/ui/len_zero_ranges.rs b/tests/ui/len_zero_ranges.rs index a5c9a969aaa6..4d6295047e12 100644 --- a/tests/ui/len_zero_ranges.rs +++ b/tests/ui/len_zero_ranges.rs @@ -4,11 +4,11 @@ // Now that `Range(Inclusive)::is_empty` is stable (1.47), we can always suggest this mod issue_3807 { fn suggestion_is_fine_range() { - let _ = (0..42).len() == 0; + let _ = (0..42).len() == 0; //~ len_zero } fn suggestion_is_fine_range_inclusive() { - let _ = (0_u8..=42).len() == 0; + let _ = (0_u8..=42).len() == 0; //~ len_zero } } diff --git a/tests/ui/let_underscore_untyped.rs b/tests/ui/let_underscore_untyped.rs index bd94a3ada18b..de895a81dc02 100644 --- a/tests/ui/let_underscore_untyped.rs +++ b/tests/ui/let_underscore_untyped.rs @@ -48,12 +48,12 @@ with_span!( ); fn main() { - let _ = a(); - let _ = b(1); + let _ = a(); //~ let_underscore_untyped + let _ = b(1); //~ let_underscore_untyped let _ = c(); - let _ = d(&1); - let _ = e(); - let _ = f(); + let _ = d(&1); //~ let_underscore_untyped + let _ = e(); //~ let_underscore_untyped + let _ = f(); //~ let_underscore_untyped let _ = g(); let closure = || {}; diff --git a/tests/ui/let_unit.fixed b/tests/ui/let_unit.fixed index 4d41b5e5e503..89cbec946ecf 100644 --- a/tests/ui/let_unit.fixed +++ b/tests/ui/let_unit.fixed @@ -9,7 +9,7 @@ macro_rules! let_and_return { } fn main() { - println!("x"); + println!("x"); //~ let_unit_value let _y = 1; // this is fine let _z = ((), 1); // this as well if true { @@ -57,6 +57,7 @@ fn consume_units_with_for_loop() { fn multiline_sugg() { let v: Vec = vec![2]; + //~v let_unit_value v .into_iter() .map(|i| i * 2) @@ -106,6 +107,7 @@ fn _returns_generic() { let _: () = if true { f() } else { f2(0) }; let x: () = if true { f() } else { f2(0) }; + //~v let_unit_value match Some(0) { None => f2(1), Some(0) => f(), diff --git a/tests/ui/let_unit.rs b/tests/ui/let_unit.rs index daa660be25e6..0e007ab8e403 100644 --- a/tests/ui/let_unit.rs +++ b/tests/ui/let_unit.rs @@ -9,7 +9,7 @@ macro_rules! let_and_return { } fn main() { - let _x = println!("x"); + let _x = println!("x"); //~ let_unit_value let _y = 1; // this is fine let _z = ((), 1); // this as well if true { @@ -57,6 +57,7 @@ fn consume_units_with_for_loop() { fn multiline_sugg() { let v: Vec = vec![2]; + //~v let_unit_value let _ = v .into_iter() .map(|i| i * 2) @@ -106,6 +107,7 @@ fn _returns_generic() { let _: () = if true { f() } else { f2(0) }; let x: () = if true { f() } else { f2(0) }; + //~v let_unit_value let x = match Some(0) { None => f2(1), Some(0) => f(), diff --git a/tests/ui/let_unit.stderr b/tests/ui/let_unit.stderr index 00a3c439ba06..c299be38d562 100644 --- a/tests/ui/let_unit.stderr +++ b/tests/ui/let_unit.stderr @@ -8,7 +8,7 @@ LL | let _x = println!("x"); = help: to override `-D warnings` add `#[allow(clippy::let_unit_value)]` error: this let-binding has unit value - --> $DIR/let_unit.rs:60:5 + --> $DIR/let_unit.rs:61:5 | LL | / let _ = v LL | | .into_iter() @@ -31,7 +31,7 @@ LL + .unwrap(); | error: this let-binding has unit value - --> $DIR/let_unit.rs:109:5 + --> $DIR/let_unit.rs:111:5 | LL | / let x = match Some(0) { LL | | None => f2(1), diff --git a/tests/ui/let_with_type_underscore.rs b/tests/ui/let_with_type_underscore.rs index ae1a480bcfc5..29147ec12e65 100644 --- a/tests/ui/let_with_type_underscore.rs +++ b/tests/ui/let_with_type_underscore.rs @@ -12,17 +12,17 @@ fn func() -> &'static str { #[rustfmt::skip] fn main() { // Will lint - let x: _ = 1; - let _: _ = 2; - let x: _ = func(); - let x: _; + let x: _ = 1; //~ let_with_type_underscore + let _: _ = 2; //~ let_with_type_underscore + let x: _ = func(); //~ let_with_type_underscore + let x: _; //~ let_with_type_underscore x = (); let x = 1; // Will not lint, Rust infers this to an integer before Clippy let x = func(); let x: Vec<_> = Vec::::new(); let x: [_; 1] = [1]; - let x : _ = 1; + let x : _ = 1; //~ let_with_type_underscore // Do not lint from procedural macros proc_macros::with_span! { diff --git a/tests/ui/lines_filter_map_ok.fixed b/tests/ui/lines_filter_map_ok.fixed index 621115cc1325..9689cc813306 100644 --- a/tests/ui/lines_filter_map_ok.fixed +++ b/tests/ui/lines_filter_map_ok.fixed @@ -7,20 +7,26 @@ fn main() -> io::Result<()> { let f = std::fs::File::open("/")?; // Lint BufReader::new(f).lines().map_while(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok // Lint let f = std::fs::File::open("/")?; BufReader::new(f).lines().map_while(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok // Lint let f = std::fs::File::open("/")?; BufReader::new(f).lines().map_while(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok let s = "foo\nbar\nbaz\n"; // Lint io::stdin().lines().map_while(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok // Lint io::stdin().lines().map_while(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok // Lint io::stdin().lines().map_while(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok // Do not lint (not a `Lines` iterator) io::stdin() .lines() diff --git a/tests/ui/lines_filter_map_ok.rs b/tests/ui/lines_filter_map_ok.rs index a86efbd66862..63b77453e575 100644 --- a/tests/ui/lines_filter_map_ok.rs +++ b/tests/ui/lines_filter_map_ok.rs @@ -7,20 +7,26 @@ fn main() -> io::Result<()> { let f = std::fs::File::open("/")?; // Lint BufReader::new(f).lines().filter_map(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok // Lint let f = std::fs::File::open("/")?; BufReader::new(f).lines().flat_map(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok // Lint let f = std::fs::File::open("/")?; BufReader::new(f).lines().flatten().for_each(|_| ()); + //~^ lines_filter_map_ok let s = "foo\nbar\nbaz\n"; // Lint io::stdin().lines().filter_map(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok // Lint io::stdin().lines().filter_map(|x| x.ok()).for_each(|_| ()); + //~^ lines_filter_map_ok // Lint io::stdin().lines().flatten().for_each(|_| ()); + //~^ lines_filter_map_ok // Do not lint (not a `Lines` iterator) io::stdin() .lines() diff --git a/tests/ui/lines_filter_map_ok.stderr b/tests/ui/lines_filter_map_ok.stderr index 9833ab16473c..d08c6c9192cb 100644 --- a/tests/ui/lines_filter_map_ok.stderr +++ b/tests/ui/lines_filter_map_ok.stderr @@ -13,61 +13,61 @@ LL | BufReader::new(f).lines().filter_map(Result::ok).for_each(|_| ()); = help: to override `-D warnings` add `#[allow(clippy::lines_filter_map_ok)]` error: `flat_map()` will run forever if the iterator repeatedly produces an `Err` - --> $DIR/lines_filter_map_ok.rs:12:31 + --> $DIR/lines_filter_map_ok.rs:13:31 | LL | BufReader::new(f).lines().flat_map(Result::ok).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^^ help: replace with: `map_while(Result::ok)` | note: this expression returning a `std::io::Lines` may produce an infinite number of `Err` in case of a read error - --> $DIR/lines_filter_map_ok.rs:12:5 + --> $DIR/lines_filter_map_ok.rs:13:5 | LL | BufReader::new(f).lines().flat_map(Result::ok).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `flatten()` will run forever if the iterator repeatedly produces an `Err` - --> $DIR/lines_filter_map_ok.rs:15:31 + --> $DIR/lines_filter_map_ok.rs:17:31 | LL | BufReader::new(f).lines().flatten().for_each(|_| ()); | ^^^^^^^^^ help: replace with: `map_while(Result::ok)` | note: this expression returning a `std::io::Lines` may produce an infinite number of `Err` in case of a read error - --> $DIR/lines_filter_map_ok.rs:15:5 + --> $DIR/lines_filter_map_ok.rs:17:5 | LL | BufReader::new(f).lines().flatten().for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `filter_map()` will run forever if the iterator repeatedly produces an `Err` - --> $DIR/lines_filter_map_ok.rs:19:25 + --> $DIR/lines_filter_map_ok.rs:22:25 | LL | io::stdin().lines().filter_map(Result::ok).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `map_while(Result::ok)` | note: this expression returning a `std::io::Lines` may produce an infinite number of `Err` in case of a read error - --> $DIR/lines_filter_map_ok.rs:19:5 + --> $DIR/lines_filter_map_ok.rs:22:5 | LL | io::stdin().lines().filter_map(Result::ok).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^ error: `filter_map()` will run forever if the iterator repeatedly produces an `Err` - --> $DIR/lines_filter_map_ok.rs:21:25 + --> $DIR/lines_filter_map_ok.rs:25:25 | LL | io::stdin().lines().filter_map(|x| x.ok()).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `map_while(Result::ok)` | note: this expression returning a `std::io::Lines` may produce an infinite number of `Err` in case of a read error - --> $DIR/lines_filter_map_ok.rs:21:5 + --> $DIR/lines_filter_map_ok.rs:25:5 | LL | io::stdin().lines().filter_map(|x| x.ok()).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^ error: `flatten()` will run forever if the iterator repeatedly produces an `Err` - --> $DIR/lines_filter_map_ok.rs:23:25 + --> $DIR/lines_filter_map_ok.rs:28:25 | LL | io::stdin().lines().flatten().for_each(|_| ()); | ^^^^^^^^^ help: replace with: `map_while(Result::ok)` | note: this expression returning a `std::io::Lines` may produce an infinite number of `Err` in case of a read error - --> $DIR/lines_filter_map_ok.rs:23:5 + --> $DIR/lines_filter_map_ok.rs:28:5 | LL | io::stdin().lines().flatten().for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/lossy_float_literal.fixed b/tests/ui/lossy_float_literal.fixed index 92a0084a6aeb..2484cc56bf0c 100644 --- a/tests/ui/lossy_float_literal.fixed +++ b/tests/ui/lossy_float_literal.fixed @@ -3,17 +3,17 @@ fn main() { // Lossy whole-number float literals - let _: f32 = 16_777_216.0; - let _: f32 = 16_777_220.0; - let _: f32 = 16_777_220.0; - let _: f32 = 16_777_220.0; - let _ = 16_777_220_f32; - let _: f32 = -16_777_220.0; - let _: f64 = 9_007_199_254_740_992.0; - let _: f64 = 9_007_199_254_740_992.0; - let _: f64 = 9_007_199_254_740_992.0; - let _ = 9_007_199_254_740_992_f64; - let _: f64 = -9_007_199_254_740_992.0; + let _: f32 = 16_777_216.0; //~ lossy_float_literal + let _: f32 = 16_777_220.0; //~ lossy_float_literal + let _: f32 = 16_777_220.0; //~ lossy_float_literal + let _: f32 = 16_777_220.0; //~ lossy_float_literal + let _ = 16_777_220_f32; //~ lossy_float_literal + let _: f32 = -16_777_220.0; //~ lossy_float_literal + let _: f64 = 9_007_199_254_740_992.0; //~ lossy_float_literal + let _: f64 = 9_007_199_254_740_992.0; //~ lossy_float_literal + let _: f64 = 9_007_199_254_740_992.0; //~ lossy_float_literal + let _ = 9_007_199_254_740_992_f64; //~ lossy_float_literal + let _: f64 = -9_007_199_254_740_992.0; //~ lossy_float_literal // Lossless whole number float literals let _: f32 = 16_777_216.0; diff --git a/tests/ui/lossy_float_literal.rs b/tests/ui/lossy_float_literal.rs index 5abef3c442ec..57448e3fa144 100644 --- a/tests/ui/lossy_float_literal.rs +++ b/tests/ui/lossy_float_literal.rs @@ -3,17 +3,17 @@ fn main() { // Lossy whole-number float literals - let _: f32 = 16_777_217.0; - let _: f32 = 16_777_219.0; - let _: f32 = 16_777_219.; - let _: f32 = 16_777_219.000; - let _ = 16_777_219f32; - let _: f32 = -16_777_219.0; - let _: f64 = 9_007_199_254_740_993.0; - let _: f64 = 9_007_199_254_740_993.; - let _: f64 = 9_007_199_254_740_993.00; - let _ = 9_007_199_254_740_993f64; - let _: f64 = -9_007_199_254_740_993.0; + let _: f32 = 16_777_217.0; //~ lossy_float_literal + let _: f32 = 16_777_219.0; //~ lossy_float_literal + let _: f32 = 16_777_219.; //~ lossy_float_literal + let _: f32 = 16_777_219.000; //~ lossy_float_literal + let _ = 16_777_219f32; //~ lossy_float_literal + let _: f32 = -16_777_219.0; //~ lossy_float_literal + let _: f64 = 9_007_199_254_740_993.0; //~ lossy_float_literal + let _: f64 = 9_007_199_254_740_993.; //~ lossy_float_literal + let _: f64 = 9_007_199_254_740_993.00; //~ lossy_float_literal + let _ = 9_007_199_254_740_993f64; //~ lossy_float_literal + let _: f64 = -9_007_199_254_740_993.0; //~ lossy_float_literal // Lossless whole number float literals let _: f32 = 16_777_216.0; diff --git a/tests/ui/macro_use_imports.fixed b/tests/ui/macro_use_imports.fixed index 46c053b779e7..e917fd1039dd 100644 --- a/tests/ui/macro_use_imports.fixed +++ b/tests/ui/macro_use_imports.fixed @@ -16,13 +16,13 @@ extern crate macro_use_helper as mac; extern crate proc_macro_derive as mini_mac; mod a { - use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro}; + use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro}; //~ macro_use_imports use mac; - use mini_mac::ClippyMiniMacroTest; + use mini_mac::ClippyMiniMacroTest; //~ macro_use_imports use mini_mac; - use mac::{inner::mut_mut, inner::try_err}; + use mac::{inner::mut_mut, inner::try_err}; //~ macro_use_imports use mac::inner; - use mac::inner::nested::string_add; + use mac::inner::nested::string_add; //~ macro_use_imports use mac::inner::nested; #[derive(ClippyMiniMacroTest)] diff --git a/tests/ui/macro_use_imports.rs b/tests/ui/macro_use_imports.rs index 47f5c9bf8845..b265c384b28b 100644 --- a/tests/ui/macro_use_imports.rs +++ b/tests/ui/macro_use_imports.rs @@ -16,13 +16,13 @@ extern crate macro_use_helper as mac; extern crate proc_macro_derive as mini_mac; mod a { - #[macro_use] + #[macro_use] //~ macro_use_imports use mac; - #[macro_use] + #[macro_use] //~ macro_use_imports use mini_mac; - #[macro_use] + #[macro_use] //~ macro_use_imports use mac::inner; - #[macro_use] + #[macro_use] //~ macro_use_imports use mac::inner::nested; #[derive(ClippyMiniMacroTest)] diff --git a/tests/ui/manual_assert.edition2018.fixed b/tests/ui/manual_assert.edition2018.fixed index 75beedfa4508..a295c17ad9bd 100644 --- a/tests/ui/manual_assert.edition2018.fixed +++ b/tests/ui/manual_assert.edition2018.fixed @@ -27,7 +27,9 @@ fn main() { { panic!("qaqaq{:?}", a); } + //~v manual_assert assert!(a.is_empty(), "qaqaq{:?}", a); + //~v manual_assert assert!(a.is_empty(), "qwqwq"); if a.len() == 3 { println!("qwq"); @@ -43,11 +45,17 @@ fn main() { println!("qwq"); } let b = vec![1, 2, 3]; + //~v manual_assert assert!(!b.is_empty(), "panic1"); + //~v manual_assert assert!(!(b.is_empty() && a.is_empty()), "panic2"); + //~v manual_assert assert!(!(a.is_empty() && !b.is_empty()), "panic3"); + //~v manual_assert assert!(!(b.is_empty() || a.is_empty()), "panic4"); + //~v manual_assert assert!(!(a.is_empty() || !b.is_empty()), "panic5"); + //~v manual_assert assert!(!a.is_empty(), "with expansion {}", one!()); if a.is_empty() { let _ = 0; @@ -58,6 +66,7 @@ fn main() { fn issue7730(a: u8) { // Suggestion should preserve comment + //~v manual_assert // comment /* this is a multiline diff --git a/tests/ui/manual_assert.edition2018.stderr b/tests/ui/manual_assert.edition2018.stderr index b19cca4d5f91..6eebb49ad296 100644 --- a/tests/ui/manual_assert.edition2018.stderr +++ b/tests/ui/manual_assert.edition2018.stderr @@ -1,5 +1,5 @@ error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:30:5 + --> $DIR/manual_assert.rs:31:5 | LL | / if !a.is_empty() { LL | | panic!("qaqaq{:?}", a); @@ -10,7 +10,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::manual_assert)]` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:33:5 + --> $DIR/manual_assert.rs:35:5 | LL | / if !a.is_empty() { LL | | panic!("qwqwq"); @@ -18,7 +18,7 @@ LL | | } | |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:50:5 + --> $DIR/manual_assert.rs:53:5 | LL | / if b.is_empty() { LL | | panic!("panic1"); @@ -26,7 +26,7 @@ LL | | } | |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:53:5 + --> $DIR/manual_assert.rs:57:5 | LL | / if b.is_empty() && a.is_empty() { LL | | panic!("panic2"); @@ -34,7 +34,7 @@ LL | | } | |_____^ help: try instead: `assert!(!(b.is_empty() && a.is_empty()), "panic2");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:56:5 + --> $DIR/manual_assert.rs:61:5 | LL | / if a.is_empty() && !b.is_empty() { LL | | panic!("panic3"); @@ -42,7 +42,7 @@ LL | | } | |_____^ help: try instead: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:59:5 + --> $DIR/manual_assert.rs:65:5 | LL | / if b.is_empty() || a.is_empty() { LL | | panic!("panic4"); @@ -50,7 +50,7 @@ LL | | } | |_____^ help: try instead: `assert!(!(b.is_empty() || a.is_empty()), "panic4");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:62:5 + --> $DIR/manual_assert.rs:69:5 | LL | / if a.is_empty() || !b.is_empty() { LL | | panic!("panic5"); @@ -58,7 +58,7 @@ LL | | } | |_____^ help: try instead: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:65:5 + --> $DIR/manual_assert.rs:73:5 | LL | / if a.is_empty() { LL | | panic!("with expansion {}", one!()) @@ -66,7 +66,7 @@ LL | | } | |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:77:5 + --> $DIR/manual_assert.rs:86:5 | LL | / if a > 2 { LL | | // comment diff --git a/tests/ui/manual_assert.edition2021.fixed b/tests/ui/manual_assert.edition2021.fixed index 75beedfa4508..a295c17ad9bd 100644 --- a/tests/ui/manual_assert.edition2021.fixed +++ b/tests/ui/manual_assert.edition2021.fixed @@ -27,7 +27,9 @@ fn main() { { panic!("qaqaq{:?}", a); } + //~v manual_assert assert!(a.is_empty(), "qaqaq{:?}", a); + //~v manual_assert assert!(a.is_empty(), "qwqwq"); if a.len() == 3 { println!("qwq"); @@ -43,11 +45,17 @@ fn main() { println!("qwq"); } let b = vec![1, 2, 3]; + //~v manual_assert assert!(!b.is_empty(), "panic1"); + //~v manual_assert assert!(!(b.is_empty() && a.is_empty()), "panic2"); + //~v manual_assert assert!(!(a.is_empty() && !b.is_empty()), "panic3"); + //~v manual_assert assert!(!(b.is_empty() || a.is_empty()), "panic4"); + //~v manual_assert assert!(!(a.is_empty() || !b.is_empty()), "panic5"); + //~v manual_assert assert!(!a.is_empty(), "with expansion {}", one!()); if a.is_empty() { let _ = 0; @@ -58,6 +66,7 @@ fn main() { fn issue7730(a: u8) { // Suggestion should preserve comment + //~v manual_assert // comment /* this is a multiline diff --git a/tests/ui/manual_assert.edition2021.stderr b/tests/ui/manual_assert.edition2021.stderr index b19cca4d5f91..6eebb49ad296 100644 --- a/tests/ui/manual_assert.edition2021.stderr +++ b/tests/ui/manual_assert.edition2021.stderr @@ -1,5 +1,5 @@ error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:30:5 + --> $DIR/manual_assert.rs:31:5 | LL | / if !a.is_empty() { LL | | panic!("qaqaq{:?}", a); @@ -10,7 +10,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::manual_assert)]` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:33:5 + --> $DIR/manual_assert.rs:35:5 | LL | / if !a.is_empty() { LL | | panic!("qwqwq"); @@ -18,7 +18,7 @@ LL | | } | |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:50:5 + --> $DIR/manual_assert.rs:53:5 | LL | / if b.is_empty() { LL | | panic!("panic1"); @@ -26,7 +26,7 @@ LL | | } | |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:53:5 + --> $DIR/manual_assert.rs:57:5 | LL | / if b.is_empty() && a.is_empty() { LL | | panic!("panic2"); @@ -34,7 +34,7 @@ LL | | } | |_____^ help: try instead: `assert!(!(b.is_empty() && a.is_empty()), "panic2");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:56:5 + --> $DIR/manual_assert.rs:61:5 | LL | / if a.is_empty() && !b.is_empty() { LL | | panic!("panic3"); @@ -42,7 +42,7 @@ LL | | } | |_____^ help: try instead: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:59:5 + --> $DIR/manual_assert.rs:65:5 | LL | / if b.is_empty() || a.is_empty() { LL | | panic!("panic4"); @@ -50,7 +50,7 @@ LL | | } | |_____^ help: try instead: `assert!(!(b.is_empty() || a.is_empty()), "panic4");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:62:5 + --> $DIR/manual_assert.rs:69:5 | LL | / if a.is_empty() || !b.is_empty() { LL | | panic!("panic5"); @@ -58,7 +58,7 @@ LL | | } | |_____^ help: try instead: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:65:5 + --> $DIR/manual_assert.rs:73:5 | LL | / if a.is_empty() { LL | | panic!("with expansion {}", one!()) @@ -66,7 +66,7 @@ LL | | } | |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:77:5 + --> $DIR/manual_assert.rs:86:5 | LL | / if a > 2 { LL | | // comment diff --git a/tests/ui/manual_assert.rs b/tests/ui/manual_assert.rs index 5979496ca836..43a0f7660035 100644 --- a/tests/ui/manual_assert.rs +++ b/tests/ui/manual_assert.rs @@ -27,9 +27,11 @@ fn main() { { panic!("qaqaq{:?}", a); } + //~v manual_assert if !a.is_empty() { panic!("qaqaq{:?}", a); } + //~v manual_assert if !a.is_empty() { panic!("qwqwq"); } @@ -47,21 +49,27 @@ fn main() { println!("qwq"); } let b = vec![1, 2, 3]; + //~v manual_assert if b.is_empty() { panic!("panic1"); } + //~v manual_assert if b.is_empty() && a.is_empty() { panic!("panic2"); } + //~v manual_assert if a.is_empty() && !b.is_empty() { panic!("panic3"); } + //~v manual_assert if b.is_empty() || a.is_empty() { panic!("panic4"); } + //~v manual_assert if a.is_empty() || !b.is_empty() { panic!("panic5"); } + //~v manual_assert if a.is_empty() { panic!("with expansion {}", one!()) } @@ -74,6 +82,7 @@ fn main() { fn issue7730(a: u8) { // Suggestion should preserve comment + //~v manual_assert if a > 2 { // comment /* this is a diff --git a/tests/ui/manual_async_fn.fixed b/tests/ui/manual_async_fn.fixed index 18444090a426..8993025c593e 100644 --- a/tests/ui/manual_async_fn.fixed +++ b/tests/ui/manual_async_fn.fixed @@ -3,22 +3,29 @@ use std::future::Future; +//~v manual_async_fn async fn fut() -> i32 { 42 } #[rustfmt::skip] +//~v manual_async_fn async fn fut2() -> i32 { 42 } #[rustfmt::skip] +//~v manual_async_fn async fn fut3() -> i32 { 42 } +//~v manual_async_fn async fn empty_fut() {} #[rustfmt::skip] +//~v manual_async_fn async fn empty_fut2() {} #[rustfmt::skip] +//~v manual_async_fn async fn empty_fut3() {} +//~v manual_async_fn async fn core_fut() -> i32 { 42 } // should be ignored @@ -39,6 +46,7 @@ async fn already_async() -> impl Future { struct S; impl S { + //~v manual_async_fn async fn inh_fut() -> i32 { // NOTE: this code is here just to check that the indentation is correct in the suggested fix let a = 42; @@ -72,6 +80,7 @@ impl S { // Tests related to lifetime capture +//~v manual_async_fn async fn elided(_: &i32) -> i32 { 42 } // should be ignored @@ -79,6 +88,7 @@ fn elided_not_bound(_: &i32) -> impl Future { async { 42 } } +//~v manual_async_fn async fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> i32 { 42 } // should be ignored @@ -106,10 +116,13 @@ mod issue_5765 { } } +//~v manual_async_fn pub async fn issue_10450() -> i32 { 42 } +//~v manual_async_fn pub(crate) async fn issue_10450_2() -> i32 { 42 } +//~v manual_async_fn pub(self) async fn issue_10450_3() -> i32 { 42 } fn main() {} diff --git a/tests/ui/manual_async_fn.rs b/tests/ui/manual_async_fn.rs index d42165bbe3d8..b9b123591bf3 100644 --- a/tests/ui/manual_async_fn.rs +++ b/tests/ui/manual_async_fn.rs @@ -3,34 +3,41 @@ use std::future::Future; +//~v manual_async_fn fn fut() -> impl Future { async { 42 } } #[rustfmt::skip] +//~v manual_async_fn fn fut2() ->impl Future { async { 42 } } #[rustfmt::skip] +//~v manual_async_fn fn fut3()-> impl Future { async { 42 } } +//~v manual_async_fn fn empty_fut() -> impl Future { async {} } #[rustfmt::skip] +//~v manual_async_fn fn empty_fut2() ->impl Future { async {} } #[rustfmt::skip] +//~v manual_async_fn fn empty_fut3()-> impl Future { async {} } +//~v manual_async_fn fn core_fut() -> impl core::future::Future { async move { 42 } } @@ -53,6 +60,7 @@ async fn already_async() -> impl Future { struct S; impl S { + //~v manual_async_fn fn inh_fut() -> impl Future { async { // NOTE: this code is here just to check that the indentation is correct in the suggested fix @@ -88,6 +96,7 @@ impl S { // Tests related to lifetime capture +//~v manual_async_fn fn elided(_: &i32) -> impl Future + '_ { async { 42 } } @@ -97,6 +106,7 @@ fn elided_not_bound(_: &i32) -> impl Future { async { 42 } } +//~v manual_async_fn fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + 'a + 'b { async { 42 } } @@ -126,14 +136,17 @@ mod issue_5765 { } } +//~v manual_async_fn pub fn issue_10450() -> impl Future { async { 42 } } +//~v manual_async_fn pub(crate) fn issue_10450_2() -> impl Future { async { 42 } } +//~v manual_async_fn pub(self) fn issue_10450_3() -> impl Future { async { 42 } } diff --git a/tests/ui/manual_async_fn.stderr b/tests/ui/manual_async_fn.stderr index c0c471912e49..50b2fb2c96f2 100644 --- a/tests/ui/manual_async_fn.stderr +++ b/tests/ui/manual_async_fn.stderr @@ -1,5 +1,5 @@ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:6:1 + --> $DIR/manual_async_fn.rs:7:1 | LL | fn fut() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | fn fut() -> impl Future { 42 } | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:11:1 + --> $DIR/manual_async_fn.rs:13:1 | LL | fn fut2() ->impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +31,7 @@ LL | fn fut2() ->impl Future { 42 } | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:16:1 + --> $DIR/manual_async_fn.rs:19:1 | LL | fn fut3()-> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | fn fut3()-> impl Future { 42 } | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:20:1 + --> $DIR/manual_async_fn.rs:24:1 | LL | fn empty_fut() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | fn empty_fut() -> impl Future {} | ~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:25:1 + --> $DIR/manual_async_fn.rs:30:1 | LL | fn empty_fut2() ->impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -76,7 +76,7 @@ LL | fn empty_fut2() ->impl Future {} | ~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:30:1 + --> $DIR/manual_async_fn.rs:36:1 | LL | fn empty_fut3()-> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -91,7 +91,7 @@ LL | fn empty_fut3()-> impl Future {} | ~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:34:1 + --> $DIR/manual_async_fn.rs:41:1 | LL | fn core_fut() -> impl core::future::Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -106,7 +106,7 @@ LL | fn core_fut() -> impl core::future::Future { 42 } | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:56:5 + --> $DIR/manual_async_fn.rs:64:5 | LL | fn inh_fut() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + } | error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:91:1 + --> $DIR/manual_async_fn.rs:100:1 | LL | fn elided(_: &i32) -> impl Future + '_ { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -148,7 +148,7 @@ LL | fn elided(_: &i32) -> impl Future + '_ { 42 } | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:100:1 + --> $DIR/manual_async_fn.rs:110:1 | LL | fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + 'a + 'b { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -163,7 +163,7 @@ LL | fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:129:1 + --> $DIR/manual_async_fn.rs:140:1 | LL | pub fn issue_10450() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -178,7 +178,7 @@ LL | pub fn issue_10450() -> impl Future { 42 } | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:133:1 + --> $DIR/manual_async_fn.rs:145:1 | LL | pub(crate) fn issue_10450_2() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL | pub(crate) fn issue_10450_2() -> impl Future { 42 } | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:137:1 + --> $DIR/manual_async_fn.rs:150:1 | LL | pub(self) fn issue_10450_3() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/manual_bits.fixed b/tests/ui/manual_bits.fixed index 4de01905e8ad..ec3edc969b49 100644 --- a/tests/ui/manual_bits.fixed +++ b/tests/ui/manual_bits.fixed @@ -11,33 +11,33 @@ use std::mem::{size_of, size_of_val}; fn main() { - i8::BITS as usize; - i16::BITS as usize; - i32::BITS as usize; - i64::BITS as usize; - i128::BITS as usize; - isize::BITS as usize; - - u8::BITS as usize; - u16::BITS as usize; - u32::BITS as usize; - u64::BITS as usize; - u128::BITS as usize; - usize::BITS as usize; - - i8::BITS as usize; - i16::BITS as usize; - i32::BITS as usize; - i64::BITS as usize; - i128::BITS as usize; - isize::BITS as usize; - - u8::BITS as usize; - u16::BITS as usize; - u32::BITS as usize; - u64::BITS as usize; - u128::BITS as usize; - usize::BITS as usize; + i8::BITS as usize; //~ manual_bits + i16::BITS as usize; //~ manual_bits + i32::BITS as usize; //~ manual_bits + i64::BITS as usize; //~ manual_bits + i128::BITS as usize; //~ manual_bits + isize::BITS as usize; //~ manual_bits + + u8::BITS as usize; //~ manual_bits + u16::BITS as usize; //~ manual_bits + u32::BITS as usize; //~ manual_bits + u64::BITS as usize; //~ manual_bits + u128::BITS as usize; //~ manual_bits + usize::BITS as usize; //~ manual_bits + + i8::BITS as usize; //~ manual_bits + i16::BITS as usize; //~ manual_bits + i32::BITS as usize; //~ manual_bits + i64::BITS as usize; //~ manual_bits + i128::BITS as usize; //~ manual_bits + isize::BITS as usize; //~ manual_bits + + u8::BITS as usize; //~ manual_bits + u16::BITS as usize; //~ manual_bits + u32::BITS as usize; //~ manual_bits + u64::BITS as usize; //~ manual_bits + u128::BITS as usize; //~ manual_bits + usize::BITS as usize; //~ manual_bits size_of::() * 4; 4 * size_of::(); @@ -47,12 +47,13 @@ fn main() { size_of_val(&0u32) * 8; type Word = u32; - Word::BITS as usize; + Word::BITS as usize; //~ manual_bits type Bool = bool; size_of::() * 8; - let _: u32 = u128::BITS as u32; + let _: u32 = u128::BITS as u32; //~ manual_bits let _: u32 = u128::BITS.try_into().unwrap(); - let _ = (u128::BITS as usize).pow(5); - let _ = &(u128::BITS as usize); + //~^ manual_bits + let _ = (u128::BITS as usize).pow(5); //~ manual_bits + let _ = &(u128::BITS as usize); //~ manual_bits } diff --git a/tests/ui/manual_bits.rs b/tests/ui/manual_bits.rs index d4f369fcf87d..a89ab9964899 100644 --- a/tests/ui/manual_bits.rs +++ b/tests/ui/manual_bits.rs @@ -11,33 +11,33 @@ use std::mem::{size_of, size_of_val}; fn main() { - size_of::() * 8; - size_of::() * 8; - size_of::() * 8; - size_of::() * 8; - size_of::() * 8; - size_of::() * 8; - - size_of::() * 8; - size_of::() * 8; - size_of::() * 8; - size_of::() * 8; - size_of::() * 8; - size_of::() * 8; - - 8 * size_of::(); - 8 * size_of::(); - 8 * size_of::(); - 8 * size_of::(); - 8 * size_of::(); - 8 * size_of::(); - - 8 * size_of::(); - 8 * size_of::(); - 8 * size_of::(); - 8 * size_of::(); - 8 * size_of::(); - 8 * size_of::(); + size_of::() * 8; //~ manual_bits + size_of::() * 8; //~ manual_bits + size_of::() * 8; //~ manual_bits + size_of::() * 8; //~ manual_bits + size_of::() * 8; //~ manual_bits + size_of::() * 8; //~ manual_bits + + size_of::() * 8; //~ manual_bits + size_of::() * 8; //~ manual_bits + size_of::() * 8; //~ manual_bits + size_of::() * 8; //~ manual_bits + size_of::() * 8; //~ manual_bits + size_of::() * 8; //~ manual_bits + + 8 * size_of::(); //~ manual_bits + 8 * size_of::(); //~ manual_bits + 8 * size_of::(); //~ manual_bits + 8 * size_of::(); //~ manual_bits + 8 * size_of::(); //~ manual_bits + 8 * size_of::(); //~ manual_bits + + 8 * size_of::(); //~ manual_bits + 8 * size_of::(); //~ manual_bits + 8 * size_of::(); //~ manual_bits + 8 * size_of::(); //~ manual_bits + 8 * size_of::(); //~ manual_bits + 8 * size_of::(); //~ manual_bits size_of::() * 4; 4 * size_of::(); @@ -47,12 +47,13 @@ fn main() { size_of_val(&0u32) * 8; type Word = u32; - size_of::() * 8; + size_of::() * 8; //~ manual_bits type Bool = bool; size_of::() * 8; - let _: u32 = (size_of::() * 8) as u32; + let _: u32 = (size_of::() * 8) as u32; //~ manual_bits let _: u32 = (size_of::() * 8).try_into().unwrap(); - let _ = (size_of::() * 8).pow(5); - let _ = &(size_of::() * 8); + //~^ manual_bits + let _ = (size_of::() * 8).pow(5); //~ manual_bits + let _ = &(size_of::() * 8); //~ manual_bits } diff --git a/tests/ui/manual_bits.stderr b/tests/ui/manual_bits.stderr index 2f2ed5909c1a..eab6a094eecb 100644 --- a/tests/ui/manual_bits.stderr +++ b/tests/ui/manual_bits.stderr @@ -164,13 +164,13 @@ LL | let _: u32 = (size_of::() * 8).try_into().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `u128::BITS` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:56:13 + --> $DIR/manual_bits.rs:57:13 | LL | let _ = (size_of::() * 8).pow(5); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(u128::BITS as usize)` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:57:14 + --> $DIR/manual_bits.rs:58:14 | LL | let _ = &(size_of::() * 8); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(u128::BITS as usize)` diff --git a/tests/ui/manual_c_str_literals.fixed b/tests/ui/manual_c_str_literals.fixed index a24d7088c882..d5ca3bbdbbc0 100644 --- a/tests/ui/manual_c_str_literals.fixed +++ b/tests/ui/manual_c_str_literals.fixed @@ -28,30 +28,35 @@ fn pre_stabilization() { #[clippy::msrv = "1.77.0"] fn post_stabilization() { - c"foo"; + c"foo"; //~ manual_c_str_literals } fn main() { + c"foo"; //~ manual_c_str_literals + c"foo"; //~ manual_c_str_literals c"foo"; - c"foo"; - c"foo"; + //~^ manual_c_str_literals c"foo\\0sdsd"; + //~^ manual_c_str_literals CStr::from_bytes_with_nul(br"foo\\0sdsd\0").unwrap(); CStr::from_bytes_with_nul(br"foo\x00").unwrap(); CStr::from_bytes_with_nul(br##"foo#a\0"##).unwrap(); unsafe { c"foo" }; + //~^ manual_c_str_literals unsafe { c"foo" }; - let _: *const _ = c"foo".as_ptr(); - let _: *const _ = c"foo".as_ptr(); + //~^ manual_c_str_literals + let _: *const _ = c"foo".as_ptr(); //~ manual_c_str_literals + let _: *const _ = c"foo".as_ptr(); //~ manual_c_str_literals let _: *const _ = "foo".as_ptr(); // not a C-string let _: *const _ = "".as_ptr(); let _: *const _ = c"foo".as_ptr().cast::(); + //~^ manual_c_str_literals let _ = "电脑".as_ptr(); let _ = "电脑\\".as_ptr(); - let _ = c"电脑\\".as_ptr(); - let _ = c"电脑".as_ptr(); - let _ = c"电脑".as_ptr(); + let _ = c"电脑\\".as_ptr(); //~ manual_c_str_literals + let _ = c"电脑".as_ptr(); //~ manual_c_str_literals + let _ = c"电脑".as_ptr(); //~ manual_c_str_literals // Macro cases, don't lint: cstr!("foo"); diff --git a/tests/ui/manual_c_str_literals.rs b/tests/ui/manual_c_str_literals.rs index 0a007786720f..116488afcace 100644 --- a/tests/ui/manual_c_str_literals.rs +++ b/tests/ui/manual_c_str_literals.rs @@ -28,30 +28,35 @@ fn pre_stabilization() { #[clippy::msrv = "1.77.0"] fn post_stabilization() { - CStr::from_bytes_with_nul(b"foo\0"); + CStr::from_bytes_with_nul(b"foo\0"); //~ manual_c_str_literals } fn main() { - CStr::from_bytes_with_nul(b"foo\0"); - CStr::from_bytes_with_nul(b"foo\x00"); + CStr::from_bytes_with_nul(b"foo\0"); //~ manual_c_str_literals + CStr::from_bytes_with_nul(b"foo\x00"); //~ manual_c_str_literals CStr::from_bytes_with_nul(b"foo\0").unwrap(); + //~^ manual_c_str_literals CStr::from_bytes_with_nul(b"foo\\0sdsd\0").unwrap(); + //~^ manual_c_str_literals CStr::from_bytes_with_nul(br"foo\\0sdsd\0").unwrap(); CStr::from_bytes_with_nul(br"foo\x00").unwrap(); CStr::from_bytes_with_nul(br##"foo#a\0"##).unwrap(); unsafe { CStr::from_ptr(b"foo\0".as_ptr().cast()) }; + //~^ manual_c_str_literals unsafe { CStr::from_ptr(b"foo\0".as_ptr() as *const _) }; - let _: *const _ = b"foo\0".as_ptr(); - let _: *const _ = "foo\0".as_ptr(); + //~^ manual_c_str_literals + let _: *const _ = b"foo\0".as_ptr(); //~ manual_c_str_literals + let _: *const _ = "foo\0".as_ptr(); //~ manual_c_str_literals let _: *const _ = "foo".as_ptr(); // not a C-string let _: *const _ = "".as_ptr(); let _: *const _ = b"foo\0".as_ptr().cast::(); + //~^ manual_c_str_literals let _ = "电脑".as_ptr(); let _ = "电脑\\".as_ptr(); - let _ = "电脑\\\0".as_ptr(); - let _ = "电脑\0".as_ptr(); - let _ = "电脑\x00".as_ptr(); + let _ = "电脑\\\0".as_ptr(); //~ manual_c_str_literals + let _ = "电脑\0".as_ptr(); //~ manual_c_str_literals + let _ = "电脑\x00".as_ptr(); //~ manual_c_str_literals // Macro cases, don't lint: cstr!("foo"); diff --git a/tests/ui/manual_c_str_literals.stderr b/tests/ui/manual_c_str_literals.stderr index 8de4e16f010d..4bb19259678c 100644 --- a/tests/ui/manual_c_str_literals.stderr +++ b/tests/ui/manual_c_str_literals.stderr @@ -26,55 +26,55 @@ LL | CStr::from_bytes_with_nul(b"foo\0").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"` error: calling `CStr::new` with a byte string literal - --> $DIR/manual_c_str_literals.rs:38:5 + --> $DIR/manual_c_str_literals.rs:39:5 | LL | CStr::from_bytes_with_nul(b"foo\\0sdsd\0").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo\\0sdsd"` error: calling `CStr::from_ptr` with a byte string literal - --> $DIR/manual_c_str_literals.rs:43:14 + --> $DIR/manual_c_str_literals.rs:45:14 | LL | unsafe { CStr::from_ptr(b"foo\0".as_ptr().cast()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"` error: calling `CStr::from_ptr` with a byte string literal - --> $DIR/manual_c_str_literals.rs:44:14 + --> $DIR/manual_c_str_literals.rs:47:14 | LL | unsafe { CStr::from_ptr(b"foo\0".as_ptr() as *const _) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"` error: manually constructing a nul-terminated string - --> $DIR/manual_c_str_literals.rs:45:23 + --> $DIR/manual_c_str_literals.rs:49:23 | LL | let _: *const _ = b"foo\0".as_ptr(); | ^^^^^^^^ help: use a `c""` literal: `c"foo"` error: manually constructing a nul-terminated string - --> $DIR/manual_c_str_literals.rs:46:23 + --> $DIR/manual_c_str_literals.rs:50:23 | LL | let _: *const _ = "foo\0".as_ptr(); | ^^^^^^^ help: use a `c""` literal: `c"foo"` error: manually constructing a nul-terminated string - --> $DIR/manual_c_str_literals.rs:49:23 + --> $DIR/manual_c_str_literals.rs:53:23 | LL | let _: *const _ = b"foo\0".as_ptr().cast::(); | ^^^^^^^^ help: use a `c""` literal: `c"foo"` error: manually constructing a nul-terminated string - --> $DIR/manual_c_str_literals.rs:52:13 + --> $DIR/manual_c_str_literals.rs:57:13 | LL | let _ = "电脑\\\0".as_ptr(); | ^^^^^^^^^^ help: use a `c""` literal: `c"电脑\\"` error: manually constructing a nul-terminated string - --> $DIR/manual_c_str_literals.rs:53:13 + --> $DIR/manual_c_str_literals.rs:58:13 | LL | let _ = "电脑\0".as_ptr(); | ^^^^^^^^ help: use a `c""` literal: `c"电脑"` error: manually constructing a nul-terminated string - --> $DIR/manual_c_str_literals.rs:54:13 + --> $DIR/manual_c_str_literals.rs:59:13 | LL | let _ = "电脑\x00".as_ptr(); | ^^^^^^^^^^ help: use a `c""` literal: `c"电脑"` diff --git a/tests/ui/manual_filter.fixed b/tests/ui/manual_filter.fixed index a0fb0e32d601..237efa020e17 100644 --- a/tests/ui/manual_filter.fixed +++ b/tests/ui/manual_filter.fixed @@ -2,28 +2,39 @@ #![allow(unused_variables, dead_code, clippy::useless_vec)] fn main() { + //~v manual_filter Some(0).filter(|&x| x <= 0); + //~v manual_filter Some(1).filter(|&x| x <= 0); + //~v manual_filter Some(2).filter(|&x| x <= 0); + //~v manual_filter Some(3).filter(|&x| x > 0); let y = Some(4); + //~v manual_filter y.filter(|&x| x <= 0); + //~v manual_filter Some(5).filter(|&x| x > 0); + //~v manual_filter Some(6).as_ref().filter(|&x| x > &0); let external_cond = true; + //~v manual_filter Some(String::new()).filter(|x| external_cond); + //~v manual_filter Some(7).filter(|&x| external_cond); + //~v manual_filter Some(8).filter(|&x| x != 0); + //~v manual_filter Some(9).filter(|&x| x > 10 && x < 100); const fn f1() { @@ -41,6 +52,7 @@ fn main() { } #[allow(clippy::blocks_in_conditions)] + //~v manual_filter Some(11).filter(|&x| { println!("foo"); x > 10 && x < 100 @@ -75,12 +87,15 @@ fn main() { unsafe fn f(x: u32) -> bool { true } + //~v manual_filter let _ = Some(14).filter(|&x| unsafe { f(x) }); + //~v manual_filter let _ = Some(15).filter(|&x| unsafe { f(x) }); #[allow(clippy::redundant_pattern_matching)] if let Some(_) = Some(16) { Some(16) + //~v manual_filter } else { Some(16).filter(|&x| x % 2 == 0) }; match Some((17, 17)) { diff --git a/tests/ui/manual_filter.rs b/tests/ui/manual_filter.rs index 0ac6cbefc4ec..4844017b4114 100644 --- a/tests/ui/manual_filter.rs +++ b/tests/ui/manual_filter.rs @@ -2,6 +2,7 @@ #![allow(unused_variables, dead_code, clippy::useless_vec)] fn main() { + //~v manual_filter match Some(0) { None => None, Some(x) => { @@ -13,6 +14,7 @@ fn main() { }, }; + //~v manual_filter match Some(1) { Some(x) => { if x > 0 { @@ -24,6 +26,7 @@ fn main() { None => None, }; + //~v manual_filter match Some(2) { Some(x) => { if x > 0 { @@ -35,6 +38,7 @@ fn main() { _ => None, }; + //~v manual_filter match Some(3) { Some(x) => { if x > 0 { @@ -47,6 +51,7 @@ fn main() { }; let y = Some(4); + //~v manual_filter match y { // Some(4) None => None, @@ -59,6 +64,7 @@ fn main() { }, }; + //~v manual_filter match Some(5) { Some(x) => { if x > 0 { @@ -70,6 +76,7 @@ fn main() { _ => None, }; + //~v manual_filter match Some(6) { Some(ref x) => { if x > &0 { @@ -82,6 +89,7 @@ fn main() { }; let external_cond = true; + //~v manual_filter match Some(String::new()) { Some(x) => { if external_cond { @@ -93,12 +101,14 @@ fn main() { _ => None, }; + //~v manual_filter if let Some(x) = Some(7) { if external_cond { Some(x) } else { None } } else { None }; + //~v manual_filter match &Some(8) { &Some(x) => { if x != 0 { @@ -110,6 +120,7 @@ fn main() { _ => None, }; + //~v manual_filter match Some(9) { Some(x) => { if x > 10 && x < 100 { @@ -136,6 +147,7 @@ fn main() { } #[allow(clippy::blocks_in_conditions)] + //~v manual_filter match Some(11) { // Lint, statement is preserved by `.filter` Some(x) => { @@ -180,6 +192,7 @@ fn main() { unsafe fn f(x: u32) -> bool { true } + //~v manual_filter let _ = match Some(14) { Some(x) => { if unsafe { f(x) } { @@ -190,6 +203,7 @@ fn main() { }, None => None, }; + //~v manual_filter let _ = match Some(15) { Some(x) => unsafe { if f(x) { Some(x) } else { None } }, None => None, @@ -198,6 +212,7 @@ fn main() { #[allow(clippy::redundant_pattern_matching)] if let Some(_) = Some(16) { Some(16) + //~v manual_filter } else if let Some(x) = Some(16) { // Lint starting from here if x % 2 == 0 { Some(x) } else { None } diff --git a/tests/ui/manual_filter.stderr b/tests/ui/manual_filter.stderr index b23ad887eb2c..1ebf10568898 100644 --- a/tests/ui/manual_filter.stderr +++ b/tests/ui/manual_filter.stderr @@ -1,5 +1,5 @@ error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:5:5 + --> $DIR/manual_filter.rs:6:5 | LL | / match Some(0) { LL | | None => None, @@ -14,7 +14,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::manual_filter)]` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:16:5 + --> $DIR/manual_filter.rs:18:5 | LL | / match Some(1) { LL | | Some(x) => { @@ -26,7 +26,7 @@ LL | | }; | |_____^ help: try: `Some(1).filter(|&x| x <= 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:27:5 + --> $DIR/manual_filter.rs:30:5 | LL | / match Some(2) { LL | | Some(x) => { @@ -38,7 +38,7 @@ LL | | }; | |_____^ help: try: `Some(2).filter(|&x| x <= 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:38:5 + --> $DIR/manual_filter.rs:42:5 | LL | / match Some(3) { LL | | Some(x) => { @@ -50,7 +50,7 @@ LL | | }; | |_____^ help: try: `Some(3).filter(|&x| x > 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:50:5 + --> $DIR/manual_filter.rs:55:5 | LL | / match y { LL | | // Some(4) @@ -62,7 +62,7 @@ LL | | }; | |_____^ help: try: `y.filter(|&x| x <= 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:62:5 + --> $DIR/manual_filter.rs:68:5 | LL | / match Some(5) { LL | | Some(x) => { @@ -74,7 +74,7 @@ LL | | }; | |_____^ help: try: `Some(5).filter(|&x| x > 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:73:5 + --> $DIR/manual_filter.rs:80:5 | LL | / match Some(6) { LL | | Some(ref x) => { @@ -86,7 +86,7 @@ LL | | }; | |_____^ help: try: `Some(6).as_ref().filter(|&x| x > &0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:85:5 + --> $DIR/manual_filter.rs:93:5 | LL | / match Some(String::new()) { LL | | Some(x) => { @@ -98,7 +98,7 @@ LL | | }; | |_____^ help: try: `Some(String::new()).filter(|x| external_cond)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:96:5 + --> $DIR/manual_filter.rs:105:5 | LL | / if let Some(x) = Some(7) { LL | | if external_cond { Some(x) } else { None } @@ -108,7 +108,7 @@ LL | | }; | |_____^ help: try: `Some(7).filter(|&x| external_cond)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:102:5 + --> $DIR/manual_filter.rs:112:5 | LL | / match &Some(8) { LL | | &Some(x) => { @@ -120,7 +120,7 @@ LL | | }; | |_____^ help: try: `Some(8).filter(|&x| x != 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:113:5 + --> $DIR/manual_filter.rs:124:5 | LL | / match Some(9) { LL | | Some(x) => { @@ -132,7 +132,7 @@ LL | | }; | |_____^ help: try: `Some(9).filter(|&x| x > 10 && x < 100)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:139:5 + --> $DIR/manual_filter.rs:151:5 | LL | / match Some(11) { LL | | // Lint, statement is preserved by `.filter` @@ -152,7 +152,7 @@ LL ~ }); | error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:183:13 + --> $DIR/manual_filter.rs:196:13 | LL | let _ = match Some(14) { | _____________^ @@ -165,7 +165,7 @@ LL | | }; | |_____^ help: try: `Some(14).filter(|&x| unsafe { f(x) })` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:193:13 + --> $DIR/manual_filter.rs:207:13 | LL | let _ = match Some(15) { | _____________^ @@ -175,7 +175,7 @@ LL | | }; | |_____^ help: try: `Some(15).filter(|&x| unsafe { f(x) })` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:201:12 + --> $DIR/manual_filter.rs:216:12 | LL | } else if let Some(x) = Some(16) { | ____________^ diff --git a/tests/ui/manual_filter_map.fixed b/tests/ui/manual_filter_map.fixed index a44c46c145c6..c442def6ef0b 100644 --- a/tests/ui/manual_filter_map.fixed +++ b/tests/ui/manual_filter_map.fixed @@ -7,38 +7,56 @@ fn main() { // is_some(), unwrap() let _ = (0..).filter_map(|a| to_opt(a)); + //~^ manual_filter_map // ref pattern, expect() let _ = (0..).filter_map(|a| to_opt(a)); + //~^ manual_filter_map // is_ok(), unwrap_or() let _ = (0..).filter_map(|a| to_res(a).ok()); + //~^ manual_filter_map let _ = (1..5) + //~v manual_filter_map .filter_map(|y| *to_ref(to_opt(y))); let _ = (1..5) + //~v manual_filter_map .filter_map(|y| *to_ref(to_opt(y))); let _ = (1..5) + //~v manual_filter_map .filter_map(|y| to_ref(to_res(y)).ok()); let _ = (1..5) + //~v manual_filter_map .filter_map(|y| to_ref(to_res(y)).ok()); } #[rustfmt::skip] fn simple_equal() { iter::>().find_map(|x| x.cloned()); + //~^ manual_find_map iter::<&Option<&u8>>().find_map(|x| x.cloned()); + //~^ manual_find_map iter::<&Option>().find_map(|x| x.as_deref()); + //~^ manual_find_map iter::>().find_map(|y| to_ref(y).cloned()); + //~^ manual_find_map iter::>().find_map(|x| x.ok()); + //~^ manual_find_map iter::<&Result>().find_map(|x| x.ok()); + //~^ manual_find_map iter::<&&Result>().find_map(|x| x.ok()); + //~^ manual_find_map iter::>().find_map(|x| x.cloned().ok()); + //~^ manual_find_map iter::<&Result<&u8, ()>>().find_map(|x| x.cloned().ok()); + //~^ manual_find_map iter::<&Result>().find_map(|x| x.as_deref().ok()); + //~^ manual_find_map iter::>().find_map(|y| to_ref(y).cloned().ok()); + //~^ manual_find_map } fn no_lint() { @@ -86,38 +104,47 @@ fn issue_8920() { let _ = vec .iter() + //~v manual_filter_map .filter_map(|f| f.option_field.clone()); let _ = vec .iter() + //~v manual_filter_map .filter_map(|f| f.ref_field.cloned()); let _ = vec .iter() + //~v manual_filter_map .filter_map(|f| f.ref_field.copied()); let _ = vec .iter() + //~v manual_filter_map .filter_map(|f| f.result_field.clone().ok()); let _ = vec .iter() + //~v manual_filter_map .filter_map(|f| f.result_field.as_ref().ok()); let _ = vec .iter() + //~v manual_filter_map .filter_map(|f| f.result_field.as_deref().ok()); let _ = vec .iter_mut() + //~v manual_filter_map .filter_map(|f| f.result_field.as_mut().ok()); let _ = vec .iter_mut() + //~v manual_filter_map .filter_map(|f| f.result_field.as_deref_mut().ok()); let _ = vec .iter() + //~v manual_filter_map .filter_map(|f| f.result_field.to_owned().ok()); } @@ -130,6 +157,7 @@ fn issue8010() { let iter = [Enum::A(123), Enum::B].into_iter(); + //~v manual_filter_map let _x = iter.clone().filter_map(|x| match x { Enum::A(s) => Some(s), _ => None }); let _x = iter.clone().filter(|x| matches!(x, Enum::B)).map(|x| match x { Enum::A(s) => s, @@ -137,6 +165,7 @@ fn issue8010() { }); let _x = iter .clone() + //~v manual_filter_map .filter_map(|x| match x { Enum::A(s) => Some(s), _ => None }); #[allow(clippy::unused_unit)] let _x = iter diff --git a/tests/ui/manual_filter_map.rs b/tests/ui/manual_filter_map.rs index e72d0c4305b3..457282e7dd8a 100644 --- a/tests/ui/manual_filter_map.rs +++ b/tests/ui/manual_filter_map.rs @@ -7,24 +7,31 @@ fn main() { // is_some(), unwrap() let _ = (0..).filter(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap()); + //~^ manual_filter_map // ref pattern, expect() let _ = (0..).filter(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi")); + //~^ manual_filter_map // is_ok(), unwrap_or() let _ = (0..).filter(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1)); + //~^ manual_filter_map let _ = (1..5) + //~v manual_filter_map .filter(|&x| to_ref(to_opt(x)).is_some()) .map(|y| to_ref(to_opt(y)).unwrap()); let _ = (1..5) + //~v manual_filter_map .filter(|x| to_ref(to_opt(*x)).is_some()) .map(|y| to_ref(to_opt(y)).unwrap()); let _ = (1..5) + //~v manual_filter_map .filter(|&x| to_ref(to_res(x)).is_ok()) .map(|y| to_ref(to_res(y)).unwrap()); let _ = (1..5) + //~v manual_filter_map .filter(|x| to_ref(to_res(*x)).is_ok()) .map(|y| to_ref(to_res(y)).unwrap()); } @@ -32,17 +39,28 @@ fn main() { #[rustfmt::skip] fn simple_equal() { iter::>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); + //~^ manual_find_map iter::<&Option<&u8>>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); + //~^ manual_find_map iter::<&Option>().find(|x| x.is_some()).map(|x| x.as_deref().unwrap()); + //~^ manual_find_map iter::>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap()); + //~^ manual_find_map iter::>().find(|x| x.is_ok()).map(|x| x.unwrap()); + //~^ manual_find_map iter::<&Result>().find(|x| x.is_ok()).map(|x| x.unwrap()); + //~^ manual_find_map iter::<&&Result>().find(|x| x.is_ok()).map(|x| x.unwrap()); + //~^ manual_find_map iter::>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap()); + //~^ manual_find_map iter::<&Result<&u8, ()>>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap()); + //~^ manual_find_map iter::<&Result>().find(|x| x.is_ok()).map(|x| x.as_deref().unwrap()); + //~^ manual_find_map iter::>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap()); + //~^ manual_find_map } fn no_lint() { @@ -90,46 +108,55 @@ fn issue_8920() { let _ = vec .iter() + //~v manual_filter_map .filter(|f| f.option_field.is_some()) .map(|f| f.option_field.clone().unwrap()); let _ = vec .iter() + //~v manual_filter_map .filter(|f| f.ref_field.is_some()) .map(|f| f.ref_field.cloned().unwrap()); let _ = vec .iter() + //~v manual_filter_map .filter(|f| f.ref_field.is_some()) .map(|f| f.ref_field.copied().unwrap()); let _ = vec .iter() + //~v manual_filter_map .filter(|f| f.result_field.is_ok()) .map(|f| f.result_field.clone().unwrap()); let _ = vec .iter() + //~v manual_filter_map .filter(|f| f.result_field.is_ok()) .map(|f| f.result_field.as_ref().unwrap()); let _ = vec .iter() + //~v manual_filter_map .filter(|f| f.result_field.is_ok()) .map(|f| f.result_field.as_deref().unwrap()); let _ = vec .iter_mut() + //~v manual_filter_map .filter(|f| f.result_field.is_ok()) .map(|f| f.result_field.as_mut().unwrap()); let _ = vec .iter_mut() + //~v manual_filter_map .filter(|f| f.result_field.is_ok()) .map(|f| f.result_field.as_deref_mut().unwrap()); let _ = vec .iter() + //~v manual_filter_map .filter(|f| f.result_field.is_ok()) .map(|f| f.result_field.to_owned().unwrap()); } @@ -143,6 +170,7 @@ fn issue8010() { let iter = [Enum::A(123), Enum::B].into_iter(); + //~v manual_filter_map let _x = iter.clone().filter(|x| matches!(x, Enum::A(_))).map(|x| match x { Enum::A(s) => s, _ => unreachable!(), @@ -153,6 +181,7 @@ fn issue8010() { }); let _x = iter .clone() + //~v manual_filter_map .filter(|x| matches!(x, Enum::A(_))) .map(|x| if let Enum::A(s) = x { s } else { unreachable!() }); #[allow(clippy::unused_unit)] diff --git a/tests/ui/manual_filter_map.stderr b/tests/ui/manual_filter_map.stderr index cf64bb25951a..f45927e7807d 100644 --- a/tests/ui/manual_filter_map.stderr +++ b/tests/ui/manual_filter_map.stderr @@ -13,31 +13,31 @@ LL | let _ = (0..).filter(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap = help: to override `-D warnings` add `#[allow(clippy::manual_filter_map)]` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:12:19 + --> $DIR/manual_filter_map.rs:13:19 | LL | let _ = (0..).filter(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `filter_map(|a| to_opt(a))` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_filter_map.rs:12:31 + --> $DIR/manual_filter_map.rs:13:31 | LL | let _ = (0..).filter(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi")); | ^^^^^^^^^ error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:15:19 + --> $DIR/manual_filter_map.rs:17:19 | LL | let _ = (0..).filter(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `filter_map(|a| to_res(a).ok())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_filter_map.rs:15:31 + --> $DIR/manual_filter_map.rs:17:31 | LL | let _ = (0..).filter(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1)); | ^^^^^^^^^ error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:18:10 + --> $DIR/manual_filter_map.rs:22:10 | LL | .filter(|&x| to_ref(to_opt(x)).is_some()) | __________^ @@ -45,13 +45,13 @@ LL | | .map(|y| to_ref(to_opt(y)).unwrap()); | |____________________________________________^ help: try: `filter_map(|y| *to_ref(to_opt(y)))` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_filter_map.rs:18:22 + --> $DIR/manual_filter_map.rs:22:22 | LL | .filter(|&x| to_ref(to_opt(x)).is_some()) | ^^^^^^^^^^^^^^^^^ error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:21:10 + --> $DIR/manual_filter_map.rs:26:10 | LL | .filter(|x| to_ref(to_opt(*x)).is_some()) | __________^ @@ -59,13 +59,13 @@ LL | | .map(|y| to_ref(to_opt(y)).unwrap()); | |____________________________________________^ help: try: `filter_map(|y| *to_ref(to_opt(y)))` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_filter_map.rs:21:21 + --> $DIR/manual_filter_map.rs:26:21 | LL | .filter(|x| to_ref(to_opt(*x)).is_some()) | ^^^^^^^^^^^^^^^^^^ error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:25:10 + --> $DIR/manual_filter_map.rs:31:10 | LL | .filter(|&x| to_ref(to_res(x)).is_ok()) | __________^ @@ -73,13 +73,13 @@ LL | | .map(|y| to_ref(to_res(y)).unwrap()); | |____________________________________________^ help: try: `filter_map(|y| to_ref(to_res(y)).ok())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_filter_map.rs:25:22 + --> $DIR/manual_filter_map.rs:31:22 | LL | .filter(|&x| to_ref(to_res(x)).is_ok()) | ^^^^^^^^^^^^^^^^^ error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:28:10 + --> $DIR/manual_filter_map.rs:35:10 | LL | .filter(|x| to_ref(to_res(*x)).is_ok()) | __________^ @@ -87,13 +87,13 @@ LL | | .map(|y| to_ref(to_res(y)).unwrap()); | |____________________________________________^ help: try: `filter_map(|y| to_ref(to_res(y)).ok())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_filter_map.rs:28:21 + --> $DIR/manual_filter_map.rs:35:21 | LL | .filter(|x| to_ref(to_res(*x)).is_ok()) | ^^^^^^^^^^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:34:27 + --> $DIR/manual_filter_map.rs:41:27 | LL | iter::>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned())` @@ -102,79 +102,79 @@ LL | iter::>().find(|x| x.is_some()).map(|x| x.cloned().unwrap() = help: to override `-D warnings` add `#[allow(clippy::manual_find_map)]` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:35:28 + --> $DIR/manual_filter_map.rs:43:28 | LL | iter::<&Option<&u8>>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:36:31 + --> $DIR/manual_filter_map.rs:45:31 | LL | iter::<&Option>().find(|x| x.is_some()).map(|x| x.as_deref().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.as_deref())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:37:31 + --> $DIR/manual_filter_map.rs:47:31 | LL | iter::>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|y| to_ref(y).cloned())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_filter_map.rs:37:41 + --> $DIR/manual_filter_map.rs:47:41 | LL | iter::>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap()); | ^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:39:30 + --> $DIR/manual_filter_map.rs:50:30 | LL | iter::>().find(|x| x.is_ok()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:40:31 + --> $DIR/manual_filter_map.rs:52:31 | LL | iter::<&Result>().find(|x| x.is_ok()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:41:32 + --> $DIR/manual_filter_map.rs:54:32 | LL | iter::<&&Result>().find(|x| x.is_ok()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:42:31 + --> $DIR/manual_filter_map.rs:56:31 | LL | iter::>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:43:32 + --> $DIR/manual_filter_map.rs:58:32 | LL | iter::<&Result<&u8, ()>>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:44:35 + --> $DIR/manual_filter_map.rs:60:35 | LL | iter::<&Result>().find(|x| x.is_ok()).map(|x| x.as_deref().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.as_deref().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:45:35 + --> $DIR/manual_filter_map.rs:62:35 | LL | iter::>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|y| to_ref(y).cloned().ok())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_filter_map.rs:45:45 + --> $DIR/manual_filter_map.rs:62:45 | LL | iter::>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap()); | ^^^^^^^^^ error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:93:10 + --> $DIR/manual_filter_map.rs:112:10 | LL | .filter(|f| f.option_field.is_some()) | __________^ @@ -182,7 +182,7 @@ LL | | .map(|f| f.option_field.clone().unwrap()); | |_________________________________________________^ help: try: `filter_map(|f| f.option_field.clone())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:98:10 + --> $DIR/manual_filter_map.rs:118:10 | LL | .filter(|f| f.ref_field.is_some()) | __________^ @@ -190,7 +190,7 @@ LL | | .map(|f| f.ref_field.cloned().unwrap()); | |_______________________________________________^ help: try: `filter_map(|f| f.ref_field.cloned())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:103:10 + --> $DIR/manual_filter_map.rs:124:10 | LL | .filter(|f| f.ref_field.is_some()) | __________^ @@ -198,7 +198,7 @@ LL | | .map(|f| f.ref_field.copied().unwrap()); | |_______________________________________________^ help: try: `filter_map(|f| f.ref_field.copied())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:108:10 + --> $DIR/manual_filter_map.rs:130:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -206,7 +206,7 @@ LL | | .map(|f| f.result_field.clone().unwrap()); | |_________________________________________________^ help: try: `filter_map(|f| f.result_field.clone().ok())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:113:10 + --> $DIR/manual_filter_map.rs:136:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -214,7 +214,7 @@ LL | | .map(|f| f.result_field.as_ref().unwrap()); | |__________________________________________________^ help: try: `filter_map(|f| f.result_field.as_ref().ok())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:118:10 + --> $DIR/manual_filter_map.rs:142:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -222,7 +222,7 @@ LL | | .map(|f| f.result_field.as_deref().unwrap()); | |____________________________________________________^ help: try: `filter_map(|f| f.result_field.as_deref().ok())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:123:10 + --> $DIR/manual_filter_map.rs:148:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -230,7 +230,7 @@ LL | | .map(|f| f.result_field.as_mut().unwrap()); | |__________________________________________________^ help: try: `filter_map(|f| f.result_field.as_mut().ok())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:128:10 + --> $DIR/manual_filter_map.rs:154:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -238,7 +238,7 @@ LL | | .map(|f| f.result_field.as_deref_mut().unwrap()); | |________________________________________________________^ help: try: `filter_map(|f| f.result_field.as_deref_mut().ok())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:133:10 + --> $DIR/manual_filter_map.rs:160:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -246,7 +246,7 @@ LL | | .map(|f| f.result_field.to_owned().unwrap()); | |____________________________________________________^ help: try: `filter_map(|f| f.result_field.to_owned().ok())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:146:27 + --> $DIR/manual_filter_map.rs:174:27 | LL | let _x = iter.clone().filter(|x| matches!(x, Enum::A(_))).map(|x| match x { | ___________________________^ @@ -256,7 +256,7 @@ LL | | }); | |______^ help: try: `filter_map(|x| match x { Enum::A(s) => Some(s), _ => None })` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:156:10 + --> $DIR/manual_filter_map.rs:185:10 | LL | .filter(|x| matches!(x, Enum::A(_))) | __________^ diff --git a/tests/ui/manual_find_fixable.fixed b/tests/ui/manual_find_fixable.fixed index 5e6849a4dfb0..5bf40e8952ff 100644 --- a/tests/ui/manual_find_fixable.fixed +++ b/tests/ui/manual_find_fixable.fixed @@ -7,10 +7,12 @@ use std::collections::HashMap; const ARRAY: &[u32; 5] = &[2, 7, 1, 9, 3]; fn lookup(n: u32) -> Option { + //~v manual_find ARRAY.iter().find(|&&v| v == n).copied() } fn with_pat(arr: Vec<(u32, u32)>) -> Option { + //~v manual_find arr.into_iter().map(|(a, _)| a).find(|&a| a % 2 == 0) } @@ -19,11 +21,13 @@ struct Data { is_true: bool, } fn with_struct(arr: Vec) -> Option { + //~v manual_find arr.into_iter().find(|el| el.name.len() == 10) } struct Tuple(usize, usize); fn with_tuple_struct(arr: Vec) -> Option { + //~v manual_find arr.into_iter().map(|Tuple(a, _)| a).find(|&a| a >= 3) } @@ -34,20 +38,24 @@ impl A { } } fn with_method_call(arr: Vec) -> Option { + //~v manual_find arr.into_iter().find(|el| el.should_keep()) } fn with_closure(arr: Vec) -> Option { let f = |el: u32| -> u32 { el + 10 }; + //~v manual_find arr.into_iter().find(|&el| f(el) == 20) } fn with_closure2(arr: HashMap) -> Option { let f = |el: i32| -> bool { el == 10 }; + //~v manual_find arr.values().find(|&&el| f(el)).copied() } fn with_bool(arr: Vec) -> Option { + //~v manual_find arr.into_iter().find(|el| el.is_true) } @@ -73,14 +81,17 @@ fn with_else(arr: Vec) -> Option { } fn tuple_with_ref(v: [(u8, &u8); 3]) -> Option { + //~v manual_find v.into_iter().map(|(_, &x)| x).find(|&x| x > 10) } fn ref_to_tuple_with_ref(v: &[(u8, &u8)]) -> Option { + //~v manual_find v.iter().map(|&(_, &x)| x).find(|&x| x > 10) } fn explicit_ret(arr: Vec) -> Option { + //~v manual_find arr.into_iter().find(|&x| x >= 5) } @@ -131,6 +142,7 @@ fn mixed_binding_modes(arr: Vec<(i32, String)>) -> Option { fn as_closure() { #[rustfmt::skip] let f = |arr: Vec| -> Option { + //~v manual_find arr.into_iter().find(|&x| x < 1) }; } diff --git a/tests/ui/manual_find_fixable.rs b/tests/ui/manual_find_fixable.rs index 56c3f2629c7a..0d8802aec987 100644 --- a/tests/ui/manual_find_fixable.rs +++ b/tests/ui/manual_find_fixable.rs @@ -7,6 +7,7 @@ use std::collections::HashMap; const ARRAY: &[u32; 5] = &[2, 7, 1, 9, 3]; fn lookup(n: u32) -> Option { + //~v manual_find for &v in ARRAY { if v == n { return Some(v); @@ -16,6 +17,7 @@ fn lookup(n: u32) -> Option { } fn with_pat(arr: Vec<(u32, u32)>) -> Option { + //~v manual_find for (a, _) in arr { if a % 2 == 0 { return Some(a); @@ -29,6 +31,7 @@ struct Data { is_true: bool, } fn with_struct(arr: Vec) -> Option { + //~v manual_find for el in arr { if el.name.len() == 10 { return Some(el); @@ -39,6 +42,7 @@ fn with_struct(arr: Vec) -> Option { struct Tuple(usize, usize); fn with_tuple_struct(arr: Vec) -> Option { + //~v manual_find for Tuple(a, _) in arr { if a >= 3 { return Some(a); @@ -54,6 +58,7 @@ impl A { } } fn with_method_call(arr: Vec) -> Option { + //~v manual_find for el in arr { if el.should_keep() { return Some(el); @@ -64,6 +69,7 @@ fn with_method_call(arr: Vec) -> Option { fn with_closure(arr: Vec) -> Option { let f = |el: u32| -> u32 { el + 10 }; + //~v manual_find for el in arr { if f(el) == 20 { return Some(el); @@ -74,6 +80,7 @@ fn with_closure(arr: Vec) -> Option { fn with_closure2(arr: HashMap) -> Option { let f = |el: i32| -> bool { el == 10 }; + //~v manual_find for &el in arr.values() { if f(el) { return Some(el); @@ -83,6 +90,7 @@ fn with_closure2(arr: HashMap) -> Option { } fn with_bool(arr: Vec) -> Option { + //~v manual_find for el in arr { if el.is_true { return Some(el); @@ -113,6 +121,7 @@ fn with_else(arr: Vec) -> Option { } fn tuple_with_ref(v: [(u8, &u8); 3]) -> Option { + //~v manual_find for (_, &x) in v { if x > 10 { return Some(x); @@ -122,6 +131,7 @@ fn tuple_with_ref(v: [(u8, &u8); 3]) -> Option { } fn ref_to_tuple_with_ref(v: &[(u8, &u8)]) -> Option { + //~v manual_find for &(_, &x) in v { if x > 10 { return Some(x); @@ -131,6 +141,7 @@ fn ref_to_tuple_with_ref(v: &[(u8, &u8)]) -> Option { } fn explicit_ret(arr: Vec) -> Option { + //~v manual_find for x in arr { if x >= 5 { return Some(x); @@ -186,6 +197,7 @@ fn mixed_binding_modes(arr: Vec<(i32, String)>) -> Option { fn as_closure() { #[rustfmt::skip] let f = |arr: Vec| -> Option { + //~v manual_find for x in arr { if x < 1 { return Some(x); diff --git a/tests/ui/manual_find_fixable.stderr b/tests/ui/manual_find_fixable.stderr index 387d1509c136..945755d4c4e2 100644 --- a/tests/ui/manual_find_fixable.stderr +++ b/tests/ui/manual_find_fixable.stderr @@ -1,5 +1,5 @@ error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:10:5 + --> $DIR/manual_find_fixable.rs:11:5 | LL | / for &v in ARRAY { LL | | if v == n { @@ -13,7 +13,7 @@ LL | | None = help: to override `-D warnings` add `#[allow(clippy::manual_find)]` error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:19:5 + --> $DIR/manual_find_fixable.rs:21:5 | LL | / for (a, _) in arr { LL | | if a % 2 == 0 { @@ -24,7 +24,7 @@ LL | | None | |________^ help: replace with an iterator: `arr.into_iter().map(|(a, _)| a).find(|&a| a % 2 == 0)` error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:32:5 + --> $DIR/manual_find_fixable.rs:35:5 | LL | / for el in arr { LL | | if el.name.len() == 10 { @@ -37,7 +37,7 @@ LL | | None = note: you may need to dereference some variables error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:42:5 + --> $DIR/manual_find_fixable.rs:46:5 | LL | / for Tuple(a, _) in arr { LL | | if a >= 3 { @@ -48,7 +48,7 @@ LL | | None | |________^ help: replace with an iterator: `arr.into_iter().map(|Tuple(a, _)| a).find(|&a| a >= 3)` error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:57:5 + --> $DIR/manual_find_fixable.rs:62:5 | LL | / for el in arr { LL | | if el.should_keep() { @@ -61,7 +61,7 @@ LL | | None = note: you may need to dereference some variables error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:67:5 + --> $DIR/manual_find_fixable.rs:73:5 | LL | / for el in arr { LL | | if f(el) == 20 { @@ -72,7 +72,7 @@ LL | | None | |________^ help: replace with an iterator: `arr.into_iter().find(|&el| f(el) == 20)` error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:77:5 + --> $DIR/manual_find_fixable.rs:84:5 | LL | / for &el in arr.values() { LL | | if f(el) { @@ -83,7 +83,7 @@ LL | | None | |________^ help: replace with an iterator: `arr.values().find(|&&el| f(el)).copied()` error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:86:5 + --> $DIR/manual_find_fixable.rs:94:5 | LL | / for el in arr { LL | | if el.is_true { @@ -96,7 +96,7 @@ LL | | None = note: you may need to dereference some variables error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:116:5 + --> $DIR/manual_find_fixable.rs:125:5 | LL | / for (_, &x) in v { LL | | if x > 10 { @@ -107,7 +107,7 @@ LL | | None | |________^ help: replace with an iterator: `v.into_iter().map(|(_, &x)| x).find(|&x| x > 10)` error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:125:5 + --> $DIR/manual_find_fixable.rs:135:5 | LL | / for &(_, &x) in v { LL | | if x > 10 { @@ -118,7 +118,7 @@ LL | | None | |________^ help: replace with an iterator: `v.iter().map(|&(_, &x)| x).find(|&x| x > 10)` error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:134:5 + --> $DIR/manual_find_fixable.rs:145:5 | LL | / for x in arr { LL | | if x >= 5 { @@ -129,7 +129,7 @@ LL | | return None; | |________________^ help: replace with an iterator: `arr.into_iter().find(|&x| x >= 5)` error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:189:9 + --> $DIR/manual_find_fixable.rs:201:9 | LL | / for x in arr { LL | | if x < 1 { diff --git a/tests/ui/manual_find_map.fixed b/tests/ui/manual_find_map.fixed index 2d9a356b9bcd..db0ba83422f4 100644 --- a/tests/ui/manual_find_map.fixed +++ b/tests/ui/manual_find_map.fixed @@ -7,41 +7,62 @@ fn main() { // is_some(), unwrap() let _ = (0..).find_map(|a| to_opt(a)); + //~^ manual_find_map // ref pattern, expect() let _ = (0..).find_map(|a| to_opt(a)); + //~^ manual_find_map // is_ok(), unwrap_or() let _ = (0..).find_map(|a| to_res(a).ok()); + //~^ manual_find_map let _ = (1..5) + //~v manual_find_map .find_map(|y| *to_ref(to_opt(y))); let _ = (1..5) + //~v manual_find_map .find_map(|y| *to_ref(to_opt(y))); let _ = (1..5) + //~v manual_find_map .find_map(|y| to_ref(to_res(y)).ok()); let _ = (1..5) + //~v manual_find_map .find_map(|y| to_ref(to_res(y)).ok()); } #[rustfmt::skip] fn simple_equal() { iter::>().find_map(|x| x); + //~^ manual_find_map iter::<&Option>().find_map(|x| *x); + //~^ manual_find_map iter::<&&Option>().find_map(|x| **x); + //~^ manual_find_map iter::>().find_map(|x| x.cloned()); + //~^ manual_find_map iter::<&Option<&u8>>().find_map(|x| x.cloned()); + //~^ manual_find_map iter::<&Option>().find_map(|x| x.as_deref()); + //~^ manual_find_map iter::>().find_map(|y| to_ref(y).cloned()); + //~^ manual_find_map iter::>().find_map(|x| x.ok()); + //~^ manual_find_map iter::<&Result>().find_map(|x| x.ok()); + //~^ manual_find_map iter::<&&Result>().find_map(|x| x.ok()); + //~^ manual_find_map iter::>().find_map(|x| x.cloned().ok()); + //~^ manual_find_map iter::<&Result<&u8, ()>>().find_map(|x| x.cloned().ok()); + //~^ manual_find_map iter::<&Result>().find_map(|x| x.as_deref().ok()); + //~^ manual_find_map iter::>().find_map(|y| to_ref(y).cloned().ok()); + //~^ manual_find_map } fn no_lint() { @@ -89,37 +110,46 @@ fn issue_8920() { let _ = vec .iter() + //~v manual_find_map .find_map(|f| f.option_field.clone()); let _ = vec .iter() + //~v manual_find_map .find_map(|f| f.ref_field.cloned()); let _ = vec .iter() + //~v manual_find_map .find_map(|f| f.ref_field.copied()); let _ = vec .iter() + //~v manual_find_map .find_map(|f| f.result_field.clone().ok()); let _ = vec .iter() + //~v manual_find_map .find_map(|f| f.result_field.as_ref().ok()); let _ = vec .iter() + //~v manual_find_map .find_map(|f| f.result_field.as_deref().ok()); let _ = vec .iter_mut() + //~v manual_find_map .find_map(|f| f.result_field.as_mut().ok()); let _ = vec .iter_mut() + //~v manual_find_map .find_map(|f| f.result_field.as_deref_mut().ok()); let _ = vec .iter() + //~v manual_find_map .find_map(|f| f.result_field.to_owned().ok()); } diff --git a/tests/ui/manual_find_map.rs b/tests/ui/manual_find_map.rs index 7c5cc136695a..0188c184eb04 100644 --- a/tests/ui/manual_find_map.rs +++ b/tests/ui/manual_find_map.rs @@ -7,24 +7,31 @@ fn main() { // is_some(), unwrap() let _ = (0..).find(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap()); + //~^ manual_find_map // ref pattern, expect() let _ = (0..).find(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi")); + //~^ manual_find_map // is_ok(), unwrap_or() let _ = (0..).find(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1)); + //~^ manual_find_map let _ = (1..5) + //~v manual_find_map .find(|&x| to_ref(to_opt(x)).is_some()) .map(|y| to_ref(to_opt(y)).unwrap()); let _ = (1..5) + //~v manual_find_map .find(|x| to_ref(to_opt(*x)).is_some()) .map(|y| to_ref(to_opt(y)).unwrap()); let _ = (1..5) + //~v manual_find_map .find(|&x| to_ref(to_res(x)).is_ok()) .map(|y| to_ref(to_res(y)).unwrap()); let _ = (1..5) + //~v manual_find_map .find(|x| to_ref(to_res(*x)).is_ok()) .map(|y| to_ref(to_res(y)).unwrap()); } @@ -32,20 +39,34 @@ fn main() { #[rustfmt::skip] fn simple_equal() { iter::>().find(|x| x.is_some()).map(|x| x.unwrap()); + //~^ manual_find_map iter::<&Option>().find(|x| x.is_some()).map(|x| x.unwrap()); + //~^ manual_find_map iter::<&&Option>().find(|x| x.is_some()).map(|x| x.unwrap()); + //~^ manual_find_map iter::>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); + //~^ manual_find_map iter::<&Option<&u8>>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); + //~^ manual_find_map iter::<&Option>().find(|x| x.is_some()).map(|x| x.as_deref().unwrap()); + //~^ manual_find_map iter::>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap()); + //~^ manual_find_map iter::>().find(|x| x.is_ok()).map(|x| x.unwrap()); + //~^ manual_find_map iter::<&Result>().find(|x| x.is_ok()).map(|x| x.unwrap()); + //~^ manual_find_map iter::<&&Result>().find(|x| x.is_ok()).map(|x| x.unwrap()); + //~^ manual_find_map iter::>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap()); + //~^ manual_find_map iter::<&Result<&u8, ()>>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap()); + //~^ manual_find_map iter::<&Result>().find(|x| x.is_ok()).map(|x| x.as_deref().unwrap()); + //~^ manual_find_map iter::>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap()); + //~^ manual_find_map } fn no_lint() { @@ -93,46 +114,55 @@ fn issue_8920() { let _ = vec .iter() + //~v manual_find_map .find(|f| f.option_field.is_some()) .map(|f| f.option_field.clone().unwrap()); let _ = vec .iter() + //~v manual_find_map .find(|f| f.ref_field.is_some()) .map(|f| f.ref_field.cloned().unwrap()); let _ = vec .iter() + //~v manual_find_map .find(|f| f.ref_field.is_some()) .map(|f| f.ref_field.copied().unwrap()); let _ = vec .iter() + //~v manual_find_map .find(|f| f.result_field.is_ok()) .map(|f| f.result_field.clone().unwrap()); let _ = vec .iter() + //~v manual_find_map .find(|f| f.result_field.is_ok()) .map(|f| f.result_field.as_ref().unwrap()); let _ = vec .iter() + //~v manual_find_map .find(|f| f.result_field.is_ok()) .map(|f| f.result_field.as_deref().unwrap()); let _ = vec .iter_mut() + //~v manual_find_map .find(|f| f.result_field.is_ok()) .map(|f| f.result_field.as_mut().unwrap()); let _ = vec .iter_mut() + //~v manual_find_map .find(|f| f.result_field.is_ok()) .map(|f| f.result_field.as_deref_mut().unwrap()); let _ = vec .iter() + //~v manual_find_map .find(|f| f.result_field.is_ok()) .map(|f| f.result_field.to_owned().unwrap()); } diff --git a/tests/ui/manual_find_map.stderr b/tests/ui/manual_find_map.stderr index 0526382323d3..0f291b21b2c1 100644 --- a/tests/ui/manual_find_map.stderr +++ b/tests/ui/manual_find_map.stderr @@ -13,31 +13,31 @@ LL | let _ = (0..).find(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap() = help: to override `-D warnings` add `#[allow(clippy::manual_find_map)]` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:12:19 + --> $DIR/manual_find_map.rs:13:19 | LL | let _ = (0..).find(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|a| to_opt(a))` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_find_map.rs:12:29 + --> $DIR/manual_find_map.rs:13:29 | LL | let _ = (0..).find(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi")); | ^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:15:19 + --> $DIR/manual_find_map.rs:17:19 | LL | let _ = (0..).find(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|a| to_res(a).ok())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_find_map.rs:15:29 + --> $DIR/manual_find_map.rs:17:29 | LL | let _ = (0..).find(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1)); | ^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:18:10 + --> $DIR/manual_find_map.rs:22:10 | LL | .find(|&x| to_ref(to_opt(x)).is_some()) | __________^ @@ -45,13 +45,13 @@ LL | | .map(|y| to_ref(to_opt(y)).unwrap()); | |____________________________________________^ help: try: `find_map(|y| *to_ref(to_opt(y)))` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_find_map.rs:18:20 + --> $DIR/manual_find_map.rs:22:20 | LL | .find(|&x| to_ref(to_opt(x)).is_some()) | ^^^^^^^^^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:21:10 + --> $DIR/manual_find_map.rs:26:10 | LL | .find(|x| to_ref(to_opt(*x)).is_some()) | __________^ @@ -59,13 +59,13 @@ LL | | .map(|y| to_ref(to_opt(y)).unwrap()); | |____________________________________________^ help: try: `find_map(|y| *to_ref(to_opt(y)))` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_find_map.rs:21:19 + --> $DIR/manual_find_map.rs:26:19 | LL | .find(|x| to_ref(to_opt(*x)).is_some()) | ^^^^^^^^^^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:25:10 + --> $DIR/manual_find_map.rs:31:10 | LL | .find(|&x| to_ref(to_res(x)).is_ok()) | __________^ @@ -73,13 +73,13 @@ LL | | .map(|y| to_ref(to_res(y)).unwrap()); | |____________________________________________^ help: try: `find_map(|y| to_ref(to_res(y)).ok())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_find_map.rs:25:20 + --> $DIR/manual_find_map.rs:31:20 | LL | .find(|&x| to_ref(to_res(x)).is_ok()) | ^^^^^^^^^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:28:10 + --> $DIR/manual_find_map.rs:35:10 | LL | .find(|x| to_ref(to_res(*x)).is_ok()) | __________^ @@ -87,109 +87,109 @@ LL | | .map(|y| to_ref(to_res(y)).unwrap()); | |____________________________________________^ help: try: `find_map(|y| to_ref(to_res(y)).ok())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_find_map.rs:28:19 + --> $DIR/manual_find_map.rs:35:19 | LL | .find(|x| to_ref(to_res(*x)).is_ok()) | ^^^^^^^^^^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:34:26 + --> $DIR/manual_find_map.rs:41:26 | LL | iter::>().find(|x| x.is_some()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x)` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:35:27 + --> $DIR/manual_find_map.rs:43:27 | LL | iter::<&Option>().find(|x| x.is_some()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| *x)` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:36:28 + --> $DIR/manual_find_map.rs:45:28 | LL | iter::<&&Option>().find(|x| x.is_some()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| **x)` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:37:27 + --> $DIR/manual_find_map.rs:47:27 | LL | iter::>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:38:28 + --> $DIR/manual_find_map.rs:49:28 | LL | iter::<&Option<&u8>>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:39:31 + --> $DIR/manual_find_map.rs:51:31 | LL | iter::<&Option>().find(|x| x.is_some()).map(|x| x.as_deref().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.as_deref())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:40:31 + --> $DIR/manual_find_map.rs:53:31 | LL | iter::>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|y| to_ref(y).cloned())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_find_map.rs:40:41 + --> $DIR/manual_find_map.rs:53:41 | LL | iter::>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap()); | ^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:42:30 + --> $DIR/manual_find_map.rs:56:30 | LL | iter::>().find(|x| x.is_ok()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:43:31 + --> $DIR/manual_find_map.rs:58:31 | LL | iter::<&Result>().find(|x| x.is_ok()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:44:32 + --> $DIR/manual_find_map.rs:60:32 | LL | iter::<&&Result>().find(|x| x.is_ok()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:45:31 + --> $DIR/manual_find_map.rs:62:31 | LL | iter::>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:46:32 + --> $DIR/manual_find_map.rs:64:32 | LL | iter::<&Result<&u8, ()>>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:47:35 + --> $DIR/manual_find_map.rs:66:35 | LL | iter::<&Result>().find(|x| x.is_ok()).map(|x| x.as_deref().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.as_deref().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:48:35 + --> $DIR/manual_find_map.rs:68:35 | LL | iter::>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|y| to_ref(y).cloned().ok())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_find_map.rs:48:45 + --> $DIR/manual_find_map.rs:68:45 | LL | iter::>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap()); | ^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:96:10 + --> $DIR/manual_find_map.rs:118:10 | LL | .find(|f| f.option_field.is_some()) | __________^ @@ -197,7 +197,7 @@ LL | | .map(|f| f.option_field.clone().unwrap()); | |_________________________________________________^ help: try: `find_map(|f| f.option_field.clone())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:101:10 + --> $DIR/manual_find_map.rs:124:10 | LL | .find(|f| f.ref_field.is_some()) | __________^ @@ -205,7 +205,7 @@ LL | | .map(|f| f.ref_field.cloned().unwrap()); | |_______________________________________________^ help: try: `find_map(|f| f.ref_field.cloned())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:106:10 + --> $DIR/manual_find_map.rs:130:10 | LL | .find(|f| f.ref_field.is_some()) | __________^ @@ -213,7 +213,7 @@ LL | | .map(|f| f.ref_field.copied().unwrap()); | |_______________________________________________^ help: try: `find_map(|f| f.ref_field.copied())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:111:10 + --> $DIR/manual_find_map.rs:136:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ @@ -221,7 +221,7 @@ LL | | .map(|f| f.result_field.clone().unwrap()); | |_________________________________________________^ help: try: `find_map(|f| f.result_field.clone().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:116:10 + --> $DIR/manual_find_map.rs:142:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ @@ -229,7 +229,7 @@ LL | | .map(|f| f.result_field.as_ref().unwrap()); | |__________________________________________________^ help: try: `find_map(|f| f.result_field.as_ref().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:121:10 + --> $DIR/manual_find_map.rs:148:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ @@ -237,7 +237,7 @@ LL | | .map(|f| f.result_field.as_deref().unwrap()); | |____________________________________________________^ help: try: `find_map(|f| f.result_field.as_deref().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:126:10 + --> $DIR/manual_find_map.rs:154:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ @@ -245,7 +245,7 @@ LL | | .map(|f| f.result_field.as_mut().unwrap()); | |__________________________________________________^ help: try: `find_map(|f| f.result_field.as_mut().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:131:10 + --> $DIR/manual_find_map.rs:160:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ @@ -253,7 +253,7 @@ LL | | .map(|f| f.result_field.as_deref_mut().unwrap()); | |________________________________________________________^ help: try: `find_map(|f| f.result_field.as_deref_mut().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:136:10 + --> $DIR/manual_find_map.rs:166:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ diff --git a/tests/ui/manual_float_methods.rs b/tests/ui/manual_float_methods.rs index f3e95d6807d3..f4a7826b7f82 100644 --- a/tests/ui/manual_float_methods.rs +++ b/tests/ui/manual_float_methods.rs @@ -21,12 +21,16 @@ fn fn_test_not_inf() -> f64 { fn main() { let x = 1.0f32; if x == f32::INFINITY || x == f32::NEG_INFINITY {} + //~^ manual_is_infinite if x != f32::INFINITY && x != f32::NEG_INFINITY {} - if x == INFINITE || x == NEG_INFINITE {} - if x != INFINITE && x != NEG_INFINITE {} + //~^ manual_is_finite + if x == INFINITE || x == NEG_INFINITE {} //~ manual_is_infinite + if x != INFINITE && x != NEG_INFINITE {} //~ manual_is_finite let x = 1.0f64; if x == f64::INFINITY || x == f64::NEG_INFINITY {} + //~^ manual_is_infinite if x != f64::INFINITY && x != f64::NEG_INFINITY {} + //~^ manual_is_finite // Don't lint if x.is_infinite() {} if x.is_finite() {} diff --git a/tests/ui/manual_float_methods.stderr b/tests/ui/manual_float_methods.stderr index 680ab2efa094..b54d759200d1 100644 --- a/tests/ui/manual_float_methods.stderr +++ b/tests/ui/manual_float_methods.stderr @@ -8,7 +8,7 @@ LL | if x == f32::INFINITY || x == f32::NEG_INFINITY {} = help: to override `-D warnings` add `#[allow(clippy::manual_is_infinite)]` error: manually checking if a float is finite - --> $DIR/manual_float_methods.rs:24:8 + --> $DIR/manual_float_methods.rs:25:8 | LL | if x != f32::INFINITY && x != f32::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -29,13 +29,13 @@ LL | if !x.is_infinite() {} | ~~~~~~~~~~~~~~~~ error: manually checking if a float is infinite - --> $DIR/manual_float_methods.rs:25:8 + --> $DIR/manual_float_methods.rs:27:8 | LL | if x == INFINITE || x == NEG_INFINITE {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()` error: manually checking if a float is finite - --> $DIR/manual_float_methods.rs:26:8 + --> $DIR/manual_float_methods.rs:28:8 | LL | if x != INFINITE && x != NEG_INFINITE {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -54,13 +54,13 @@ LL | if !x.is_infinite() {} | ~~~~~~~~~~~~~~~~ error: manually checking if a float is infinite - --> $DIR/manual_float_methods.rs:28:8 + --> $DIR/manual_float_methods.rs:30:8 | LL | if x == f64::INFINITY || x == f64::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()` error: manually checking if a float is finite - --> $DIR/manual_float_methods.rs:29:8 + --> $DIR/manual_float_methods.rs:32:8 | LL | if x != f64::INFINITY && x != f64::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/manual_hash_one.fixed b/tests/ui/manual_hash_one.fixed index edfd9c4a47bb..41eacb2b0423 100644 --- a/tests/ui/manual_hash_one.fixed +++ b/tests/ui/manual_hash_one.fixed @@ -6,19 +6,19 @@ use std::hash::{BuildHasher, Hash, Hasher}; fn returned(b: impl BuildHasher) -> u64 { - b.hash_one(&true) + b.hash_one(&true) //~ manual_hash_one } fn unsized_receiver(b: impl BuildHasher, s: &str) { - let _ = b.hash_one(&s[4..10]); + let _ = b.hash_one(&s[4..10]); //~ manual_hash_one } fn owned_value(b: impl BuildHasher, v: Vec) -> Vec { - let _ = b.hash_one(&v); + let _ = b.hash_one(&v); //~ manual_hash_one v } @@ -85,5 +85,5 @@ fn msrv_1_70(b: impl BuildHasher, v: impl Hash) { fn msrv_1_71(b: impl BuildHasher, v: impl Hash) { - let _ = b.hash_one(&v); + let _ = b.hash_one(&v); //~ manual_hash_one } diff --git a/tests/ui/manual_hash_one.rs b/tests/ui/manual_hash_one.rs index ee61522853f0..b458bf37beaf 100644 --- a/tests/ui/manual_hash_one.rs +++ b/tests/ui/manual_hash_one.rs @@ -6,19 +6,19 @@ use std::hash::{BuildHasher, Hash, Hasher}; fn returned(b: impl BuildHasher) -> u64 { let mut hasher = b.build_hasher(); true.hash(&mut hasher); - hasher.finish() + hasher.finish() //~ manual_hash_one } fn unsized_receiver(b: impl BuildHasher, s: &str) { let mut hasher = b.build_hasher(); s[4..10].hash(&mut hasher); - let _ = hasher.finish(); + let _ = hasher.finish(); //~ manual_hash_one } fn owned_value(b: impl BuildHasher, v: Vec) -> Vec { let mut hasher = b.build_hasher(); v.hash(&mut hasher); - let _ = hasher.finish(); + let _ = hasher.finish(); //~ manual_hash_one v } @@ -85,5 +85,5 @@ fn msrv_1_70(b: impl BuildHasher, v: impl Hash) { fn msrv_1_71(b: impl BuildHasher, v: impl Hash) { let mut hasher = b.build_hasher(); v.hash(&mut hasher); - let _ = hasher.finish(); + let _ = hasher.finish(); //~ manual_hash_one } diff --git a/tests/ui/manual_instant_elapsed.fixed b/tests/ui/manual_instant_elapsed.fixed index 1811337652dd..e1f392322118 100644 --- a/tests/ui/manual_instant_elapsed.fixed +++ b/tests/ui/manual_instant_elapsed.fixed @@ -15,6 +15,7 @@ fn main() { } let duration = prev_instant.elapsed(); + //~^ manual_instant_elapsed // don't catch let duration = prev_instant.elapsed(); @@ -23,5 +24,6 @@ fn main() { let ref_to_instant = &Instant::now(); + //~v manual_instant_elapsed (*ref_to_instant).elapsed(); // to ensure parens are added correctly } diff --git a/tests/ui/manual_instant_elapsed.rs b/tests/ui/manual_instant_elapsed.rs index fedca38b158a..3333ee64adde 100644 --- a/tests/ui/manual_instant_elapsed.rs +++ b/tests/ui/manual_instant_elapsed.rs @@ -15,6 +15,7 @@ fn main() { } let duration = Instant::now() - prev_instant; + //~^ manual_instant_elapsed // don't catch let duration = prev_instant.elapsed(); @@ -23,5 +24,6 @@ fn main() { let ref_to_instant = &Instant::now(); + //~v manual_instant_elapsed Instant::now() - *ref_to_instant; // to ensure parens are added correctly } diff --git a/tests/ui/manual_instant_elapsed.stderr b/tests/ui/manual_instant_elapsed.stderr index 56d0b9cd77b2..2ea86a3f3e35 100644 --- a/tests/ui/manual_instant_elapsed.stderr +++ b/tests/ui/manual_instant_elapsed.stderr @@ -8,7 +8,7 @@ LL | let duration = Instant::now() - prev_instant; = help: to override `-D warnings` add `#[allow(clippy::manual_instant_elapsed)]` error: manual implementation of `Instant::elapsed` - --> $DIR/manual_instant_elapsed.rs:26:5 + --> $DIR/manual_instant_elapsed.rs:28:5 | LL | Instant::now() - *ref_to_instant; // to ensure parens are added correctly | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(*ref_to_instant).elapsed()` diff --git a/tests/ui/manual_is_ascii_check.fixed b/tests/ui/manual_is_ascii_check.fixed index 9c4bd335ad8b..95d005f57c15 100644 --- a/tests/ui/manual_is_ascii_check.fixed +++ b/tests/ui/manual_is_ascii_check.fixed @@ -2,30 +2,31 @@ #![warn(clippy::manual_is_ascii_check)] fn main() { - assert!('x'.is_ascii_lowercase()); - assert!('X'.is_ascii_uppercase()); - assert!(b'x'.is_ascii_lowercase()); - assert!(b'X'.is_ascii_uppercase()); + assert!('x'.is_ascii_lowercase()); //~ manual_is_ascii_check + assert!('X'.is_ascii_uppercase()); //~ manual_is_ascii_check + assert!(b'x'.is_ascii_lowercase()); //~ manual_is_ascii_check + assert!(b'X'.is_ascii_uppercase()); //~ manual_is_ascii_check let num = '2'; - assert!(num.is_ascii_digit()); - assert!(b'1'.is_ascii_digit()); + assert!(num.is_ascii_digit()); //~ manual_is_ascii_check + assert!(b'1'.is_ascii_digit()); //~ manual_is_ascii_check assert!('x'.is_ascii_alphabetic()); + //~^ manual_is_ascii_check assert!(matches!('x', 'A'..='Z' | 'a'..='z' | '_')); - b'0'.is_ascii_digit(); - b'a'.is_ascii_lowercase(); - b'A'.is_ascii_uppercase(); + b'0'.is_ascii_digit(); //~ manual_is_ascii_check + b'a'.is_ascii_lowercase(); //~ manual_is_ascii_check + b'A'.is_ascii_uppercase(); //~ manual_is_ascii_check - '0'.is_ascii_digit(); - 'a'.is_ascii_lowercase(); - 'A'.is_ascii_uppercase(); + '0'.is_ascii_digit(); //~ manual_is_ascii_check + 'a'.is_ascii_lowercase(); //~ manual_is_ascii_check + 'A'.is_ascii_uppercase(); //~ manual_is_ascii_check let cool_letter = &'g'; - cool_letter.is_ascii_digit(); - cool_letter.is_ascii_lowercase(); - cool_letter.is_ascii_uppercase(); + cool_letter.is_ascii_digit(); //~ manual_is_ascii_check + cool_letter.is_ascii_lowercase(); //~ manual_is_ascii_check + cool_letter.is_ascii_uppercase(); //~ manual_is_ascii_check } #[clippy::msrv = "1.23"] @@ -38,10 +39,12 @@ fn msrv_1_23() { #[clippy::msrv = "1.24"] fn msrv_1_24() { - assert!(b'1'.is_ascii_digit()); - assert!('X'.is_ascii_uppercase()); + assert!(b'1'.is_ascii_digit()); //~ manual_is_ascii_check + assert!('X'.is_ascii_uppercase()); //~ manual_is_ascii_check assert!('x'.is_ascii_alphabetic()); + //~^ manual_is_ascii_check assert!('x'.is_ascii_hexdigit()); + //~^ manual_is_ascii_check } #[clippy::msrv = "1.46"] @@ -53,5 +56,7 @@ fn msrv_1_46() { #[clippy::msrv = "1.47"] fn msrv_1_47() { const FOO: bool = 'x'.is_ascii_digit(); + //~^ manual_is_ascii_check const BAR: bool = 'x'.is_ascii_hexdigit(); + //~^ manual_is_ascii_check } diff --git a/tests/ui/manual_is_ascii_check.rs b/tests/ui/manual_is_ascii_check.rs index 785943cd24d2..498e13cc6b53 100644 --- a/tests/ui/manual_is_ascii_check.rs +++ b/tests/ui/manual_is_ascii_check.rs @@ -2,30 +2,31 @@ #![warn(clippy::manual_is_ascii_check)] fn main() { - assert!(matches!('x', 'a'..='z')); - assert!(matches!('X', 'A'..='Z')); - assert!(matches!(b'x', b'a'..=b'z')); - assert!(matches!(b'X', b'A'..=b'Z')); + assert!(matches!('x', 'a'..='z')); //~ manual_is_ascii_check + assert!(matches!('X', 'A'..='Z')); //~ manual_is_ascii_check + assert!(matches!(b'x', b'a'..=b'z')); //~ manual_is_ascii_check + assert!(matches!(b'X', b'A'..=b'Z')); //~ manual_is_ascii_check let num = '2'; - assert!(matches!(num, '0'..='9')); - assert!(matches!(b'1', b'0'..=b'9')); + assert!(matches!(num, '0'..='9')); //~ manual_is_ascii_check + assert!(matches!(b'1', b'0'..=b'9')); //~ manual_is_ascii_check assert!(matches!('x', 'A'..='Z' | 'a'..='z')); + //~^ manual_is_ascii_check assert!(matches!('x', 'A'..='Z' | 'a'..='z' | '_')); - (b'0'..=b'9').contains(&b'0'); - (b'a'..=b'z').contains(&b'a'); - (b'A'..=b'Z').contains(&b'A'); + (b'0'..=b'9').contains(&b'0'); //~ manual_is_ascii_check + (b'a'..=b'z').contains(&b'a'); //~ manual_is_ascii_check + (b'A'..=b'Z').contains(&b'A'); //~ manual_is_ascii_check - ('0'..='9').contains(&'0'); - ('a'..='z').contains(&'a'); - ('A'..='Z').contains(&'A'); + ('0'..='9').contains(&'0'); //~ manual_is_ascii_check + ('a'..='z').contains(&'a'); //~ manual_is_ascii_check + ('A'..='Z').contains(&'A'); //~ manual_is_ascii_check let cool_letter = &'g'; - ('0'..='9').contains(cool_letter); - ('a'..='z').contains(cool_letter); - ('A'..='Z').contains(cool_letter); + ('0'..='9').contains(cool_letter); //~ manual_is_ascii_check + ('a'..='z').contains(cool_letter); //~ manual_is_ascii_check + ('A'..='Z').contains(cool_letter); //~ manual_is_ascii_check } #[clippy::msrv = "1.23"] @@ -38,10 +39,12 @@ fn msrv_1_23() { #[clippy::msrv = "1.24"] fn msrv_1_24() { - assert!(matches!(b'1', b'0'..=b'9')); - assert!(matches!('X', 'A'..='Z')); + assert!(matches!(b'1', b'0'..=b'9')); //~ manual_is_ascii_check + assert!(matches!('X', 'A'..='Z')); //~ manual_is_ascii_check assert!(matches!('x', 'A'..='Z' | 'a'..='z')); + //~^ manual_is_ascii_check assert!(matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F')); + //~^ manual_is_ascii_check } #[clippy::msrv = "1.46"] @@ -53,5 +56,7 @@ fn msrv_1_46() { #[clippy::msrv = "1.47"] fn msrv_1_47() { const FOO: bool = matches!('x', '0'..='9'); + //~^ manual_is_ascii_check const BAR: bool = matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F'); + //~^ manual_is_ascii_check } diff --git a/tests/ui/manual_is_ascii_check.stderr b/tests/ui/manual_is_ascii_check.stderr index f69522c5ff84..4032fd8e743c 100644 --- a/tests/ui/manual_is_ascii_check.stderr +++ b/tests/ui/manual_is_ascii_check.stderr @@ -44,91 +44,91 @@ LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:17:5 + --> $DIR/manual_is_ascii_check.rs:18:5 | LL | (b'0'..=b'9').contains(&b'0'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'0'.is_ascii_digit()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:18:5 + --> $DIR/manual_is_ascii_check.rs:19:5 | LL | (b'a'..=b'z').contains(&b'a'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'a'.is_ascii_lowercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:19:5 + --> $DIR/manual_is_ascii_check.rs:20:5 | LL | (b'A'..=b'Z').contains(&b'A'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'A'.is_ascii_uppercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:21:5 + --> $DIR/manual_is_ascii_check.rs:22:5 | LL | ('0'..='9').contains(&'0'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'0'.is_ascii_digit()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:22:5 + --> $DIR/manual_is_ascii_check.rs:23:5 | LL | ('a'..='z').contains(&'a'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'a'.is_ascii_lowercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:23:5 + --> $DIR/manual_is_ascii_check.rs:24:5 | LL | ('A'..='Z').contains(&'A'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'A'.is_ascii_uppercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:26:5 + --> $DIR/manual_is_ascii_check.rs:27:5 | LL | ('0'..='9').contains(cool_letter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_digit()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:27:5 + --> $DIR/manual_is_ascii_check.rs:28:5 | LL | ('a'..='z').contains(cool_letter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_lowercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:28:5 + --> $DIR/manual_is_ascii_check.rs:29:5 | LL | ('A'..='Z').contains(cool_letter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_uppercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:41:13 + --> $DIR/manual_is_ascii_check.rs:42:13 | LL | assert!(matches!(b'1', b'0'..=b'9')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'1'.is_ascii_digit()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:42:13 + --> $DIR/manual_is_ascii_check.rs:43:13 | LL | assert!(matches!('X', 'A'..='Z')); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'X'.is_ascii_uppercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:43:13 + --> $DIR/manual_is_ascii_check.rs:44:13 | LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:44:13 + --> $DIR/manual_is_ascii_check.rs:46:13 | LL | assert!(matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_hexdigit()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:55:23 + --> $DIR/manual_is_ascii_check.rs:58:23 | LL | const FOO: bool = matches!('x', '0'..='9'); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_digit()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:56:23 + --> $DIR/manual_is_ascii_check.rs:60:23 | LL | const BAR: bool = matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_hexdigit()` diff --git a/tests/ui/manual_is_variant_and.fixed b/tests/ui/manual_is_variant_and.fixed index 8c34b51103c1..92d1b02bc49a 100644 --- a/tests/ui/manual_is_variant_and.fixed +++ b/tests/ui/manual_is_variant_and.fixed @@ -10,19 +10,24 @@ fn option_methods() { // Check for `option.map(_).unwrap_or_default()` use. // Single line case. + //~v manual_is_variant_and let _ = opt.is_some_and(|x| x > 1); // Multi-line cases. + //~v manual_is_variant_and let _ = opt.is_some_and(|x| { x > 1 }); let _ = opt.is_some_and(|x| x > 1); + //~^ manual_is_variant_and let _ = opt + //~v manual_is_variant_and .is_some_and(|x| x > 1); // won't fix because the return type of the closure is not `bool` let _ = opt.map(|x| x + 1).unwrap_or_default(); let opt2 = Some('a'); + //~v manual_is_variant_and let _ = opt2.is_some_and(char::is_alphanumeric); // should lint let _ = opt_map!(opt2, |x| x == 'a').unwrap_or_default(); // should not lint } @@ -32,15 +37,18 @@ fn result_methods() { let res: Result = Ok(1); // multi line cases + //~v manual_is_variant_and let _ = res.is_ok_and(|x| { x > 1 }); + //~v manual_is_variant_and let _ = res.is_ok_and(|x| x > 1); // won't fix because the return type of the closure is not `bool` let _ = res.map(|x| x + 1).unwrap_or_default(); let res2: Result = Ok('a'); + //~v manual_is_variant_and let _ = res2.is_ok_and(char::is_alphanumeric); // should lint let _ = opt_map!(res2, |x| x == 'a').unwrap_or_default(); // should not lint } diff --git a/tests/ui/manual_is_variant_and.rs b/tests/ui/manual_is_variant_and.rs index 25b2489d9421..b2e5bb184755 100644 --- a/tests/ui/manual_is_variant_and.rs +++ b/tests/ui/manual_is_variant_and.rs @@ -10,16 +10,20 @@ fn option_methods() { // Check for `option.map(_).unwrap_or_default()` use. // Single line case. + //~v manual_is_variant_and let _ = opt.map(|x| x > 1) // Should lint even though this call is on a separate line. .unwrap_or_default(); // Multi-line cases. + //~v manual_is_variant_and let _ = opt.map(|x| { x > 1 } ).unwrap_or_default(); let _ = opt.map(|x| x > 1).unwrap_or_default(); + //~^ manual_is_variant_and let _ = opt + //~v manual_is_variant_and .map(|x| x > 1) .unwrap_or_default(); @@ -27,6 +31,7 @@ fn option_methods() { let _ = opt.map(|x| x + 1).unwrap_or_default(); let opt2 = Some('a'); + //~v manual_is_variant_and let _ = opt2.map(char::is_alphanumeric).unwrap_or_default(); // should lint let _ = opt_map!(opt2, |x| x == 'a').unwrap_or_default(); // should not lint } @@ -36,10 +41,12 @@ fn result_methods() { let res: Result = Ok(1); // multi line cases + //~v manual_is_variant_and let _ = res.map(|x| { x > 1 } ).unwrap_or_default(); + //~v manual_is_variant_and let _ = res.map(|x| x > 1) .unwrap_or_default(); @@ -47,6 +54,7 @@ fn result_methods() { let _ = res.map(|x| x + 1).unwrap_or_default(); let res2: Result = Ok('a'); + //~v manual_is_variant_and let _ = res2.map(char::is_alphanumeric).unwrap_or_default(); // should lint let _ = opt_map!(res2, |x| x == 'a').unwrap_or_default(); // should not lint } diff --git a/tests/ui/manual_is_variant_and.stderr b/tests/ui/manual_is_variant_and.stderr index c243de098dc6..168494734658 100644 --- a/tests/ui/manual_is_variant_and.stderr +++ b/tests/ui/manual_is_variant_and.stderr @@ -1,5 +1,5 @@ error: called `map().unwrap_or_default()` on an `Option` value - --> $DIR/manual_is_variant_and.rs:13:17 + --> $DIR/manual_is_variant_and.rs:14:17 | LL | let _ = opt.map(|x| x > 1) | _________________^ @@ -11,7 +11,7 @@ LL | | .unwrap_or_default(); = help: to override `-D warnings` add `#[allow(clippy::manual_is_variant_and)]` error: called `map().unwrap_or_default()` on an `Option` value - --> $DIR/manual_is_variant_and.rs:17:17 + --> $DIR/manual_is_variant_and.rs:19:17 | LL | let _ = opt.map(|x| { | _________________^ @@ -28,13 +28,13 @@ LL ~ }); | error: called `map().unwrap_or_default()` on an `Option` value - --> $DIR/manual_is_variant_and.rs:21:17 + --> $DIR/manual_is_variant_and.rs:23:17 | LL | let _ = opt.map(|x| x > 1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `is_some_and(|x| x > 1)` error: called `map().unwrap_or_default()` on an `Option` value - --> $DIR/manual_is_variant_and.rs:23:10 + --> $DIR/manual_is_variant_and.rs:27:10 | LL | .map(|x| x > 1) | __________^ @@ -42,13 +42,13 @@ LL | | .unwrap_or_default(); | |____________________________^ help: use: `is_some_and(|x| x > 1)` error: called `map().unwrap_or_default()` on an `Option` value - --> $DIR/manual_is_variant_and.rs:30:18 + --> $DIR/manual_is_variant_and.rs:35:18 | LL | let _ = opt2.map(char::is_alphanumeric).unwrap_or_default(); // should lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `is_some_and(char::is_alphanumeric)` error: called `map().unwrap_or_default()` on a `Result` value - --> $DIR/manual_is_variant_and.rs:39:17 + --> $DIR/manual_is_variant_and.rs:45:17 | LL | let _ = res.map(|x| { | _________________^ @@ -65,7 +65,7 @@ LL ~ }); | error: called `map().unwrap_or_default()` on a `Result` value - --> $DIR/manual_is_variant_and.rs:43:17 + --> $DIR/manual_is_variant_and.rs:50:17 | LL | let _ = res.map(|x| x > 1) | _________________^ @@ -73,7 +73,7 @@ LL | | .unwrap_or_default(); | |____________________________^ help: use: `is_ok_and(|x| x > 1)` error: called `map().unwrap_or_default()` on a `Result` value - --> $DIR/manual_is_variant_and.rs:50:18 + --> $DIR/manual_is_variant_and.rs:58:18 | LL | let _ = res2.map(char::is_alphanumeric).unwrap_or_default(); // should lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `is_ok_and(char::is_alphanumeric)` diff --git a/tests/ui/manual_let_else.rs b/tests/ui/manual_let_else.rs index 5d94660ec89a..cfbba5442965 100644 --- a/tests/ui/manual_let_else.rs +++ b/tests/ui/manual_let_else.rs @@ -210,6 +210,7 @@ fn fire() { macro_rules! create_binding_if_some { ($n:ident, $e:expr) => { let $n = if let Some(v) = $e { v } else { return }; + //~^ manual_let_else }; } create_binding_if_some!(w, g()); diff --git a/tests/ui/manual_let_else.stderr b/tests/ui/manual_let_else.stderr index 3beaf766efb1..94ac14df21e8 100644 --- a/tests/ui/manual_let_else.stderr +++ b/tests/ui/manual_let_else.stderr @@ -375,19 +375,19 @@ LL | create_binding_if_some!(w, g()); = note: this error originates in the macro `create_binding_if_some` (in Nightly builds, run with -Z macro-backtrace for more info) error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:221:5 + --> $DIR/manual_let_else.rs:222:5 | LL | let v = if let Variant::A(a, 0) = e() { a } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Variant::A(v, 0) = e() else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:225:5 + --> $DIR/manual_let_else.rs:226:5 | LL | let mut v = if let Variant::B(b) = e() { b } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Variant::B(mut v) = e() else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:230:5 + --> $DIR/manual_let_else.rs:231:5 | LL | / let v = if let Ok(Some(Variant::B(b))) | Err(Some(Variant::A(b, _))) = nested { LL | | @@ -405,19 +405,19 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:237:5 + --> $DIR/manual_let_else.rs:238:5 | LL | let v = if let Variant::A(.., a) = e() { a } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Variant::A(.., v) = e() else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:241:5 + --> $DIR/manual_let_else.rs:242:5 | LL | let w = if let (Some(v), ()) = (g(), ()) { v } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let (Some(w), ()) = (g(), ()) else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:245:5 + --> $DIR/manual_let_else.rs:246:5 | LL | / let w = if let Some(S { v: x }) = Some(S { v: 0 }) { LL | | @@ -435,7 +435,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:253:5 + --> $DIR/manual_let_else.rs:254:5 | LL | / let v = if let Some(S { v: x }) = Some(S { v: 0 }) { LL | | @@ -453,7 +453,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:261:5 + --> $DIR/manual_let_else.rs:262:5 | LL | / let (x, S { v }, w) = if let Some(U { v, w, x }) = None::>> { LL | | @@ -471,7 +471,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:378:5 + --> $DIR/manual_let_else.rs:379:5 | LL | / let _ = match ff { LL | | diff --git a/tests/ui/manual_let_else_question_mark.fixed b/tests/ui/manual_let_else_question_mark.fixed index 6b29ce759857..a27d208261c2 100644 --- a/tests/ui/manual_let_else_question_mark.fixed +++ b/tests/ui/manual_let_else_question_mark.fixed @@ -26,19 +26,21 @@ fn main() {} fn foo() -> Option<()> { // Fire here, normal case - let v = g()?; + let v = g()?; //~ question_mark // Don't fire here, the pattern is refutable let Variant::A(v, w) = e() else { return None }; // Fire here, the pattern is irrefutable - let (v, w) = g()?; + let (v, w) = g()?; //~ question_mark // Don't fire manual_let_else in this instance: question mark can be used instead. let v = g()?; + //~^ question_mark // Do fire manual_let_else in this instance: question mark cannot be used here due to the return // body. + //~v manual_let_else let Some(v) = g() else { return Some(()); }; @@ -48,6 +50,7 @@ fn foo() -> Option<()> { // lint, so for rustfix reasons, we allow the question_mark lint here. #[allow(clippy::question_mark)] { + //~v manual_let_else let Some(v) = g() else { return None }; } @@ -56,6 +59,7 @@ fn foo() -> Option<()> { #[allow(clippy::question_mark)] { let Some(v) = g() else { return None }; + //~^ manual_let_else } Some(()) @@ -63,6 +67,7 @@ fn foo() -> Option<()> { // lint not just `return None`, but also `return None;` (note the semicolon) fn issue11993(y: Option) -> Option { + //~v question_mark let x = y?; // don't lint: more than one statement in the else body diff --git a/tests/ui/manual_let_else_question_mark.rs b/tests/ui/manual_let_else_question_mark.rs index e92c4c1375e5..b82b5f31859e 100644 --- a/tests/ui/manual_let_else_question_mark.rs +++ b/tests/ui/manual_let_else_question_mark.rs @@ -26,19 +26,21 @@ fn main() {} fn foo() -> Option<()> { // Fire here, normal case - let Some(v) = g() else { return None }; + let Some(v) = g() else { return None }; //~ question_mark // Don't fire here, the pattern is refutable let Variant::A(v, w) = e() else { return None }; // Fire here, the pattern is irrefutable - let Some((v, w)) = g() else { return None }; + let Some((v, w)) = g() else { return None }; //~ question_mark // Don't fire manual_let_else in this instance: question mark can be used instead. let v = if let Some(v_some) = g() { v_some } else { return None }; + //~^ question_mark // Do fire manual_let_else in this instance: question mark cannot be used here due to the return // body. + //~v manual_let_else let v = if let Some(v_some) = g() { v_some } else { @@ -50,6 +52,7 @@ fn foo() -> Option<()> { // lint, so for rustfix reasons, we allow the question_mark lint here. #[allow(clippy::question_mark)] { + //~v manual_let_else let v = match g() { Some(v_some) => v_some, _ => return None, @@ -61,6 +64,7 @@ fn foo() -> Option<()> { #[allow(clippy::question_mark)] { let v = if let Some(v_some) = g() { v_some } else { return None }; + //~^ manual_let_else } Some(()) @@ -68,6 +72,7 @@ fn foo() -> Option<()> { // lint not just `return None`, but also `return None;` (note the semicolon) fn issue11993(y: Option) -> Option { + //~v question_mark let Some(x) = y else { return None; }; diff --git a/tests/ui/manual_let_else_question_mark.stderr b/tests/ui/manual_let_else_question_mark.stderr index dec6947697a7..e68d1cf319d0 100644 --- a/tests/ui/manual_let_else_question_mark.stderr +++ b/tests/ui/manual_let_else_question_mark.stderr @@ -20,7 +20,7 @@ LL | let v = if let Some(v_some) = g() { v_some } else { return None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `g()?` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_question_mark.rs:42:5 + --> $DIR/manual_let_else_question_mark.rs:44:5 | LL | / let v = if let Some(v_some) = g() { LL | | v_some @@ -39,7 +39,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_question_mark.rs:53:9 + --> $DIR/manual_let_else_question_mark.rs:56:9 | LL | / let v = match g() { LL | | Some(v_some) => v_some, @@ -48,13 +48,13 @@ LL | | }; | |__________^ help: consider writing: `let Some(v) = g() else { return None };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_question_mark.rs:63:9 + --> $DIR/manual_let_else_question_mark.rs:66:9 | LL | let v = if let Some(v_some) = g() { v_some } else { return None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { return None };` error: this `let...else` may be rewritten with the `?` operator - --> $DIR/manual_let_else_question_mark.rs:71:5 + --> $DIR/manual_let_else_question_mark.rs:76:5 | LL | / let Some(x) = y else { LL | | return None; diff --git a/tests/ui/manual_main_separator_str.fixed b/tests/ui/manual_main_separator_str.fixed index 6441d6edef8c..6e5478ad009e 100644 --- a/tests/ui/manual_main_separator_str.fixed +++ b/tests/ui/manual_main_separator_str.fixed @@ -19,12 +19,16 @@ struct V { fn main() { // Should lint let _: &str = std::path::MAIN_SEPARATOR_STR; + //~^ manual_main_separator_str let _ = len(std::path::MAIN_SEPARATOR_STR); + //~^ manual_main_separator_str let _: Vec = std::path::MAIN_SEPARATOR_STR.encode_utf16().collect(); + //~^ manual_main_separator_str // Should lint for field `f` only let _ = U { f: std::path::MAIN_SEPARATOR_STR, + //~^ manual_main_separator_str g: &MAIN_SEPARATOR.to_string(), }; diff --git a/tests/ui/manual_main_separator_str.rs b/tests/ui/manual_main_separator_str.rs index 339dfd8bb473..170af2da143f 100644 --- a/tests/ui/manual_main_separator_str.rs +++ b/tests/ui/manual_main_separator_str.rs @@ -19,12 +19,16 @@ struct V { fn main() { // Should lint let _: &str = &MAIN_SEPARATOR.to_string(); + //~^ manual_main_separator_str let _ = len(&MAIN_SEPARATOR.to_string()); + //~^ manual_main_separator_str let _: Vec = MAIN_SEPARATOR.to_string().encode_utf16().collect(); + //~^ manual_main_separator_str // Should lint for field `f` only let _ = U { f: &MAIN_SEPARATOR.to_string(), + //~^ manual_main_separator_str g: &MAIN_SEPARATOR.to_string(), }; diff --git a/tests/ui/manual_main_separator_str.stderr b/tests/ui/manual_main_separator_str.stderr index 3e92bd0238c3..731da54d24c5 100644 --- a/tests/ui/manual_main_separator_str.stderr +++ b/tests/ui/manual_main_separator_str.stderr @@ -8,19 +8,19 @@ LL | let _: &str = &MAIN_SEPARATOR.to_string(); = help: to override `-D warnings` add `#[allow(clippy::manual_main_separator_str)]` error: taking a reference on `std::path::MAIN_SEPARATOR` conversion to `String` - --> $DIR/manual_main_separator_str.rs:22:17 + --> $DIR/manual_main_separator_str.rs:23:17 | LL | let _ = len(&MAIN_SEPARATOR.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `std::path::MAIN_SEPARATOR_STR` error: taking a reference on `std::path::MAIN_SEPARATOR` conversion to `String` - --> $DIR/manual_main_separator_str.rs:23:23 + --> $DIR/manual_main_separator_str.rs:25:23 | LL | let _: Vec = MAIN_SEPARATOR.to_string().encode_utf16().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `std::path::MAIN_SEPARATOR_STR` error: taking a reference on `std::path::MAIN_SEPARATOR` conversion to `String` - --> $DIR/manual_main_separator_str.rs:27:12 + --> $DIR/manual_main_separator_str.rs:30:12 | LL | f: &MAIN_SEPARATOR.to_string(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `std::path::MAIN_SEPARATOR_STR` diff --git a/tests/ui/manual_map_option.fixed b/tests/ui/manual_map_option.fixed index 16cee3fd3823..ab5cfcdde483 100644 --- a/tests/ui/manual_map_option.fixed +++ b/tests/ui/manual_map_option.fixed @@ -11,17 +11,23 @@ )] fn main() { + //~v manual_map Some(0).map(|_| 2); + //~v manual_map Some(0).map(|x| x + 1); + //~v manual_map Some("").map(|x| x.is_empty()); + //~v manual_map Some(0).map(|x| !x); #[rustfmt::skip] + //~v manual_map Some(0).map(std::convert::identity); + //~v manual_map Some(&String::new()).map(|x| str::len(x)); match Some(0) { @@ -29,14 +35,19 @@ fn main() { _ => None, }; + //~v manual_map Some([0, 1]).as_ref().map(|x| x[0]); + //~v manual_map Some(0).map(|x| x * 2); + //~v manual_map Some(String::new()).as_ref().map(|x| x.is_empty()); + //~v manual_map Some(String::new()).as_ref().map(|x| x.len()); + //~v manual_map Some(0).map(|x| x + x); #[warn(clippy::option_map_unit_fn)] @@ -47,17 +58,23 @@ fn main() { #[allow(clippy::option_map_unit_fn)] { + //~v manual_map Some(String::new()).as_mut().map(|x| x.push_str("")); } + //~v manual_map Some(String::new()).as_ref().map(|x| x.len()); + //~v manual_map Some(String::new()).as_ref().map(|x| x.is_empty()); + //~v manual_map Some((0, 1, 2)).map(|(x, y, z)| x + y + z); + //~v manual_map Some([1, 2, 3]).map(|[first, ..]| first); + //~v manual_map Some((String::new(), "test")).as_ref().map(|(x, y)| (y, x)); match Some((String::new(), 0)) { @@ -113,8 +130,10 @@ fn main() { } // #6811 + //~v manual_map Some(0).map(|x| vec![x]); + //~v manual_map option_env!("").map(String::from); // #6819 @@ -132,10 +151,12 @@ fn main() { // #6847 if let Some(_) = Some(0) { Some(0) + //~v manual_map } else { Some(0).map(|x| x + 1) }; if true { Some(0) + //~v manual_map } else { Some(0).map(|x| x + 1) }; // #6967 diff --git a/tests/ui/manual_map_option.rs b/tests/ui/manual_map_option.rs index 4655acf1406c..47e4e8910975 100644 --- a/tests/ui/manual_map_option.rs +++ b/tests/ui/manual_map_option.rs @@ -11,21 +11,25 @@ )] fn main() { + //~v manual_map match Some(0) { Some(_) => Some(2), None:: => None, }; + //~v manual_map match Some(0) { Some(x) => Some(x + 1), _ => None, }; + //~v manual_map match Some("") { Some(x) => Some(x.is_empty()), None => None, }; + //~v manual_map if let Some(x) = Some(0) { Some(!x) } else { @@ -33,11 +37,13 @@ fn main() { }; #[rustfmt::skip] + //~v manual_map match Some(0) { Some(x) => { Some(std::convert::identity(x)) } None => { None } }; + //~v manual_map match Some(&String::new()) { Some(x) => Some(str::len(x)), None => None, @@ -48,26 +54,31 @@ fn main() { _ => None, }; + //~v manual_map match &Some([0, 1]) { Some(x) => Some(x[0]), &None => None, }; + //~v manual_map match &Some(0) { &Some(x) => Some(x * 2), None => None, }; + //~v manual_map match Some(String::new()) { Some(ref x) => Some(x.is_empty()), _ => None, }; + //~v manual_map match &&Some(String::new()) { Some(x) => Some(x.len()), _ => None, }; + //~v manual_map match &&Some(0) { &&Some(x) => Some(x + x), &&_ => None, @@ -81,32 +92,38 @@ fn main() { #[allow(clippy::option_map_unit_fn)] { + //~v manual_map match &mut Some(String::new()) { Some(x) => Some(x.push_str("")), None => None, }; } + //~v manual_map match &mut Some(String::new()) { Some(ref x) => Some(x.len()), None => None, }; + //~v manual_map match &mut &Some(String::new()) { Some(x) => Some(x.is_empty()), &mut _ => None, }; + //~v manual_map match Some((0, 1, 2)) { Some((x, y, z)) => Some(x + y + z), None => None, }; + //~v manual_map match Some([1, 2, 3]) { Some([first, ..]) => Some(first), None => None, }; + //~v manual_map match &Some((String::new(), "test")) { Some((x, y)) => Some((y, x)), None => None, @@ -165,11 +182,13 @@ fn main() { } // #6811 + //~v manual_map match Some(0) { Some(x) => Some(vec![x]), None => None, }; + //~v manual_map match option_env!("") { Some(x) => Some(String::from(x)), None => None, @@ -190,6 +209,7 @@ fn main() { // #6847 if let Some(_) = Some(0) { Some(0) + //~v manual_map } else if let Some(x) = Some(0) { Some(x + 1) } else { @@ -198,6 +218,7 @@ fn main() { if true { Some(0) + //~v manual_map } else if let Some(x) = Some(0) { Some(x + 1) } else { diff --git a/tests/ui/manual_map_option.stderr b/tests/ui/manual_map_option.stderr index 3754a982cb9b..137e0d18d863 100644 --- a/tests/ui/manual_map_option.stderr +++ b/tests/ui/manual_map_option.stderr @@ -1,5 +1,5 @@ error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:14:5 + --> $DIR/manual_map_option.rs:15:5 | LL | / match Some(0) { LL | | Some(_) => Some(2), @@ -11,7 +11,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::manual_map)]` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:19:5 + --> $DIR/manual_map_option.rs:21:5 | LL | / match Some(0) { LL | | Some(x) => Some(x + 1), @@ -20,7 +20,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| x + 1)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:24:5 + --> $DIR/manual_map_option.rs:27:5 | LL | / match Some("") { LL | | Some(x) => Some(x.is_empty()), @@ -29,7 +29,7 @@ LL | | }; | |_____^ help: try: `Some("").map(|x| x.is_empty())` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:29:5 + --> $DIR/manual_map_option.rs:33:5 | LL | / if let Some(x) = Some(0) { LL | | Some(!x) @@ -39,7 +39,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| !x)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:36:5 + --> $DIR/manual_map_option.rs:41:5 | LL | / match Some(0) { LL | | Some(x) => { Some(std::convert::identity(x)) } @@ -48,7 +48,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(std::convert::identity)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:41:5 + --> $DIR/manual_map_option.rs:47:5 | LL | / match Some(&String::new()) { LL | | Some(x) => Some(str::len(x)), @@ -57,7 +57,7 @@ LL | | }; | |_____^ help: try: `Some(&String::new()).map(|x| str::len(x))` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:51:5 + --> $DIR/manual_map_option.rs:58:5 | LL | / match &Some([0, 1]) { LL | | Some(x) => Some(x[0]), @@ -66,7 +66,7 @@ LL | | }; | |_____^ help: try: `Some([0, 1]).as_ref().map(|x| x[0])` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:56:5 + --> $DIR/manual_map_option.rs:64:5 | LL | / match &Some(0) { LL | | &Some(x) => Some(x * 2), @@ -75,7 +75,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| x * 2)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:61:5 + --> $DIR/manual_map_option.rs:70:5 | LL | / match Some(String::new()) { LL | | Some(ref x) => Some(x.is_empty()), @@ -84,7 +84,7 @@ LL | | }; | |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.is_empty())` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:66:5 + --> $DIR/manual_map_option.rs:76:5 | LL | / match &&Some(String::new()) { LL | | Some(x) => Some(x.len()), @@ -93,7 +93,7 @@ LL | | }; | |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.len())` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:71:5 + --> $DIR/manual_map_option.rs:82:5 | LL | / match &&Some(0) { LL | | &&Some(x) => Some(x + x), @@ -102,7 +102,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| x + x)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:84:9 + --> $DIR/manual_map_option.rs:96:9 | LL | / match &mut Some(String::new()) { LL | | Some(x) => Some(x.push_str("")), @@ -111,7 +111,7 @@ LL | | }; | |_________^ help: try: `Some(String::new()).as_mut().map(|x| x.push_str(""))` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:90:5 + --> $DIR/manual_map_option.rs:103:5 | LL | / match &mut Some(String::new()) { LL | | Some(ref x) => Some(x.len()), @@ -120,7 +120,7 @@ LL | | }; | |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.len())` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:95:5 + --> $DIR/manual_map_option.rs:109:5 | LL | / match &mut &Some(String::new()) { LL | | Some(x) => Some(x.is_empty()), @@ -129,7 +129,7 @@ LL | | }; | |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.is_empty())` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:100:5 + --> $DIR/manual_map_option.rs:115:5 | LL | / match Some((0, 1, 2)) { LL | | Some((x, y, z)) => Some(x + y + z), @@ -138,7 +138,7 @@ LL | | }; | |_____^ help: try: `Some((0, 1, 2)).map(|(x, y, z)| x + y + z)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:105:5 + --> $DIR/manual_map_option.rs:121:5 | LL | / match Some([1, 2, 3]) { LL | | Some([first, ..]) => Some(first), @@ -147,7 +147,7 @@ LL | | }; | |_____^ help: try: `Some([1, 2, 3]).map(|[first, ..]| first)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:110:5 + --> $DIR/manual_map_option.rs:127:5 | LL | / match &Some((String::new(), "test")) { LL | | Some((x, y)) => Some((y, x)), @@ -156,7 +156,7 @@ LL | | }; | |_____^ help: try: `Some((String::new(), "test")).as_ref().map(|(x, y)| (y, x))` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:168:5 + --> $DIR/manual_map_option.rs:186:5 | LL | / match Some(0) { LL | | Some(x) => Some(vec![x]), @@ -165,7 +165,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| vec![x])` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:173:5 + --> $DIR/manual_map_option.rs:192:5 | LL | / match option_env!("") { LL | | Some(x) => Some(String::from(x)), @@ -174,7 +174,7 @@ LL | | }; | |_____^ help: try: `option_env!("").map(String::from)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:193:12 + --> $DIR/manual_map_option.rs:213:12 | LL | } else if let Some(x) = Some(0) { | ____________^ @@ -185,7 +185,7 @@ LL | | }; | |_____^ help: try: `{ Some(0).map(|x| x + 1) }` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:201:12 + --> $DIR/manual_map_option.rs:222:12 | LL | } else if let Some(x) = Some(0) { | ____________^ diff --git a/tests/ui/manual_map_option_2.fixed b/tests/ui/manual_map_option_2.fixed index f5bb4e0af1ba..2e1374323b20 100644 --- a/tests/ui/manual_map_option_2.fixed +++ b/tests/ui/manual_map_option_2.fixed @@ -3,6 +3,7 @@ fn main() { // Lint. `y` is declared within the arm, so it isn't captured by the map closure + //~v manual_map let _ = Some(0).map(|x| { let y = (String::new(), String::new()); (x, y.0) @@ -42,6 +43,7 @@ fn main() { // Lint. `s` is captured by reference, so no lifetime issues. let s = Some(String::new()); + //~v manual_map let _ = s.as_ref().map(|x| { if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }); // Issue #7820 @@ -49,8 +51,11 @@ fn main() { x } unsafe { + //~v manual_map let _ = Some(0).map(|x| f(x)); } + //~v manual_map let _ = Some(0).map(|x| unsafe { f(x) }); + //~v manual_map let _ = Some(0).map(|x| unsafe { f(x) }); } diff --git a/tests/ui/manual_map_option_2.rs b/tests/ui/manual_map_option_2.rs index cbc2356e0a2d..30cbd04ab8f5 100644 --- a/tests/ui/manual_map_option_2.rs +++ b/tests/ui/manual_map_option_2.rs @@ -3,6 +3,7 @@ fn main() { // Lint. `y` is declared within the arm, so it isn't captured by the map closure + //~v manual_map let _ = match Some(0) { Some(x) => Some({ let y = (String::new(), String::new()); @@ -45,6 +46,7 @@ fn main() { // Lint. `s` is captured by reference, so no lifetime issues. let s = Some(String::new()); + //~v manual_map let _ = match &s { Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }), None => None, @@ -55,15 +57,18 @@ fn main() { x } unsafe { + //~v manual_map let _ = match Some(0) { Some(x) => Some(f(x)), None => None, }; } + //~v manual_map let _ = match Some(0) { Some(x) => unsafe { Some(f(x)) }, None => None, }; + //~v manual_map let _ = match Some(0) { Some(x) => Some(unsafe { f(x) }), None => None, diff --git a/tests/ui/manual_map_option_2.stderr b/tests/ui/manual_map_option_2.stderr index d3754f22d899..3a3c72887f08 100644 --- a/tests/ui/manual_map_option_2.stderr +++ b/tests/ui/manual_map_option_2.stderr @@ -1,5 +1,5 @@ error: manual implementation of `Option::map` - --> $DIR/manual_map_option_2.rs:6:13 + --> $DIR/manual_map_option_2.rs:7:13 | LL | let _ = match Some(0) { | _____________^ @@ -22,7 +22,7 @@ LL ~ }); | error: manual implementation of `Option::map` - --> $DIR/manual_map_option_2.rs:48:13 + --> $DIR/manual_map_option_2.rs:50:13 | LL | let _ = match &s { | _____________^ @@ -32,7 +32,7 @@ LL | | }; | |_____^ help: try: `s.as_ref().map(|x| { if let Some(ref s) = s { (x.clone(), s) } else { panic!() } })` error: manual implementation of `Option::map` - --> $DIR/manual_map_option_2.rs:58:17 + --> $DIR/manual_map_option_2.rs:61:17 | LL | let _ = match Some(0) { | _________________^ @@ -42,7 +42,7 @@ LL | | }; | |_________^ help: try: `Some(0).map(|x| f(x))` error: manual implementation of `Option::map` - --> $DIR/manual_map_option_2.rs:63:13 + --> $DIR/manual_map_option_2.rs:67:13 | LL | let _ = match Some(0) { | _____________^ @@ -52,7 +52,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| unsafe { f(x) })` error: manual implementation of `Option::map` - --> $DIR/manual_map_option_2.rs:67:13 + --> $DIR/manual_map_option_2.rs:72:13 | LL | let _ = match Some(0) { | _____________^ diff --git a/tests/ui/manual_next_back.fixed b/tests/ui/manual_next_back.fixed index 75828f355d90..c2d9041337eb 100644 --- a/tests/ui/manual_next_back.fixed +++ b/tests/ui/manual_next_back.fixed @@ -29,6 +29,6 @@ fn main() { FakeIter(0..10).rev().next(); // should lint - let _ = (0..10).next_back().unwrap(); - let _ = "something".bytes().next_back(); + let _ = (0..10).next_back().unwrap(); //~ manual_next_back + let _ = "something".bytes().next_back(); //~ manual_next_back } diff --git a/tests/ui/manual_next_back.rs b/tests/ui/manual_next_back.rs index b980e90e1144..8cff8027b243 100644 --- a/tests/ui/manual_next_back.rs +++ b/tests/ui/manual_next_back.rs @@ -29,6 +29,6 @@ fn main() { FakeIter(0..10).rev().next(); // should lint - let _ = (0..10).rev().next().unwrap(); - let _ = "something".bytes().rev().next(); + let _ = (0..10).rev().next().unwrap(); //~ manual_next_back + let _ = "something".bytes().rev().next(); //~ manual_next_back } diff --git a/tests/ui/manual_non_exhaustive_enum.rs b/tests/ui/manual_non_exhaustive_enum.rs index eb3875320311..9b703b444af7 100644 --- a/tests/ui/manual_non_exhaustive_enum.rs +++ b/tests/ui/manual_non_exhaustive_enum.rs @@ -27,6 +27,7 @@ enum NoDocHidden { } // name of variant with doc hidden does not start with underscore +//~v manual_non_exhaustive enum NoUnderscore { A, B, diff --git a/tests/ui/manual_non_exhaustive_enum.stderr b/tests/ui/manual_non_exhaustive_enum.stderr index c4b13a577a96..d74071514866 100644 --- a/tests/ui/manual_non_exhaustive_enum.stderr +++ b/tests/ui/manual_non_exhaustive_enum.stderr @@ -23,7 +23,7 @@ LL | _C, = help: to override `-D warnings` add `#[allow(clippy::manual_non_exhaustive)]` error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive_enum.rs:30:1 + --> $DIR/manual_non_exhaustive_enum.rs:31:1 | LL | enum NoUnderscore { | ^---------------- @@ -38,7 +38,7 @@ LL | | } | |_^ | help: remove this variant - --> $DIR/manual_non_exhaustive_enum.rs:34:5 + --> $DIR/manual_non_exhaustive_enum.rs:35:5 | LL | C, | ^ diff --git a/tests/ui/manual_non_exhaustive_struct.rs b/tests/ui/manual_non_exhaustive_struct.rs index 4b2803ccc4a7..227097d6c24c 100644 --- a/tests/ui/manual_non_exhaustive_struct.rs +++ b/tests/ui/manual_non_exhaustive_struct.rs @@ -26,6 +26,7 @@ mod structs { } // private field name does not start with underscore, should be ignored + //~v manual_non_exhaustive struct NoUnderscore { pub a: i32, pub b: i32, diff --git a/tests/ui/manual_non_exhaustive_struct.stderr b/tests/ui/manual_non_exhaustive_struct.stderr index 0b88b19691e1..ffd9bf29a1d4 100644 --- a/tests/ui/manual_non_exhaustive_struct.stderr +++ b/tests/ui/manual_non_exhaustive_struct.stderr @@ -39,7 +39,7 @@ LL | _c: (), | ^^^^^^ error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive_struct.rs:29:5 + --> $DIR/manual_non_exhaustive_struct.rs:30:5 | LL | struct NoUnderscore { | ^------------------ @@ -53,13 +53,13 @@ LL | | } | |_____^ | help: remove this field - --> $DIR/manual_non_exhaustive_struct.rs:32:9 + --> $DIR/manual_non_exhaustive_struct.rs:33:9 | LL | c: (), | ^^^^^ error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive_struct.rs:56:5 + --> $DIR/manual_non_exhaustive_struct.rs:57:5 | LL | struct T(pub i32, pub i32, ()); | --------^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,19 +67,19 @@ LL | struct T(pub i32, pub i32, ()); | help: add the attribute: `#[non_exhaustive] struct T` | help: remove this field - --> $DIR/manual_non_exhaustive_struct.rs:56:32 + --> $DIR/manual_non_exhaustive_struct.rs:57:32 | LL | struct T(pub i32, pub i32, ()); | ^^ error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive_struct.rs:61:5 + --> $DIR/manual_non_exhaustive_struct.rs:62:5 | LL | struct Tp(pub i32, pub i32, ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove this field - --> $DIR/manual_non_exhaustive_struct.rs:61:33 + --> $DIR/manual_non_exhaustive_struct.rs:62:33 | LL | struct Tp(pub i32, pub i32, ()); | ^^ diff --git a/tests/ui/manual_ok_or.fixed b/tests/ui/manual_ok_or.fixed index cc53cb416a22..c8c014779167 100644 --- a/tests/ui/manual_ok_or.fixed +++ b/tests/ui/manual_ok_or.fixed @@ -8,16 +8,19 @@ fn main() { // basic case let foo: Option = None; - foo.ok_or("error"); + foo.ok_or("error"); //~ manual_ok_or // eta expansion case foo.ok_or("error"); + //~^ manual_ok_or + //~| option_map_or_err_ok // turbo fish syntax - None::.ok_or("error"); + None::.ok_or("error"); //~ manual_ok_or // multiline case #[rustfmt::skip] + //~v manual_ok_or foo.ok_or(&format!( "{}{}{}{}{}{}{}", "Alice", "Bob", "Sarah", "Marc", "Sandra", "Eric", "Jenifer")); diff --git a/tests/ui/manual_ok_or.rs b/tests/ui/manual_ok_or.rs index 39c61a1e490f..42da39aff0ac 100644 --- a/tests/ui/manual_ok_or.rs +++ b/tests/ui/manual_ok_or.rs @@ -8,16 +8,19 @@ fn main() { // basic case let foo: Option = None; - foo.map_or(Err("error"), |v| Ok(v)); + foo.map_or(Err("error"), |v| Ok(v)); //~ manual_ok_or // eta expansion case foo.map_or(Err("error"), Ok); + //~^ manual_ok_or + //~| option_map_or_err_ok // turbo fish syntax - None::.map_or(Err("error"), |v| Ok(v)); + None::.map_or(Err("error"), |v| Ok(v)); //~ manual_ok_or // multiline case #[rustfmt::skip] + //~v manual_ok_or foo.map_or(Err::( &format!( "{}{}{}{}{}{}{}", diff --git a/tests/ui/manual_ok_or.stderr b/tests/ui/manual_ok_or.stderr index 89df6cdbedbc..c99ec9940a9b 100644 --- a/tests/ui/manual_ok_or.stderr +++ b/tests/ui/manual_ok_or.stderr @@ -23,13 +23,13 @@ LL | foo.map_or(Err("error"), Ok); = help: to override `-D warnings` add `#[allow(clippy::option_map_or_err_ok)]` error: this pattern reimplements `Option::ok_or` - --> $DIR/manual_ok_or.rs:17:5 + --> $DIR/manual_ok_or.rs:19:5 | LL | None::.map_or(Err("error"), |v| Ok(v)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `None::.ok_or("error")` error: this pattern reimplements `Option::ok_or` - --> $DIR/manual_ok_or.rs:21:5 + --> $DIR/manual_ok_or.rs:24:5 | LL | / foo.map_or(Err::( LL | | &format!( diff --git a/tests/ui/manual_range_patterns.fixed b/tests/ui/manual_range_patterns.fixed index b348d7071f6e..137f1356c843 100644 --- a/tests/ui/manual_range_patterns.fixed +++ b/tests/ui/manual_range_patterns.fixed @@ -6,42 +6,54 @@ fn main() { let f = 6; let _ = matches!(f, 1..=10); + //~^ manual_range_patterns let _ = matches!(f, 1..=10); + //~^ manual_range_patterns let _ = matches!(f, 4 | 2 | 3 | 1 | 5 | 6 | 9 | 8 | 10); // 7 is missing let _ = matches!(f, | 4); let _ = matches!(f, 4 | 5); let _ = matches!(f, 1 | 2147483647); let _ = matches!(f, 0 | 2147483647); let _ = matches!(f, -2147483647 | 2147483647); - let _ = matches!(f, 1..=4); - let _ = matches!(f, 1..4); + let _ = matches!(f, 1..=4); //~ manual_range_patterns + let _ = matches!(f, 1..4); //~ manual_range_patterns let _ = matches!(f, 1..=48324729); + //~^ manual_range_patterns let _ = matches!(f, 0..=48324730); + //~^ manual_range_patterns let _ = matches!(f, 0..=3); + //~^ manual_range_patterns #[allow(clippy::match_like_matches_macro)] let _ = match f { 1..=10 => true, + //~^ manual_range_patterns _ => false, }; let _ = matches!(f, -5..=3); + //~^ manual_range_patterns let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1); // 2 is missing let _ = matches!(f, -1_000_001..=1_000_001); + //~^ manual_range_patterns let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_002); matches!(f, 0x00..=0x03); + //~^ manual_range_patterns matches!(f, 0x00..=0x07); + //~^ manual_range_patterns matches!(f, -0x09..=0x00); + //~^ manual_range_patterns - matches!(f, 0..=5); - matches!(f, 0..5); + matches!(f, 0..=5); //~ manual_range_patterns + matches!(f, 0..5); //~ manual_range_patterns - matches!(f, 0..10); - matches!(f, 0..=10); - matches!(f, 0..=10); + matches!(f, 0..10); //~ manual_range_patterns + matches!(f, 0..=10); //~ manual_range_patterns + matches!(f, 0..=10); //~ manual_range_patterns macro_rules! mac { ($e:expr) => { matches!($e, 1..=10) + //~^ manual_range_patterns }; } mac!(f); diff --git a/tests/ui/manual_range_patterns.rs b/tests/ui/manual_range_patterns.rs index a0750f54b73f..5dfb4757203e 100644 --- a/tests/ui/manual_range_patterns.rs +++ b/tests/ui/manual_range_patterns.rs @@ -6,42 +6,54 @@ fn main() { let f = 6; let _ = matches!(f, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10); + //~^ manual_range_patterns let _ = matches!(f, 4 | 2 | 3 | 1 | 5 | 6 | 9 | 7 | 8 | 10); + //~^ manual_range_patterns let _ = matches!(f, 4 | 2 | 3 | 1 | 5 | 6 | 9 | 8 | 10); // 7 is missing let _ = matches!(f, | 4); let _ = matches!(f, 4 | 5); let _ = matches!(f, 1 | 2147483647); let _ = matches!(f, 0 | 2147483647); let _ = matches!(f, -2147483647 | 2147483647); - let _ = matches!(f, 1 | (2..=4)); - let _ = matches!(f, 1 | (2..4)); + let _ = matches!(f, 1 | (2..=4)); //~ manual_range_patterns + let _ = matches!(f, 1 | (2..4)); //~ manual_range_patterns let _ = matches!(f, (1..=10) | (2..=13) | (14..=48324728) | 48324729); + //~^ manual_range_patterns let _ = matches!(f, 0 | (1..=10) | 48324730 | (2..=13) | (14..=48324728) | 48324729); + //~^ manual_range_patterns let _ = matches!(f, 0..=1 | 0..=2 | 0..=3); + //~^ manual_range_patterns #[allow(clippy::match_like_matches_macro)] let _ = match f { 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 => true, + //~^ manual_range_patterns _ => false, }; let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1 | 2); + //~^ manual_range_patterns let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1); // 2 is missing let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_001); + //~^ manual_range_patterns let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_002); matches!(f, 0x00 | 0x01 | 0x02 | 0x03); + //~^ manual_range_patterns matches!(f, 0x00..=0x05 | 0x06 | 0x07); + //~^ manual_range_patterns matches!(f, -0x09 | -0x08 | -0x07..=0x00); + //~^ manual_range_patterns - matches!(f, 0..5 | 5); - matches!(f, 0 | 1..5); + matches!(f, 0..5 | 5); //~ manual_range_patterns + matches!(f, 0 | 1..5); //~ manual_range_patterns - matches!(f, 0..=5 | 6..10); - matches!(f, 0..5 | 5..=10); - matches!(f, 5..=10 | 0..5); + matches!(f, 0..=5 | 6..10); //~ manual_range_patterns + matches!(f, 0..5 | 5..=10); //~ manual_range_patterns + matches!(f, 5..=10 | 0..5); //~ manual_range_patterns macro_rules! mac { ($e:expr) => { matches!($e, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10) + //~^ manual_range_patterns }; } mac!(f); diff --git a/tests/ui/manual_range_patterns.stderr b/tests/ui/manual_range_patterns.stderr index fbeb9455769d..2282fe9e76b7 100644 --- a/tests/ui/manual_range_patterns.stderr +++ b/tests/ui/manual_range_patterns.stderr @@ -8,109 +8,109 @@ LL | let _ = matches!(f, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10); = help: to override `-D warnings` add `#[allow(clippy::manual_range_patterns)]` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:9:25 + --> $DIR/manual_range_patterns.rs:10:25 | LL | let _ = matches!(f, 4 | 2 | 3 | 1 | 5 | 6 | 9 | 7 | 8 | 10); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:16:25 + --> $DIR/manual_range_patterns.rs:18:25 | LL | let _ = matches!(f, 1 | (2..=4)); | ^^^^^^^^^^^ help: try: `1..=4` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:17:25 + --> $DIR/manual_range_patterns.rs:19:25 | LL | let _ = matches!(f, 1 | (2..4)); | ^^^^^^^^^^ help: try: `1..4` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:18:25 + --> $DIR/manual_range_patterns.rs:20:25 | LL | let _ = matches!(f, (1..=10) | (2..=13) | (14..=48324728) | 48324729); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=48324729` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:19:25 + --> $DIR/manual_range_patterns.rs:22:25 | LL | let _ = matches!(f, 0 | (1..=10) | 48324730 | (2..=13) | (14..=48324728) | 48324729); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0..=48324730` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:20:25 + --> $DIR/manual_range_patterns.rs:24:25 | LL | let _ = matches!(f, 0..=1 | 0..=2 | 0..=3); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `0..=3` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:23:9 + --> $DIR/manual_range_patterns.rs:28:9 | LL | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 => true, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:26:25 + --> $DIR/manual_range_patterns.rs:32:25 | LL | let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1 | 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-5..=3` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:28:25 + --> $DIR/manual_range_patterns.rs:35:25 | LL | let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_001); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-1_000_001..=1_000_001` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:31:17 + --> $DIR/manual_range_patterns.rs:39:17 | LL | matches!(f, 0x00 | 0x01 | 0x02 | 0x03); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0x00..=0x03` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:32:17 + --> $DIR/manual_range_patterns.rs:41:17 | LL | matches!(f, 0x00..=0x05 | 0x06 | 0x07); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0x00..=0x07` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:33:17 + --> $DIR/manual_range_patterns.rs:43:17 | LL | matches!(f, -0x09 | -0x08 | -0x07..=0x00); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-0x09..=0x00` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:35:17 + --> $DIR/manual_range_patterns.rs:46:17 | LL | matches!(f, 0..5 | 5); | ^^^^^^^^ help: try: `0..=5` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:36:17 + --> $DIR/manual_range_patterns.rs:47:17 | LL | matches!(f, 0 | 1..5); | ^^^^^^^^ help: try: `0..5` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:38:17 + --> $DIR/manual_range_patterns.rs:49:17 | LL | matches!(f, 0..=5 | 6..10); | ^^^^^^^^^^^^^ help: try: `0..10` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:39:17 + --> $DIR/manual_range_patterns.rs:50:17 | LL | matches!(f, 0..5 | 5..=10); | ^^^^^^^^^^^^^ help: try: `0..=10` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:40:17 + --> $DIR/manual_range_patterns.rs:51:17 | LL | matches!(f, 5..=10 | 0..5); | ^^^^^^^^^^^^^ help: try: `0..=10` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:44:26 + --> $DIR/manual_range_patterns.rs:55:26 | LL | matches!($e, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` diff --git a/tests/ui/manual_rem_euclid.fixed b/tests/ui/manual_rem_euclid.fixed index 2d50865586d1..2f6078b147f1 100644 --- a/tests/ui/manual_rem_euclid.fixed +++ b/tests/ui/manual_rem_euclid.fixed @@ -10,11 +10,11 @@ use proc_macros::{external, inline_macros}; fn main() { let value: i32 = 5; - let _: i32 = value.rem_euclid(4); - let _: i32 = value.rem_euclid(4); - let _: i32 = value.rem_euclid(4); - let _: i32 = value.rem_euclid(4); - let _: i32 = 1 + value.rem_euclid(4); + let _: i32 = value.rem_euclid(4); //~ manual_rem_euclid + let _: i32 = value.rem_euclid(4); //~ manual_rem_euclid + let _: i32 = value.rem_euclid(4); //~ manual_rem_euclid + let _: i32 = value.rem_euclid(4); //~ manual_rem_euclid + let _: i32 = 1 + value.rem_euclid(4); //~ manual_rem_euclid let _: i32 = (3 + value % 4) % 4; let _: i32 = (-4 + value % -4) % -4; @@ -34,7 +34,7 @@ fn main() { // Lint in internal macros inline!( let value: i32 = 5; - let _: i32 = value.rem_euclid(4); + let _: i32 = value.rem_euclid(4); //~ manual_rem_euclid ); // Do not lint in external macros @@ -46,12 +46,12 @@ fn main() { // Should lint for params too pub fn rem_euclid_4(num: i32) -> i32 { - num.rem_euclid(4) + num.rem_euclid(4) //~ manual_rem_euclid } // Constant version came later, should still lint pub const fn const_rem_euclid_4(num: i32) -> i32 { - num.rem_euclid(4) + num.rem_euclid(4) //~ manual_rem_euclid } #[clippy::msrv = "1.37"] @@ -63,7 +63,7 @@ pub fn msrv_1_37() { #[clippy::msrv = "1.38"] pub fn msrv_1_38() { let x: i32 = 10; - let _: i32 = x.rem_euclid(4); + let _: i32 = x.rem_euclid(4); //~ manual_rem_euclid } // For const fns: @@ -76,5 +76,5 @@ pub const fn msrv_1_51() { #[clippy::msrv = "1.52"] pub const fn msrv_1_52() { let x: i32 = 10; - let _: i32 = x.rem_euclid(4); + let _: i32 = x.rem_euclid(4); //~ manual_rem_euclid } diff --git a/tests/ui/manual_rem_euclid.rs b/tests/ui/manual_rem_euclid.rs index e405a2db4765..ef73ff2927ef 100644 --- a/tests/ui/manual_rem_euclid.rs +++ b/tests/ui/manual_rem_euclid.rs @@ -10,11 +10,11 @@ use proc_macros::{external, inline_macros}; fn main() { let value: i32 = 5; - let _: i32 = ((value % 4) + 4) % 4; - let _: i32 = (4 + (value % 4)) % 4; - let _: i32 = (value % 4 + 4) % 4; - let _: i32 = (4 + value % 4) % 4; - let _: i32 = 1 + (4 + value % 4) % 4; + let _: i32 = ((value % 4) + 4) % 4; //~ manual_rem_euclid + let _: i32 = (4 + (value % 4)) % 4; //~ manual_rem_euclid + let _: i32 = (value % 4 + 4) % 4; //~ manual_rem_euclid + let _: i32 = (4 + value % 4) % 4; //~ manual_rem_euclid + let _: i32 = 1 + (4 + value % 4) % 4; //~ manual_rem_euclid let _: i32 = (3 + value % 4) % 4; let _: i32 = (-4 + value % -4) % -4; @@ -34,7 +34,7 @@ fn main() { // Lint in internal macros inline!( let value: i32 = 5; - let _: i32 = ((value % 4) + 4) % 4; + let _: i32 = ((value % 4) + 4) % 4; //~ manual_rem_euclid ); // Do not lint in external macros @@ -46,12 +46,12 @@ fn main() { // Should lint for params too pub fn rem_euclid_4(num: i32) -> i32 { - ((num % 4) + 4) % 4 + ((num % 4) + 4) % 4 //~ manual_rem_euclid } // Constant version came later, should still lint pub const fn const_rem_euclid_4(num: i32) -> i32 { - ((num % 4) + 4) % 4 + ((num % 4) + 4) % 4 //~ manual_rem_euclid } #[clippy::msrv = "1.37"] @@ -63,7 +63,7 @@ pub fn msrv_1_37() { #[clippy::msrv = "1.38"] pub fn msrv_1_38() { let x: i32 = 10; - let _: i32 = ((x % 4) + 4) % 4; + let _: i32 = ((x % 4) + 4) % 4; //~ manual_rem_euclid } // For const fns: @@ -76,5 +76,5 @@ pub const fn msrv_1_51() { #[clippy::msrv = "1.52"] pub const fn msrv_1_52() { let x: i32 = 10; - let _: i32 = ((x % 4) + 4) % 4; + let _: i32 = ((x % 4) + 4) % 4; //~ manual_rem_euclid } diff --git a/tests/ui/manual_retain.fixed b/tests/ui/manual_retain.fixed index 5540029bf6b1..f05dd5558074 100644 --- a/tests/ui/manual_retain.fixed +++ b/tests/ui/manual_retain.fixed @@ -23,13 +23,18 @@ fn binary_heap_retain() { let mut binary_heap = BinaryHeap::from([1, 2, 3]); // Do lint. binary_heap.retain(|x| x % 2 == 0); + //~^ manual_retain binary_heap.retain(|x| x % 2 == 0); + //~^ manual_retain binary_heap.retain(|x| x % 2 == 0); + //~^ manual_retain // Do lint, because we use pattern matching let mut tuples = BinaryHeap::from([(0, 1), (1, 2), (2, 3)]); tuples.retain(|(ref x, ref y)| *x == 0); + //~^ manual_retain tuples.retain(|(x, y)| *x == 0); + //~^ manual_retain // Do not lint, because type conversion is performed binary_heap = binary_heap @@ -60,7 +65,11 @@ fn btree_map_retain() { let mut btree_map: BTreeMap = (0..8).map(|x| (x, x * 10)).collect(); // Do lint. btree_map.retain(|k, _| k % 2 == 0); + //~^ manual_retain btree_map.retain(|_, &mut v| v % 2 == 0); + //~^ manual_retain + + //~v manual_retain btree_map.retain(|k, &mut v| (k % 2 == 0) && (v % 2 == 0)); // Do not lint, because the parameters are not matched in tuple pattern @@ -84,13 +93,18 @@ fn btree_set_retain() { // Do lint. btree_set.retain(|x| x % 2 == 0); + //~^ manual_retain btree_set.retain(|x| x % 2 == 0); + //~^ manual_retain btree_set.retain(|x| x % 2 == 0); + //~^ manual_retain // Do lint, because we use pattern matching let mut tuples = BTreeSet::from([(0, 1), (1, 2), (2, 3)]); tuples.retain(|(ref x, ref y)| *x == 0); + //~^ manual_retain tuples.retain(|(x, y)| *x == 0); + //~^ manual_retain // Do not lint, because type conversion is performed btree_set = btree_set @@ -121,7 +135,11 @@ fn hash_map_retain() { let mut hash_map: HashMap = (0..8).map(|x| (x, x * 10)).collect(); // Do lint. hash_map.retain(|k, _| k % 2 == 0); + //~^ manual_retain hash_map.retain(|_, &mut v| v % 2 == 0); + //~^ manual_retain + + //~v manual_retain hash_map.retain(|k, &mut v| (k % 2 == 0) && (v % 2 == 0)); // Do not lint, because the parameters are not matched in tuple pattern @@ -144,13 +162,18 @@ fn hash_set_retain() { let mut hash_set = HashSet::from([1, 2, 3, 4, 5, 6]); // Do lint. hash_set.retain(|x| x % 2 == 0); + //~^ manual_retain hash_set.retain(|x| x % 2 == 0); + //~^ manual_retain hash_set.retain(|x| x % 2 == 0); + //~^ manual_retain // Do lint, because we use pattern matching let mut tuples = HashSet::from([(0, 1), (1, 2), (2, 3)]); tuples.retain(|(ref x, ref y)| *x == 0); + //~^ manual_retain tuples.retain(|(x, y)| *x == 0); + //~^ manual_retain // Do not lint, because type conversion is performed hash_set = hash_set.into_iter().filter(|x| x % 2 == 0).collect::>(); @@ -180,6 +203,7 @@ fn string_retain() { let mut s = String::from("foobar"); // Do lint. s.retain(|c| c != 'o'); + //~^ manual_retain // Do not lint, because this expression is not assign. let mut bar: String = s.chars().filter(|&c| c != 'o').to_owned().collect(); @@ -192,13 +216,18 @@ fn vec_retain() { let mut vec = vec![0, 1, 2]; // Do lint. vec.retain(|x| x % 2 == 0); + //~^ manual_retain vec.retain(|x| x % 2 == 0); + //~^ manual_retain vec.retain(|x| x % 2 == 0); + //~^ manual_retain // Do lint, because we use pattern matching let mut tuples = vec![(0, 1), (1, 2), (2, 3)]; tuples.retain(|(ref x, ref y)| *x == 0); + //~^ manual_retain tuples.retain(|(x, y)| *x == 0); + //~^ manual_retain // Do not lint, because type conversion is performed vec = vec.into_iter().filter(|x| x % 2 == 0).collect::>(); @@ -221,8 +250,11 @@ fn vec_deque_retain() { // Do lint. vec_deque.retain(|x| x % 2 == 0); + //~^ manual_retain vec_deque.retain(|x| x % 2 == 0); + //~^ manual_retain vec_deque.retain(|x| x % 2 == 0); + //~^ manual_retain // Do not lint, because type conversion is performed vec_deque = vec_deque @@ -280,10 +312,12 @@ fn issue_10393() { // Do lint let mut vec = vec![(0, 1), (1, 2), (2, 3)]; vec.retain(|(x, y)| *x == 0); + //~^ manual_retain // Do lint let mut tuples = vec![(true, -2), (false, 3)]; tuples.retain(|(_, n)| *n > 0); + //~^ manual_retain } fn issue_11457() { @@ -301,11 +335,17 @@ fn issue_12081() { // Do lint vec.retain(|&x| x == 0); + //~^ manual_retain vec.retain(|&x| x == 0); + //~^ manual_retain vec.retain(|&x| x == 0); + //~^ manual_retain // Do lint vec.retain(|x| *x == 0); + //~^ manual_retain vec.retain(|x| *x == 0); + //~^ manual_retain vec.retain(|x| *x == 0); + //~^ manual_retain } diff --git a/tests/ui/manual_retain.rs b/tests/ui/manual_retain.rs index cee641d9d65f..17d9c196c601 100644 --- a/tests/ui/manual_retain.rs +++ b/tests/ui/manual_retain.rs @@ -23,13 +23,18 @@ fn binary_heap_retain() { let mut binary_heap = BinaryHeap::from([1, 2, 3]); // Do lint. binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); + //~^ manual_retain binary_heap = binary_heap.iter().filter(|&x| x % 2 == 0).copied().collect(); + //~^ manual_retain binary_heap = binary_heap.iter().filter(|&x| x % 2 == 0).cloned().collect(); + //~^ manual_retain // Do lint, because we use pattern matching let mut tuples = BinaryHeap::from([(0, 1), (1, 2), (2, 3)]); tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); + //~^ manual_retain tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); + //~^ manual_retain // Do not lint, because type conversion is performed binary_heap = binary_heap @@ -60,7 +65,11 @@ fn btree_map_retain() { let mut btree_map: BTreeMap = (0..8).map(|x| (x, x * 10)).collect(); // Do lint. btree_map = btree_map.into_iter().filter(|(k, _)| k % 2 == 0).collect(); + //~^ manual_retain btree_map = btree_map.into_iter().filter(|(_, v)| v % 2 == 0).collect(); + //~^ manual_retain + + //~v manual_retain btree_map = btree_map .into_iter() .filter(|(k, v)| (k % 2 == 0) && (v % 2 == 0)) @@ -87,13 +96,18 @@ fn btree_set_retain() { // Do lint. btree_set = btree_set.iter().filter(|&x| x % 2 == 0).copied().collect(); + //~^ manual_retain btree_set = btree_set.iter().filter(|&x| x % 2 == 0).cloned().collect(); + //~^ manual_retain btree_set = btree_set.into_iter().filter(|x| x % 2 == 0).collect(); + //~^ manual_retain // Do lint, because we use pattern matching let mut tuples = BTreeSet::from([(0, 1), (1, 2), (2, 3)]); tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); + //~^ manual_retain tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); + //~^ manual_retain // Do not lint, because type conversion is performed btree_set = btree_set @@ -124,7 +138,11 @@ fn hash_map_retain() { let mut hash_map: HashMap = (0..8).map(|x| (x, x * 10)).collect(); // Do lint. hash_map = hash_map.into_iter().filter(|(k, _)| k % 2 == 0).collect(); + //~^ manual_retain hash_map = hash_map.into_iter().filter(|(_, v)| v % 2 == 0).collect(); + //~^ manual_retain + + //~v manual_retain hash_map = hash_map .into_iter() .filter(|(k, v)| (k % 2 == 0) && (v % 2 == 0)) @@ -150,13 +168,18 @@ fn hash_set_retain() { let mut hash_set = HashSet::from([1, 2, 3, 4, 5, 6]); // Do lint. hash_set = hash_set.into_iter().filter(|x| x % 2 == 0).collect(); + //~^ manual_retain hash_set = hash_set.iter().filter(|&x| x % 2 == 0).copied().collect(); + //~^ manual_retain hash_set = hash_set.iter().filter(|&x| x % 2 == 0).cloned().collect(); + //~^ manual_retain // Do lint, because we use pattern matching let mut tuples = HashSet::from([(0, 1), (1, 2), (2, 3)]); tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); + //~^ manual_retain tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); + //~^ manual_retain // Do not lint, because type conversion is performed hash_set = hash_set.into_iter().filter(|x| x % 2 == 0).collect::>(); @@ -186,6 +209,7 @@ fn string_retain() { let mut s = String::from("foobar"); // Do lint. s = s.chars().filter(|&c| c != 'o').to_owned().collect(); + //~^ manual_retain // Do not lint, because this expression is not assign. let mut bar: String = s.chars().filter(|&c| c != 'o').to_owned().collect(); @@ -198,13 +222,18 @@ fn vec_retain() { let mut vec = vec![0, 1, 2]; // Do lint. vec = vec.iter().filter(|&x| x % 2 == 0).copied().collect(); + //~^ manual_retain vec = vec.iter().filter(|&x| x % 2 == 0).cloned().collect(); + //~^ manual_retain vec = vec.into_iter().filter(|x| x % 2 == 0).collect(); + //~^ manual_retain // Do lint, because we use pattern matching let mut tuples = vec![(0, 1), (1, 2), (2, 3)]; tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); + //~^ manual_retain tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); + //~^ manual_retain // Do not lint, because type conversion is performed vec = vec.into_iter().filter(|x| x % 2 == 0).collect::>(); @@ -227,8 +256,11 @@ fn vec_deque_retain() { // Do lint. vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).copied().collect(); + //~^ manual_retain vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).cloned().collect(); + //~^ manual_retain vec_deque = vec_deque.into_iter().filter(|x| x % 2 == 0).collect(); + //~^ manual_retain // Do not lint, because type conversion is performed vec_deque = vec_deque @@ -286,10 +318,12 @@ fn issue_10393() { // Do lint let mut vec = vec![(0, 1), (1, 2), (2, 3)]; vec = vec.into_iter().filter(|(x, y)| *x == 0).collect(); + //~^ manual_retain // Do lint let mut tuples = vec![(true, -2), (false, 3)]; tuples = tuples.into_iter().filter(|(_, n)| *n > 0).collect(); + //~^ manual_retain } fn issue_11457() { @@ -307,11 +341,17 @@ fn issue_12081() { // Do lint vec = vec.iter().filter(|&&x| x == 0).copied().collect(); + //~^ manual_retain vec = vec.iter().filter(|&&x| x == 0).cloned().collect(); + //~^ manual_retain vec = vec.into_iter().filter(|&x| x == 0).collect(); + //~^ manual_retain // Do lint vec = vec.iter().filter(|&x| *x == 0).copied().collect(); + //~^ manual_retain vec = vec.iter().filter(|&x| *x == 0).cloned().collect(); + //~^ manual_retain vec = vec.into_iter().filter(|x| *x == 0).collect(); + //~^ manual_retain } diff --git a/tests/ui/manual_retain.stderr b/tests/ui/manual_retain.stderr index 2c872f3b430e..2c347313489c 100644 --- a/tests/ui/manual_retain.stderr +++ b/tests/ui/manual_retain.stderr @@ -8,43 +8,43 @@ LL | binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); = help: to override `-D warnings` add `#[allow(clippy::manual_retain)]` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:26:5 + --> $DIR/manual_retain.rs:27:5 | LL | binary_heap = binary_heap.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `binary_heap.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:27:5 + --> $DIR/manual_retain.rs:29:5 | LL | binary_heap = binary_heap.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `binary_heap.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:31:5 + --> $DIR/manual_retain.rs:34:5 | LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:32:5 + --> $DIR/manual_retain.rs:36:5 | LL | tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(x, y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:62:5 + --> $DIR/manual_retain.rs:67:5 | LL | btree_map = btree_map.into_iter().filter(|(k, _)| k % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_map.retain(|k, _| k % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:63:5 + --> $DIR/manual_retain.rs:69:5 | LL | btree_map = btree_map.into_iter().filter(|(_, v)| v % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_map.retain(|_, &mut v| v % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:64:5 + --> $DIR/manual_retain.rs:73:5 | LL | / btree_map = btree_map LL | | .into_iter() @@ -53,49 +53,49 @@ LL | | .collect(); | |__________________^ help: consider calling `.retain()` instead: `btree_map.retain(|k, &mut v| (k % 2 == 0) && (v % 2 == 0))` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:89:5 + --> $DIR/manual_retain.rs:98:5 | LL | btree_set = btree_set.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:90:5 + --> $DIR/manual_retain.rs:100:5 | LL | btree_set = btree_set.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:91:5 + --> $DIR/manual_retain.rs:102:5 | LL | btree_set = btree_set.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:95:5 + --> $DIR/manual_retain.rs:107:5 | LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:96:5 + --> $DIR/manual_retain.rs:109:5 | LL | tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(x, y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:126:5 + --> $DIR/manual_retain.rs:140:5 | LL | hash_map = hash_map.into_iter().filter(|(k, _)| k % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_map.retain(|k, _| k % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:127:5 + --> $DIR/manual_retain.rs:142:5 | LL | hash_map = hash_map.into_iter().filter(|(_, v)| v % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_map.retain(|_, &mut v| v % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:128:5 + --> $DIR/manual_retain.rs:146:5 | LL | / hash_map = hash_map LL | | .into_iter() @@ -104,133 +104,133 @@ LL | | .collect(); | |__________________^ help: consider calling `.retain()` instead: `hash_map.retain(|k, &mut v| (k % 2 == 0) && (v % 2 == 0))` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:152:5 + --> $DIR/manual_retain.rs:170:5 | LL | hash_set = hash_set.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:153:5 + --> $DIR/manual_retain.rs:172:5 | LL | hash_set = hash_set.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:154:5 + --> $DIR/manual_retain.rs:174:5 | LL | hash_set = hash_set.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:158:5 + --> $DIR/manual_retain.rs:179:5 | LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:159:5 + --> $DIR/manual_retain.rs:181:5 | LL | tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(x, y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:188:5 + --> $DIR/manual_retain.rs:211:5 | LL | s = s.chars().filter(|&c| c != 'o').to_owned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `s.retain(|c| c != 'o')` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:200:5 + --> $DIR/manual_retain.rs:224:5 | LL | vec = vec.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:201:5 + --> $DIR/manual_retain.rs:226:5 | LL | vec = vec.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:202:5 + --> $DIR/manual_retain.rs:228:5 | LL | vec = vec.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:206:5 + --> $DIR/manual_retain.rs:233:5 | LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:207:5 + --> $DIR/manual_retain.rs:235:5 | LL | tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(x, y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:229:5 + --> $DIR/manual_retain.rs:258:5 | LL | vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:230:5 + --> $DIR/manual_retain.rs:260:5 | LL | vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:231:5 + --> $DIR/manual_retain.rs:262:5 | LL | vec_deque = vec_deque.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:288:5 + --> $DIR/manual_retain.rs:320:5 | LL | vec = vec.into_iter().filter(|(x, y)| *x == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|(x, y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:292:5 + --> $DIR/manual_retain.rs:325:5 | LL | tuples = tuples.into_iter().filter(|(_, n)| *n > 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(_, n)| *n > 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:309:5 + --> $DIR/manual_retain.rs:343:5 | LL | vec = vec.iter().filter(|&&x| x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|&x| x == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:310:5 + --> $DIR/manual_retain.rs:345:5 | LL | vec = vec.iter().filter(|&&x| x == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|&x| x == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:311:5 + --> $DIR/manual_retain.rs:347:5 | LL | vec = vec.into_iter().filter(|&x| x == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|&x| x == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:314:5 + --> $DIR/manual_retain.rs:351:5 | LL | vec = vec.iter().filter(|&x| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| *x == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:315:5 + --> $DIR/manual_retain.rs:353:5 | LL | vec = vec.iter().filter(|&x| *x == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| *x == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:316:5 + --> $DIR/manual_retain.rs:355:5 | LL | vec = vec.into_iter().filter(|x| *x == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| *x == 0)` diff --git a/tests/ui/manual_saturating_arithmetic.fixed b/tests/ui/manual_saturating_arithmetic.fixed index 8218f10881a7..162847b42e75 100644 --- a/tests/ui/manual_saturating_arithmetic.fixed +++ b/tests/ui/manual_saturating_arithmetic.fixed @@ -4,38 +4,67 @@ use std::{i128, i32, u128, u32}; fn main() { let _ = 1u32.saturating_add(1); + //~^ manual_saturating_arithmetic let _ = 1u32.saturating_add(1); + //~^ manual_saturating_arithmetic let _ = 1u8.saturating_add(1); + //~^ manual_saturating_arithmetic + + //~v manual_saturating_arithmetic let _ = 1u128.saturating_add(1); let _ = 1u32.checked_add(1).unwrap_or(1234); // ok let _ = 1u8.checked_add(1).unwrap_or(0); // ok let _ = 1u32.saturating_mul(1); + //~^ manual_saturating_arithmetic let _ = 1u32.saturating_sub(1); + //~^ manual_saturating_arithmetic let _ = 1u32.saturating_sub(1); + //~^ manual_saturating_arithmetic let _ = 1u8.saturating_sub(1); + //~^ manual_saturating_arithmetic let _ = 1u32.checked_sub(1).unwrap_or(1234); // ok let _ = 1u8.checked_sub(1).unwrap_or(255); // ok let _ = 1i32.saturating_add(1); + //~^ manual_saturating_arithmetic let _ = 1i32.saturating_add(1); + //~^ manual_saturating_arithmetic let _ = 1i8.saturating_add(1); + //~^ manual_saturating_arithmetic + + //~v manual_saturating_arithmetic let _ = 1i128.saturating_add(1); let _ = 1i32.saturating_add(-1); + //~^ manual_saturating_arithmetic let _ = 1i32.saturating_add(-1); + //~^ manual_saturating_arithmetic let _ = 1i8.saturating_add(-1); + //~^ manual_saturating_arithmetic + + //~v manual_saturating_arithmetic let _ = 1i128.saturating_add(-1); let _ = 1i32.checked_add(1).unwrap_or(1234); // ok let _ = 1i8.checked_add(1).unwrap_or(-128); // ok let _ = 1i8.checked_add(-1).unwrap_or(127); // ok let _ = 1i32.saturating_sub(1); + //~^ manual_saturating_arithmetic let _ = 1i32.saturating_sub(1); + //~^ manual_saturating_arithmetic let _ = 1i8.saturating_sub(1); + //~^ manual_saturating_arithmetic + + //~v manual_saturating_arithmetic let _ = 1i128.saturating_sub(1); let _ = 1i32.saturating_sub(-1); + //~^ manual_saturating_arithmetic let _ = 1i32.saturating_sub(-1); + //~^ manual_saturating_arithmetic let _ = 1i8.saturating_sub(-1); + //~^ manual_saturating_arithmetic + + //~v manual_saturating_arithmetic let _ = 1i128.saturating_sub(-1); let _ = 1i32.checked_sub(1).unwrap_or(1234); // ok let _ = 1i8.checked_sub(1).unwrap_or(127); // ok diff --git a/tests/ui/manual_saturating_arithmetic.rs b/tests/ui/manual_saturating_arithmetic.rs index 60022b54b02d..e848c7e1ed27 100644 --- a/tests/ui/manual_saturating_arithmetic.rs +++ b/tests/ui/manual_saturating_arithmetic.rs @@ -4,30 +4,49 @@ use std::{i128, i32, u128, u32}; fn main() { let _ = 1u32.checked_add(1).unwrap_or(u32::max_value()); + //~^ manual_saturating_arithmetic let _ = 1u32.checked_add(1).unwrap_or(u32::MAX); + //~^ manual_saturating_arithmetic let _ = 1u8.checked_add(1).unwrap_or(255); + //~^ manual_saturating_arithmetic + + //~v manual_saturating_arithmetic let _ = 1u128 .checked_add(1) .unwrap_or(340_282_366_920_938_463_463_374_607_431_768_211_455); let _ = 1u32.checked_add(1).unwrap_or(1234); // ok let _ = 1u8.checked_add(1).unwrap_or(0); // ok let _ = 1u32.checked_mul(1).unwrap_or(u32::MAX); + //~^ manual_saturating_arithmetic let _ = 1u32.checked_sub(1).unwrap_or(u32::min_value()); + //~^ manual_saturating_arithmetic let _ = 1u32.checked_sub(1).unwrap_or(u32::MIN); + //~^ manual_saturating_arithmetic let _ = 1u8.checked_sub(1).unwrap_or(0); + //~^ manual_saturating_arithmetic let _ = 1u32.checked_sub(1).unwrap_or(1234); // ok let _ = 1u8.checked_sub(1).unwrap_or(255); // ok let _ = 1i32.checked_add(1).unwrap_or(i32::max_value()); + //~^ manual_saturating_arithmetic let _ = 1i32.checked_add(1).unwrap_or(i32::MAX); + //~^ manual_saturating_arithmetic let _ = 1i8.checked_add(1).unwrap_or(127); + //~^ manual_saturating_arithmetic + + //~v manual_saturating_arithmetic let _ = 1i128 .checked_add(1) .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727); let _ = 1i32.checked_add(-1).unwrap_or(i32::min_value()); + //~^ manual_saturating_arithmetic let _ = 1i32.checked_add(-1).unwrap_or(i32::MIN); + //~^ manual_saturating_arithmetic let _ = 1i8.checked_add(-1).unwrap_or(-128); + //~^ manual_saturating_arithmetic + + //~v manual_saturating_arithmetic let _ = 1i128 .checked_add(-1) .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); @@ -36,14 +55,24 @@ fn main() { let _ = 1i8.checked_add(-1).unwrap_or(127); // ok let _ = 1i32.checked_sub(1).unwrap_or(i32::min_value()); + //~^ manual_saturating_arithmetic let _ = 1i32.checked_sub(1).unwrap_or(i32::MIN); + //~^ manual_saturating_arithmetic let _ = 1i8.checked_sub(1).unwrap_or(-128); + //~^ manual_saturating_arithmetic + + //~v manual_saturating_arithmetic let _ = 1i128 .checked_sub(1) .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); let _ = 1i32.checked_sub(-1).unwrap_or(i32::max_value()); + //~^ manual_saturating_arithmetic let _ = 1i32.checked_sub(-1).unwrap_or(i32::MAX); + //~^ manual_saturating_arithmetic let _ = 1i8.checked_sub(-1).unwrap_or(127); + //~^ manual_saturating_arithmetic + + //~v manual_saturating_arithmetic let _ = 1i128 .checked_sub(-1) .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727); diff --git a/tests/ui/manual_saturating_arithmetic.stderr b/tests/ui/manual_saturating_arithmetic.stderr index 3ce108b1ca81..7bd70e5437e7 100644 --- a/tests/ui/manual_saturating_arithmetic.stderr +++ b/tests/ui/manual_saturating_arithmetic.stderr @@ -8,19 +8,19 @@ LL | let _ = 1u32.checked_add(1).unwrap_or(u32::max_value()); = help: to override `-D warnings` add `#[allow(clippy::manual_saturating_arithmetic)]` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:7:13 + --> $DIR/manual_saturating_arithmetic.rs:8:13 | LL | let _ = 1u32.checked_add(1).unwrap_or(u32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1u32.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:8:13 + --> $DIR/manual_saturating_arithmetic.rs:10:13 | LL | let _ = 1u8.checked_add(1).unwrap_or(255); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1u8.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:9:13 + --> $DIR/manual_saturating_arithmetic.rs:14:13 | LL | let _ = 1u128 | _____________^ @@ -29,49 +29,49 @@ LL | | .unwrap_or(340_282_366_920_938_463_463_374_607_431_768_211_455); | |_______________________________________________________________________^ help: consider using `saturating_add`: `1u128.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:14:13 + --> $DIR/manual_saturating_arithmetic.rs:19:13 | LL | let _ = 1u32.checked_mul(1).unwrap_or(u32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_mul`: `1u32.saturating_mul(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:16:13 + --> $DIR/manual_saturating_arithmetic.rs:22:13 | LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::min_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1u32.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:17:13 + --> $DIR/manual_saturating_arithmetic.rs:24:13 | LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1u32.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:18:13 + --> $DIR/manual_saturating_arithmetic.rs:26:13 | LL | let _ = 1u8.checked_sub(1).unwrap_or(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1u8.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:22:13 + --> $DIR/manual_saturating_arithmetic.rs:31:13 | LL | let _ = 1i32.checked_add(1).unwrap_or(i32::max_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:23:13 + --> $DIR/manual_saturating_arithmetic.rs:33:13 | LL | let _ = 1i32.checked_add(1).unwrap_or(i32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:24:13 + --> $DIR/manual_saturating_arithmetic.rs:35:13 | LL | let _ = 1i8.checked_add(1).unwrap_or(127); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i8.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:25:13 + --> $DIR/manual_saturating_arithmetic.rs:39:13 | LL | let _ = 1i128 | _____________^ @@ -80,25 +80,25 @@ LL | | .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727); | |_______________________________________________________________________^ help: consider using `saturating_add`: `1i128.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:28:13 + --> $DIR/manual_saturating_arithmetic.rs:42:13 | LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::min_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:29:13 + --> $DIR/manual_saturating_arithmetic.rs:44:13 | LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:30:13 + --> $DIR/manual_saturating_arithmetic.rs:46:13 | LL | let _ = 1i8.checked_add(-1).unwrap_or(-128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i8.saturating_add(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:31:13 + --> $DIR/manual_saturating_arithmetic.rs:50:13 | LL | let _ = 1i128 | _____________^ @@ -107,25 +107,25 @@ LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); | |________________________________________________________________________^ help: consider using `saturating_add`: `1i128.saturating_add(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:38:13 + --> $DIR/manual_saturating_arithmetic.rs:57:13 | LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::min_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:39:13 + --> $DIR/manual_saturating_arithmetic.rs:59:13 | LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:40:13 + --> $DIR/manual_saturating_arithmetic.rs:61:13 | LL | let _ = 1i8.checked_sub(1).unwrap_or(-128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i8.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:41:13 + --> $DIR/manual_saturating_arithmetic.rs:65:13 | LL | let _ = 1i128 | _____________^ @@ -134,25 +134,25 @@ LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); | |________________________________________________________________________^ help: consider using `saturating_sub`: `1i128.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:44:13 + --> $DIR/manual_saturating_arithmetic.rs:68:13 | LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::max_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:45:13 + --> $DIR/manual_saturating_arithmetic.rs:70:13 | LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:46:13 + --> $DIR/manual_saturating_arithmetic.rs:72:13 | LL | let _ = 1i8.checked_sub(-1).unwrap_or(127); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i8.saturating_sub(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:47:13 + --> $DIR/manual_saturating_arithmetic.rs:76:13 | LL | let _ = 1i128 | _____________^ diff --git a/tests/ui/manual_slice_size_calculation.fixed b/tests/ui/manual_slice_size_calculation.fixed index 62b372f4b8d9..7fab0ecb56fa 100644 --- a/tests/ui/manual_slice_size_calculation.fixed +++ b/tests/ui/manual_slice_size_calculation.fixed @@ -12,17 +12,28 @@ fn main() { let s_i32 = v_i32.as_slice(); // True positives: + //~v manual_slice_size_calculation let _ = std::mem::size_of_val(s_i32); // WARNING + + //~v manual_slice_size_calculation let _ = std::mem::size_of_val(s_i32); // WARNING + + //~v manual_slice_size_calculation let _ = std::mem::size_of_val(s_i32) * 5; // WARNING let len = s_i32.len(); let size = size_of::(); + //~v manual_slice_size_calculation let _ = std::mem::size_of_val(s_i32); // WARNING + + //~v manual_slice_size_calculation let _ = std::mem::size_of_val(s_i32); // WARNING + + //~v manual_slice_size_calculation let _ = std::mem::size_of_val(s_i32); // WARNING let _ = std::mem::size_of_val(external!(&[1u64][..])); + //~^ manual_slice_size_calculation // True negatives: let _ = size_of::() + s_i32.len(); // Ok, not a multiplication diff --git a/tests/ui/manual_slice_size_calculation.rs b/tests/ui/manual_slice_size_calculation.rs index d59f5fd8b942..62f97a4062e3 100644 --- a/tests/ui/manual_slice_size_calculation.rs +++ b/tests/ui/manual_slice_size_calculation.rs @@ -12,17 +12,28 @@ fn main() { let s_i32 = v_i32.as_slice(); // True positives: + //~v manual_slice_size_calculation let _ = s_i32.len() * size_of::(); // WARNING + + //~v manual_slice_size_calculation let _ = size_of::() * s_i32.len(); // WARNING + + //~v manual_slice_size_calculation let _ = size_of::() * s_i32.len() * 5; // WARNING let len = s_i32.len(); let size = size_of::(); + //~v manual_slice_size_calculation let _ = len * size_of::(); // WARNING + + //~v manual_slice_size_calculation let _ = s_i32.len() * size; // WARNING + + //~v manual_slice_size_calculation let _ = len * size; // WARNING let _ = external!(&[1u64][..]).len() * size_of::(); + //~^ manual_slice_size_calculation // True negatives: let _ = size_of::() + s_i32.len(); // Ok, not a multiplication diff --git a/tests/ui/manual_slice_size_calculation.stderr b/tests/ui/manual_slice_size_calculation.stderr index ebdb748137a9..c1ff8ae8454a 100644 --- a/tests/ui/manual_slice_size_calculation.stderr +++ b/tests/ui/manual_slice_size_calculation.stderr @@ -1,5 +1,5 @@ error: manual slice size calculation - --> $DIR/manual_slice_size_calculation.rs:15:13 + --> $DIR/manual_slice_size_calculation.rs:16:13 | LL | let _ = s_i32.len() * size_of::(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` @@ -8,37 +8,37 @@ LL | let _ = s_i32.len() * size_of::(); // WARNING = help: to override `-D warnings` add `#[allow(clippy::manual_slice_size_calculation)]` error: manual slice size calculation - --> $DIR/manual_slice_size_calculation.rs:16:13 + --> $DIR/manual_slice_size_calculation.rs:19:13 | LL | let _ = size_of::() * s_i32.len(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> $DIR/manual_slice_size_calculation.rs:17:13 + --> $DIR/manual_slice_size_calculation.rs:22:13 | LL | let _ = size_of::() * s_i32.len() * 5; // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> $DIR/manual_slice_size_calculation.rs:21:13 + --> $DIR/manual_slice_size_calculation.rs:27:13 | LL | let _ = len * size_of::(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> $DIR/manual_slice_size_calculation.rs:22:13 + --> $DIR/manual_slice_size_calculation.rs:30:13 | LL | let _ = s_i32.len() * size; // WARNING | ^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> $DIR/manual_slice_size_calculation.rs:23:13 + --> $DIR/manual_slice_size_calculation.rs:33:13 | LL | let _ = len * size; // WARNING | ^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> $DIR/manual_slice_size_calculation.rs:25:13 + --> $DIR/manual_slice_size_calculation.rs:35:13 | LL | let _ = external!(&[1u64][..]).len() * size_of::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(external!(&[1u64][..]))` diff --git a/tests/ui/manual_split_once.fixed b/tests/ui/manual_split_once.fixed index aaac6a048e1d..100489c8e190 100644 --- a/tests/ui/manual_split_once.fixed +++ b/tests/ui/manual_split_once.fixed @@ -9,23 +9,29 @@ use itertools::Itertools; fn main() { let _ = "key=value".splitn(2, '=').nth(2); let _ = "key=value".split_once('=').unwrap().1; + //~^ manual_split_once let _ = "key=value".split_once('=').unwrap().1; + //~^ manual_split_once let (_, _) = "key=value".split_once('=').unwrap(); + //~^ manual_split_once let s = String::from("key=value"); - let _ = s.split_once('=').unwrap().1; + let _ = s.split_once('=').unwrap().1; //~ manual_split_once let s = Box::::from("key=value"); - let _ = s.split_once('=').unwrap().1; + let _ = s.split_once('=').unwrap().1; //~ manual_split_once let s = &"key=value"; let _ = s.split_once('=').unwrap().1; + //~^ manual_split_once fn _f(s: &str) -> Option<&str> { + let _ = s.split_once('=')?.1; //~ manual_split_once let _ = s.split_once('=')?.1; - let _ = s.split_once('=')?.1; - let _ = s.rsplit_once('=')?.0; + //~^ manual_split_once + let _ = s.rsplit_once('=')?.0; //~ manual_split_once let _ = s.rsplit_once('=')?.0; + //~^ manual_split_once None } @@ -34,24 +40,26 @@ fn main() { // `rsplitn` gives the results in the reverse order of `rsplit_once` let _ = "key=value".rsplit_once('=').unwrap().0; + //~^ manual_split_once let (_, _) = "key=value".rsplit_once('=').map(|(x, y)| (y, x)).unwrap(); - let _ = s.rsplit_once('=').map(|x| x.0); + //~^ manual_split_once + let _ = s.rsplit_once('=').map(|x| x.0); //~ manual_split_once } fn indirect() -> Option<()> { - let (l, r) = "a.b.c".split_once('.').unwrap(); + let (l, r) = "a.b.c".split_once('.').unwrap(); //~ manual_split_once - let (l, r) = "a.b.c".split_once('.')?; + let (l, r) = "a.b.c".split_once('.')?; //~ manual_split_once - let (l, r) = "a.b.c".rsplit_once('.').unwrap(); + let (l, r) = "a.b.c".rsplit_once('.').unwrap(); //~ manual_split_once - let (l, r) = "a.b.c".rsplit_once('.')?; + let (l, r) = "a.b.c".rsplit_once('.')?; //~ manual_split_once @@ -137,8 +145,9 @@ fn _msrv_1_51() { #[clippy::msrv = "1.52"] fn _msrv_1_52() { let _ = "key=value".split_once('=').unwrap().1; + //~^ manual_split_once - let (a, b) = "a.b.c".split_once('.').unwrap(); + let (a, b) = "a.b.c".split_once('.').unwrap(); //~ manual_split_once } diff --git a/tests/ui/manual_split_once.rs b/tests/ui/manual_split_once.rs index 113e1737c97d..f708e9fb278a 100644 --- a/tests/ui/manual_split_once.rs +++ b/tests/ui/manual_split_once.rs @@ -9,23 +9,29 @@ use itertools::Itertools; fn main() { let _ = "key=value".splitn(2, '=').nth(2); let _ = "key=value".splitn(2, '=').nth(1).unwrap(); + //~^ manual_split_once let _ = "key=value".splitn(2, '=').skip(1).next().unwrap(); + //~^ manual_split_once let (_, _) = "key=value".splitn(2, '=').next_tuple().unwrap(); + //~^ manual_split_once let s = String::from("key=value"); - let _ = s.splitn(2, '=').nth(1).unwrap(); + let _ = s.splitn(2, '=').nth(1).unwrap(); //~ manual_split_once let s = Box::::from("key=value"); - let _ = s.splitn(2, '=').nth(1).unwrap(); + let _ = s.splitn(2, '=').nth(1).unwrap(); //~ manual_split_once let s = &"key=value"; let _ = s.splitn(2, '=').skip(1).next().unwrap(); + //~^ manual_split_once fn _f(s: &str) -> Option<&str> { - let _ = s.splitn(2, '=').nth(1)?; + let _ = s.splitn(2, '=').nth(1)?; //~ manual_split_once let _ = s.splitn(2, '=').skip(1).next()?; - let _ = s.rsplitn(2, '=').nth(1)?; + //~^ manual_split_once + let _ = s.rsplitn(2, '=').nth(1)?; //~ manual_split_once let _ = s.rsplitn(2, '=').skip(1).next()?; + //~^ manual_split_once None } @@ -34,24 +40,26 @@ fn main() { // `rsplitn` gives the results in the reverse order of `rsplit_once` let _ = "key=value".rsplitn(2, '=').nth(1).unwrap(); + //~^ manual_split_once let (_, _) = "key=value".rsplitn(2, '=').next_tuple().unwrap(); - let _ = s.rsplitn(2, '=').nth(1); + //~^ manual_split_once + let _ = s.rsplitn(2, '=').nth(1); //~ manual_split_once } fn indirect() -> Option<()> { - let mut iter = "a.b.c".splitn(2, '.'); + let mut iter = "a.b.c".splitn(2, '.'); //~ manual_split_once let l = iter.next().unwrap(); let r = iter.next().unwrap(); - let mut iter = "a.b.c".splitn(2, '.'); + let mut iter = "a.b.c".splitn(2, '.'); //~ manual_split_once let l = iter.next()?; let r = iter.next()?; - let mut iter = "a.b.c".rsplitn(2, '.'); + let mut iter = "a.b.c".rsplitn(2, '.'); //~ manual_split_once let r = iter.next().unwrap(); let l = iter.next().unwrap(); - let mut iter = "a.b.c".rsplitn(2, '.'); + let mut iter = "a.b.c".rsplitn(2, '.'); //~ manual_split_once let r = iter.next()?; let l = iter.next()?; @@ -137,8 +145,9 @@ fn _msrv_1_51() { #[clippy::msrv = "1.52"] fn _msrv_1_52() { let _ = "key=value".splitn(2, '=').nth(1).unwrap(); + //~^ manual_split_once - let mut iter = "a.b.c".splitn(2, '.'); + let mut iter = "a.b.c".splitn(2, '.'); //~ manual_split_once let a = iter.next().unwrap(); let b = iter.next().unwrap(); } diff --git a/tests/ui/manual_split_once.stderr b/tests/ui/manual_split_once.stderr index 494a035edc3a..d0d7c7a7b131 100644 --- a/tests/ui/manual_split_once.stderr +++ b/tests/ui/manual_split_once.stderr @@ -8,79 +8,79 @@ LL | let _ = "key=value".splitn(2, '=').nth(1).unwrap(); = help: to override `-D warnings` add `#[allow(clippy::manual_split_once)]` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:12:13 + --> $DIR/manual_split_once.rs:13:13 | LL | let _ = "key=value".splitn(2, '=').skip(1).next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split_once('=').unwrap().1` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:13:18 + --> $DIR/manual_split_once.rs:15:18 | LL | let (_, _) = "key=value".splitn(2, '=').next_tuple().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split_once('=')` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:16:13 + --> $DIR/manual_split_once.rs:19:13 | LL | let _ = s.splitn(2, '=').nth(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=').unwrap().1` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:19:13 + --> $DIR/manual_split_once.rs:22:13 | LL | let _ = s.splitn(2, '=').nth(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=').unwrap().1` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:22:13 + --> $DIR/manual_split_once.rs:25:13 | LL | let _ = s.splitn(2, '=').skip(1).next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=').unwrap().1` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:25:17 + --> $DIR/manual_split_once.rs:29:17 | LL | let _ = s.splitn(2, '=').nth(1)?; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=')?.1` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:26:17 + --> $DIR/manual_split_once.rs:30:17 | LL | let _ = s.splitn(2, '=').skip(1).next()?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=')?.1` error: manual implementation of `rsplit_once` - --> $DIR/manual_split_once.rs:27:17 + --> $DIR/manual_split_once.rs:32:17 | LL | let _ = s.rsplitn(2, '=').nth(1)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.rsplit_once('=')?.0` error: manual implementation of `rsplit_once` - --> $DIR/manual_split_once.rs:28:17 + --> $DIR/manual_split_once.rs:33:17 | LL | let _ = s.rsplitn(2, '=').skip(1).next()?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.rsplit_once('=')?.0` error: manual implementation of `rsplit_once` - --> $DIR/manual_split_once.rs:36:13 + --> $DIR/manual_split_once.rs:42:13 | LL | let _ = "key=value".rsplitn(2, '=').nth(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".rsplit_once('=').unwrap().0` error: manual implementation of `rsplit_once` - --> $DIR/manual_split_once.rs:37:18 + --> $DIR/manual_split_once.rs:44:18 | LL | let (_, _) = "key=value".rsplitn(2, '=').next_tuple().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".rsplit_once('=').map(|(x, y)| (y, x))` error: manual implementation of `rsplit_once` - --> $DIR/manual_split_once.rs:38:13 + --> $DIR/manual_split_once.rs:46:13 | LL | let _ = s.rsplitn(2, '=').nth(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.rsplit_once('=').map(|x| x.0)` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:42:5 + --> $DIR/manual_split_once.rs:50:5 | LL | let mut iter = "a.b.c".splitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -92,7 +92,7 @@ LL | let r = iter.next().unwrap(); help: try `split_once` | LL | let (l, r) = "a.b.c".split_once('.').unwrap(); - | + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ help: remove the `iter` usages | LL - let l = iter.next().unwrap(); @@ -105,7 +105,7 @@ LL + | error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:46:5 + --> $DIR/manual_split_once.rs:54:5 | LL | let mut iter = "a.b.c".splitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -117,7 +117,7 @@ LL | let r = iter.next()?; help: try `split_once` | LL | let (l, r) = "a.b.c".split_once('.')?; - | + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ help: remove the `iter` usages | LL - let l = iter.next()?; @@ -130,7 +130,7 @@ LL + | error: manual implementation of `rsplit_once` - --> $DIR/manual_split_once.rs:50:5 + --> $DIR/manual_split_once.rs:58:5 | LL | let mut iter = "a.b.c".rsplitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -142,7 +142,7 @@ LL | let l = iter.next().unwrap(); help: try `rsplit_once` | LL | let (l, r) = "a.b.c".rsplit_once('.').unwrap(); - | + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ help: remove the `iter` usages | LL - let r = iter.next().unwrap(); @@ -155,7 +155,7 @@ LL + | error: manual implementation of `rsplit_once` - --> $DIR/manual_split_once.rs:54:5 + --> $DIR/manual_split_once.rs:62:5 | LL | let mut iter = "a.b.c".rsplitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -167,7 +167,7 @@ LL | let l = iter.next()?; help: try `rsplit_once` | LL | let (l, r) = "a.b.c".rsplit_once('.')?; - | + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ help: remove the `iter` usages | LL - let r = iter.next()?; @@ -180,13 +180,13 @@ LL + | error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:139:13 + --> $DIR/manual_split_once.rs:147:13 | LL | let _ = "key=value".splitn(2, '=').nth(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split_once('=').unwrap().1` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:141:5 + --> $DIR/manual_split_once.rs:150:5 | LL | let mut iter = "a.b.c".splitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -198,7 +198,7 @@ LL | let b = iter.next().unwrap(); help: try `split_once` | LL | let (a, b) = "a.b.c".split_once('.').unwrap(); - | + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ help: remove the `iter` usages | LL - let a = iter.next().unwrap(); diff --git a/tests/ui/manual_str_repeat.fixed b/tests/ui/manual_str_repeat.fixed index 888a466278cc..1a2b324897b5 100644 --- a/tests/ui/manual_str_repeat.fixed +++ b/tests/ui/manual_str_repeat.fixed @@ -5,13 +5,18 @@ use std::iter::repeat; fn main() { let _: String = "test".repeat(10); + //~^ manual_str_repeat let _: String = "x".repeat(10); + //~^ manual_str_repeat let _: String = "'".repeat(10); + //~^ manual_str_repeat let _: String = "\"".repeat(10); + //~^ manual_str_repeat let x = "test"; let count = 10; let _ = x.repeat(count + 2); + //~^ manual_str_repeat macro_rules! m { ($e:expr) => {{ $e }}; @@ -21,6 +26,7 @@ fn main() { let x = &x; let _: String = (*x).repeat(count); + //~^ manual_str_repeat macro_rules! repeat_m { ($e:expr) => {{ repeat($e) }}; @@ -30,6 +36,7 @@ fn main() { let x: Box = Box::from("test"); let _: String = x.repeat(count); + //~^ manual_str_repeat #[derive(Clone)] struct S; @@ -42,9 +49,11 @@ fn main() { let _: String = repeat(Box::new(S)).take(count).collect(); let _: String = Cow::Borrowed("test").repeat(count); + //~^ manual_str_repeat let x = "x".to_owned(); let _: String = x.repeat(count); + //~^ manual_str_repeat let x = 'x'; // Don't lint, not char literal @@ -60,4 +69,5 @@ fn _msrv_1_15() { #[clippy::msrv = "1.16"] fn _msrv_1_16() { let _: String = "test".repeat(10); + //~^ manual_str_repeat } diff --git a/tests/ui/manual_str_repeat.rs b/tests/ui/manual_str_repeat.rs index a366351ffa45..ea1707fce27b 100644 --- a/tests/ui/manual_str_repeat.rs +++ b/tests/ui/manual_str_repeat.rs @@ -5,13 +5,18 @@ use std::iter::repeat; fn main() { let _: String = std::iter::repeat("test").take(10).collect(); + //~^ manual_str_repeat let _: String = std::iter::repeat('x').take(10).collect(); + //~^ manual_str_repeat let _: String = std::iter::repeat('\'').take(10).collect(); + //~^ manual_str_repeat let _: String = std::iter::repeat('"').take(10).collect(); + //~^ manual_str_repeat let x = "test"; let count = 10; let _ = repeat(x).take(count + 2).collect::(); + //~^ manual_str_repeat macro_rules! m { ($e:expr) => {{ $e }}; @@ -21,6 +26,7 @@ fn main() { let x = &x; let _: String = repeat(*x).take(count).collect(); + //~^ manual_str_repeat macro_rules! repeat_m { ($e:expr) => {{ repeat($e) }}; @@ -30,6 +36,7 @@ fn main() { let x: Box = Box::from("test"); let _: String = repeat(x).take(count).collect(); + //~^ manual_str_repeat #[derive(Clone)] struct S; @@ -42,9 +49,11 @@ fn main() { let _: String = repeat(Box::new(S)).take(count).collect(); let _: String = repeat(Cow::Borrowed("test")).take(count).collect(); + //~^ manual_str_repeat let x = "x".to_owned(); let _: String = repeat(x).take(count).collect(); + //~^ manual_str_repeat let x = 'x'; // Don't lint, not char literal @@ -60,4 +69,5 @@ fn _msrv_1_15() { #[clippy::msrv = "1.16"] fn _msrv_1_16() { let _: String = std::iter::repeat("test").take(10).collect(); + //~^ manual_str_repeat } diff --git a/tests/ui/manual_str_repeat.stderr b/tests/ui/manual_str_repeat.stderr index 9a13aa972273..6aed5938e4bb 100644 --- a/tests/ui/manual_str_repeat.stderr +++ b/tests/ui/manual_str_repeat.stderr @@ -8,55 +8,55 @@ LL | let _: String = std::iter::repeat("test").take(10).collect(); = help: to override `-D warnings` add `#[allow(clippy::manual_str_repeat)]` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:8:21 + --> $DIR/manual_str_repeat.rs:9:21 | LL | let _: String = std::iter::repeat('x').take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"x".repeat(10)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:9:21 + --> $DIR/manual_str_repeat.rs:11:21 | LL | let _: String = std::iter::repeat('\'').take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"'".repeat(10)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:10:21 + --> $DIR/manual_str_repeat.rs:13:21 | LL | let _: String = std::iter::repeat('"').take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"\"".repeat(10)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:14:13 + --> $DIR/manual_str_repeat.rs:18:13 | LL | let _ = repeat(x).take(count + 2).collect::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count + 2)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:23:21 + --> $DIR/manual_str_repeat.rs:28:21 | LL | let _: String = repeat(*x).take(count).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(*x).repeat(count)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:32:21 + --> $DIR/manual_str_repeat.rs:38:21 | LL | let _: String = repeat(x).take(count).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:44:21 + --> $DIR/manual_str_repeat.rs:51:21 | LL | let _: String = repeat(Cow::Borrowed("test")).take(count).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Cow::Borrowed("test").repeat(count)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:47:21 + --> $DIR/manual_str_repeat.rs:55:21 | LL | let _: String = repeat(x).take(count).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:62:21 + --> $DIR/manual_str_repeat.rs:71:21 | LL | let _: String = std::iter::repeat("test").take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"test".repeat(10)` diff --git a/tests/ui/manual_string_new.fixed b/tests/ui/manual_string_new.fixed index 2d4c5a029153..c87114ac67f1 100644 --- a/tests/ui/manual_string_new.fixed +++ b/tests/ui/manual_string_new.fixed @@ -11,40 +11,42 @@ macro_rules! create_strings_from_macro { fn main() { // Method calls - let _ = String::new(); + let _ = String::new(); //~ manual_string_new let _ = "no warning".to_string(); - let _ = String::new(); + let _ = String::new(); //~ manual_string_new let _ = "no warning".to_owned(); - let _: String = String::new(); + let _: String = String::new(); //~ manual_string_new let _: String = "no warning".into(); let _: SomeOtherStruct = "no warning".into(); let _: SomeOtherStruct = "".into(); // No warning too. We are not converting into String. // Calls - let _ = String::new(); - let _ = String::new(); + let _ = String::new(); //~ manual_string_new + let _ = String::new(); //~ manual_string_new let _ = String::from("no warning"); let _ = SomeOtherStruct::from("no warning"); let _ = SomeOtherStruct::from(""); // Again: no warning. - let _ = String::new(); + let _ = String::new(); //~ manual_string_new let _ = String::try_from("no warning").unwrap(); let _ = String::try_from("no warning").expect("this should not warn"); let _ = SomeOtherStruct::try_from("no warning").unwrap(); let _ = SomeOtherStruct::try_from("").unwrap(); // Again: no warning. - let _: String = String::new(); + let _: String = String::new(); //~ manual_string_new let _: String = From::from("no warning"); let _: SomeOtherStruct = From::from("no warning"); let _: SomeOtherStruct = From::from(""); // Again: no warning. let _: String = String::new(); + //~^ manual_string_new let _: String = TryFrom::try_from("no warning").unwrap(); let _: String = TryFrom::try_from("no warning").expect("this should not warn"); let _: String = String::new(); + //~^ manual_string_new let _: SomeOtherStruct = TryFrom::try_from("no_warning").unwrap(); let _: SomeOtherStruct = TryFrom::try_from("").unwrap(); // Again: no warning. diff --git a/tests/ui/manual_string_new.rs b/tests/ui/manual_string_new.rs index 20f0be6aaf97..092f6823ad5a 100644 --- a/tests/ui/manual_string_new.rs +++ b/tests/ui/manual_string_new.rs @@ -11,40 +11,42 @@ macro_rules! create_strings_from_macro { fn main() { // Method calls - let _ = "".to_string(); + let _ = "".to_string(); //~ manual_string_new let _ = "no warning".to_string(); - let _ = "".to_owned(); + let _ = "".to_owned(); //~ manual_string_new let _ = "no warning".to_owned(); - let _: String = "".into(); + let _: String = "".into(); //~ manual_string_new let _: String = "no warning".into(); let _: SomeOtherStruct = "no warning".into(); let _: SomeOtherStruct = "".into(); // No warning too. We are not converting into String. // Calls - let _ = String::from(""); - let _ = ::from(""); + let _ = String::from(""); //~ manual_string_new + let _ = ::from(""); //~ manual_string_new let _ = String::from("no warning"); let _ = SomeOtherStruct::from("no warning"); let _ = SomeOtherStruct::from(""); // Again: no warning. - let _ = String::try_from("").unwrap(); + let _ = String::try_from("").unwrap(); //~ manual_string_new let _ = String::try_from("no warning").unwrap(); let _ = String::try_from("no warning").expect("this should not warn"); let _ = SomeOtherStruct::try_from("no warning").unwrap(); let _ = SomeOtherStruct::try_from("").unwrap(); // Again: no warning. - let _: String = From::from(""); + let _: String = From::from(""); //~ manual_string_new let _: String = From::from("no warning"); let _: SomeOtherStruct = From::from("no warning"); let _: SomeOtherStruct = From::from(""); // Again: no warning. let _: String = TryFrom::try_from("").unwrap(); + //~^ manual_string_new let _: String = TryFrom::try_from("no warning").unwrap(); let _: String = TryFrom::try_from("no warning").expect("this should not warn"); let _: String = TryFrom::try_from("").expect("this should warn"); + //~^ manual_string_new let _: SomeOtherStruct = TryFrom::try_from("no_warning").unwrap(); let _: SomeOtherStruct = TryFrom::try_from("").unwrap(); // Again: no warning. diff --git a/tests/ui/manual_string_new.stderr b/tests/ui/manual_string_new.stderr index cb2d78c39ed1..27a4ba7f4ff0 100644 --- a/tests/ui/manual_string_new.stderr +++ b/tests/ui/manual_string_new.stderr @@ -50,7 +50,7 @@ LL | let _: String = TryFrom::try_from("").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_string_new.rs:47:21 + --> $DIR/manual_string_new.rs:48:21 | LL | let _: String = TryFrom::try_from("").expect("this should warn"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::new()` diff --git a/tests/ui/manual_try_fold.rs b/tests/ui/manual_try_fold.rs index 7299d7cf9862..c91ea41bb84c 100644 --- a/tests/ui/manual_try_fold.rs +++ b/tests/ui/manual_try_fold.rs @@ -57,13 +57,16 @@ fn main() { [1, 2, 3] .iter() .fold(Some(0i32), |sum, i| sum?.checked_add(*i)) + //~^ manual_try_fold .unwrap(); [1, 2, 3] .iter() .fold(NotOption(0i32, 0i32), |sum, i| NotOption(0i32, 0i32)); + //~^ manual_try_fold [1, 2, 3] .iter() .fold(NotOptionButWorse(0i32), |sum, i| NotOptionButWorse(0i32)); + //~^ manual_try_fold // Do not lint [1, 2, 3].iter().try_fold(0i32, |sum, i| sum.checked_add(*i)).unwrap(); [1, 2, 3].iter().fold(0i32, |sum, i| sum + i); @@ -94,6 +97,7 @@ fn msrv_juust_right() { [1, 2, 3] .iter() .fold(Some(0i32), |sum, i| sum?.checked_add(*i)) + //~^ manual_try_fold .unwrap(); } diff --git a/tests/ui/manual_try_fold.stderr b/tests/ui/manual_try_fold.stderr index 4eb3e302b214..e12148eb6fcf 100644 --- a/tests/ui/manual_try_fold.stderr +++ b/tests/ui/manual_try_fold.stderr @@ -8,19 +8,19 @@ LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*i)) = help: to override `-D warnings` add `#[allow(clippy::manual_try_fold)]` error: usage of `Iterator::fold` on a type that implements `Try` - --> $DIR/manual_try_fold.rs:63:10 + --> $DIR/manual_try_fold.rs:64:10 | LL | .fold(NotOption(0i32, 0i32), |sum, i| NotOption(0i32, 0i32)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(..., |sum, i| ...)` error: usage of `Iterator::fold` on a type that implements `Try` - --> $DIR/manual_try_fold.rs:66:10 + --> $DIR/manual_try_fold.rs:68:10 | LL | .fold(NotOptionButWorse(0i32), |sum, i| NotOptionButWorse(0i32)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(0i32, |sum, i| ...)` error: usage of `Iterator::fold` on a type that implements `Try` - --> $DIR/manual_try_fold.rs:96:10 + --> $DIR/manual_try_fold.rs:99:10 | LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*i)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(0i32, |sum, i| ...)` diff --git a/tests/ui/manual_unwrap_or.fixed b/tests/ui/manual_unwrap_or.fixed index 737d4c90dca4..9339f11a25dc 100644 --- a/tests/ui/manual_unwrap_or.fixed +++ b/tests/ui/manual_unwrap_or.fixed @@ -3,16 +3,20 @@ fn option_unwrap_or() { // int case + //~v manual_unwrap_or Some(1).unwrap_or(42); // int case reversed + //~v manual_unwrap_or Some(1).unwrap_or(42); // richer none expr + //~v manual_unwrap_or Some(1).unwrap_or(1 + 42); // multiline case #[rustfmt::skip] + //~v manual_unwrap_or Some(1).unwrap_or({ 42 + 42 + 42 + 42 + 42 @@ -20,6 +24,7 @@ fn option_unwrap_or() { }); // string case + //~v manual_unwrap_or Some("Bob").unwrap_or("Alice"); // don't lint @@ -67,13 +72,16 @@ fn option_unwrap_or() { fn result_unwrap_or() { // int case + //~v manual_unwrap_or Ok::(1).unwrap_or(42); // int case, scrutinee is a binding let a = Ok::(1); + //~v manual_unwrap_or a.unwrap_or(42); // int case, suggestion must surround Result expr with parentheses + //~v manual_unwrap_or (Ok(1) as Result).unwrap_or(42); // method call case, suggestion must not surround Result expr `s.method()` with parentheses @@ -84,16 +92,20 @@ fn result_unwrap_or() { } } let s = S {}; + //~v manual_unwrap_or s.method().unwrap_or(42); // int case reversed + //~v manual_unwrap_or Ok::(1).unwrap_or(42); // richer none expr + //~v manual_unwrap_or Ok::(1).unwrap_or(1 + 42); // multiline case #[rustfmt::skip] + //~v manual_unwrap_or Ok::(1).unwrap_or({ 42 + 42 + 42 + 42 + 42 @@ -101,6 +113,7 @@ fn result_unwrap_or() { }); // string case + //~v manual_unwrap_or Ok::<&str, &str>("Bob").unwrap_or("Alice"); // don't lint @@ -158,6 +171,7 @@ mod issue6965 { } fn test() { + //~v manual_unwrap_or let _ = some_macro!().unwrap_or(0); } } diff --git a/tests/ui/manual_unwrap_or.rs b/tests/ui/manual_unwrap_or.rs index f59fb87529f8..9e41449a2e2a 100644 --- a/tests/ui/manual_unwrap_or.rs +++ b/tests/ui/manual_unwrap_or.rs @@ -3,18 +3,21 @@ fn option_unwrap_or() { // int case + //~v manual_unwrap_or match Some(1) { Some(i) => i, None => 42, }; // int case reversed + //~v manual_unwrap_or match Some(1) { None => 42, Some(i) => i, }; // richer none expr + //~v manual_unwrap_or match Some(1) { Some(i) => i, None => 1 + 42, @@ -22,6 +25,7 @@ fn option_unwrap_or() { // multiline case #[rustfmt::skip] + //~v manual_unwrap_or match Some(1) { Some(i) => i, None => { @@ -32,6 +36,7 @@ fn option_unwrap_or() { }; // string case + //~v manual_unwrap_or match Some("Bob") { Some(i) => i, None => "Alice", @@ -82,6 +87,7 @@ fn option_unwrap_or() { fn result_unwrap_or() { // int case + //~v manual_unwrap_or match Ok::(1) { Ok(i) => i, Err(_) => 42, @@ -89,12 +95,14 @@ fn result_unwrap_or() { // int case, scrutinee is a binding let a = Ok::(1); + //~v manual_unwrap_or match a { Ok(i) => i, Err(_) => 42, }; // int case, suggestion must surround Result expr with parentheses + //~v manual_unwrap_or match Ok(1) as Result { Ok(i) => i, Err(_) => 42, @@ -108,18 +116,21 @@ fn result_unwrap_or() { } } let s = S {}; + //~v manual_unwrap_or match s.method() { Some(i) => i, None => 42, }; // int case reversed + //~v manual_unwrap_or match Ok::(1) { Err(_) => 42, Ok(i) => i, }; // richer none expr + //~v manual_unwrap_or match Ok::(1) { Ok(i) => i, Err(_) => 1 + 42, @@ -127,6 +138,7 @@ fn result_unwrap_or() { // multiline case #[rustfmt::skip] + //~v manual_unwrap_or match Ok::(1) { Ok(i) => i, Err(_) => { @@ -137,6 +149,7 @@ fn result_unwrap_or() { }; // string case + //~v manual_unwrap_or match Ok::<&str, &str>("Bob") { Ok(i) => i, Err(_) => "Alice", @@ -197,6 +210,7 @@ mod issue6965 { } fn test() { + //~v manual_unwrap_or let _ = match some_macro!() { Some(val) => val, None => 0, diff --git a/tests/ui/manual_unwrap_or.stderr b/tests/ui/manual_unwrap_or.stderr index 3a0759dccaf2..a90b5a5ede2f 100644 --- a/tests/ui/manual_unwrap_or.stderr +++ b/tests/ui/manual_unwrap_or.stderr @@ -1,5 +1,5 @@ error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:6:5 + --> $DIR/manual_unwrap_or.rs:7:5 | LL | / match Some(1) { LL | | Some(i) => i, @@ -11,7 +11,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::manual_unwrap_or)]` error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:12:5 + --> $DIR/manual_unwrap_or.rs:14:5 | LL | / match Some(1) { LL | | None => 42, @@ -20,7 +20,7 @@ LL | | }; | |_____^ help: replace with: `Some(1).unwrap_or(42)` error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:18:5 + --> $DIR/manual_unwrap_or.rs:21:5 | LL | / match Some(1) { LL | | Some(i) => i, @@ -29,7 +29,7 @@ LL | | }; | |_____^ help: replace with: `Some(1).unwrap_or(1 + 42)` error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:25:5 + --> $DIR/manual_unwrap_or.rs:29:5 | LL | / match Some(1) { LL | | Some(i) => i, @@ -50,7 +50,7 @@ LL ~ }); | error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:35:5 + --> $DIR/manual_unwrap_or.rs:40:5 | LL | / match Some("Bob") { LL | | Some(i) => i, @@ -59,7 +59,7 @@ LL | | }; | |_____^ help: replace with: `Some("Bob").unwrap_or("Alice")` error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:85:5 + --> $DIR/manual_unwrap_or.rs:91:5 | LL | / match Ok::(1) { LL | | Ok(i) => i, @@ -68,7 +68,7 @@ LL | | }; | |_____^ help: replace with: `Ok::(1).unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:92:5 + --> $DIR/manual_unwrap_or.rs:99:5 | LL | / match a { LL | | Ok(i) => i, @@ -77,7 +77,7 @@ LL | | }; | |_____^ help: replace with: `a.unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:98:5 + --> $DIR/manual_unwrap_or.rs:106:5 | LL | / match Ok(1) as Result { LL | | Ok(i) => i, @@ -86,7 +86,7 @@ LL | | }; | |_____^ help: replace with: `(Ok(1) as Result).unwrap_or(42)` error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:111:5 + --> $DIR/manual_unwrap_or.rs:120:5 | LL | / match s.method() { LL | | Some(i) => i, @@ -95,7 +95,7 @@ LL | | }; | |_____^ help: replace with: `s.method().unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:117:5 + --> $DIR/manual_unwrap_or.rs:127:5 | LL | / match Ok::(1) { LL | | Err(_) => 42, @@ -104,7 +104,7 @@ LL | | }; | |_____^ help: replace with: `Ok::(1).unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:123:5 + --> $DIR/manual_unwrap_or.rs:134:5 | LL | / match Ok::(1) { LL | | Ok(i) => i, @@ -113,7 +113,7 @@ LL | | }; | |_____^ help: replace with: `Ok::(1).unwrap_or(1 + 42)` error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:130:5 + --> $DIR/manual_unwrap_or.rs:142:5 | LL | / match Ok::(1) { LL | | Ok(i) => i, @@ -134,7 +134,7 @@ LL ~ }); | error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:140:5 + --> $DIR/manual_unwrap_or.rs:153:5 | LL | / match Ok::<&str, &str>("Bob") { LL | | Ok(i) => i, @@ -143,7 +143,7 @@ LL | | }; | |_____^ help: replace with: `Ok::<&str, &str>("Bob").unwrap_or("Alice")` error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:200:17 + --> $DIR/manual_unwrap_or.rs:214:17 | LL | let _ = match some_macro!() { | _________________^ diff --git a/tests/ui/manual_while_let_some.fixed b/tests/ui/manual_while_let_some.fixed index c70d258dfe6e..c0f6522d5fb8 100644 --- a/tests/ui/manual_while_let_some.fixed +++ b/tests/ui/manual_while_let_some.fixed @@ -19,6 +19,7 @@ fn main() { let mut numbers = vec![1, 2, 3, 4, 5]; while let Some(number) = numbers.pop() { + //~^ manual_while_let_some } let mut val = VecInStruct { @@ -27,14 +28,17 @@ fn main() { }; while let Some(number) = val.numbers.pop() { + //~^ manual_while_let_some } while let Some(element) = numbers.pop() { accept_i32(element); + //~^ manual_while_let_some } while let Some(element) = numbers.pop() { accept_i32(element); + //~^ manual_while_let_some } // This should not warn. It "conditionally" pops elements. @@ -78,14 +82,17 @@ fn main() { let mut numbers = vec![(0, 0), (1, 1), (2, 2)]; while let Some((a, b)) = numbers.pop() { + //~^ manual_while_let_some } while let Some(element) = numbers.pop() { accept_i32_tuple(element); + //~^ manual_while_let_some } let mut results = vec![Foo { a: 1, b: 2 }, Foo { a: 3, b: 4 }]; while let Some(Foo { a, b }) = results.pop() { + //~^ manual_while_let_some } } diff --git a/tests/ui/manual_while_let_some.rs b/tests/ui/manual_while_let_some.rs index 415bb5798667..f69eb66af1d7 100644 --- a/tests/ui/manual_while_let_some.rs +++ b/tests/ui/manual_while_let_some.rs @@ -19,6 +19,7 @@ fn main() { let mut numbers = vec![1, 2, 3, 4, 5]; while !numbers.is_empty() { let number = numbers.pop().unwrap(); + //~^ manual_while_let_some } let mut val = VecInStruct { @@ -27,14 +28,17 @@ fn main() { }; while !val.numbers.is_empty() { let number = val.numbers.pop().unwrap(); + //~^ manual_while_let_some } while !numbers.is_empty() { accept_i32(numbers.pop().unwrap()); + //~^ manual_while_let_some } while !numbers.is_empty() { accept_i32(numbers.pop().expect("")); + //~^ manual_while_let_some } // This should not warn. It "conditionally" pops elements. @@ -78,14 +82,17 @@ fn main() { let mut numbers = vec![(0, 0), (1, 1), (2, 2)]; while !numbers.is_empty() { let (a, b) = numbers.pop().unwrap(); + //~^ manual_while_let_some } while !numbers.is_empty() { accept_i32_tuple(numbers.pop().unwrap()); + //~^ manual_while_let_some } let mut results = vec![Foo { a: 1, b: 2 }, Foo { a: 3, b: 4 }]; while !results.is_empty() { let Foo { a, b } = results.pop().unwrap(); + //~^ manual_while_let_some } } diff --git a/tests/ui/manual_while_let_some.stderr b/tests/ui/manual_while_let_some.stderr index 37387c8c320f..b3c01a04b9b0 100644 --- a/tests/ui/manual_while_let_some.stderr +++ b/tests/ui/manual_while_let_some.stderr @@ -13,7 +13,7 @@ LL ~ | error: you seem to be trying to pop elements from a `Vec` in a loop - --> $DIR/manual_while_let_some.rs:29:9 + --> $DIR/manual_while_let_some.rs:30:9 | LL | let number = val.numbers.pop().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL ~ | error: you seem to be trying to pop elements from a `Vec` in a loop - --> $DIR/manual_while_let_some.rs:33:20 + --> $DIR/manual_while_let_some.rs:35:20 | LL | accept_i32(numbers.pop().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL ~ accept_i32(element); | error: you seem to be trying to pop elements from a `Vec` in a loop - --> $DIR/manual_while_let_some.rs:37:20 + --> $DIR/manual_while_let_some.rs:40:20 | LL | accept_i32(numbers.pop().expect("")); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL ~ accept_i32(element); | error: you seem to be trying to pop elements from a `Vec` in a loop - --> $DIR/manual_while_let_some.rs:80:9 + --> $DIR/manual_while_let_some.rs:84:9 | LL | let (a, b) = numbers.pop().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL ~ | error: you seem to be trying to pop elements from a `Vec` in a loop - --> $DIR/manual_while_let_some.rs:84:26 + --> $DIR/manual_while_let_some.rs:89:26 | LL | accept_i32_tuple(numbers.pop().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL ~ accept_i32_tuple(element); | error: you seem to be trying to pop elements from a `Vec` in a loop - --> $DIR/manual_while_let_some.rs:89:9 + --> $DIR/manual_while_let_some.rs:95:9 | LL | let Foo { a, b } = results.pop().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/map_clone.fixed b/tests/ui/map_clone.fixed index 395eea69294d..a503a9737234 100644 --- a/tests/ui/map_clone.fixed +++ b/tests/ui/map_clone.fixed @@ -11,11 +11,14 @@ fn main() { let _: Vec = vec![5_i8; 6].iter().copied().collect(); + //~^ map_clone let _: Vec = vec![String::new()].iter().cloned().collect(); + //~^ map_clone let _: Vec = vec![42, 43].iter().copied().collect(); + //~^ map_clone let _: Option = Some(Box::new(16)).map(|b| *b); - let _: Option = Some(&16).copied(); - let _: Option = Some(&1).copied(); + let _: Option = Some(&16).copied(); //~ map_clone + let _: Option = Some(&1).copied(); //~ map_clone // Don't lint these let v = vec![5_i8; 6]; @@ -26,7 +29,7 @@ fn main() { let _ = v.iter().map(|&_x| a); // Issue #498 - let _ = std::env::args(); + let _ = std::env::args(); //~ map_clone // Issue #4824 item types that aren't references { diff --git a/tests/ui/map_clone.rs b/tests/ui/map_clone.rs index 82a103edf5a9..e60e7eb2dbed 100644 --- a/tests/ui/map_clone.rs +++ b/tests/ui/map_clone.rs @@ -11,11 +11,14 @@ fn main() { let _: Vec = vec![5_i8; 6].iter().map(|x| *x).collect(); + //~^ map_clone let _: Vec = vec![String::new()].iter().map(|x| x.clone()).collect(); + //~^ map_clone let _: Vec = vec![42, 43].iter().map(|&x| x).collect(); + //~^ map_clone let _: Option = Some(Box::new(16)).map(|b| *b); - let _: Option = Some(&16).map(|b| *b); - let _: Option = Some(&1).map(|x| x.clone()); + let _: Option = Some(&16).map(|b| *b); //~ map_clone + let _: Option = Some(&1).map(|x| x.clone()); //~ map_clone // Don't lint these let v = vec![5_i8; 6]; @@ -26,7 +29,7 @@ fn main() { let _ = v.iter().map(|&_x| a); // Issue #498 - let _ = std::env::args().map(|v| v.clone()); + let _ = std::env::args().map(|v| v.clone()); //~ map_clone // Issue #4824 item types that aren't references { diff --git a/tests/ui/map_clone.stderr b/tests/ui/map_clone.stderr index 2c86a67fab8d..7b1537a8574c 100644 --- a/tests/ui/map_clone.stderr +++ b/tests/ui/map_clone.stderr @@ -8,85 +8,85 @@ LL | let _: Vec = vec![5_i8; 6].iter().map(|x| *x).collect(); = help: to override `-D warnings` add `#[allow(clippy::map_clone)]` error: you are using an explicit closure for cloning elements - --> $DIR/map_clone.rs:14:26 + --> $DIR/map_clone.rs:15:26 | LL | let _: Vec = vec![String::new()].iter().map(|x| x.clone()).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `vec![String::new()].iter().cloned()` error: you are using an explicit closure for copying elements - --> $DIR/map_clone.rs:15:23 + --> $DIR/map_clone.rs:17:23 | LL | let _: Vec = vec![42, 43].iter().map(|&x| x).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `vec![42, 43].iter().copied()` error: you are using an explicit closure for copying elements - --> $DIR/map_clone.rs:17:26 + --> $DIR/map_clone.rs:20:26 | LL | let _: Option = Some(&16).map(|b| *b); | ^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `Some(&16).copied()` error: you are using an explicit closure for copying elements - --> $DIR/map_clone.rs:18:25 + --> $DIR/map_clone.rs:21:25 | LL | let _: Option = Some(&1).map(|x| x.clone()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `Some(&1).copied()` error: you are needlessly cloning iterator elements - --> $DIR/map_clone.rs:29:29 + --> $DIR/map_clone.rs:32:29 | LL | let _ = std::env::args().map(|v| v.clone()); | ^^^^^^^^^^^^^^^^^^^ help: remove the `map` call error: you are explicitly cloning with `.map()` - --> $DIR/map_clone.rs:68:13 + --> $DIR/map_clone.rs:71:13 | LL | let y = x.map(|x| String::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> $DIR/map_clone.rs:70:13 + --> $DIR/map_clone.rs:73:13 | LL | let y = x.map(Clone::clone); | ^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> $DIR/map_clone.rs:73:13 + --> $DIR/map_clone.rs:76:13 | LL | let y = x.map(String::clone); | ^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> $DIR/map_clone.rs:79:13 + --> $DIR/map_clone.rs:82:13 | LL | let y = x.map(|x| u32::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.copied()` error: you are explicitly cloning with `.map()` - --> $DIR/map_clone.rs:82:13 + --> $DIR/map_clone.rs:85:13 | LL | let y = x.map(|x| Clone::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.copied()` error: you are explicitly cloning with `.map()` - --> $DIR/map_clone.rs:94:13 + --> $DIR/map_clone.rs:97:13 | LL | let y = x.map(|x| String::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> $DIR/map_clone.rs:97:13 + --> $DIR/map_clone.rs:100:13 | LL | let y = x.map(|x| Clone::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> $DIR/map_clone.rs:103:13 + --> $DIR/map_clone.rs:106:13 | LL | let y = x.map(|x| u32::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.copied()` error: you are explicitly cloning with `.map()` - --> $DIR/map_clone.rs:106:13 + --> $DIR/map_clone.rs:109:13 | LL | let y = x.map(|x| Clone::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.copied()` diff --git a/tests/ui/map_collect_result_unit.fixed b/tests/ui/map_collect_result_unit.fixed index 374af105f889..26957e59f14a 100644 --- a/tests/ui/map_collect_result_unit.fixed +++ b/tests/ui/map_collect_result_unit.fixed @@ -3,7 +3,9 @@ fn main() { { let _ = (0..3).try_for_each(|t| Err(t + 1)); + //~^ map_collect_result_unit let _: Result<(), _> = (0..3).try_for_each(|t| Err(t + 1)); + //~^ map_collect_result_unit let _ = (0..3).try_for_each(|t| Err(t + 1)); } diff --git a/tests/ui/map_collect_result_unit.rs b/tests/ui/map_collect_result_unit.rs index 5c6fb23e2372..cdd73bfe6544 100644 --- a/tests/ui/map_collect_result_unit.rs +++ b/tests/ui/map_collect_result_unit.rs @@ -3,7 +3,9 @@ fn main() { { let _ = (0..3).map(|t| Err(t + 1)).collect::>(); + //~^ map_collect_result_unit let _: Result<(), _> = (0..3).map(|t| Err(t + 1)).collect(); + //~^ map_collect_result_unit let _ = (0..3).try_for_each(|t| Err(t + 1)); } diff --git a/tests/ui/map_collect_result_unit.stderr b/tests/ui/map_collect_result_unit.stderr index 1a505d4cecc3..21cdca535caa 100644 --- a/tests/ui/map_collect_result_unit.stderr +++ b/tests/ui/map_collect_result_unit.stderr @@ -8,7 +8,7 @@ LL | let _ = (0..3).map(|t| Err(t + 1)).collect::>(); = help: to override `-D warnings` add `#[allow(clippy::map_collect_result_unit)]` error: `.map().collect()` can be replaced with `.try_for_each()` - --> $DIR/map_collect_result_unit.rs:6:32 + --> $DIR/map_collect_result_unit.rs:7:32 | LL | let _: Result<(), _> = (0..3).map(|t| Err(t + 1)).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(0..3).try_for_each(|t| Err(t + 1))` diff --git a/tests/ui/map_flatten_fixable.fixed b/tests/ui/map_flatten_fixable.fixed index 1932f412d2ca..4951692d62eb 100644 --- a/tests/ui/map_flatten_fixable.fixed +++ b/tests/ui/map_flatten_fixable.fixed @@ -14,18 +14,25 @@ fn main() { let option_id_ref: fn(i8) -> Option = option_id; let option_id_closure = |x| Some(x); let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(option_id).collect(); + //~^ map_flatten let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(option_id_ref).collect(); + //~^ map_flatten let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(option_id_closure).collect(); + //~^ map_flatten let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(|x| x.checked_add(1)).collect(); + //~^ map_flatten // mapping to Iterator on Iterator let _: Vec<_> = vec![5_i8; 6].into_iter().flat_map(|x| 0..x).collect(); + //~^ map_flatten // mapping to Option on Option let _: Option<_> = (Some(Some(1))).and_then(|x| x); + //~^ map_flatten // mapping to Result on Result let _: Result<_, &str> = (Ok(Ok(1))).and_then(|x| x); + //~^ map_flatten issue8734(); issue8878(); @@ -34,6 +41,7 @@ fn main() { fn issue8734() { let _ = [0u8, 1, 2, 3] .into_iter() + //~v map_flatten .flat_map(|n| match n { 1 => [n .saturating_add(1) @@ -53,6 +61,7 @@ fn issue8734() { fn issue8878() { std::collections::HashMap::::new() .get(&0) + //~v map_flatten .and_then(|_| { // we need some newlines // so that the span is big enough diff --git a/tests/ui/map_flatten_fixable.rs b/tests/ui/map_flatten_fixable.rs index 093fd9b6cae2..e98db49cf786 100644 --- a/tests/ui/map_flatten_fixable.rs +++ b/tests/ui/map_flatten_fixable.rs @@ -14,18 +14,25 @@ fn main() { let option_id_ref: fn(i8) -> Option = option_id; let option_id_closure = |x| Some(x); let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().collect(); + //~^ map_flatten let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_ref).flatten().collect(); + //~^ map_flatten let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_closure).flatten().collect(); + //~^ map_flatten let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| x.checked_add(1)).flatten().collect(); + //~^ map_flatten // mapping to Iterator on Iterator let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect(); + //~^ map_flatten // mapping to Option on Option let _: Option<_> = (Some(Some(1))).map(|x| x).flatten(); + //~^ map_flatten // mapping to Result on Result let _: Result<_, &str> = (Ok(Ok(1))).map(|x| x).flatten(); + //~^ map_flatten issue8734(); issue8878(); @@ -34,6 +41,7 @@ fn main() { fn issue8734() { let _ = [0u8, 1, 2, 3] .into_iter() + //~v map_flatten .map(|n| match n { 1 => [n .saturating_add(1) @@ -54,6 +62,7 @@ fn issue8734() { fn issue8878() { std::collections::HashMap::::new() .get(&0) + //~v map_flatten .map(|_| { // we need some newlines // so that the span is big enough diff --git a/tests/ui/map_flatten_fixable.stderr b/tests/ui/map_flatten_fixable.stderr index e5387eead2e0..94e13cd104ba 100644 --- a/tests/ui/map_flatten_fixable.stderr +++ b/tests/ui/map_flatten_fixable.stderr @@ -8,43 +8,43 @@ LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().coll = help: to override `-D warnings` add `#[allow(clippy::map_flatten)]` error: called `map(..).flatten()` on `Iterator` - --> $DIR/map_flatten_fixable.rs:17:47 + --> $DIR/map_flatten_fixable.rs:18:47 | LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_ref).flatten().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(option_id_ref)` error: called `map(..).flatten()` on `Iterator` - --> $DIR/map_flatten_fixable.rs:18:47 + --> $DIR/map_flatten_fixable.rs:20:47 | LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_closure).flatten().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(option_id_closure)` error: called `map(..).flatten()` on `Iterator` - --> $DIR/map_flatten_fixable.rs:19:47 + --> $DIR/map_flatten_fixable.rs:22:47 | LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| x.checked_add(1)).flatten().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(|x| x.checked_add(1))` error: called `map(..).flatten()` on `Iterator` - --> $DIR/map_flatten_fixable.rs:22:47 + --> $DIR/map_flatten_fixable.rs:26:47 | LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `flat_map` and remove the `.flatten()`: `flat_map(|x| 0..x)` error: called `map(..).flatten()` on `Option` - --> $DIR/map_flatten_fixable.rs:25:40 + --> $DIR/map_flatten_fixable.rs:30:40 | LL | let _: Option<_> = (Some(Some(1))).map(|x| x).flatten(); | ^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `and_then` and remove the `.flatten()`: `and_then(|x| x)` error: called `map(..).flatten()` on `Result` - --> $DIR/map_flatten_fixable.rs:28:42 + --> $DIR/map_flatten_fixable.rs:34:42 | LL | let _: Result<_, &str> = (Ok(Ok(1))).map(|x| x).flatten(); | ^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `and_then` and remove the `.flatten()`: `and_then(|x| x)` error: called `map(..).flatten()` on `Iterator` - --> $DIR/map_flatten_fixable.rs:37:10 + --> $DIR/map_flatten_fixable.rs:45:10 | LL | .map(|n| match n { | __________^ @@ -73,7 +73,7 @@ LL ~ }); | error: called `map(..).flatten()` on `Option` - --> $DIR/map_flatten_fixable.rs:57:10 + --> $DIR/map_flatten_fixable.rs:66:10 | LL | .map(|_| { | __________^ diff --git a/tests/ui/map_identity.fixed b/tests/ui/map_identity.fixed index 53ebfb40ba0d..3bb466c91c5f 100644 --- a/tests/ui/map_identity.fixed +++ b/tests/ui/map_identity.fixed @@ -5,8 +5,13 @@ fn main() { let x: [u16; 3] = [1, 2, 3]; // should lint let _: Vec<_> = x.iter().map(not_identity).collect(); + //~^ map_identity let _: Vec<_> = x.iter().collect(); - let _: Option = Some(3); + //~^ map_identity + //~| map_identity + let _: Option = Some(3); //~ map_identity + + //~v map_identity let _: Result = Ok(-3); // should not lint let _: Vec<_> = x.iter().map(|x| 2 * x).collect(); @@ -15,7 +20,7 @@ fn main() { let _: Result = Err(2.3).map(|x: i8| { return x + 3; }); - let _: Result = Ok(1); + let _: Result = Ok(1); //~ map_identity let _: Result = Ok(1).map_err(|a: u32| a * 42); // : u32 guides type inference let _ = Ok(1).map_err(|a: u32| a); @@ -25,12 +30,15 @@ fn main() { fn issue7189() { // should lint let x = [(1, 2), (3, 4)].iter().copied(); + let _ = x.clone(); //~ map_identity + + //~v map_identity let _ = x.clone(); - let _ = x.clone(); - let _ = x.clone(); + let _ = x.clone(); //~ map_identity let y = [(1, 2, (3, (4,))), (5, 6, (7, (8,)))].iter().copied(); let _ = y.clone(); + //~^ map_identity // should not lint let _ = x.clone().map(|(x, y)| (x, y, y)); @@ -59,5 +67,5 @@ fn issue11764() { let _ = x.iter().map(|x| (x.0,)).map(|(x,)| x); // no match ergonomics for `(i32, i32)` - let _ = x.iter().copied(); + let _ = x.iter().copied(); //~ map_identity } diff --git a/tests/ui/map_identity.rs b/tests/ui/map_identity.rs index c646c0568595..b9a812bcca74 100644 --- a/tests/ui/map_identity.rs +++ b/tests/ui/map_identity.rs @@ -5,8 +5,13 @@ fn main() { let x: [u16; 3] = [1, 2, 3]; // should lint let _: Vec<_> = x.iter().map(not_identity).map(|x| return x).collect(); + //~^ map_identity let _: Vec<_> = x.iter().map(std::convert::identity).map(|y| y).collect(); - let _: Option = Some(3).map(|x| x); + //~^ map_identity + //~| map_identity + let _: Option = Some(3).map(|x| x); //~ map_identity + + //~v map_identity let _: Result = Ok(-3).map(|x| { return x; }); @@ -17,7 +22,7 @@ fn main() { let _: Result = Err(2.3).map(|x: i8| { return x + 3; }); - let _: Result = Ok(1).map_err(|a| a); + let _: Result = Ok(1).map_err(|a| a); //~ map_identity let _: Result = Ok(1).map_err(|a: u32| a * 42); // : u32 guides type inference let _ = Ok(1).map_err(|a: u32| a); @@ -27,14 +32,17 @@ fn main() { fn issue7189() { // should lint let x = [(1, 2), (3, 4)].iter().copied(); - let _ = x.clone().map(|(x, y)| (x, y)); + let _ = x.clone().map(|(x, y)| (x, y)); //~ map_identity + + //~v map_identity let _ = x.clone().map(|(x, y)| { return (x, y); }); - let _ = x.clone().map(|(x, y)| return (x, y)); + let _ = x.clone().map(|(x, y)| return (x, y)); //~ map_identity let y = [(1, 2, (3, (4,))), (5, 6, (7, (8,)))].iter().copied(); let _ = y.clone().map(|(x, y, (z, (w,)))| (x, y, (z, (w,)))); + //~^ map_identity // should not lint let _ = x.clone().map(|(x, y)| (x, y, y)); @@ -63,5 +71,5 @@ fn issue11764() { let _ = x.iter().map(|x| (x.0,)).map(|(x,)| x); // no match ergonomics for `(i32, i32)` - let _ = x.iter().copied().map(|(x, y)| (x, y)); + let _ = x.iter().copied().map(|(x, y)| (x, y)); //~ map_identity } diff --git a/tests/ui/map_identity.stderr b/tests/ui/map_identity.stderr index ea077d66d640..7c8fd7a1bbd7 100644 --- a/tests/ui/map_identity.stderr +++ b/tests/ui/map_identity.stderr @@ -8,25 +8,25 @@ LL | let _: Vec<_> = x.iter().map(not_identity).map(|x| return x).collect(); = help: to override `-D warnings` add `#[allow(clippy::map_identity)]` error: unnecessary map of the identity function - --> $DIR/map_identity.rs:8:57 + --> $DIR/map_identity.rs:9:57 | LL | let _: Vec<_> = x.iter().map(std::convert::identity).map(|y| y).collect(); | ^^^^^^^^^^^ help: remove the call to `map` error: unnecessary map of the identity function - --> $DIR/map_identity.rs:8:29 + --> $DIR/map_identity.rs:9:29 | LL | let _: Vec<_> = x.iter().map(std::convert::identity).map(|y| y).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map` error: unnecessary map of the identity function - --> $DIR/map_identity.rs:9:32 + --> $DIR/map_identity.rs:12:32 | LL | let _: Option = Some(3).map(|x| x); | ^^^^^^^^^^^ help: remove the call to `map` error: unnecessary map of the identity function - --> $DIR/map_identity.rs:10:36 + --> $DIR/map_identity.rs:15:36 | LL | let _: Result = Ok(-3).map(|x| { | ____________________________________^ @@ -35,19 +35,19 @@ LL | | }); | |______^ help: remove the call to `map` error: unnecessary map of the identity function - --> $DIR/map_identity.rs:20:36 + --> $DIR/map_identity.rs:25:36 | LL | let _: Result = Ok(1).map_err(|a| a); | ^^^^^^^^^^^^^^^ help: remove the call to `map_err` error: unnecessary map of the identity function - --> $DIR/map_identity.rs:30:22 + --> $DIR/map_identity.rs:35:22 | LL | let _ = x.clone().map(|(x, y)| (x, y)); | ^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map` error: unnecessary map of the identity function - --> $DIR/map_identity.rs:31:22 + --> $DIR/map_identity.rs:38:22 | LL | let _ = x.clone().map(|(x, y)| { | ______________________^ @@ -56,19 +56,19 @@ LL | | }); | |______^ help: remove the call to `map` error: unnecessary map of the identity function - --> $DIR/map_identity.rs:34:22 + --> $DIR/map_identity.rs:41:22 | LL | let _ = x.clone().map(|(x, y)| return (x, y)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map` error: unnecessary map of the identity function - --> $DIR/map_identity.rs:37:22 + --> $DIR/map_identity.rs:44:22 | LL | let _ = y.clone().map(|(x, y, (z, (w,)))| (x, y, (z, (w,)))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map` error: unnecessary map of the identity function - --> $DIR/map_identity.rs:66:30 + --> $DIR/map_identity.rs:74:30 | LL | let _ = x.iter().copied().map(|(x, y)| (x, y)); | ^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map` diff --git a/tests/ui/map_unwrap_or.rs b/tests/ui/map_unwrap_or.rs index dfaa8f24f987..f167822eaef1 100644 --- a/tests/ui/map_unwrap_or.rs +++ b/tests/ui/map_unwrap_or.rs @@ -14,25 +14,31 @@ fn option_methods() { // Check for `option.map(_).unwrap_or(_)` use. // Single line case. + //~v map_unwrap_or let _ = opt.map(|x| x + 1) // Should lint even though this call is on a separate line. .unwrap_or(0); // Multi-line cases. + //~v map_unwrap_or let _ = opt.map(|x| { x + 1 } ).unwrap_or(0); + //~v map_unwrap_or let _ = opt.map(|x| x + 1) .unwrap_or({ 0 }); // Single line `map(f).unwrap_or(None)` case. let _ = opt.map(|x| Some(x + 1)).unwrap_or(None); + //~^ map_unwrap_or // Multi-line `map(f).unwrap_or(None)` cases. + //~v map_unwrap_or let _ = opt.map(|x| { Some(x + 1) } ).unwrap_or(None); + //~v map_unwrap_or let _ = opt .map(|x| Some(x + 1)) .unwrap_or(None); @@ -45,20 +51,23 @@ fn option_methods() { // ...but DO lint if the `unwrap_or` argument is not used in the `map` let id: String = "identifier".to_string(); let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id); + //~^ map_unwrap_or // Check for `option.map(_).unwrap_or_else(_)` use. // Multi-line cases. + //~v map_unwrap_or let _ = opt.map(|x| { x + 1 } ).unwrap_or_else(|| 0); + //~v map_unwrap_or let _ = opt.map(|x| x + 1) .unwrap_or_else(|| 0 ); // Check for `map(f).unwrap_or(false)` use. - let _ = opt.map(|x| x > 5).unwrap_or(false); + let _ = opt.map(|x| x > 5).unwrap_or(false); //~ map_unwrap_or } @@ -68,10 +77,12 @@ fn result_methods() { // Check for `result.map(_).unwrap_or_else(_)` use. // multi line cases + //~v map_unwrap_or let _ = res.map(|x| { x + 1 } ).unwrap_or_else(|_e| 0); + //~v map_unwrap_or let _ = res.map(|x| x + 1) .unwrap_or_else(|_e| { 0 @@ -97,20 +108,21 @@ fn msrv_1_41() { let res: Result = Ok(1); let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0); + //~^ map_unwrap_or } #[clippy::msrv = "1.69"] fn msrv_1_69() { let opt: Option = Some(1); - let _ = opt.map(|x| x > 5).unwrap_or(false); + let _ = opt.map(|x| x > 5).unwrap_or(false); //~ map_unwrap_or } #[clippy::msrv = "1.70"] fn msrv_1_70() { let opt: Option = Some(1); - let _ = opt.map(|x| x > 5).unwrap_or(false); + let _ = opt.map(|x| x > 5).unwrap_or(false); //~ map_unwrap_or } mod issue_10579 { diff --git a/tests/ui/map_unwrap_or.stderr b/tests/ui/map_unwrap_or.stderr index 54ddd1402e3d..3119029902bf 100644 --- a/tests/ui/map_unwrap_or.stderr +++ b/tests/ui/map_unwrap_or.stderr @@ -1,5 +1,5 @@ error: called `map().unwrap_or()` on an `Option` value - --> $DIR/map_unwrap_or.rs:17:13 + --> $DIR/map_unwrap_or.rs:18:13 | LL | let _ = opt.map(|x| x + 1) | _____________^ @@ -16,7 +16,7 @@ LL + let _ = opt.map_or(0, |x| x + 1); | error: called `map().unwrap_or()` on an `Option` value - --> $DIR/map_unwrap_or.rs:21:13 + --> $DIR/map_unwrap_or.rs:23:13 | LL | let _ = opt.map(|x| { | _____________^ @@ -34,7 +34,7 @@ LL ~ ); | error: called `map().unwrap_or()` on an `Option` value - --> $DIR/map_unwrap_or.rs:25:13 + --> $DIR/map_unwrap_or.rs:28:13 | LL | let _ = opt.map(|x| x + 1) | _____________^ @@ -51,7 +51,7 @@ LL ~ }, |x| x + 1); | error: called `map().unwrap_or(None)` on an `Option` value - --> $DIR/map_unwrap_or.rs:30:13 + --> $DIR/map_unwrap_or.rs:33:13 | LL | let _ = opt.map(|x| Some(x + 1)).unwrap_or(None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -63,7 +63,7 @@ LL + let _ = opt.and_then(|x| Some(x + 1)); | error: called `map().unwrap_or(None)` on an `Option` value - --> $DIR/map_unwrap_or.rs:32:13 + --> $DIR/map_unwrap_or.rs:37:13 | LL | let _ = opt.map(|x| { | _____________^ @@ -81,7 +81,7 @@ LL ~ ); | error: called `map().unwrap_or(None)` on an `Option` value - --> $DIR/map_unwrap_or.rs:36:13 + --> $DIR/map_unwrap_or.rs:42:13 | LL | let _ = opt | _____________^ @@ -96,7 +96,7 @@ LL + .and_then(|x| Some(x + 1)); | error: called `map().unwrap_or()` on an `Option` value - --> $DIR/map_unwrap_or.rs:47:13 + --> $DIR/map_unwrap_or.rs:53:13 | LL | let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL + let _ = Some("prefix").map_or(id, |p| format!("{}.", p)); | error: called `map().unwrap_or_else()` on an `Option` value - --> $DIR/map_unwrap_or.rs:51:13 + --> $DIR/map_unwrap_or.rs:59:13 | LL | let _ = opt.map(|x| { | _____________^ @@ -118,7 +118,7 @@ LL | | ).unwrap_or_else(|| 0); | |__________________________^ error: called `map().unwrap_or_else()` on an `Option` value - --> $DIR/map_unwrap_or.rs:55:13 + --> $DIR/map_unwrap_or.rs:64:13 | LL | let _ = opt.map(|x| x + 1) | _____________^ @@ -128,7 +128,7 @@ LL | | ); | |_________^ error: called `map().unwrap_or(false)` on an `Option` value - --> $DIR/map_unwrap_or.rs:61:13 + --> $DIR/map_unwrap_or.rs:70:13 | LL | let _ = opt.map(|x| x > 5).unwrap_or(false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -140,7 +140,7 @@ LL + let _ = opt.is_some_and(|x| x > 5); | error: called `map().unwrap_or_else()` on a `Result` value - --> $DIR/map_unwrap_or.rs:71:13 + --> $DIR/map_unwrap_or.rs:81:13 | LL | let _ = res.map(|x| { | _____________^ @@ -150,7 +150,7 @@ LL | | ).unwrap_or_else(|_e| 0); | |____________________________^ error: called `map().unwrap_or_else()` on a `Result` value - --> $DIR/map_unwrap_or.rs:75:13 + --> $DIR/map_unwrap_or.rs:86:13 | LL | let _ = res.map(|x| x + 1) | _____________^ @@ -160,13 +160,13 @@ LL | | }); | |__________^ error: called `map().unwrap_or_else()` on a `Result` value - --> $DIR/map_unwrap_or.rs:99:13 + --> $DIR/map_unwrap_or.rs:110:13 | LL | let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `res.map_or_else(|_e| 0, |x| x + 1)` error: called `map().unwrap_or()` on an `Option` value - --> $DIR/map_unwrap_or.rs:106:13 + --> $DIR/map_unwrap_or.rs:118:13 | LL | let _ = opt.map(|x| x > 5).unwrap_or(false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -178,7 +178,7 @@ LL + let _ = opt.map_or(false, |x| x > 5); | error: called `map().unwrap_or(false)` on an `Option` value - --> $DIR/map_unwrap_or.rs:113:13 + --> $DIR/map_unwrap_or.rs:125:13 | LL | let _ = opt.map(|x| x > 5).unwrap_or(false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/map_unwrap_or_fixable.fixed b/tests/ui/map_unwrap_or_fixable.fixed index 90f3cf8bab04..062c9dcc90fc 100644 --- a/tests/ui/map_unwrap_or_fixable.fixed +++ b/tests/ui/map_unwrap_or_fixable.fixed @@ -13,6 +13,7 @@ fn option_methods() { // Check for `option.map(_).unwrap_or_else(_)` use. // single line case + //~v map_unwrap_or let _ = opt.map_or_else(|| 0, |x| x + 1); // Macro case. @@ -41,6 +42,7 @@ fn result_methods() { // Check for `result.map(_).unwrap_or_else(_)` use. // single line case + //~v map_unwrap_or let _ = res.map_or_else(|_e| 0, |x| x + 1); // macro case diff --git a/tests/ui/map_unwrap_or_fixable.rs b/tests/ui/map_unwrap_or_fixable.rs index d3d0ae0154c1..4280b1c03257 100644 --- a/tests/ui/map_unwrap_or_fixable.rs +++ b/tests/ui/map_unwrap_or_fixable.rs @@ -13,6 +13,7 @@ fn option_methods() { // Check for `option.map(_).unwrap_or_else(_)` use. // single line case + //~v map_unwrap_or let _ = opt.map(|x| x + 1) // Should lint even though this call is on a separate line. .unwrap_or_else(|| 0); @@ -43,6 +44,7 @@ fn result_methods() { // Check for `result.map(_).unwrap_or_else(_)` use. // single line case + //~v map_unwrap_or let _ = res.map(|x| x + 1) // should lint even though this call is on a separate line .unwrap_or_else(|_e| 0); diff --git a/tests/ui/map_unwrap_or_fixable.stderr b/tests/ui/map_unwrap_or_fixable.stderr index d1a9fdd6ecff..c11eabbafedf 100644 --- a/tests/ui/map_unwrap_or_fixable.stderr +++ b/tests/ui/map_unwrap_or_fixable.stderr @@ -1,5 +1,5 @@ error: called `map().unwrap_or_else()` on an `Option` value - --> $DIR/map_unwrap_or_fixable.rs:16:13 + --> $DIR/map_unwrap_or_fixable.rs:17:13 | LL | let _ = opt.map(|x| x + 1) | _____________^ @@ -11,7 +11,7 @@ LL | | .unwrap_or_else(|| 0); = help: to override `-D warnings` add `#[allow(clippy::map_unwrap_or)]` error: called `map().unwrap_or_else()` on a `Result` value - --> $DIR/map_unwrap_or_fixable.rs:46:13 + --> $DIR/map_unwrap_or_fixable.rs:48:13 | LL | let _ = res.map(|x| x + 1) | _____________^ diff --git a/tests/ui/match_as_ref.fixed b/tests/ui/match_as_ref.fixed index 8c07076af4a4..1fcbdf13754e 100644 --- a/tests/ui/match_as_ref.fixed +++ b/tests/ui/match_as_ref.fixed @@ -3,9 +3,11 @@ fn match_as_ref() { let owned: Option<()> = None; + //~v match_as_ref let borrowed: Option<&()> = owned.as_ref(); let mut mut_owned: Option<()> = None; + //~v match_as_ref let borrow_mut: Option<&mut ()> = mut_owned.as_mut(); } @@ -21,6 +23,7 @@ mod issue4437 { impl Error for E { fn source(&self) -> Option<&(dyn Error + 'static)> { + //~v match_as_ref self.source.as_ref().map(|x| x as _) } } diff --git a/tests/ui/match_as_ref.rs b/tests/ui/match_as_ref.rs index 655e16623697..2d5ffc3defa6 100644 --- a/tests/ui/match_as_ref.rs +++ b/tests/ui/match_as_ref.rs @@ -3,12 +3,14 @@ fn match_as_ref() { let owned: Option<()> = None; + //~v match_as_ref let borrowed: Option<&()> = match owned { None => None, Some(ref v) => Some(v), }; let mut mut_owned: Option<()> = None; + //~v match_as_ref let borrow_mut: Option<&mut ()> = match mut_owned { None => None, Some(ref mut v) => Some(v), @@ -27,6 +29,7 @@ mod issue4437 { impl Error for E { fn source(&self) -> Option<&(dyn Error + 'static)> { + //~v match_as_ref match self.source { Some(ref s) => Some(s), None => None, diff --git a/tests/ui/match_as_ref.stderr b/tests/ui/match_as_ref.stderr index cb0191370eaa..fbcc0f5cebc0 100644 --- a/tests/ui/match_as_ref.stderr +++ b/tests/ui/match_as_ref.stderr @@ -1,5 +1,5 @@ error: use `as_ref()` instead - --> $DIR/match_as_ref.rs:6:33 + --> $DIR/match_as_ref.rs:7:33 | LL | let borrowed: Option<&()> = match owned { | _________________________________^ @@ -12,7 +12,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::match_as_ref)]` error: use `as_mut()` instead - --> $DIR/match_as_ref.rs:12:39 + --> $DIR/match_as_ref.rs:14:39 | LL | let borrow_mut: Option<&mut ()> = match mut_owned { | _______________________________________^ @@ -22,7 +22,7 @@ LL | | }; | |_____^ help: try: `mut_owned.as_mut()` error: use `as_ref()` instead - --> $DIR/match_as_ref.rs:30:13 + --> $DIR/match_as_ref.rs:33:13 | LL | / match self.source { LL | | Some(ref s) => Some(s), diff --git a/tests/ui/match_expr_like_matches_macro.fixed b/tests/ui/match_expr_like_matches_macro.fixed index 05edc024ba9f..7a5b714d440d 100644 --- a/tests/ui/match_expr_like_matches_macro.fixed +++ b/tests/ui/match_expr_like_matches_macro.fixed @@ -11,19 +11,24 @@ fn main() { let x = Some(5); // Lint + //~v match_like_matches_macro let _y = matches!(x, Some(0)); // Lint + //~v redundant_pattern_matching let _w = x.is_some(); // Turn into is_none + //~v redundant_pattern_matching let _z = x.is_none(); // Lint + //~v match_like_matches_macro let _zz = !matches!(x, Some(r) if r == 0); // Lint let _zzz = matches!(x, Some(5)); + //~^ match_like_matches_macro // No lint let _a = match x { @@ -47,16 +52,19 @@ fn main() { let x = E::A(2); { // lint + //~v match_like_matches_macro let _ans = matches!(x, E::A(_) | E::B(_)); } { // lint // skip rustfmt to prevent removing block for first pattern #[rustfmt::skip] + //~v match_like_matches_macro let _ans = matches!(x, E::A(_) | E::B(_)); } { // lint + //~v match_like_matches_macro let _ans = !matches!(x, E::B(_) | E::C); } { @@ -113,12 +121,14 @@ fn main() { { // should print "z" in suggestion (#6503) let z = &Some(3); + //~v match_like_matches_macro let _z = matches!(z, Some(3)); } { // this could also print "z" in suggestion..? let z = Some(3); + //~v match_like_matches_macro let _z = matches!(&z, Some(3)); } @@ -133,6 +143,7 @@ fn main() { fn main() { let z = AnEnum::X; // we can't remove the reference here! + //~v match_like_matches_macro let _ = matches!(&z, AnEnum::X); foo(z); } @@ -144,6 +155,7 @@ fn main() { fn fun(_val: Option) {} let val = Some(S(42)); // we need the reference here because later val is consumed by fun() + //~v match_like_matches_macro let _res = matches!(&val, &Some(ref _a)); fun(val); } @@ -153,6 +165,7 @@ fn main() { fn fun(_val: Option) {} let val = Some(S(42)); + //~v match_like_matches_macro let _res = matches!(&val, &Some(ref _a)); fun(val); } @@ -208,5 +221,6 @@ fn msrv_1_41() { #[clippy::msrv = "1.42"] fn msrv_1_42() { + //~v match_like_matches_macro let _y = matches!(Some(5), Some(0)); } diff --git a/tests/ui/match_expr_like_matches_macro.rs b/tests/ui/match_expr_like_matches_macro.rs index d6a0313cde43..80d17cef533f 100644 --- a/tests/ui/match_expr_like_matches_macro.rs +++ b/tests/ui/match_expr_like_matches_macro.rs @@ -11,24 +11,28 @@ fn main() { let x = Some(5); // Lint + //~v match_like_matches_macro let _y = match x { Some(0) => true, _ => false, }; // Lint + //~v redundant_pattern_matching let _w = match x { Some(_) => true, _ => false, }; // Turn into is_none + //~v redundant_pattern_matching let _z = match x { Some(_) => false, None => true, }; // Lint + //~v match_like_matches_macro let _zz = match x { Some(r) if r == 0 => false, _ => true, @@ -36,6 +40,7 @@ fn main() { // Lint let _zzz = if let Some(5) = x { true } else { false }; + //~^ match_like_matches_macro // No lint let _a = match x { @@ -59,6 +64,7 @@ fn main() { let x = E::A(2); { // lint + //~v match_like_matches_macro let _ans = match x { E::A(_) => true, E::B(_) => true, @@ -69,6 +75,7 @@ fn main() { // lint // skip rustfmt to prevent removing block for first pattern #[rustfmt::skip] + //~v match_like_matches_macro let _ans = match x { E::A(_) => { true @@ -79,6 +86,7 @@ fn main() { } { // lint + //~v match_like_matches_macro let _ans = match x { E::B(_) => false, E::C => false, @@ -139,6 +147,7 @@ fn main() { { // should print "z" in suggestion (#6503) let z = &Some(3); + //~v match_like_matches_macro let _z = match &z { Some(3) => true, _ => false, @@ -148,6 +157,7 @@ fn main() { { // this could also print "z" in suggestion..? let z = Some(3); + //~v match_like_matches_macro let _z = match &z { Some(3) => true, _ => false, @@ -165,6 +175,7 @@ fn main() { fn main() { let z = AnEnum::X; // we can't remove the reference here! + //~v match_like_matches_macro let _ = match &z { AnEnum::X => true, _ => false, @@ -179,6 +190,7 @@ fn main() { fn fun(_val: Option) {} let val = Some(S(42)); // we need the reference here because later val is consumed by fun() + //~v match_like_matches_macro let _res = match &val { &Some(ref _a) => true, _ => false, @@ -191,6 +203,7 @@ fn main() { fn fun(_val: Option) {} let val = Some(S(42)); + //~v match_like_matches_macro let _res = match &val { &Some(ref _a) => true, _ => false, @@ -249,6 +262,7 @@ fn msrv_1_41() { #[clippy::msrv = "1.42"] fn msrv_1_42() { + //~v match_like_matches_macro let _y = match Some(5) { Some(0) => true, _ => false, diff --git a/tests/ui/match_expr_like_matches_macro.stderr b/tests/ui/match_expr_like_matches_macro.stderr index c702523783e7..709f70e66cb3 100644 --- a/tests/ui/match_expr_like_matches_macro.stderr +++ b/tests/ui/match_expr_like_matches_macro.stderr @@ -1,5 +1,5 @@ error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:14:14 + --> $DIR/match_expr_like_matches_macro.rs:15:14 | LL | let _y = match x { | ______________^ @@ -12,7 +12,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::match_like_matches_macro)]` error: redundant pattern matching, consider using `is_some()` - --> $DIR/match_expr_like_matches_macro.rs:20:14 + --> $DIR/match_expr_like_matches_macro.rs:22:14 | LL | let _w = match x { | ______________^ @@ -25,7 +25,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_none()` - --> $DIR/match_expr_like_matches_macro.rs:26:14 + --> $DIR/match_expr_like_matches_macro.rs:29:14 | LL | let _z = match x { | ______________^ @@ -35,7 +35,7 @@ LL | | }; | |_____^ help: try: `x.is_none()` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:32:15 + --> $DIR/match_expr_like_matches_macro.rs:36:15 | LL | let _zz = match x { | _______________^ @@ -45,13 +45,13 @@ LL | | }; | |_____^ help: try: `!matches!(x, Some(r) if r == 0)` error: if let .. else expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:38:16 + --> $DIR/match_expr_like_matches_macro.rs:42:16 | LL | let _zzz = if let Some(5) = x { true } else { false }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(x, Some(5))` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:62:20 + --> $DIR/match_expr_like_matches_macro.rs:68:20 | LL | let _ans = match x { | ____________________^ @@ -62,7 +62,7 @@ LL | | }; | |_________^ help: try: `matches!(x, E::A(_) | E::B(_))` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:72:20 + --> $DIR/match_expr_like_matches_macro.rs:79:20 | LL | let _ans = match x { | ____________________^ @@ -75,7 +75,7 @@ LL | | }; | |_________^ help: try: `matches!(x, E::A(_) | E::B(_))` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:82:20 + --> $DIR/match_expr_like_matches_macro.rs:90:20 | LL | let _ans = match x { | ____________________^ @@ -86,7 +86,7 @@ LL | | }; | |_________^ help: try: `!matches!(x, E::B(_) | E::C)` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:142:18 + --> $DIR/match_expr_like_matches_macro.rs:151:18 | LL | let _z = match &z { | __________________^ @@ -96,7 +96,7 @@ LL | | }; | |_________^ help: try: `matches!(z, Some(3))` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:151:18 + --> $DIR/match_expr_like_matches_macro.rs:161:18 | LL | let _z = match &z { | __________________^ @@ -106,7 +106,7 @@ LL | | }; | |_________^ help: try: `matches!(&z, Some(3))` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:168:21 + --> $DIR/match_expr_like_matches_macro.rs:179:21 | LL | let _ = match &z { | _____________________^ @@ -116,7 +116,7 @@ LL | | }; | |_____________^ help: try: `matches!(&z, AnEnum::X)` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:182:20 + --> $DIR/match_expr_like_matches_macro.rs:194:20 | LL | let _res = match &val { | ____________________^ @@ -126,7 +126,7 @@ LL | | }; | |_________^ help: try: `matches!(&val, &Some(ref _a))` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:194:20 + --> $DIR/match_expr_like_matches_macro.rs:207:20 | LL | let _res = match &val { | ____________________^ @@ -136,7 +136,7 @@ LL | | }; | |_________^ help: try: `matches!(&val, &Some(ref _a))` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:252:14 + --> $DIR/match_expr_like_matches_macro.rs:266:14 | LL | let _y = match Some(5) { | ______________^ diff --git a/tests/ui/match_ref_pats.fixed b/tests/ui/match_ref_pats.fixed index f8d47b0fdc7d..41dce1a381c7 100644 --- a/tests/ui/match_ref_pats.fixed +++ b/tests/ui/match_ref_pats.fixed @@ -5,6 +5,7 @@ fn ref_pats() { { let v = &Some(0); + //~v match_ref_pats match *v { Some(v) => println!("{:?}", v), None => println!("none"), @@ -22,6 +23,7 @@ fn ref_pats() { } // Special case: using `&` both in expr and pats. let w = Some(0); + //~v match_ref_pats match w { Some(v) => println!("{:?}", v), None => println!("none"), @@ -34,11 +36,13 @@ fn ref_pats() { } let a = &Some(0); + //~v redundant_pattern_matching if a.is_none() { println!("none"); } let b = Some(0); + //~v redundant_pattern_matching if b.is_none() { println!("none"); } @@ -99,6 +103,7 @@ mod issue_7740 { fn issue_7740() { // Issue #7740 + //~v match_ref_pats match *foobar_variant!(0) { FooBar::Foo => println!("Foo"), FooBar::Bar => println!("Bar"), diff --git a/tests/ui/match_ref_pats.rs b/tests/ui/match_ref_pats.rs index bcd7bf7ab51b..ae1d1732167d 100644 --- a/tests/ui/match_ref_pats.rs +++ b/tests/ui/match_ref_pats.rs @@ -5,6 +5,7 @@ fn ref_pats() { { let v = &Some(0); + //~v match_ref_pats match v { &Some(v) => println!("{:?}", v), &None => println!("none"), @@ -22,6 +23,7 @@ fn ref_pats() { } // Special case: using `&` both in expr and pats. let w = Some(0); + //~v match_ref_pats match &w { &Some(v) => println!("{:?}", v), &None => println!("none"), @@ -34,11 +36,13 @@ fn ref_pats() { } let a = &Some(0); + //~v redundant_pattern_matching if let &None = a { println!("none"); } let b = Some(0); + //~v redundant_pattern_matching if let &None = &b { println!("none"); } @@ -99,6 +103,7 @@ mod issue_7740 { fn issue_7740() { // Issue #7740 + //~v match_ref_pats match foobar_variant!(0) { &FooBar::Foo => println!("Foo"), &FooBar::Bar => println!("Bar"), diff --git a/tests/ui/match_ref_pats.stderr b/tests/ui/match_ref_pats.stderr index e3bb2824aa07..1b89243b84f6 100644 --- a/tests/ui/match_ref_pats.stderr +++ b/tests/ui/match_ref_pats.stderr @@ -1,5 +1,5 @@ error: you don't need to add `&` to all patterns - --> $DIR/match_ref_pats.rs:8:9 + --> $DIR/match_ref_pats.rs:9:9 | LL | / match v { LL | | &Some(v) => println!("{:?}", v), @@ -17,7 +17,7 @@ LL ~ None => println!("none"), | error: you don't need to add `&` to both the expression and the patterns - --> $DIR/match_ref_pats.rs:25:5 + --> $DIR/match_ref_pats.rs:27:5 | LL | / match &w { LL | | &Some(v) => println!("{:?}", v), @@ -33,7 +33,7 @@ LL ~ None => println!("none"), | error: redundant pattern matching, consider using `is_none()` - --> $DIR/match_ref_pats.rs:37:12 + --> $DIR/match_ref_pats.rs:40:12 | LL | if let &None = a { | -------^^^^^---- help: try: `if a.is_none()` @@ -42,13 +42,13 @@ LL | if let &None = a { = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_none()` - --> $DIR/match_ref_pats.rs:42:12 + --> $DIR/match_ref_pats.rs:46:12 | LL | if let &None = &b { | -------^^^^^----- help: try: `if b.is_none()` error: you don't need to add `&` to all patterns - --> $DIR/match_ref_pats.rs:102:9 + --> $DIR/match_ref_pats.rs:107:9 | LL | / match foobar_variant!(0) { LL | | &FooBar::Foo => println!("Foo"), diff --git a/tests/ui/match_result_ok.fixed b/tests/ui/match_result_ok.fixed index 8d7cddc0ad74..5ba8ff823a30 100644 --- a/tests/ui/match_result_ok.fixed +++ b/tests/ui/match_result_ok.fixed @@ -6,6 +6,7 @@ fn str_to_int(x: &str) -> i32 { if let Ok(y) = x.parse() { y } else { 0 } + //~^ match_result_ok } fn str_to_int_ok(x: &str) -> i32 { @@ -15,6 +16,7 @@ fn str_to_int_ok(x: &str) -> i32 { #[rustfmt::skip] fn strange_some_no_else(x: &str) -> i32 { { + //~v match_result_ok if let Ok(y) = x . parse() { return y; }; @@ -41,6 +43,7 @@ impl Wat { fn base_1(x: i32) { let mut wat = Wat { counter: x }; + //~v match_result_ok while let Ok(a) = wat.next() { println!("{}", a); } diff --git a/tests/ui/match_result_ok.rs b/tests/ui/match_result_ok.rs index 9a18b813aca3..eb6002a5765f 100644 --- a/tests/ui/match_result_ok.rs +++ b/tests/ui/match_result_ok.rs @@ -6,6 +6,7 @@ fn str_to_int(x: &str) -> i32 { if let Some(y) = x.parse().ok() { y } else { 0 } + //~^ match_result_ok } fn str_to_int_ok(x: &str) -> i32 { @@ -15,6 +16,7 @@ fn str_to_int_ok(x: &str) -> i32 { #[rustfmt::skip] fn strange_some_no_else(x: &str) -> i32 { { + //~v match_result_ok if let Some(y) = x . parse() . ok () { return y; }; @@ -41,6 +43,7 @@ impl Wat { fn base_1(x: i32) { let mut wat = Wat { counter: x }; + //~v match_result_ok while let Some(a) = wat.next().ok() { println!("{}", a); } diff --git a/tests/ui/match_result_ok.stderr b/tests/ui/match_result_ok.stderr index de0361bd6b41..e28baea4e92e 100644 --- a/tests/ui/match_result_ok.stderr +++ b/tests/ui/match_result_ok.stderr @@ -12,7 +12,7 @@ LL | if let Ok(y) = x.parse() { y } else { 0 } | ~~~~~~~~~~~~~~~~~~~~~~~~ error: matching on `Some` with `ok()` is redundant - --> $DIR/match_result_ok.rs:18:9 + --> $DIR/match_result_ok.rs:20:9 | LL | if let Some(y) = x . parse() . ok () { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | if let Ok(y) = x . parse() { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: matching on `Some` with `ok()` is redundant - --> $DIR/match_result_ok.rs:44:5 + --> $DIR/match_result_ok.rs:47:5 | LL | while let Some(a) = wat.next().ok() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/match_same_arms2.rs b/tests/ui/match_same_arms2.rs index 3428ff459060..b0f7ee0ac24a 100644 --- a/tests/ui/match_same_arms2.rs +++ b/tests/ui/match_same_arms2.rs @@ -164,6 +164,7 @@ fn match_expr_like_matches_macro_priority() { C, } let x = E::A; + //~v match_like_matches_macro let _ans = match x { E::A => false, E::B => false, @@ -243,7 +244,7 @@ fn main() { let _ = match 0 { 0 => cfg!(not_enable), - 1 => cfg!(not_enable), + 1 => cfg!(not_enable), //~ match_same_arms _ => false, }; } diff --git a/tests/ui/match_same_arms2.stderr b/tests/ui/match_same_arms2.stderr index 512ca7413a79..13ab699a38b0 100644 --- a/tests/ui/match_same_arms2.stderr +++ b/tests/ui/match_same_arms2.stderr @@ -136,7 +136,7 @@ LL | | }, | |_________^ error: match expression looks like `matches!` macro - --> $DIR/match_same_arms2.rs:167:16 + --> $DIR/match_same_arms2.rs:168:16 | LL | let _ans = match x { | ________________^ @@ -150,7 +150,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::match_like_matches_macro)]` error: this match arm has an identical body to another arm - --> $DIR/match_same_arms2.rs:199:9 + --> $DIR/match_same_arms2.rs:200:9 | LL | Foo::X(0) => 1, | ---------^^^^^ @@ -159,13 +159,13 @@ LL | Foo::X(0) => 1, | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms2.rs:201:9 + --> $DIR/match_same_arms2.rs:202:9 | LL | Foo::Z(_) => 1, | ^^^^^^^^^^^^^^ error: this match arm has an identical body to another arm - --> $DIR/match_same_arms2.rs:209:9 + --> $DIR/match_same_arms2.rs:210:9 | LL | Foo::Z(_) => 1, | ---------^^^^^ @@ -174,13 +174,13 @@ LL | Foo::Z(_) => 1, | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms2.rs:207:9 + --> $DIR/match_same_arms2.rs:208:9 | LL | Foo::X(0) => 1, | ^^^^^^^^^^^^^^ error: this match arm has an identical body to another arm - --> $DIR/match_same_arms2.rs:232:9 + --> $DIR/match_same_arms2.rs:233:9 | LL | Some(Bar { y: 0, x: 5, .. }) => 1, | ----------------------------^^^^^ @@ -189,13 +189,13 @@ LL | Some(Bar { y: 0, x: 5, .. }) => 1, | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms2.rs:229:9 + --> $DIR/match_same_arms2.rs:230:9 | LL | Some(Bar { x: 0, y: 5, .. }) => 1, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this match arm has an identical body to another arm - --> $DIR/match_same_arms2.rs:246:9 + --> $DIR/match_same_arms2.rs:247:9 | LL | 1 => cfg!(not_enable), | -^^^^^^^^^^^^^^^^^^^^ @@ -204,7 +204,7 @@ LL | 1 => cfg!(not_enable), | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms2.rs:245:9 + --> $DIR/match_same_arms2.rs:246:9 | LL | 0 => cfg!(not_enable), | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/match_single_binding.fixed b/tests/ui/match_single_binding.fixed index 3a3eee4c958b..508e0be01469 100644 --- a/tests/ui/match_single_binding.fixed +++ b/tests/ui/match_single_binding.fixed @@ -30,11 +30,13 @@ fn main() { let b = 2; let c = 3; // Lint + //~v match_single_binding let (x, y, z) = (a, b, c); { println!("{} {} {}", x, y, z); } // Lint + //~v match_single_binding let (x, y, z) = (a, b, c); println!("{} {} {}", x, y, z); // Ok @@ -51,13 +53,16 @@ fn main() { _ => println!("None"), } // Lint + //~v match_single_binding println!("whatever"); // Lint + //~v match_single_binding { let x = 29; println!("x has a value of {}", x); } // Lint + //~v match_single_binding { let e = 5 * a; if e >= 5 { @@ -66,20 +71,25 @@ fn main() { } // Lint let p = Point { x: 0, y: 7 }; + //~v match_single_binding let Point { x, y } = p; println!("Coords: ({}, {})", x, y); // Lint + //~v match_single_binding let Point { x: x1, y: y1 } = p; println!("Coords: ({}, {})", x1, y1); // Lint let x = 5; + //~v match_single_binding let ref r = x; println!("Got a reference to {}", r); // Lint let mut x = 5; + //~v match_single_binding let ref mut mr = x; println!("Got a mutable reference to {}", mr); // Lint + //~v match_single_binding let Point { x, y } = coords(); let product = x * y; // Lint @@ -87,6 +97,7 @@ fn main() { #[allow(clippy::let_and_return)] let _ = v .iter() + //~v match_single_binding .map(|i| { let unwrapped = i.unwrap(); unwrapped @@ -114,12 +125,14 @@ fn main() { // Lint let x = 1; + //~v match_single_binding println!("Not an array index start") } fn issue_8723() { let (mut val, idx) = ("a b", 1); + //~v match_single_binding let (pre, suf) = val.split_at(idx); val = { println!("{}", pre); @@ -132,6 +145,7 @@ fn issue_8723() { fn side_effects() {} fn issue_9575() { + //~v match_single_binding let _ = || { side_effects(); println!("Needs curlies") @@ -139,6 +153,7 @@ fn issue_9575() { } fn issue_9725(r: Option) { + //~v match_single_binding let x = r; match x { Some(_) => { @@ -151,21 +166,30 @@ fn issue_9725(r: Option) { } fn issue_10447() -> usize { + //~v match_single_binding (); + //~v match_single_binding let a = (); + //~v match_single_binding side_effects(); + //~v match_single_binding let b = side_effects(); + //~v match_single_binding println!("1"); + //~v match_single_binding let c = println!("1"); let in_expr = [ + //~v match_single_binding (), + //~v match_single_binding side_effects(), + //~v match_single_binding println!("1"), ]; diff --git a/tests/ui/match_single_binding.rs b/tests/ui/match_single_binding.rs index ff2f842ac39e..2e4f8df7b834 100644 --- a/tests/ui/match_single_binding.rs +++ b/tests/ui/match_single_binding.rs @@ -30,12 +30,14 @@ fn main() { let b = 2; let c = 3; // Lint + //~v match_single_binding match (a, b, c) { (x, y, z) => { println!("{} {} {}", x, y, z); }, } // Lint + //~v match_single_binding match (a, b, c) { (x, y, z) => println!("{} {} {}", x, y, z), } @@ -53,10 +55,12 @@ fn main() { _ => println!("None"), } // Lint + //~v match_single_binding match a { _ => println!("whatever"), } // Lint + //~v match_single_binding match a { _ => { let x = 29; @@ -64,6 +68,7 @@ fn main() { }, } // Lint + //~v match_single_binding match a { _ => { let e = 5 * a; @@ -74,24 +79,29 @@ fn main() { } // Lint let p = Point { x: 0, y: 7 }; + //~v match_single_binding match p { Point { x, y } => println!("Coords: ({}, {})", x, y), } // Lint + //~v match_single_binding match p { Point { x: x1, y: y1 } => println!("Coords: ({}, {})", x1, y1), } // Lint let x = 5; + //~v match_single_binding match x { ref r => println!("Got a reference to {}", r), } // Lint let mut x = 5; + //~v match_single_binding match x { ref mut mr => println!("Got a mutable reference to {}", mr), } // Lint + //~v match_single_binding let product = match coords() { Point { x, y } => x * y, }; @@ -100,6 +110,7 @@ fn main() { #[allow(clippy::let_and_return)] let _ = v .iter() + //~v match_single_binding .map(|i| match i.unwrap() { unwrapped => unwrapped, }) @@ -126,6 +137,7 @@ fn main() { // Lint let x = 1; + //~v match_single_binding match x { // => _ => println!("Not an array index start"), @@ -135,6 +147,7 @@ fn main() { fn issue_8723() { let (mut val, idx) = ("a b", 1); + //~v match_single_binding val = match val.split_at(idx) { (pre, suf) => { println!("{}", pre); @@ -148,12 +161,14 @@ fn issue_8723() { fn side_effects() {} fn issue_9575() { + //~v match_single_binding let _ = || match side_effects() { _ => println!("Needs curlies"), }; } fn issue_9725(r: Option) { + //~v match_single_binding match r { x => match x { Some(_) => { @@ -167,37 +182,46 @@ fn issue_9725(r: Option) { } fn issue_10447() -> usize { + //~v match_single_binding match 1 { _ => (), } + //~v match_single_binding let a = match 1 { _ => (), }; + //~v match_single_binding match 1 { _ => side_effects(), } + //~v match_single_binding let b = match 1 { _ => side_effects(), }; + //~v match_single_binding match 1 { _ => println!("1"), } + //~v match_single_binding let c = match 1 { _ => println!("1"), }; let in_expr = [ + //~v match_single_binding match 1 { _ => (), }, + //~v match_single_binding match 1 { _ => side_effects(), }, + //~v match_single_binding match 1 { _ => println!("1"), }, diff --git a/tests/ui/match_single_binding.stderr b/tests/ui/match_single_binding.stderr index 81ec200dfc7a..a01b493810b7 100644 --- a/tests/ui/match_single_binding.stderr +++ b/tests/ui/match_single_binding.stderr @@ -1,5 +1,5 @@ error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:33:5 + --> $DIR/match_single_binding.rs:34:5 | LL | / match (a, b, c) { LL | | (x, y, z) => { @@ -19,7 +19,7 @@ LL + } | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:39:5 + --> $DIR/match_single_binding.rs:41:5 | LL | / match (a, b, c) { LL | | (x, y, z) => println!("{} {} {}", x, y, z), @@ -33,7 +33,7 @@ LL + println!("{} {} {}", x, y, z); | error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:56:5 + --> $DIR/match_single_binding.rs:59:5 | LL | / match a { LL | | _ => println!("whatever"), @@ -41,7 +41,7 @@ LL | | } | |_____^ help: consider using the match body instead: `println!("whatever");` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:60:5 + --> $DIR/match_single_binding.rs:64:5 | LL | / match a { LL | | _ => { @@ -60,7 +60,7 @@ LL + } | error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:67:5 + --> $DIR/match_single_binding.rs:72:5 | LL | / match a { LL | | _ => { @@ -82,7 +82,7 @@ LL + } | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:77:5 + --> $DIR/match_single_binding.rs:83:5 | LL | / match p { LL | | Point { x, y } => println!("Coords: ({}, {})", x, y), @@ -96,7 +96,7 @@ LL + println!("Coords: ({}, {})", x, y); | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:81:5 + --> $DIR/match_single_binding.rs:88:5 | LL | / match p { LL | | Point { x: x1, y: y1 } => println!("Coords: ({}, {})", x1, y1), @@ -110,7 +110,7 @@ LL + println!("Coords: ({}, {})", x1, y1); | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:86:5 + --> $DIR/match_single_binding.rs:94:5 | LL | / match x { LL | | ref r => println!("Got a reference to {}", r), @@ -124,7 +124,7 @@ LL + println!("Got a reference to {}", r); | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:91:5 + --> $DIR/match_single_binding.rs:100:5 | LL | / match x { LL | | ref mut mr => println!("Got a mutable reference to {}", mr), @@ -138,7 +138,7 @@ LL + println!("Got a mutable reference to {}", mr); | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:95:5 + --> $DIR/match_single_binding.rs:105:5 | LL | / let product = match coords() { LL | | Point { x, y } => x * y, @@ -152,7 +152,7 @@ LL + let product = x * y; | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:103:18 + --> $DIR/match_single_binding.rs:114:18 | LL | .map(|i| match i.unwrap() { | __________________^ @@ -169,7 +169,7 @@ LL ~ }) | error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:129:5 + --> $DIR/match_single_binding.rs:141:5 | LL | / match x { LL | | // => @@ -178,7 +178,7 @@ LL | | } | |_____^ help: consider using the match body instead: `println!("Not an array index start")` error: this assignment could be simplified - --> $DIR/match_single_binding.rs:138:5 + --> $DIR/match_single_binding.rs:151:5 | LL | / val = match val.split_at(idx) { LL | | (pre, suf) => { @@ -198,7 +198,7 @@ LL ~ }; | error: this match could be replaced by its scrutinee and body - --> $DIR/match_single_binding.rs:151:16 + --> $DIR/match_single_binding.rs:165:16 | LL | let _ = || match side_effects() { | ________________^ @@ -215,7 +215,7 @@ LL ~ }; | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:157:5 + --> $DIR/match_single_binding.rs:172:5 | LL | / match r { LL | | x => match x { @@ -240,7 +240,7 @@ LL ~ }; | error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:170:5 + --> $DIR/match_single_binding.rs:186:5 | LL | / match 1 { LL | | _ => (), @@ -248,7 +248,7 @@ LL | | } | |_____^ help: consider using the match body instead: `();` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:174:13 + --> $DIR/match_single_binding.rs:191:13 | LL | let a = match 1 { | _____________^ @@ -257,7 +257,7 @@ LL | | }; | |_____^ help: consider using the match body instead: `()` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:178:5 + --> $DIR/match_single_binding.rs:196:5 | LL | / match 1 { LL | | _ => side_effects(), @@ -265,7 +265,7 @@ LL | | } | |_____^ help: consider using the match body instead: `side_effects();` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:182:13 + --> $DIR/match_single_binding.rs:201:13 | LL | let b = match 1 { | _____________^ @@ -274,7 +274,7 @@ LL | | }; | |_____^ help: consider using the match body instead: `side_effects()` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:186:5 + --> $DIR/match_single_binding.rs:206:5 | LL | / match 1 { LL | | _ => println!("1"), @@ -282,7 +282,7 @@ LL | | } | |_____^ help: consider using the match body instead: `println!("1");` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:190:13 + --> $DIR/match_single_binding.rs:211:13 | LL | let c = match 1 { | _____________^ @@ -291,7 +291,7 @@ LL | | }; | |_____^ help: consider using the match body instead: `println!("1")` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:195:9 + --> $DIR/match_single_binding.rs:217:9 | LL | / match 1 { LL | | _ => (), @@ -299,7 +299,7 @@ LL | | }, | |_________^ help: consider using the match body instead: `()` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:198:9 + --> $DIR/match_single_binding.rs:221:9 | LL | / match 1 { LL | | _ => side_effects(), @@ -307,7 +307,7 @@ LL | | }, | |_________^ help: consider using the match body instead: `side_effects()` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:201:9 + --> $DIR/match_single_binding.rs:225:9 | LL | / match 1 { LL | | _ => println!("1"), diff --git a/tests/ui/match_single_binding2.fixed b/tests/ui/match_single_binding2.fixed index 5673aa78c76a..027ba00179b2 100644 --- a/tests/ui/match_single_binding2.fixed +++ b/tests/ui/match_single_binding2.fixed @@ -14,6 +14,7 @@ fn main() { #[allow(dead_code)] fn size_hint(iter: &AppendIter) -> (usize, Option) { match &iter.inner { + //~v match_single_binding Some((iter, _item)) => { let (min, max) = iter.size_hint(); (min.saturating_add(1), max.and_then(|max| max.checked_add(1))) @@ -28,6 +29,7 @@ fn main() { match opt { #[rustfmt::skip] Some((first, _second)) => { + //~v match_single_binding let (a, b) = get_tup(); println!("a {:?} and b {:?}", a, b) }, @@ -38,12 +40,14 @@ fn main() { // Lint (scrutinee has side effects) // issue #7094 + //~v match_single_binding side_effects(); println!("Side effects"); // Lint (scrutinee has side effects) // issue #7094 let x = 1; + //~v match_single_binding match x { 0 => 1, _ => 2, diff --git a/tests/ui/match_single_binding2.rs b/tests/ui/match_single_binding2.rs index 575e7f5816b8..a94659f667ae 100644 --- a/tests/ui/match_single_binding2.rs +++ b/tests/ui/match_single_binding2.rs @@ -14,6 +14,7 @@ fn main() { #[allow(dead_code)] fn size_hint(iter: &AppendIter) -> (usize, Option) { match &iter.inner { + //~v match_single_binding Some((iter, _item)) => match iter.size_hint() { (min, max) => (min.saturating_add(1), max.and_then(|max| max.checked_add(1))), }, @@ -27,6 +28,7 @@ fn main() { match opt { #[rustfmt::skip] Some((first, _second)) => { + //~v match_single_binding match get_tup() { (a, b) => println!("a {:?} and b {:?}", a, b), } @@ -38,6 +40,7 @@ fn main() { // Lint (scrutinee has side effects) // issue #7094 + //~v match_single_binding match side_effects() { _ => println!("Side effects"), } @@ -45,6 +48,7 @@ fn main() { // Lint (scrutinee has side effects) // issue #7094 let x = 1; + //~v match_single_binding match match x { 0 => 1, _ => 2, diff --git a/tests/ui/match_single_binding2.stderr b/tests/ui/match_single_binding2.stderr index e7b9ef8a1cda..5adb31e0eb12 100644 --- a/tests/ui/match_single_binding2.stderr +++ b/tests/ui/match_single_binding2.stderr @@ -1,5 +1,5 @@ error: this match could be written as a `let` statement - --> $DIR/match_single_binding2.rs:17:36 + --> $DIR/match_single_binding2.rs:18:36 | LL | Some((iter, _item)) => match iter.size_hint() { | ____________________________________^ @@ -18,7 +18,7 @@ LL ~ }, | error: this match could be written as a `let` statement - --> $DIR/match_single_binding2.rs:30:13 + --> $DIR/match_single_binding2.rs:32:13 | LL | / match get_tup() { LL | | (a, b) => println!("a {:?} and b {:?}", a, b), @@ -32,7 +32,7 @@ LL + println!("a {:?} and b {:?}", a, b) | error: this match could be replaced by its scrutinee and body - --> $DIR/match_single_binding2.rs:41:5 + --> $DIR/match_single_binding2.rs:44:5 | LL | / match side_effects() { LL | | _ => println!("Side effects"), @@ -46,7 +46,7 @@ LL + println!("Side effects"); | error: this match could be replaced by its scrutinee and body - --> $DIR/match_single_binding2.rs:48:5 + --> $DIR/match_single_binding2.rs:52:5 | LL | / match match x { LL | | 0 => 1, diff --git a/tests/ui/match_str_case_mismatch.fixed b/tests/ui/match_str_case_mismatch.fixed index a608ab0c0cb0..dfc78f36393c 100644 --- a/tests/ui/match_str_case_mismatch.fixed +++ b/tests/ui/match_str_case_mismatch.fixed @@ -109,7 +109,7 @@ fn as_str_match_mismatch() { match var.to_ascii_lowercase().as_str() { "foo" => {}, - "bar" => {}, + "bar" => {}, //~ match_str_case_mismatch _ => {}, } } @@ -119,7 +119,7 @@ fn non_alphabetic_mismatch() { match var.to_ascii_lowercase().as_str() { "1234567890" => {}, - "~!@#$%^&*()-_=+foo" => {}, + "~!@#$%^&*()-_=+foo" => {}, //~ match_str_case_mismatch "\n\r\t\x7F" => {}, _ => {}, } @@ -131,7 +131,7 @@ fn unicode_cased_mismatch() { match var.to_lowercase().as_str() { "水" => {}, "νερό" => {}, - "воды" => {}, + "воды" => {}, //~ match_str_case_mismatch "물" => {}, _ => {}, } @@ -142,7 +142,7 @@ fn titlecase_mismatch() { match var.to_lowercase().as_str() { "foolj" => {}, - "bardz" => {}, + "bardz" => {}, //~ match_str_case_mismatch _ => {}, } } @@ -152,7 +152,7 @@ fn no_case_equivalent_mismatch() { match var.to_uppercase().as_str() { "FOOɕ" => {}, - "BARʁ" => {}, + "BARʁ" => {}, //~ match_str_case_mismatch _ => {}, } } @@ -162,7 +162,7 @@ fn addrof_unary_match_mismatch() { match &*var.to_ascii_lowercase() { "foo" => {}, - "bar" => {}, + "bar" => {}, //~ match_str_case_mismatch _ => {}, } } @@ -177,7 +177,7 @@ fn alternating_chain_mismatch() { .to_ascii_uppercase() { "FOO" => {}, - "BAR" => {}, + "BAR" => {}, //~ match_str_case_mismatch _ => {}, } } diff --git a/tests/ui/match_str_case_mismatch.rs b/tests/ui/match_str_case_mismatch.rs index 1e4269d1db5d..e4fca661a71e 100644 --- a/tests/ui/match_str_case_mismatch.rs +++ b/tests/ui/match_str_case_mismatch.rs @@ -109,7 +109,7 @@ fn as_str_match_mismatch() { match var.to_ascii_lowercase().as_str() { "foo" => {}, - "Bar" => {}, + "Bar" => {}, //~ match_str_case_mismatch _ => {}, } } @@ -119,7 +119,7 @@ fn non_alphabetic_mismatch() { match var.to_ascii_lowercase().as_str() { "1234567890" => {}, - "~!@#$%^&*()-_=+Foo" => {}, + "~!@#$%^&*()-_=+Foo" => {}, //~ match_str_case_mismatch "\n\r\t\x7F" => {}, _ => {}, } @@ -131,7 +131,7 @@ fn unicode_cased_mismatch() { match var.to_lowercase().as_str() { "水" => {}, "νερό" => {}, - "Воды" => {}, + "Воды" => {}, //~ match_str_case_mismatch "물" => {}, _ => {}, } @@ -142,7 +142,7 @@ fn titlecase_mismatch() { match var.to_lowercase().as_str() { "foolj" => {}, - "barDz" => {}, + "barDz" => {}, //~ match_str_case_mismatch _ => {}, } } @@ -152,7 +152,7 @@ fn no_case_equivalent_mismatch() { match var.to_uppercase().as_str() { "FOOɕ" => {}, - "bARʁ" => {}, + "bARʁ" => {}, //~ match_str_case_mismatch _ => {}, } } @@ -162,7 +162,7 @@ fn addrof_unary_match_mismatch() { match &*var.to_ascii_lowercase() { "foo" => {}, - "Bar" => {}, + "Bar" => {}, //~ match_str_case_mismatch _ => {}, } } @@ -177,7 +177,7 @@ fn alternating_chain_mismatch() { .to_ascii_uppercase() { "FOO" => {}, - "bAR" => {}, + "bAR" => {}, //~ match_str_case_mismatch _ => {}, } } diff --git a/tests/ui/match_wildcard_for_single_variants.fixed b/tests/ui/match_wildcard_for_single_variants.fixed index e5ea2fdde82f..46a8439d3114 100644 --- a/tests/ui/match_wildcard_for_single_variants.fixed +++ b/tests/ui/match_wildcard_for_single_variants.fixed @@ -19,7 +19,7 @@ impl Color { Self::Red => (), Self::Green => (), Self::Blue => (), - Self::Rgb(..) => (), + Self::Rgb(..) => (), //~ match_wildcard_for_single_variants }; } } @@ -29,7 +29,7 @@ fn main() { match f { Foo::A => {}, Foo::B => {}, - Foo::C => {}, + Foo::C => {}, //~ match_wildcard_for_single_variants } let color = Color::Red; @@ -39,7 +39,7 @@ fn main() { Color::Red => {}, Color::Green => {}, Color::Rgb(_r, _g, _b) => {}, - Color::Blue => {}, + Color::Blue => {}, //~ match_wildcard_for_single_variants } // check exhaustive wild @@ -47,13 +47,13 @@ fn main() { Color::Red => {}, Color::Green => {}, Color::Rgb(..) => {}, - Color::Blue => {}, + Color::Blue => {}, //~ match_wildcard_for_single_variants } match color { Color::Red => {}, Color::Green => {}, Color::Rgb(_, _, _) => {}, - Color::Blue => {}, + Color::Blue => {}, //~ match_wildcard_for_single_variants } // shouldn't lint as there is one missing variant @@ -70,7 +70,7 @@ fn main() { &Color::Red => (), Color::Green => (), &Color::Rgb(..) => (), - Color::Blue => (), + Color::Blue => (), //~ match_wildcard_for_single_variants } use self::Color as C; @@ -79,14 +79,14 @@ fn main() { C::Red => (), C::Green => (), C::Rgb(..) => (), - C::Blue => (), + C::Blue => (), //~ match_wildcard_for_single_variants } match color { C::Red => (), Color::Green => (), Color::Rgb(..) => (), - Color::Blue => (), + Color::Blue => (), //~ match_wildcard_for_single_variants } match Some(0) { @@ -121,7 +121,7 @@ fn main() { Enum::A => (), Enum::B => (), Enum::C => (), - Enum::__Private => (), + Enum::__Private => (), //~ match_wildcard_for_single_variants } match Enum::A { Enum::A => (), @@ -148,7 +148,7 @@ mod issue9993 { let _ = match Foo::B { _ if false => 0, Foo::A(_) => 1, - Foo::B => 2, + Foo::B => 2, //~ match_wildcard_for_single_variants }; } } diff --git a/tests/ui/match_wildcard_for_single_variants.rs b/tests/ui/match_wildcard_for_single_variants.rs index dbd7fbe160f0..494f87131ff7 100644 --- a/tests/ui/match_wildcard_for_single_variants.rs +++ b/tests/ui/match_wildcard_for_single_variants.rs @@ -19,7 +19,7 @@ impl Color { Self::Red => (), Self::Green => (), Self::Blue => (), - _ => (), + _ => (), //~ match_wildcard_for_single_variants }; } } @@ -29,7 +29,7 @@ fn main() { match f { Foo::A => {}, Foo::B => {}, - _ => {}, + _ => {}, //~ match_wildcard_for_single_variants } let color = Color::Red; @@ -39,7 +39,7 @@ fn main() { Color::Red => {}, Color::Green => {}, Color::Rgb(_r, _g, _b) => {}, - _ => {}, + _ => {}, //~ match_wildcard_for_single_variants } // check exhaustive wild @@ -47,13 +47,13 @@ fn main() { Color::Red => {}, Color::Green => {}, Color::Rgb(..) => {}, - _ => {}, + _ => {}, //~ match_wildcard_for_single_variants } match color { Color::Red => {}, Color::Green => {}, Color::Rgb(_, _, _) => {}, - _ => {}, + _ => {}, //~ match_wildcard_for_single_variants } // shouldn't lint as there is one missing variant @@ -70,7 +70,7 @@ fn main() { &Color::Red => (), Color::Green => (), &Color::Rgb(..) => (), - &_ => (), + &_ => (), //~ match_wildcard_for_single_variants } use self::Color as C; @@ -79,14 +79,14 @@ fn main() { C::Red => (), C::Green => (), C::Rgb(..) => (), - _ => (), + _ => (), //~ match_wildcard_for_single_variants } match color { C::Red => (), Color::Green => (), Color::Rgb(..) => (), - _ => (), + _ => (), //~ match_wildcard_for_single_variants } match Some(0) { @@ -121,7 +121,7 @@ fn main() { Enum::A => (), Enum::B => (), Enum::C => (), - _ => (), + _ => (), //~ match_wildcard_for_single_variants } match Enum::A { Enum::A => (), @@ -148,7 +148,7 @@ mod issue9993 { let _ = match Foo::B { _ if false => 0, Foo::A(_) => 1, - _ => 2, + _ => 2, //~ match_wildcard_for_single_variants }; } } diff --git a/tests/ui/mem_replace.fixed b/tests/ui/mem_replace.fixed index 78d8b3e9bce6..dc8681a2c909 100644 --- a/tests/ui/mem_replace.fixed +++ b/tests/ui/mem_replace.fixed @@ -12,53 +12,72 @@ use std::mem; fn replace_option_with_none() { let mut an_option = Some(1); let _ = an_option.take(); + //~^ mem_replace_option_with_none let an_option = &mut Some(1); let _ = an_option.take(); + //~^ mem_replace_option_with_none } fn replace_with_default() { let mut s = String::from("foo"); let _ = std::mem::take(&mut s); + //~^ mem_replace_with_default let s = &mut String::from("foo"); let _ = std::mem::take(s); + //~^ mem_replace_with_default let _ = std::mem::take(s); + //~^ mem_replace_with_default let mut v = vec![123]; let _ = std::mem::take(&mut v); + //~^ mem_replace_with_default let _ = std::mem::take(&mut v); + //~^ mem_replace_with_default let _ = std::mem::take(&mut v); + //~^ mem_replace_with_default let _ = std::mem::take(&mut v); + //~^ mem_replace_with_default let mut hash_map: HashMap = HashMap::new(); let _ = std::mem::take(&mut hash_map); + //~^ mem_replace_with_default let mut btree_map: BTreeMap = BTreeMap::new(); let _ = std::mem::take(&mut btree_map); + //~^ mem_replace_with_default let mut vd: VecDeque = VecDeque::new(); let _ = std::mem::take(&mut vd); + //~^ mem_replace_with_default let mut hash_set: HashSet<&str> = HashSet::new(); let _ = std::mem::take(&mut hash_set); + //~^ mem_replace_with_default let mut btree_set: BTreeSet<&str> = BTreeSet::new(); let _ = std::mem::take(&mut btree_set); + //~^ mem_replace_with_default let mut list: LinkedList = LinkedList::new(); let _ = std::mem::take(&mut list); + //~^ mem_replace_with_default let mut binary_heap: BinaryHeap = BinaryHeap::new(); let _ = std::mem::take(&mut binary_heap); + //~^ mem_replace_with_default let mut tuple = (vec![1, 2], BinaryHeap::::new()); let _ = std::mem::take(&mut tuple); + //~^ mem_replace_with_default let mut refstr = "hello"; let _ = std::mem::take(&mut refstr); + //~^ mem_replace_with_default let mut slice: &[i32] = &[1, 2, 3]; let _ = std::mem::take(&mut slice); + //~^ mem_replace_with_default } // lint is disabled for primitives because in this case `take` @@ -95,6 +114,7 @@ fn msrv_1_39() { fn msrv_1_40() { let mut s = String::from("foo"); let _ = std::mem::take(&mut s); + //~^ mem_replace_with_default } fn issue9824() { @@ -125,8 +145,12 @@ fn issue9824() { // replace option with none let _ = f.0.take(); + //~^ mem_replace_option_with_none let _ = (*f).take(); + //~^ mem_replace_option_with_none let _ = b.opt.take(); + //~^ mem_replace_option_with_none // replace with default let _ = std::mem::take(&mut b.val); + //~^ mem_replace_with_default } diff --git a/tests/ui/mem_replace.rs b/tests/ui/mem_replace.rs index 28915bf6daee..fa6303fadc47 100644 --- a/tests/ui/mem_replace.rs +++ b/tests/ui/mem_replace.rs @@ -12,53 +12,72 @@ use std::mem; fn replace_option_with_none() { let mut an_option = Some(1); let _ = mem::replace(&mut an_option, None); + //~^ mem_replace_option_with_none let an_option = &mut Some(1); let _ = mem::replace(an_option, None); + //~^ mem_replace_option_with_none } fn replace_with_default() { let mut s = String::from("foo"); let _ = std::mem::replace(&mut s, String::default()); + //~^ mem_replace_with_default let s = &mut String::from("foo"); let _ = std::mem::replace(s, String::default()); + //~^ mem_replace_with_default let _ = std::mem::replace(s, Default::default()); + //~^ mem_replace_with_default let mut v = vec![123]; let _ = std::mem::replace(&mut v, Vec::default()); + //~^ mem_replace_with_default let _ = std::mem::replace(&mut v, Default::default()); + //~^ mem_replace_with_default let _ = std::mem::replace(&mut v, Vec::new()); + //~^ mem_replace_with_default let _ = std::mem::replace(&mut v, vec![]); + //~^ mem_replace_with_default let mut hash_map: HashMap = HashMap::new(); let _ = std::mem::replace(&mut hash_map, HashMap::new()); + //~^ mem_replace_with_default let mut btree_map: BTreeMap = BTreeMap::new(); let _ = std::mem::replace(&mut btree_map, BTreeMap::new()); + //~^ mem_replace_with_default let mut vd: VecDeque = VecDeque::new(); let _ = std::mem::replace(&mut vd, VecDeque::new()); + //~^ mem_replace_with_default let mut hash_set: HashSet<&str> = HashSet::new(); let _ = std::mem::replace(&mut hash_set, HashSet::new()); + //~^ mem_replace_with_default let mut btree_set: BTreeSet<&str> = BTreeSet::new(); let _ = std::mem::replace(&mut btree_set, BTreeSet::new()); + //~^ mem_replace_with_default let mut list: LinkedList = LinkedList::new(); let _ = std::mem::replace(&mut list, LinkedList::new()); + //~^ mem_replace_with_default let mut binary_heap: BinaryHeap = BinaryHeap::new(); let _ = std::mem::replace(&mut binary_heap, BinaryHeap::new()); + //~^ mem_replace_with_default let mut tuple = (vec![1, 2], BinaryHeap::::new()); let _ = std::mem::replace(&mut tuple, (vec![], BinaryHeap::new())); + //~^ mem_replace_with_default let mut refstr = "hello"; let _ = std::mem::replace(&mut refstr, ""); + //~^ mem_replace_with_default let mut slice: &[i32] = &[1, 2, 3]; let _ = std::mem::replace(&mut slice, &[]); + //~^ mem_replace_with_default } // lint is disabled for primitives because in this case `take` @@ -95,6 +114,7 @@ fn msrv_1_39() { fn msrv_1_40() { let mut s = String::from("foo"); let _ = std::mem::replace(&mut s, String::default()); + //~^ mem_replace_with_default } fn issue9824() { @@ -125,8 +145,12 @@ fn issue9824() { // replace option with none let _ = std::mem::replace(&mut f.0, None); + //~^ mem_replace_option_with_none let _ = std::mem::replace(&mut *f, None); + //~^ mem_replace_option_with_none let _ = std::mem::replace(&mut b.opt, None); + //~^ mem_replace_option_with_none // replace with default let _ = std::mem::replace(&mut b.val, String::default()); + //~^ mem_replace_with_default } diff --git a/tests/ui/mem_replace.stderr b/tests/ui/mem_replace.stderr index c8ddf585fd2a..141d9482383d 100644 --- a/tests/ui/mem_replace.stderr +++ b/tests/ui/mem_replace.stderr @@ -8,13 +8,13 @@ LL | let _ = mem::replace(&mut an_option, None); = help: to override `-D warnings` add `#[allow(clippy::mem_replace_option_with_none)]` error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:16:13 + --> $DIR/mem_replace.rs:17:13 | LL | let _ = mem::replace(an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:21:13 + --> $DIR/mem_replace.rs:23:13 | LL | let _ = std::mem::replace(&mut s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)` @@ -23,127 +23,127 @@ LL | let _ = std::mem::replace(&mut s, String::default()); = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_default)]` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:24:13 + --> $DIR/mem_replace.rs:27:13 | LL | let _ = std::mem::replace(s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:25:13 + --> $DIR/mem_replace.rs:29:13 | LL | let _ = std::mem::replace(s, Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:28:13 + --> $DIR/mem_replace.rs:33:13 | LL | let _ = std::mem::replace(&mut v, Vec::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:29:13 + --> $DIR/mem_replace.rs:35:13 | LL | let _ = std::mem::replace(&mut v, Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:30:13 + --> $DIR/mem_replace.rs:37:13 | LL | let _ = std::mem::replace(&mut v, Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:31:13 + --> $DIR/mem_replace.rs:39:13 | LL | let _ = std::mem::replace(&mut v, vec![]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:34:13 + --> $DIR/mem_replace.rs:43:13 | LL | let _ = std::mem::replace(&mut hash_map, HashMap::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut hash_map)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:37:13 + --> $DIR/mem_replace.rs:47:13 | LL | let _ = std::mem::replace(&mut btree_map, BTreeMap::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut btree_map)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:40:13 + --> $DIR/mem_replace.rs:51:13 | LL | let _ = std::mem::replace(&mut vd, VecDeque::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut vd)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:43:13 + --> $DIR/mem_replace.rs:55:13 | LL | let _ = std::mem::replace(&mut hash_set, HashSet::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut hash_set)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:46:13 + --> $DIR/mem_replace.rs:59:13 | LL | let _ = std::mem::replace(&mut btree_set, BTreeSet::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut btree_set)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:49:13 + --> $DIR/mem_replace.rs:63:13 | LL | let _ = std::mem::replace(&mut list, LinkedList::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut list)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:52:13 + --> $DIR/mem_replace.rs:67:13 | LL | let _ = std::mem::replace(&mut binary_heap, BinaryHeap::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut binary_heap)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:55:13 + --> $DIR/mem_replace.rs:71:13 | LL | let _ = std::mem::replace(&mut tuple, (vec![], BinaryHeap::new())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut tuple)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:58:13 + --> $DIR/mem_replace.rs:75:13 | LL | let _ = std::mem::replace(&mut refstr, ""); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut refstr)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:61:13 + --> $DIR/mem_replace.rs:79:13 | LL | let _ = std::mem::replace(&mut slice, &[]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut slice)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:97:13 + --> $DIR/mem_replace.rs:116:13 | LL | let _ = std::mem::replace(&mut s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)` error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:127:13 + --> $DIR/mem_replace.rs:147:13 | LL | let _ = std::mem::replace(&mut f.0, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `f.0.take()` error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:128:13 + --> $DIR/mem_replace.rs:149:13 | LL | let _ = std::mem::replace(&mut *f, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `(*f).take()` error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:129:13 + --> $DIR/mem_replace.rs:151:13 | LL | let _ = std::mem::replace(&mut b.opt, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `b.opt.take()` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:131:13 + --> $DIR/mem_replace.rs:154:13 | LL | let _ = std::mem::replace(&mut b.val, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut b.val)` diff --git a/tests/ui/mem_replace_macro.rs b/tests/ui/mem_replace_macro.rs index c14ea2942f3e..9458dade3a9c 100644 --- a/tests/ui/mem_replace_macro.rs +++ b/tests/ui/mem_replace_macro.rs @@ -8,5 +8,6 @@ use proc_macros::{external, inline_macros}; fn main() { let s = &mut String::from("foo"); let _ = inline!(std::mem::replace($s, Default::default())); + //~^ mem_replace_with_default let _ = external!(std::mem::replace($s, Default::default())); } diff --git a/tests/ui/mem_replace_no_std.fixed b/tests/ui/mem_replace_no_std.fixed index c970f2ba2814..8c8f1c22f892 100644 --- a/tests/ui/mem_replace_no_std.fixed +++ b/tests/ui/mem_replace_no_std.fixed @@ -22,16 +22,20 @@ fn panic(info: &PanicInfo) -> ! { fn replace_option_with_none() { let mut an_option = Some(1); let _ = an_option.take(); + //~^ mem_replace_option_with_none let an_option = &mut Some(1); let _ = an_option.take(); + //~^ mem_replace_option_with_none } fn replace_with_default() { let mut refstr = "hello"; let _ = core::mem::take(&mut refstr); + //~^ mem_replace_with_default let mut slice: &[i32] = &[1, 2, 3]; let _ = core::mem::take(&mut slice); + //~^ mem_replace_with_default } // lint is disabled for primitives because in this case `take` @@ -75,8 +79,11 @@ fn issue9824() { // replace option with none let _ = f.0.take(); + //~^ mem_replace_option_with_none let _ = (*f).take(); + //~^ mem_replace_option_with_none let _ = b.opt.take(); + //~^ mem_replace_option_with_none // replace with default let _ = mem::replace(&mut b.val, u8::default()); } diff --git a/tests/ui/mem_replace_no_std.rs b/tests/ui/mem_replace_no_std.rs index 673d5c7b4f45..85a668c67d2c 100644 --- a/tests/ui/mem_replace_no_std.rs +++ b/tests/ui/mem_replace_no_std.rs @@ -22,16 +22,20 @@ fn panic(info: &PanicInfo) -> ! { fn replace_option_with_none() { let mut an_option = Some(1); let _ = mem::replace(&mut an_option, None); + //~^ mem_replace_option_with_none let an_option = &mut Some(1); let _ = mem::replace(an_option, None); + //~^ mem_replace_option_with_none } fn replace_with_default() { let mut refstr = "hello"; let _ = mem::replace(&mut refstr, ""); + //~^ mem_replace_with_default let mut slice: &[i32] = &[1, 2, 3]; let _ = mem::replace(&mut slice, &[]); + //~^ mem_replace_with_default } // lint is disabled for primitives because in this case `take` @@ -75,8 +79,11 @@ fn issue9824() { // replace option with none let _ = mem::replace(&mut f.0, None); + //~^ mem_replace_option_with_none let _ = mem::replace(&mut *f, None); + //~^ mem_replace_option_with_none let _ = mem::replace(&mut b.opt, None); + //~^ mem_replace_option_with_none // replace with default let _ = mem::replace(&mut b.val, u8::default()); } diff --git a/tests/ui/mem_replace_no_std.stderr b/tests/ui/mem_replace_no_std.stderr index 744fb5a15876..419db2b41646 100644 --- a/tests/ui/mem_replace_no_std.stderr +++ b/tests/ui/mem_replace_no_std.stderr @@ -8,13 +8,13 @@ LL | let _ = mem::replace(&mut an_option, None); = help: to override `-D warnings` add `#[allow(clippy::mem_replace_option_with_none)]` error: replacing an `Option` with `None` - --> $DIR/mem_replace_no_std.rs:26:13 + --> $DIR/mem_replace_no_std.rs:27:13 | LL | let _ = mem::replace(an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` error: replacing a value of type `T` with `T::default()` is better expressed using `core::mem::take` - --> $DIR/mem_replace_no_std.rs:31:13 + --> $DIR/mem_replace_no_std.rs:33:13 | LL | let _ = mem::replace(&mut refstr, ""); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `core::mem::take(&mut refstr)` @@ -23,25 +23,25 @@ LL | let _ = mem::replace(&mut refstr, ""); = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_default)]` error: replacing a value of type `T` with `T::default()` is better expressed using `core::mem::take` - --> $DIR/mem_replace_no_std.rs:34:13 + --> $DIR/mem_replace_no_std.rs:37:13 | LL | let _ = mem::replace(&mut slice, &[]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `core::mem::take(&mut slice)` error: replacing an `Option` with `None` - --> $DIR/mem_replace_no_std.rs:77:13 + --> $DIR/mem_replace_no_std.rs:81:13 | LL | let _ = mem::replace(&mut f.0, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `f.0.take()` error: replacing an `Option` with `None` - --> $DIR/mem_replace_no_std.rs:78:13 + --> $DIR/mem_replace_no_std.rs:83:13 | LL | let _ = mem::replace(&mut *f, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `(*f).take()` error: replacing an `Option` with `None` - --> $DIR/mem_replace_no_std.rs:79:13 + --> $DIR/mem_replace_no_std.rs:85:13 | LL | let _ = mem::replace(&mut b.opt, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `b.opt.take()` diff --git a/tests/ui/methods.rs b/tests/ui/methods.rs index cb1f695c651c..20ec1ad7a5eb 100644 --- a/tests/ui/methods.rs +++ b/tests/ui/methods.rs @@ -100,6 +100,7 @@ impl AsyncNew { struct BadNew; impl BadNew { + //~v new_ret_no_self fn new() -> i32 { 0 } @@ -121,6 +122,7 @@ fn filter_next() { let v = vec![3, 2, 1, 0, -1, -2, -3]; // Multi-line case. + //~v filter_next let _ = v.iter().filter(|&x| { *x < 0 } diff --git a/tests/ui/methods.stderr b/tests/ui/methods.stderr index e32b3b336af6..44c8d3373577 100644 --- a/tests/ui/methods.stderr +++ b/tests/ui/methods.stderr @@ -1,5 +1,5 @@ error: methods called `new` usually return `Self` - --> $DIR/methods.rs:103:5 + --> $DIR/methods.rs:104:5 | LL | / fn new() -> i32 { LL | | 0 @@ -10,7 +10,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::new_ret_no_self)]` error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead - --> $DIR/methods.rs:124:13 + --> $DIR/methods.rs:126:13 | LL | let _ = v.iter().filter(|&x| { | _____________^ diff --git a/tests/ui/methods_fixable.fixed b/tests/ui/methods_fixable.fixed index bb06b5a480ff..0a2e10aee0d6 100644 --- a/tests/ui/methods_fixable.fixed +++ b/tests/ui/methods_fixable.fixed @@ -6,5 +6,5 @@ fn main() { let v = vec![3, 2, 1, 0, -1, -2, -3]; // Single-line case. - let _ = v.iter().find(|&x| *x < 0); + let _ = v.iter().find(|&x| *x < 0); //~ filter_next } diff --git a/tests/ui/methods_fixable.rs b/tests/ui/methods_fixable.rs index 11de924593ed..4bbdcf98b9eb 100644 --- a/tests/ui/methods_fixable.rs +++ b/tests/ui/methods_fixable.rs @@ -6,5 +6,5 @@ fn main() { let v = vec![3, 2, 1, 0, -1, -2, -3]; // Single-line case. - let _ = v.iter().filter(|&x| *x < 0).next(); + let _ = v.iter().filter(|&x| *x < 0).next(); //~ filter_next } diff --git a/tests/ui/min_ident_chars.rs b/tests/ui/min_ident_chars.rs index 1d89f26b6ee4..1788145254ab 100644 --- a/tests/ui/min_ident_chars.rs +++ b/tests/ui/min_ident_chars.rs @@ -6,25 +6,28 @@ extern crate proc_macros; use proc_macros::{external, with_span}; +//~v min_ident_chars struct A { - a: u32, + a: u32, //~ min_ident_chars i: u32, - A: u32, - I: u32, + A: u32, //~ min_ident_chars + I: u32, //~ min_ident_chars } -struct B(u32); +struct B(u32); //~ min_ident_chars +//~v min_ident_chars struct O { - o: u32, + o: u32, //~ min_ident_chars } struct i; +//~v min_ident_chars enum C { - D, - E, - F, + D, //~ min_ident_chars + E, //~ min_ident_chars + F, //~ min_ident_chars j, } @@ -38,9 +41,9 @@ struct Vec4 { struct AA(T, E); trait Trait { - const A: u32 = 0; - type A; - fn a() {} + const A: u32 = 0; //~ min_ident_chars + type A; //~ min_ident_chars + fn a() {} //~ min_ident_chars } fn main() { @@ -54,23 +57,31 @@ fn main() { let y = 1; let z = 1; // Implicitly disallowed idents - let h = 1; - let e = 2; - let l = 3; - let l = 4; - let o = 6; + let h = 1; //~ min_ident_chars + let e = 2; //~ min_ident_chars + let l = 3; //~ min_ident_chars + let l = 4; //~ min_ident_chars + let o = 6; //~ min_ident_chars // 2 len does not lint let hi = 0; // Lint let (h, o, w) = (1, 2, 3); + //~^ min_ident_chars + //~| min_ident_chars for (a, (r, e)) in (0..1000).enumerate().enumerate() {} + //~^ min_ident_chars + //~| min_ident_chars + //~| min_ident_chars let you = Vec4 { x: 1, y: 2, z: 3, w: 4 }; while let (d, o, _i, n, g) = (true, true, false, false, true) {} + //~^ min_ident_chars + //~| min_ident_chars + //~| min_ident_chars let today = true; // Ideally this wouldn't lint, but this would (likely) require global analysis, outta scope // of this lint regardless - let o = 1; - let o = O { o }; + let o = 1; //~ min_ident_chars + let o = O { o }; //~ min_ident_chars for j in 0..1000 {} for _ in 0..10 {} @@ -84,7 +95,10 @@ fn main() { } } -fn b() {} +fn b() {} //~ min_ident_chars + +//~| min_ident_chars +//~v min_ident_chars fn wrong_pythagoras(a: f32, b: f32) -> f32 { a * a + a * b } diff --git a/tests/ui/min_ident_chars.stderr b/tests/ui/min_ident_chars.stderr index 7490878d5726..74f9944f5829 100644 --- a/tests/ui/min_ident_chars.stderr +++ b/tests/ui/min_ident_chars.stderr @@ -1,5 +1,5 @@ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:9:8 + --> $DIR/min_ident_chars.rs:10:8 | LL | struct A { | ^ @@ -8,187 +8,187 @@ LL | struct A { = help: to override `-D warnings` add `#[allow(clippy::min_ident_chars)]` error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:10:5 + --> $DIR/min_ident_chars.rs:11:5 | LL | a: u32, | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:12:5 + --> $DIR/min_ident_chars.rs:13:5 | LL | A: u32, | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:13:5 + --> $DIR/min_ident_chars.rs:14:5 | LL | I: u32, | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:16:8 + --> $DIR/min_ident_chars.rs:17:8 | LL | struct B(u32); | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:18:8 + --> $DIR/min_ident_chars.rs:20:8 | LL | struct O { | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:19:5 + --> $DIR/min_ident_chars.rs:21:5 | LL | o: u32, | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:24:6 + --> $DIR/min_ident_chars.rs:27:6 | LL | enum C { | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:25:5 + --> $DIR/min_ident_chars.rs:28:5 | LL | D, | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:26:5 + --> $DIR/min_ident_chars.rs:29:5 | LL | E, | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:27:5 + --> $DIR/min_ident_chars.rs:30:5 | LL | F, | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:41:11 + --> $DIR/min_ident_chars.rs:44:11 | LL | const A: u32 = 0; | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:42:10 + --> $DIR/min_ident_chars.rs:45:10 | LL | type A; | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:43:8 + --> $DIR/min_ident_chars.rs:46:8 | LL | fn a() {} | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:57:9 + --> $DIR/min_ident_chars.rs:60:9 | LL | let h = 1; | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:58:9 + --> $DIR/min_ident_chars.rs:61:9 | LL | let e = 2; | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:59:9 + --> $DIR/min_ident_chars.rs:62:9 | LL | let l = 3; | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:60:9 + --> $DIR/min_ident_chars.rs:63:9 | LL | let l = 4; | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:61:9 + --> $DIR/min_ident_chars.rs:64:9 | LL | let o = 6; | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:65:10 + --> $DIR/min_ident_chars.rs:68:10 | LL | let (h, o, w) = (1, 2, 3); | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:65:13 + --> $DIR/min_ident_chars.rs:68:13 | LL | let (h, o, w) = (1, 2, 3); | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:66:10 + --> $DIR/min_ident_chars.rs:71:10 | LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {} | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:66:14 + --> $DIR/min_ident_chars.rs:71:14 | LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {} | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:66:17 + --> $DIR/min_ident_chars.rs:71:17 | LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {} | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:68:16 + --> $DIR/min_ident_chars.rs:76:16 | LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {} | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:68:19 + --> $DIR/min_ident_chars.rs:76:19 | LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {} | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:68:29 + --> $DIR/min_ident_chars.rs:76:29 | LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {} | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:72:9 + --> $DIR/min_ident_chars.rs:83:9 | LL | let o = 1; | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:73:9 + --> $DIR/min_ident_chars.rs:84:9 | LL | let o = O { o }; | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:87:4 + --> $DIR/min_ident_chars.rs:98:4 | LL | fn b() {} | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:88:21 + --> $DIR/min_ident_chars.rs:102:21 | LL | fn wrong_pythagoras(a: f32, b: f32) -> f32 { | ^ error: this ident consists of a single char - --> $DIR/min_ident_chars.rs:88:29 + --> $DIR/min_ident_chars.rs:102:29 | LL | fn wrong_pythagoras(a: f32, b: f32) -> f32 { | ^ diff --git a/tests/ui/mismatched_target_os_non_unix.fixed b/tests/ui/mismatched_target_os_non_unix.fixed index de02b2bee31f..ee721c722ac7 100644 --- a/tests/ui/mismatched_target_os_non_unix.fixed +++ b/tests/ui/mismatched_target_os_non_unix.fixed @@ -1,17 +1,17 @@ #![warn(clippy::mismatched_target_os)] #![allow(unused)] -#[cfg(target_os = "hermit")] +#[cfg(target_os = "hermit")] //~ mismatched_target_os fn hermit() {} -#[cfg(target_os = "wasi")] +#[cfg(target_os = "wasi")] //~ mismatched_target_os fn wasi() {} -#[cfg(target_os = "none")] +#[cfg(target_os = "none")] //~ mismatched_target_os fn none() {} // list with conditions -#[cfg(all(not(windows), target_os = "wasi"))] +#[cfg(all(not(windows), target_os = "wasi"))] //~ mismatched_target_os fn list() {} // windows is a valid target family, should be ignored diff --git a/tests/ui/mismatched_target_os_non_unix.rs b/tests/ui/mismatched_target_os_non_unix.rs index a960518751bf..9a53a63916db 100644 --- a/tests/ui/mismatched_target_os_non_unix.rs +++ b/tests/ui/mismatched_target_os_non_unix.rs @@ -1,17 +1,17 @@ #![warn(clippy::mismatched_target_os)] #![allow(unused)] -#[cfg(hermit)] +#[cfg(hermit)] //~ mismatched_target_os fn hermit() {} -#[cfg(wasi)] +#[cfg(wasi)] //~ mismatched_target_os fn wasi() {} -#[cfg(none)] +#[cfg(none)] //~ mismatched_target_os fn none() {} // list with conditions -#[cfg(all(not(windows), wasi))] +#[cfg(all(not(windows), wasi))] //~ mismatched_target_os fn list() {} // windows is a valid target family, should be ignored diff --git a/tests/ui/mismatched_target_os_unix.fixed b/tests/ui/mismatched_target_os_unix.fixed index b945c4d9619d..76497b96df1b 100644 --- a/tests/ui/mismatched_target_os_unix.fixed +++ b/tests/ui/mismatched_target_os_unix.fixed @@ -1,56 +1,57 @@ #![warn(clippy::mismatched_target_os)] #![allow(unused)] -#[cfg(target_os = "linux")] +#[cfg(target_os = "linux")] //~ mismatched_target_os fn linux() {} -#[cfg(target_os = "freebsd")] +#[cfg(target_os = "freebsd")] //~ mismatched_target_os fn freebsd() {} -#[cfg(target_os = "dragonfly")] +#[cfg(target_os = "dragonfly")] //~ mismatched_target_os fn dragonfly() {} -#[cfg(target_os = "openbsd")] +#[cfg(target_os = "openbsd")] //~ mismatched_target_os fn openbsd() {} -#[cfg(target_os = "netbsd")] +#[cfg(target_os = "netbsd")] //~ mismatched_target_os fn netbsd() {} -#[cfg(target_os = "macos")] +#[cfg(target_os = "macos")] //~ mismatched_target_os fn macos() {} -#[cfg(target_os = "ios")] +#[cfg(target_os = "ios")] //~ mismatched_target_os fn ios() {} -#[cfg(target_os = "android")] +#[cfg(target_os = "android")] //~ mismatched_target_os fn android() {} -#[cfg(target_os = "emscripten")] +#[cfg(target_os = "emscripten")] //~ mismatched_target_os fn emscripten() {} -#[cfg(target_os = "fuchsia")] +#[cfg(target_os = "fuchsia")] //~ mismatched_target_os fn fuchsia() {} -#[cfg(target_os = "haiku")] +#[cfg(target_os = "haiku")] //~ mismatched_target_os fn haiku() {} -#[cfg(target_os = "illumos")] +#[cfg(target_os = "illumos")] //~ mismatched_target_os fn illumos() {} -#[cfg(target_os = "l4re")] +#[cfg(target_os = "l4re")] //~ mismatched_target_os fn l4re() {} -#[cfg(target_os = "redox")] +#[cfg(target_os = "redox")] //~ mismatched_target_os fn redox() {} -#[cfg(target_os = "solaris")] +#[cfg(target_os = "solaris")] //~ mismatched_target_os fn solaris() {} -#[cfg(target_os = "vxworks")] +#[cfg(target_os = "vxworks")] //~ mismatched_target_os fn vxworks() {} // list with conditions #[cfg(all(not(any(target_os = "solaris", target_os = "linux")), target_os = "freebsd"))] +//~^ mismatched_target_os fn list() {} // correct use, should be ignored diff --git a/tests/ui/mismatched_target_os_unix.rs b/tests/ui/mismatched_target_os_unix.rs index 34307facd654..a4334b3662f6 100644 --- a/tests/ui/mismatched_target_os_unix.rs +++ b/tests/ui/mismatched_target_os_unix.rs @@ -1,56 +1,57 @@ #![warn(clippy::mismatched_target_os)] #![allow(unused)] -#[cfg(linux)] +#[cfg(linux)] //~ mismatched_target_os fn linux() {} -#[cfg(freebsd)] +#[cfg(freebsd)] //~ mismatched_target_os fn freebsd() {} -#[cfg(dragonfly)] +#[cfg(dragonfly)] //~ mismatched_target_os fn dragonfly() {} -#[cfg(openbsd)] +#[cfg(openbsd)] //~ mismatched_target_os fn openbsd() {} -#[cfg(netbsd)] +#[cfg(netbsd)] //~ mismatched_target_os fn netbsd() {} -#[cfg(macos)] +#[cfg(macos)] //~ mismatched_target_os fn macos() {} -#[cfg(ios)] +#[cfg(ios)] //~ mismatched_target_os fn ios() {} -#[cfg(android)] +#[cfg(android)] //~ mismatched_target_os fn android() {} -#[cfg(emscripten)] +#[cfg(emscripten)] //~ mismatched_target_os fn emscripten() {} -#[cfg(fuchsia)] +#[cfg(fuchsia)] //~ mismatched_target_os fn fuchsia() {} -#[cfg(haiku)] +#[cfg(haiku)] //~ mismatched_target_os fn haiku() {} -#[cfg(illumos)] +#[cfg(illumos)] //~ mismatched_target_os fn illumos() {} -#[cfg(l4re)] +#[cfg(l4re)] //~ mismatched_target_os fn l4re() {} -#[cfg(redox)] +#[cfg(redox)] //~ mismatched_target_os fn redox() {} -#[cfg(solaris)] +#[cfg(solaris)] //~ mismatched_target_os fn solaris() {} -#[cfg(vxworks)] +#[cfg(vxworks)] //~ mismatched_target_os fn vxworks() {} // list with conditions #[cfg(all(not(any(solaris, linux)), freebsd))] +//~^ mismatched_target_os fn list() {} // correct use, should be ignored diff --git a/tests/ui/missing_asserts_for_indexing_unfixable.rs b/tests/ui/missing_asserts_for_indexing_unfixable.rs index de53079a4760..090f5b27fb67 100644 --- a/tests/ui/missing_asserts_for_indexing_unfixable.rs +++ b/tests/ui/missing_asserts_for_indexing_unfixable.rs @@ -21,14 +21,14 @@ fn variables(v: &[u8]) -> u8 { } fn index_different_slices(v1: &[u8], v2: &[u8]) { - let _ = v1[0] + v1[12]; - let _ = v2[5] + v2[15]; + let _ = v1[0] + v1[12]; //~ missing_asserts_for_indexing + let _ = v2[5] + v2[15]; //~ missing_asserts_for_indexing } fn index_different_slices2(v1: &[u8], v2: &[u8]) { assert!(v1.len() > 12); let _ = v1[0] + v1[12]; - let _ = v2[5] + v2[15]; + let _ = v2[5] + v2[15]; //~ missing_asserts_for_indexing } struct Foo<'a> { diff --git a/tests/ui/missing_doc.rs b/tests/ui/missing_doc.rs index 9bfad3b96cff..95fe8bba6894 100644 --- a/tests/ui/missing_doc.rs +++ b/tests/ui/missing_doc.rs @@ -13,16 +13,16 @@ extern crate proc_macros; use proc_macros::with_span; use std::arch::global_asm; -type Typedef = String; +type Typedef = String; //~ missing_docs_in_private_items pub type PubTypedef = String; -mod module_no_dox {} +mod module_no_dox {} //~ missing_docs_in_private_items pub mod pub_module_no_dox {} /// dox pub fn foo() {} pub fn foo2() {} -fn foo3() {} +fn foo3() {} //~ missing_docs_in_private_items #[allow(clippy::missing_docs_in_private_items)] pub fn foo4() {} @@ -36,9 +36,13 @@ mod a { } } +//~v missing_docs_in_private_items enum Baz { BazA { a: isize, b: isize }, - BarB, + //~^ missing_docs_in_private_items + //~| missing_docs_in_private_items + //~| missing_docs_in_private_items + BarB, //~ missing_docs_in_private_items } pub enum PubBaz { @@ -62,7 +66,7 @@ pub enum PubBaz3 { #[doc(hidden)] pub fn baz() {} -const FOO: u32 = 0; +const FOO: u32 = 0; //~ missing_docs_in_private_items /// dox pub const FOO1: u32 = 0; #[allow(clippy::missing_docs_in_private_items)] @@ -71,7 +75,7 @@ pub const FOO2: u32 = 0; pub const FOO3: u32 = 0; pub const FOO4: u32 = 0; -static BAR: u32 = 0; +static BAR: u32 = 0; //~ missing_docs_in_private_items /// dox pub static BAR1: u32 = 0; #[allow(clippy::missing_docs_in_private_items)] @@ -80,18 +84,19 @@ pub static BAR2: u32 = 0; pub static BAR3: u32 = 0; pub static BAR4: u32 = 0; +//~v missing_docs_in_private_items mod internal_impl { /// dox pub fn documented() {} pub fn undocumented1() {} pub fn undocumented2() {} - fn undocumented3() {} + fn undocumented3() {} //~ missing_docs_in_private_items /// dox pub mod globbed { /// dox pub fn also_documented() {} pub fn also_undocumented1() {} - fn also_undocumented2() {} + fn also_undocumented2() {} //~ missing_docs_in_private_items } } /// dox diff --git a/tests/ui/missing_doc.stderr b/tests/ui/missing_doc.stderr index 1d8007fa5b0f..c12e8891618a 100644 --- a/tests/ui/missing_doc.stderr +++ b/tests/ui/missing_doc.stderr @@ -20,52 +20,55 @@ LL | fn foo3() {} | ^^^^^^^^^^^^ error: missing documentation for an enum - --> $DIR/missing_doc.rs:39:1 + --> $DIR/missing_doc.rs:40:1 | LL | / enum Baz { LL | | BazA { a: isize, b: isize }, +LL | | +LL | | +LL | | LL | | BarB, LL | | } | |_^ error: missing documentation for a variant - --> $DIR/missing_doc.rs:40:5 + --> $DIR/missing_doc.rs:41:5 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a struct field - --> $DIR/missing_doc.rs:40:12 + --> $DIR/missing_doc.rs:41:12 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^ error: missing documentation for a struct field - --> $DIR/missing_doc.rs:40:22 + --> $DIR/missing_doc.rs:41:22 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^ error: missing documentation for a variant - --> $DIR/missing_doc.rs:41:5 + --> $DIR/missing_doc.rs:45:5 | LL | BarB, | ^^^^ error: missing documentation for a constant - --> $DIR/missing_doc.rs:65:1 + --> $DIR/missing_doc.rs:69:1 | LL | const FOO: u32 = 0; | ^^^^^^^^^^^^^^^^^^^ error: missing documentation for a static - --> $DIR/missing_doc.rs:74:1 + --> $DIR/missing_doc.rs:78:1 | LL | static BAR: u32 = 0; | ^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a module - --> $DIR/missing_doc.rs:83:1 + --> $DIR/missing_doc.rs:88:1 | LL | / mod internal_impl { LL | | /// dox @@ -77,13 +80,13 @@ LL | | } | |_^ error: missing documentation for a function - --> $DIR/missing_doc.rs:88:5 + --> $DIR/missing_doc.rs:93:5 | LL | fn undocumented3() {} | ^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing_doc.rs:94:9 + --> $DIR/missing_doc.rs:99:9 | LL | fn also_undocumented2() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/missing_doc_impl.rs b/tests/ui/missing_doc_impl.rs index 520ddbe16b82..e68842a4ceba 100644 --- a/tests/ui/missing_doc_impl.rs +++ b/tests/ui/missing_doc_impl.rs @@ -10,14 +10,15 @@ extern crate proc_macros; use proc_macros::with_span; +//~v missing_docs_in_private_items struct Foo { - a: isize, - b: isize, + a: isize, //~ missing_docs_in_private_items + b: isize, //~ missing_docs_in_private_items } pub struct PubFoo { pub a: isize, - b: isize, + b: isize, //~ missing_docs_in_private_items } #[allow(clippy::missing_docs_in_private_items)] @@ -64,10 +65,11 @@ pub trait E: Sized { } impl Foo { + //~v missing_docs_in_private_items pub fn new() -> Self { Foo { a: 0, b: 0 } } - fn bar() {} + fn bar() {} //~ missing_docs_in_private_items } impl PubFoo { @@ -75,6 +77,7 @@ impl PubFoo { /// dox pub fn foo1() {} #[must_use = "yep"] + //~v missing_docs_in_private_items fn foo2() -> u32 { 1 } diff --git a/tests/ui/missing_doc_impl.stderr b/tests/ui/missing_doc_impl.stderr index e303b7b7d9fd..eae199a12d93 100644 --- a/tests/ui/missing_doc_impl.stderr +++ b/tests/ui/missing_doc_impl.stderr @@ -1,5 +1,5 @@ error: missing documentation for a struct - --> $DIR/missing_doc_impl.rs:13:1 + --> $DIR/missing_doc_impl.rs:14:1 | LL | / struct Foo { LL | | a: isize, @@ -11,25 +11,25 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]` error: missing documentation for a struct field - --> $DIR/missing_doc_impl.rs:14:5 + --> $DIR/missing_doc_impl.rs:15:5 | LL | a: isize, | ^^^^^^^^ error: missing documentation for a struct field - --> $DIR/missing_doc_impl.rs:15:5 + --> $DIR/missing_doc_impl.rs:16:5 | LL | b: isize, | ^^^^^^^^ error: missing documentation for a struct field - --> $DIR/missing_doc_impl.rs:20:5 + --> $DIR/missing_doc_impl.rs:21:5 | LL | b: isize, | ^^^^^^^^ error: missing documentation for an associated function - --> $DIR/missing_doc_impl.rs:67:5 + --> $DIR/missing_doc_impl.rs:69:5 | LL | / pub fn new() -> Self { LL | | Foo { a: 0, b: 0 } @@ -37,13 +37,13 @@ LL | | } | |_____^ error: missing documentation for an associated function - --> $DIR/missing_doc_impl.rs:70:5 + --> $DIR/missing_doc_impl.rs:72:5 | LL | fn bar() {} | ^^^^^^^^^^^ error: missing documentation for an associated function - --> $DIR/missing_doc_impl.rs:78:5 + --> $DIR/missing_doc_impl.rs:81:5 | LL | / fn foo2() -> u32 { LL | | 1 diff --git a/tests/ui/missing_panics_doc.rs b/tests/ui/missing_panics_doc.rs index 0e1533fc1ab1..51ae13467a4b 100644 --- a/tests/ui/missing_panics_doc.rs +++ b/tests/ui/missing_panics_doc.rs @@ -10,17 +10,20 @@ use macro_rules::macro_with_panic; fn main() {} /// This needs to be documented +//~v missing_panics_doc pub fn unwrap() { let result = Err("Hi"); result.unwrap() } /// This needs to be documented +//~v missing_panics_doc pub fn panic() { panic!("This function panics") } /// This needs to be documented +//~v missing_panics_doc pub fn inner_body(opt: Option) { opt.map(|x| { if x == 10 { @@ -30,17 +33,20 @@ pub fn inner_body(opt: Option) { } /// This needs to be documented +//~v missing_panics_doc pub fn unreachable_and_panic() { if true { unreachable!() } else { panic!() } } /// This needs to be documented +//~v missing_panics_doc pub fn assert_eq() { let x = 0; assert_eq!(x, 0); } /// This needs to be documented +//~v missing_panics_doc pub fn assert_ne() { let x = 0; assert_ne!(x, 0); @@ -148,30 +154,36 @@ pub fn debug_assertions() { // all function must be triggered the lint. // `pub` is required, because the lint does not consider unreachable items pub mod issue10240 { + //~v missing_panics_doc pub fn option_unwrap(v: &[T]) -> &T { let o: Option<&T> = v.last(); o.unwrap() } + //~v missing_panics_doc pub fn option_expect(v: &[T]) -> &T { let o: Option<&T> = v.last(); o.expect("passed an empty thing") } + //~v missing_panics_doc pub fn result_unwrap(v: &[T]) -> &T { let res: Result<&T, &str> = v.last().ok_or("oh noes"); res.unwrap() } + //~v missing_panics_doc pub fn result_expect(v: &[T]) -> &T { let res: Result<&T, &str> = v.last().ok_or("oh noes"); res.expect("passed an empty thing") } + //~v missing_panics_doc pub fn last_unwrap(v: &[u32]) -> u32 { *v.last().unwrap() } + //~v missing_panics_doc pub fn last_expect(v: &[u32]) -> u32 { *v.last().expect("passed an empty thing") } diff --git a/tests/ui/missing_panics_doc.stderr b/tests/ui/missing_panics_doc.stderr index efee485508ec..e7975b6a5efe 100644 --- a/tests/ui/missing_panics_doc.stderr +++ b/tests/ui/missing_panics_doc.stderr @@ -1,11 +1,11 @@ error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:13:1 + --> $DIR/missing_panics_doc.rs:14:1 | LL | pub fn unwrap() { | ^^^^^^^^^^^^^^^ | note: first possible panic found here - --> $DIR/missing_panics_doc.rs:15:5 + --> $DIR/missing_panics_doc.rs:16:5 | LL | result.unwrap() | ^^^^^^^^^^^^^^^ @@ -13,133 +13,133 @@ LL | result.unwrap() = help: to override `-D warnings` add `#[allow(clippy::missing_panics_doc)]` error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:19:1 + --> $DIR/missing_panics_doc.rs:21:1 | LL | pub fn panic() { | ^^^^^^^^^^^^^^ | note: first possible panic found here - --> $DIR/missing_panics_doc.rs:20:5 + --> $DIR/missing_panics_doc.rs:22:5 | LL | panic!("This function panics") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:24:1 + --> $DIR/missing_panics_doc.rs:27:1 | LL | pub fn inner_body(opt: Option) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> $DIR/missing_panics_doc.rs:27:13 + --> $DIR/missing_panics_doc.rs:30:13 | LL | panic!() | ^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:33:1 + --> $DIR/missing_panics_doc.rs:37:1 | LL | pub fn unreachable_and_panic() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> $DIR/missing_panics_doc.rs:34:39 + --> $DIR/missing_panics_doc.rs:38:39 | LL | if true { unreachable!() } else { panic!() } | ^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:38:1 + --> $DIR/missing_panics_doc.rs:43:1 | LL | pub fn assert_eq() { | ^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> $DIR/missing_panics_doc.rs:40:5 + --> $DIR/missing_panics_doc.rs:45:5 | LL | assert_eq!(x, 0); | ^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:44:1 + --> $DIR/missing_panics_doc.rs:50:1 | LL | pub fn assert_ne() { | ^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> $DIR/missing_panics_doc.rs:46:5 + --> $DIR/missing_panics_doc.rs:52:5 | LL | assert_ne!(x, 0); | ^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:151:5 + --> $DIR/missing_panics_doc.rs:158:5 | LL | pub fn option_unwrap(v: &[T]) -> &T { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> $DIR/missing_panics_doc.rs:153:9 + --> $DIR/missing_panics_doc.rs:160:9 | LL | o.unwrap() | ^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:156:5 + --> $DIR/missing_panics_doc.rs:164:5 | LL | pub fn option_expect(v: &[T]) -> &T { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> $DIR/missing_panics_doc.rs:158:9 + --> $DIR/missing_panics_doc.rs:166:9 | LL | o.expect("passed an empty thing") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:161:5 + --> $DIR/missing_panics_doc.rs:170:5 | LL | pub fn result_unwrap(v: &[T]) -> &T { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> $DIR/missing_panics_doc.rs:163:9 + --> $DIR/missing_panics_doc.rs:172:9 | LL | res.unwrap() | ^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:166:5 + --> $DIR/missing_panics_doc.rs:176:5 | LL | pub fn result_expect(v: &[T]) -> &T { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> $DIR/missing_panics_doc.rs:168:9 + --> $DIR/missing_panics_doc.rs:178:9 | LL | res.expect("passed an empty thing") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:171:5 + --> $DIR/missing_panics_doc.rs:182:5 | LL | pub fn last_unwrap(v: &[u32]) -> u32 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> $DIR/missing_panics_doc.rs:172:10 + --> $DIR/missing_panics_doc.rs:183:10 | LL | *v.last().unwrap() | ^^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:175:5 + --> $DIR/missing_panics_doc.rs:187:5 | LL | pub fn last_expect(v: &[u32]) -> u32 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> $DIR/missing_panics_doc.rs:176:10 + --> $DIR/missing_panics_doc.rs:188:10 | LL | *v.last().expect("passed an empty thing") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/missing_spin_loop.fixed b/tests/ui/missing_spin_loop.fixed index b6520d478be8..d847c24359df 100644 --- a/tests/ui/missing_spin_loop.fixed +++ b/tests/ui/missing_spin_loop.fixed @@ -7,17 +7,21 @@ use core::sync::atomic::{AtomicBool, Ordering}; fn main() { let b = AtomicBool::new(true); // Those should lint - while b.load(Ordering::Acquire) { std::hint::spin_loop() } + while b.load(Ordering::Acquire) { std::hint::spin_loop() } //~ missing_spin_loop - while !b.load(Ordering::SeqCst) { std::hint::spin_loop() } + while !b.load(Ordering::SeqCst) { std::hint::spin_loop() } //~ missing_spin_loop while b.load(Ordering::Acquire) == false { std::hint::spin_loop() } + //~^ missing_spin_loop while { true == b.load(Ordering::Acquire) } { std::hint::spin_loop() } + //~^ missing_spin_loop while b.compare_exchange(true, false, Ordering::Acquire, Ordering::Relaxed) != Ok(true) { std::hint::spin_loop() } + //~^ missing_spin_loop while Ok(false) != b.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed) { std::hint::spin_loop() } + //~^ missing_spin_loop // This is OK, as the body is not empty while b.load(Ordering::Acquire) { diff --git a/tests/ui/missing_spin_loop.rs b/tests/ui/missing_spin_loop.rs index 7b115c66ade6..632f0d407fdb 100644 --- a/tests/ui/missing_spin_loop.rs +++ b/tests/ui/missing_spin_loop.rs @@ -7,17 +7,21 @@ use core::sync::atomic::{AtomicBool, Ordering}; fn main() { let b = AtomicBool::new(true); // Those should lint - while b.load(Ordering::Acquire) {} + while b.load(Ordering::Acquire) {} //~ missing_spin_loop - while !b.load(Ordering::SeqCst) {} + while !b.load(Ordering::SeqCst) {} //~ missing_spin_loop while b.load(Ordering::Acquire) == false {} + //~^ missing_spin_loop while { true == b.load(Ordering::Acquire) } {} + //~^ missing_spin_loop while b.compare_exchange(true, false, Ordering::Acquire, Ordering::Relaxed) != Ok(true) {} + //~^ missing_spin_loop while Ok(false) != b.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed) {} + //~^ missing_spin_loop // This is OK, as the body is not empty while b.load(Ordering::Acquire) { diff --git a/tests/ui/missing_spin_loop.stderr b/tests/ui/missing_spin_loop.stderr index a84c19d59261..422842823c71 100644 --- a/tests/ui/missing_spin_loop.stderr +++ b/tests/ui/missing_spin_loop.stderr @@ -20,19 +20,19 @@ LL | while b.load(Ordering::Acquire) == false {} | ^^ help: try: `{ std::hint::spin_loop() }` error: busy-waiting loop should at least have a spin loop hint - --> $DIR/missing_spin_loop.rs:16:49 + --> $DIR/missing_spin_loop.rs:17:49 | LL | while { true == b.load(Ordering::Acquire) } {} | ^^ help: try: `{ std::hint::spin_loop() }` error: busy-waiting loop should at least have a spin loop hint - --> $DIR/missing_spin_loop.rs:18:93 + --> $DIR/missing_spin_loop.rs:20:93 | LL | while b.compare_exchange(true, false, Ordering::Acquire, Ordering::Relaxed) != Ok(true) {} | ^^ help: try: `{ std::hint::spin_loop() }` error: busy-waiting loop should at least have a spin loop hint - --> $DIR/missing_spin_loop.rs:20:94 + --> $DIR/missing_spin_loop.rs:23:94 | LL | while Ok(false) != b.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed) {} | ^^ help: try: `{ std::hint::spin_loop() }` diff --git a/tests/ui/missing_spin_loop_no_std.fixed b/tests/ui/missing_spin_loop_no_std.fixed index 497e0e243174..cfce060a8af8 100644 --- a/tests/ui/missing_spin_loop_no_std.fixed +++ b/tests/ui/missing_spin_loop_no_std.fixed @@ -9,7 +9,7 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize { // This should trigger the lint let b = AtomicBool::new(true); // This should lint with `core::hint::spin_loop()` - while b.load(Ordering::Acquire) { core::hint::spin_loop() } + while b.load(Ordering::Acquire) { core::hint::spin_loop() } //~ missing_spin_loop 0 } diff --git a/tests/ui/missing_spin_loop_no_std.rs b/tests/ui/missing_spin_loop_no_std.rs index 1c85a9c58d65..96d5a4485805 100644 --- a/tests/ui/missing_spin_loop_no_std.rs +++ b/tests/ui/missing_spin_loop_no_std.rs @@ -9,7 +9,7 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize { // This should trigger the lint let b = AtomicBool::new(true); // This should lint with `core::hint::spin_loop()` - while b.load(Ordering::Acquire) {} + while b.load(Ordering::Acquire) {} //~ missing_spin_loop 0 } diff --git a/tests/ui/mistyped_literal_suffix.fixed b/tests/ui/mistyped_literal_suffix.fixed index 861764a2aeeb..c2e3d4d74e67 100644 --- a/tests/ui/mistyped_literal_suffix.fixed +++ b/tests/ui/mistyped_literal_suffix.fixed @@ -13,36 +13,47 @@ extern crate proc_macros; use proc_macros::with_span; fn main() { - let fail14 = 2_i32; - let fail15 = 4_i64; + let fail14 = 2_i32; //~ mistyped_literal_suffixes + let fail15 = 4_i64; //~ mistyped_literal_suffixes + + //~v mistyped_literal_suffixes let fail16 = 7_i8; // + + //~v mistyped_literal_suffixes let fail17 = 23_i16; // let ok18 = 23_128; + //~v mistyped_literal_suffixes let fail20 = 2_i8; // + + //~v mistyped_literal_suffixes let fail21 = 4_i16; // let ok24 = 12.34_64; - let fail25 = 1E2_f32; - let fail26 = 43E7_f64; - let fail27 = 243E17_f32; - let fail28 = 241_251_235E723_f64; + let fail25 = 1E2_f32; //~ mistyped_literal_suffixes + let fail26 = 43E7_f64; //~ mistyped_literal_suffixes + let fail27 = 243E17_f32; //~ mistyped_literal_suffixes + let fail28 = 241_251_235E723_f64; //~ mistyped_literal_suffixes let ok29 = 42279.911_32; // testing that the suggestion actually fits in its type + //~v mistyped_literal_suffixes let fail30 = 127_i8; // should be i8 + + //~v mistyped_literal_suffixes let fail31 = 240_u8; // should be u8 let ok32 = 360_8; // doesnt fit in either, should be ignored - let fail33 = 0x1234_i16; - let fail34 = 0xABCD_u16; + let fail33 = 0x1234_i16; //~ mistyped_literal_suffixes + let fail34 = 0xABCD_u16; //~ mistyped_literal_suffixes let ok35 = 0x12345_16; + //~v mistyped_literal_suffixes let fail36 = 0xFFFF_FFFF_FFFF_FFFF_u64; // u64 // issue #6129 let ok37 = 123_32.123; let ok38 = 124_64.0; - let _ = 1.123_45E1_f32; + let _ = 1.123_45E1_f32; //~ mistyped_literal_suffixes let _ = with_span!(1 2_u32); } diff --git a/tests/ui/mistyped_literal_suffix.rs b/tests/ui/mistyped_literal_suffix.rs index 4a15c335fd89..3c5dbdaa2f4d 100644 --- a/tests/ui/mistyped_literal_suffix.rs +++ b/tests/ui/mistyped_literal_suffix.rs @@ -13,36 +13,47 @@ extern crate proc_macros; use proc_macros::with_span; fn main() { - let fail14 = 2_32; - let fail15 = 4_64; + let fail14 = 2_32; //~ mistyped_literal_suffixes + let fail15 = 4_64; //~ mistyped_literal_suffixes + + //~v mistyped_literal_suffixes let fail16 = 7_8; // + + //~v mistyped_literal_suffixes let fail17 = 23_16; // let ok18 = 23_128; + //~v mistyped_literal_suffixes let fail20 = 2__8; // + + //~v mistyped_literal_suffixes let fail21 = 4___16; // let ok24 = 12.34_64; - let fail25 = 1E2_32; - let fail26 = 43E7_64; - let fail27 = 243E17_32; - let fail28 = 241251235E723_64; + let fail25 = 1E2_32; //~ mistyped_literal_suffixes + let fail26 = 43E7_64; //~ mistyped_literal_suffixes + let fail27 = 243E17_32; //~ mistyped_literal_suffixes + let fail28 = 241251235E723_64; //~ mistyped_literal_suffixes let ok29 = 42279.911_32; // testing that the suggestion actually fits in its type + //~v mistyped_literal_suffixes let fail30 = 127_8; // should be i8 + + //~v mistyped_literal_suffixes let fail31 = 240_8; // should be u8 let ok32 = 360_8; // doesnt fit in either, should be ignored - let fail33 = 0x1234_16; - let fail34 = 0xABCD_16; + let fail33 = 0x1234_16; //~ mistyped_literal_suffixes + let fail34 = 0xABCD_16; //~ mistyped_literal_suffixes let ok35 = 0x12345_16; + //~v mistyped_literal_suffixes let fail36 = 0xFFFF_FFFF_FFFF_FFFF_64; // u64 // issue #6129 let ok37 = 123_32.123; let ok38 = 124_64.0; - let _ = 1.12345E1_32; + let _ = 1.12345E1_32; //~ mistyped_literal_suffixes let _ = with_span!(1 2_u32); } diff --git a/tests/ui/mistyped_literal_suffix.stderr b/tests/ui/mistyped_literal_suffix.stderr index ecd73497a8e7..13577b9d39c5 100644 --- a/tests/ui/mistyped_literal_suffix.stderr +++ b/tests/ui/mistyped_literal_suffix.stderr @@ -13,85 +13,85 @@ LL | let fail15 = 4_64; | ^^^^ help: did you mean to write: `4_i64` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:18:18 + --> $DIR/mistyped_literal_suffix.rs:20:18 | LL | let fail16 = 7_8; // | ^^^ help: did you mean to write: `7_i8` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:19:18 + --> $DIR/mistyped_literal_suffix.rs:23:18 | LL | let fail17 = 23_16; // | ^^^^^ help: did you mean to write: `23_i16` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:22:18 + --> $DIR/mistyped_literal_suffix.rs:27:18 | LL | let fail20 = 2__8; // | ^^^^ help: did you mean to write: `2_i8` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:23:18 + --> $DIR/mistyped_literal_suffix.rs:30:18 | LL | let fail21 = 4___16; // | ^^^^^^ help: did you mean to write: `4_i16` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:26:18 + --> $DIR/mistyped_literal_suffix.rs:33:18 | LL | let fail25 = 1E2_32; | ^^^^^^ help: did you mean to write: `1E2_f32` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:27:18 + --> $DIR/mistyped_literal_suffix.rs:34:18 | LL | let fail26 = 43E7_64; | ^^^^^^^ help: did you mean to write: `43E7_f64` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:28:18 + --> $DIR/mistyped_literal_suffix.rs:35:18 | LL | let fail27 = 243E17_32; | ^^^^^^^^^ help: did you mean to write: `243E17_f32` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:29:18 + --> $DIR/mistyped_literal_suffix.rs:36:18 | LL | let fail28 = 241251235E723_64; | ^^^^^^^^^^^^^^^^ help: did you mean to write: `241_251_235E723_f64` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:33:18 + --> $DIR/mistyped_literal_suffix.rs:41:18 | LL | let fail30 = 127_8; // should be i8 | ^^^^^ help: did you mean to write: `127_i8` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:34:18 + --> $DIR/mistyped_literal_suffix.rs:44:18 | LL | let fail31 = 240_8; // should be u8 | ^^^^^ help: did you mean to write: `240_u8` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:36:18 + --> $DIR/mistyped_literal_suffix.rs:46:18 | LL | let fail33 = 0x1234_16; | ^^^^^^^^^ help: did you mean to write: `0x1234_i16` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:37:18 + --> $DIR/mistyped_literal_suffix.rs:47:18 | LL | let fail34 = 0xABCD_16; | ^^^^^^^^^ help: did you mean to write: `0xABCD_u16` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:39:18 + --> $DIR/mistyped_literal_suffix.rs:50:18 | LL | let fail36 = 0xFFFF_FFFF_FFFF_FFFF_64; // u64 | ^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean to write: `0xFFFF_FFFF_FFFF_FFFF_u64` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:45:13 + --> $DIR/mistyped_literal_suffix.rs:56:13 | LL | let _ = 1.12345E1_32; | ^^^^^^^^^^^^ help: did you mean to write: `1.123_45E1_f32` diff --git a/tests/ui/multiple_unsafe_ops_per_block.rs b/tests/ui/multiple_unsafe_ops_per_block.rs index 8afb4df20af4..66c78fe0ab77 100644 --- a/tests/ui/multiple_unsafe_ops_per_block.rs +++ b/tests/ui/multiple_unsafe_ops_per_block.rs @@ -33,6 +33,7 @@ union U { static mut STATIC: i32 = 0; fn test1() { + //~v multiple_unsafe_ops_per_block unsafe { STATIC += 1; not_very_safe(); @@ -42,6 +43,7 @@ fn test1() { fn test2() { let u = U { i: 0 }; + //~v multiple_unsafe_ops_per_block unsafe { drop(u.u); *raw_ptr(); @@ -49,6 +51,7 @@ fn test2() { } fn test3() { + //~v multiple_unsafe_ops_per_block unsafe { asm!("nop"); sample.not_very_safe(); @@ -58,6 +61,7 @@ fn test3() { fn test_all() { let u = U { i: 0 }; + //~v multiple_unsafe_ops_per_block unsafe { drop(u.u); drop(STATIC); @@ -103,6 +107,7 @@ fn correct3() { unsafe fn read_char_bad(ptr: *const u8) -> char { unsafe { char::from_u32_unchecked(*ptr.cast::()) } + //~^ multiple_unsafe_ops_per_block } // no lint @@ -120,6 +125,7 @@ fn issue10259() { } fn _fn_ptr(x: unsafe fn()) { + //~v multiple_unsafe_ops_per_block unsafe { x(); x(); @@ -131,6 +137,7 @@ fn _assoc_const() { const X: unsafe fn(); } fn _f() { + //~v multiple_unsafe_ops_per_block unsafe { T::X(); T::X(); @@ -141,6 +148,7 @@ fn _assoc_const() { fn _field_fn_ptr(x: unsafe fn()) { struct X(unsafe fn()); let x = X(x); + //~v multiple_unsafe_ops_per_block unsafe { x.0(); x.0(); diff --git a/tests/ui/multiple_unsafe_ops_per_block.stderr b/tests/ui/multiple_unsafe_ops_per_block.stderr index 4803a5089ab2..d6848ea0c3e3 100644 --- a/tests/ui/multiple_unsafe_ops_per_block.stderr +++ b/tests/ui/multiple_unsafe_ops_per_block.stderr @@ -1,5 +1,5 @@ error: this `unsafe` block contains 2 unsafe operations, expected only one - --> $DIR/multiple_unsafe_ops_per_block.rs:36:5 + --> $DIR/multiple_unsafe_ops_per_block.rs:37:5 | LL | / unsafe { LL | | STATIC += 1; @@ -8,12 +8,12 @@ LL | | } | |_____^ | note: modification of a mutable static occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:37:9 + --> $DIR/multiple_unsafe_ops_per_block.rs:38:9 | LL | STATIC += 1; | ^^^^^^^^^^^ note: unsafe function call occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:38:9 + --> $DIR/multiple_unsafe_ops_per_block.rs:39:9 | LL | not_very_safe(); | ^^^^^^^^^^^^^^^ @@ -21,7 +21,7 @@ LL | not_very_safe(); = help: to override `-D warnings` add `#[allow(clippy::multiple_unsafe_ops_per_block)]` error: this `unsafe` block contains 2 unsafe operations, expected only one - --> $DIR/multiple_unsafe_ops_per_block.rs:45:5 + --> $DIR/multiple_unsafe_ops_per_block.rs:47:5 | LL | / unsafe { LL | | drop(u.u); @@ -30,18 +30,18 @@ LL | | } | |_____^ | note: union field access occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:46:14 + --> $DIR/multiple_unsafe_ops_per_block.rs:48:14 | LL | drop(u.u); | ^^^ note: raw pointer dereference occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:47:9 + --> $DIR/multiple_unsafe_ops_per_block.rs:49:9 | LL | *raw_ptr(); | ^^^^^^^^^^ error: this `unsafe` block contains 3 unsafe operations, expected only one - --> $DIR/multiple_unsafe_ops_per_block.rs:52:5 + --> $DIR/multiple_unsafe_ops_per_block.rs:55:5 | LL | / unsafe { LL | | asm!("nop"); @@ -51,23 +51,23 @@ LL | | } | |_____^ | note: inline assembly used here - --> $DIR/multiple_unsafe_ops_per_block.rs:53:9 + --> $DIR/multiple_unsafe_ops_per_block.rs:56:9 | LL | asm!("nop"); | ^^^^^^^^^^^ note: unsafe method call occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:54:9 + --> $DIR/multiple_unsafe_ops_per_block.rs:57:9 | LL | sample.not_very_safe(); | ^^^^^^^^^^^^^^^^^^^^^^ note: modification of a mutable static occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:55:9 + --> $DIR/multiple_unsafe_ops_per_block.rs:58:9 | LL | STATIC = 0; | ^^^^^^^^^^ error: this `unsafe` block contains 6 unsafe operations, expected only one - --> $DIR/multiple_unsafe_ops_per_block.rs:61:5 + --> $DIR/multiple_unsafe_ops_per_block.rs:65:5 | LL | / unsafe { LL | | drop(u.u); @@ -79,55 +79,55 @@ LL | | } | |_____^ | note: union field access occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:62:14 + --> $DIR/multiple_unsafe_ops_per_block.rs:66:14 | LL | drop(u.u); | ^^^ note: access of a mutable static occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:63:14 + --> $DIR/multiple_unsafe_ops_per_block.rs:67:14 | LL | drop(STATIC); | ^^^^^^ note: unsafe method call occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:64:9 + --> $DIR/multiple_unsafe_ops_per_block.rs:68:9 | LL | sample.not_very_safe(); | ^^^^^^^^^^^^^^^^^^^^^^ note: unsafe function call occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:65:9 + --> $DIR/multiple_unsafe_ops_per_block.rs:69:9 | LL | not_very_safe(); | ^^^^^^^^^^^^^^^ note: raw pointer dereference occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:66:9 + --> $DIR/multiple_unsafe_ops_per_block.rs:70:9 | LL | *raw_ptr(); | ^^^^^^^^^^ note: inline assembly used here - --> $DIR/multiple_unsafe_ops_per_block.rs:67:9 + --> $DIR/multiple_unsafe_ops_per_block.rs:71:9 | LL | asm!("nop"); | ^^^^^^^^^^^ error: this `unsafe` block contains 2 unsafe operations, expected only one - --> $DIR/multiple_unsafe_ops_per_block.rs:105:5 + --> $DIR/multiple_unsafe_ops_per_block.rs:109:5 | LL | unsafe { char::from_u32_unchecked(*ptr.cast::()) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: unsafe function call occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:105:14 + --> $DIR/multiple_unsafe_ops_per_block.rs:109:14 | LL | unsafe { char::from_u32_unchecked(*ptr.cast::()) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: raw pointer dereference occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:105:39 + --> $DIR/multiple_unsafe_ops_per_block.rs:109:39 | LL | unsafe { char::from_u32_unchecked(*ptr.cast::()) } | ^^^^^^^^^^^^^^^^^^ error: this `unsafe` block contains 2 unsafe operations, expected only one - --> $DIR/multiple_unsafe_ops_per_block.rs:123:5 + --> $DIR/multiple_unsafe_ops_per_block.rs:129:5 | LL | / unsafe { LL | | x(); @@ -136,18 +136,18 @@ LL | | } | |_____^ | note: unsafe function call occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:124:9 + --> $DIR/multiple_unsafe_ops_per_block.rs:130:9 | LL | x(); | ^^^ note: unsafe function call occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:125:9 + --> $DIR/multiple_unsafe_ops_per_block.rs:131:9 | LL | x(); | ^^^ error: this `unsafe` block contains 2 unsafe operations, expected only one - --> $DIR/multiple_unsafe_ops_per_block.rs:134:9 + --> $DIR/multiple_unsafe_ops_per_block.rs:141:9 | LL | / unsafe { LL | | T::X(); @@ -156,18 +156,18 @@ LL | | } | |_________^ | note: unsafe function call occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:135:13 + --> $DIR/multiple_unsafe_ops_per_block.rs:142:13 | LL | T::X(); | ^^^^^^ note: unsafe function call occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:136:13 + --> $DIR/multiple_unsafe_ops_per_block.rs:143:13 | LL | T::X(); | ^^^^^^ error: this `unsafe` block contains 2 unsafe operations, expected only one - --> $DIR/multiple_unsafe_ops_per_block.rs:144:5 + --> $DIR/multiple_unsafe_ops_per_block.rs:152:5 | LL | / unsafe { LL | | x.0(); @@ -176,12 +176,12 @@ LL | | } | |_____^ | note: unsafe function call occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:145:9 + --> $DIR/multiple_unsafe_ops_per_block.rs:153:9 | LL | x.0(); | ^^^^^ note: unsafe function call occurs here - --> $DIR/multiple_unsafe_ops_per_block.rs:146:9 + --> $DIR/multiple_unsafe_ops_per_block.rs:154:9 | LL | x.0(); | ^^^^^ diff --git a/tests/ui/must_use_candidates.fixed b/tests/ui/must_use_candidates.fixed index c057eba4aca1..6d57db21b2d2 100644 --- a/tests/ui/must_use_candidates.fixed +++ b/tests/ui/must_use_candidates.fixed @@ -8,11 +8,13 @@ use std::sync::Arc; pub struct MyAtomic(AtomicBool); pub struct MyPure; +//~v must_use_candidate #[must_use] pub fn pure(i: u8) -> u8 { i } impl MyPure { + //~v must_use_candidate #[must_use] pub fn inherent_pure(&self) -> u8 { 0 } @@ -44,6 +46,7 @@ pub fn with_callback bool>(f: &F) -> bool { f(0) } +//~v must_use_candidate #[must_use] pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool { true } @@ -56,6 +59,7 @@ pub fn atomics(b: &AtomicBool) -> bool { b.load(Ordering::SeqCst) } +//~v must_use_candidate #[must_use] pub fn rcd(_x: Rc) -> bool { true } @@ -64,6 +68,7 @@ pub fn rcmut(_x: Rc<&mut u32>) -> bool { true } +//~v must_use_candidate #[must_use] pub fn arcd(_x: Arc) -> bool { false } diff --git a/tests/ui/must_use_candidates.rs b/tests/ui/must_use_candidates.rs index 360196520062..8904d476db7a 100644 --- a/tests/ui/must_use_candidates.rs +++ b/tests/ui/must_use_candidates.rs @@ -8,11 +8,13 @@ use std::sync::Arc; pub struct MyAtomic(AtomicBool); pub struct MyPure; +//~v must_use_candidate pub fn pure(i: u8) -> u8 { i } impl MyPure { + //~v must_use_candidate pub fn inherent_pure(&self) -> u8 { 0 } @@ -44,6 +46,7 @@ pub fn with_callback bool>(f: &F) -> bool { f(0) } +//~v must_use_candidate pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool { true } @@ -56,6 +59,7 @@ pub fn atomics(b: &AtomicBool) -> bool { b.load(Ordering::SeqCst) } +//~v must_use_candidate pub fn rcd(_x: Rc) -> bool { true } @@ -64,6 +68,7 @@ pub fn rcmut(_x: Rc<&mut u32>) -> bool { true } +//~v must_use_candidate pub fn arcd(_x: Arc) -> bool { false } diff --git a/tests/ui/must_use_candidates.stderr b/tests/ui/must_use_candidates.stderr index 98175dbd4584..4b03acad96be 100644 --- a/tests/ui/must_use_candidates.stderr +++ b/tests/ui/must_use_candidates.stderr @@ -1,5 +1,5 @@ error: this function could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:11:1 + --> $DIR/must_use_candidates.rs:12:1 | LL | pub fn pure(i: u8) -> u8 { | ^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn pure(i: u8) -> u8` @@ -8,25 +8,25 @@ LL | pub fn pure(i: u8) -> u8 { = help: to override `-D warnings` add `#[allow(clippy::must_use_candidate)]` error: this method could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:16:5 + --> $DIR/must_use_candidates.rs:18:5 | LL | pub fn inherent_pure(&self) -> u8 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn inherent_pure(&self) -> u8` error: this function could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:47:1 + --> $DIR/must_use_candidates.rs:50:1 | LL | pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool` error: this function could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:59:1 + --> $DIR/must_use_candidates.rs:63:1 | LL | pub fn rcd(_x: Rc) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn rcd(_x: Rc) -> bool` error: this function could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:67:1 + --> $DIR/must_use_candidates.rs:72:1 | LL | pub fn arcd(_x: Arc) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn arcd(_x: Arc) -> bool` diff --git a/tests/ui/must_use_unit.fixed b/tests/ui/must_use_unit.fixed index 75f91e668242..7f45efad4c92 100644 --- a/tests/ui/must_use_unit.fixed +++ b/tests/ui/must_use_unit.fixed @@ -7,13 +7,13 @@ extern crate proc_macros; use proc_macros::external; -pub fn must_use_default() {} +pub fn must_use_default() {} //~ must_use_unit -pub fn must_use_unit() -> () {} +pub fn must_use_unit() -> () {} //~ must_use_unit -pub fn must_use_with_note() {} +pub fn must_use_with_note() {} //~ must_use_unit fn main() { must_use_default(); diff --git a/tests/ui/must_use_unit.rs b/tests/ui/must_use_unit.rs index 1305910ed0e5..6cb0ceb6713a 100644 --- a/tests/ui/must_use_unit.rs +++ b/tests/ui/must_use_unit.rs @@ -7,13 +7,13 @@ extern crate proc_macros; use proc_macros::external; #[must_use] -pub fn must_use_default() {} +pub fn must_use_default() {} //~ must_use_unit #[must_use] -pub fn must_use_unit() -> () {} +pub fn must_use_unit() -> () {} //~ must_use_unit #[must_use = "With note"] -pub fn must_use_with_note() {} +pub fn must_use_with_note() {} //~ must_use_unit fn main() { must_use_default(); diff --git a/tests/ui/mut_mut.rs b/tests/ui/mut_mut.rs index 72a171119f3c..d0c515909263 100644 --- a/tests/ui/mut_mut.rs +++ b/tests/ui/mut_mut.rs @@ -11,6 +11,7 @@ extern crate proc_macros; use proc_macros::{external, inline_macros}; +//~v mut_mut fn fun(x: &mut &mut u32) -> bool { **x > 0 } @@ -28,22 +29,27 @@ macro_rules! mut_ptr { #[allow(unused_mut, unused_variables)] #[inline_macros] fn main() { - let mut x = &mut &mut 1u32; + let mut x = &mut &mut 1u32; //~ mut_mut { - let mut y = &mut x; + let mut y = &mut x; //~ mut_mut } if fun(x) { let y: &mut &mut u32 = &mut &mut 2; + //~^ mut_mut + //~| mut_mut **y + **x; } if fun(x) { let y: &mut &mut &mut u32 = &mut &mut &mut 2; + //~^ mut_mut + //~| mut_mut + //~| mut_mut ***y + **x; } - let mut z = inline!(&mut $(&mut 3u32)); + let mut z = inline!(&mut $(&mut 3u32)); //~ mut_mut } fn issue939() { diff --git a/tests/ui/mut_mut.stderr b/tests/ui/mut_mut.stderr index 5ed9cd1aff99..426fbae07f26 100644 --- a/tests/ui/mut_mut.stderr +++ b/tests/ui/mut_mut.stderr @@ -1,5 +1,5 @@ error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:14:11 + --> $DIR/mut_mut.rs:15:11 | LL | fn fun(x: &mut &mut u32) -> bool { | ^^^^^^^^^^^^^ @@ -8,13 +8,13 @@ LL | fn fun(x: &mut &mut u32) -> bool { = help: to override `-D warnings` add `#[allow(clippy::mut_mut)]` error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:31:17 + --> $DIR/mut_mut.rs:32:17 | LL | let mut x = &mut &mut 1u32; | ^^^^^^^^^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:46:25 + --> $DIR/mut_mut.rs:52:25 | LL | let mut z = inline!(&mut $(&mut 3u32)); | ^ @@ -22,37 +22,37 @@ LL | let mut z = inline!(&mut $(&mut 3u32)); = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: this expression mutably borrows a mutable reference. Consider reborrowing - --> $DIR/mut_mut.rs:33:21 + --> $DIR/mut_mut.rs:34:21 | LL | let mut y = &mut x; | ^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:37:32 + --> $DIR/mut_mut.rs:38:32 | LL | let y: &mut &mut u32 = &mut &mut 2; | ^^^^^^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:37:16 + --> $DIR/mut_mut.rs:38:16 | LL | let y: &mut &mut u32 = &mut &mut 2; | ^^^^^^^^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:42:37 + --> $DIR/mut_mut.rs:45:37 | LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2; | ^^^^^^^^^^^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:42:16 + --> $DIR/mut_mut.rs:45:16 | LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2; | ^^^^^^^^^^^^^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:42:21 + --> $DIR/mut_mut.rs:45:21 | LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2; | ^^^^^^^^^^^^^ diff --git a/tests/ui/mut_mutex_lock.fixed b/tests/ui/mut_mutex_lock.fixed index bbedbb2bed23..e8836d7cd6bf 100644 --- a/tests/ui/mut_mutex_lock.fixed +++ b/tests/ui/mut_mutex_lock.fixed @@ -7,7 +7,7 @@ fn mut_mutex_lock() { let mut value_rc = Arc::new(Mutex::new(42_u8)); let value_mutex = Arc::get_mut(&mut value_rc).unwrap(); - let mut value = value_mutex.get_mut().unwrap(); + let mut value = value_mutex.get_mut().unwrap(); //~ mut_mutex_lock *value += 1; } diff --git a/tests/ui/mut_mutex_lock.rs b/tests/ui/mut_mutex_lock.rs index 74116100e82a..6989b8c3888b 100644 --- a/tests/ui/mut_mutex_lock.rs +++ b/tests/ui/mut_mutex_lock.rs @@ -7,7 +7,7 @@ fn mut_mutex_lock() { let mut value_rc = Arc::new(Mutex::new(42_u8)); let value_mutex = Arc::get_mut(&mut value_rc).unwrap(); - let mut value = value_mutex.lock().unwrap(); + let mut value = value_mutex.lock().unwrap(); //~ mut_mutex_lock *value += 1; } diff --git a/tests/ui/needless_arbitrary_self_type.fixed b/tests/ui/needless_arbitrary_self_type.fixed index 9da60c687d44..a2035ffeca62 100644 --- a/tests/ui/needless_arbitrary_self_type.fixed +++ b/tests/ui/needless_arbitrary_self_type.fixed @@ -7,6 +7,7 @@ pub enum ValType { } impl ValType { + //~v needless_arbitrary_self_type pub fn bad(self) { unimplemented!(); } @@ -15,6 +16,7 @@ impl ValType { unimplemented!(); } + //~v needless_arbitrary_self_type pub fn mut_bad(mut self) { unimplemented!(); } @@ -23,6 +25,7 @@ impl ValType { unimplemented!(); } + //~v needless_arbitrary_self_type pub fn ref_bad(&self) { unimplemented!(); } @@ -31,6 +34,7 @@ impl ValType { unimplemented!(); } + //~v needless_arbitrary_self_type pub fn ref_bad_with_lifetime<'a>(&'a self) { unimplemented!(); } @@ -39,6 +43,7 @@ impl ValType { unimplemented!(); } + //~v needless_arbitrary_self_type pub fn mut_ref_bad(&mut self) { unimplemented!(); } @@ -47,6 +52,7 @@ impl ValType { unimplemented!(); } + //~v needless_arbitrary_self_type pub fn mut_ref_bad_with_lifetime<'a>(&'a mut self) { unimplemented!(); } diff --git a/tests/ui/needless_arbitrary_self_type.rs b/tests/ui/needless_arbitrary_self_type.rs index fc4ec5cb0b3c..aeadc4387cf1 100644 --- a/tests/ui/needless_arbitrary_self_type.rs +++ b/tests/ui/needless_arbitrary_self_type.rs @@ -7,6 +7,7 @@ pub enum ValType { } impl ValType { + //~v needless_arbitrary_self_type pub fn bad(self: Self) { unimplemented!(); } @@ -15,6 +16,7 @@ impl ValType { unimplemented!(); } + //~v needless_arbitrary_self_type pub fn mut_bad(mut self: Self) { unimplemented!(); } @@ -23,6 +25,7 @@ impl ValType { unimplemented!(); } + //~v needless_arbitrary_self_type pub fn ref_bad(self: &Self) { unimplemented!(); } @@ -31,6 +34,7 @@ impl ValType { unimplemented!(); } + //~v needless_arbitrary_self_type pub fn ref_bad_with_lifetime<'a>(self: &'a Self) { unimplemented!(); } @@ -39,6 +43,7 @@ impl ValType { unimplemented!(); } + //~v needless_arbitrary_self_type pub fn mut_ref_bad(self: &mut Self) { unimplemented!(); } @@ -47,6 +52,7 @@ impl ValType { unimplemented!(); } + //~v needless_arbitrary_self_type pub fn mut_ref_bad_with_lifetime<'a>(self: &'a mut Self) { unimplemented!(); } diff --git a/tests/ui/needless_arbitrary_self_type.stderr b/tests/ui/needless_arbitrary_self_type.stderr index fe2ac34f79f6..84c562be1b57 100644 --- a/tests/ui/needless_arbitrary_self_type.stderr +++ b/tests/ui/needless_arbitrary_self_type.stderr @@ -1,5 +1,5 @@ error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:10:16 + --> $DIR/needless_arbitrary_self_type.rs:11:16 | LL | pub fn bad(self: Self) { | ^^^^^^^^^^ help: consider to change this parameter to: `self` @@ -8,31 +8,31 @@ LL | pub fn bad(self: Self) { = help: to override `-D warnings` add `#[allow(clippy::needless_arbitrary_self_type)]` error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:18:20 + --> $DIR/needless_arbitrary_self_type.rs:20:20 | LL | pub fn mut_bad(mut self: Self) { | ^^^^^^^^^^^^^^ help: consider to change this parameter to: `mut self` error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:26:20 + --> $DIR/needless_arbitrary_self_type.rs:29:20 | LL | pub fn ref_bad(self: &Self) { | ^^^^^^^^^^^ help: consider to change this parameter to: `&self` error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:34:38 + --> $DIR/needless_arbitrary_self_type.rs:38:38 | LL | pub fn ref_bad_with_lifetime<'a>(self: &'a Self) { | ^^^^^^^^^^^^^^ help: consider to change this parameter to: `&'a self` error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:42:24 + --> $DIR/needless_arbitrary_self_type.rs:47:24 | LL | pub fn mut_ref_bad(self: &mut Self) { | ^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&mut self` error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:50:42 + --> $DIR/needless_arbitrary_self_type.rs:56:42 | LL | pub fn mut_ref_bad_with_lifetime<'a>(self: &'a mut Self) { | ^^^^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&'a mut self` diff --git a/tests/ui/needless_arbitrary_self_type_unfixable.fixed b/tests/ui/needless_arbitrary_self_type_unfixable.fixed index 62a6e5932435..f4ee0a8bd072 100644 --- a/tests/ui/needless_arbitrary_self_type_unfixable.fixed +++ b/tests/ui/needless_arbitrary_self_type_unfixable.fixed @@ -40,6 +40,7 @@ mod issue_6089 { impl T2 for S2 { #[allow(clippy::needless_lifetimes)] fn call_with_mut_self(&mut self) {} + //~^ needless_arbitrary_self_type } } diff --git a/tests/ui/needless_arbitrary_self_type_unfixable.rs b/tests/ui/needless_arbitrary_self_type_unfixable.rs index 00871f9f450c..3f29025c1362 100644 --- a/tests/ui/needless_arbitrary_self_type_unfixable.rs +++ b/tests/ui/needless_arbitrary_self_type_unfixable.rs @@ -40,6 +40,7 @@ mod issue_6089 { impl T2 for S2 { #[allow(clippy::needless_lifetimes)] fn call_with_mut_self(self: &mut Self) {} + //~^ needless_arbitrary_self_type } } diff --git a/tests/ui/needless_bitwise_bool.fixed b/tests/ui/needless_bitwise_bool.fixed index 201f8a4c19de..48de96aba3b6 100644 --- a/tests/ui/needless_bitwise_bool.fixed +++ b/tests/ui/needless_bitwise_bool.fixed @@ -19,6 +19,7 @@ fn main() { if !returns_bool() & returns_bool() { println!("true") } + //~v needless_bitwise_bool if y && !x { println!("true") } diff --git a/tests/ui/needless_bitwise_bool.rs b/tests/ui/needless_bitwise_bool.rs index b0e5014b74b7..a7ab0bfa9fc5 100644 --- a/tests/ui/needless_bitwise_bool.rs +++ b/tests/ui/needless_bitwise_bool.rs @@ -19,6 +19,7 @@ fn main() { if !returns_bool() & returns_bool() { println!("true") } + //~v needless_bitwise_bool if y & !x { println!("true") } diff --git a/tests/ui/needless_bitwise_bool.stderr b/tests/ui/needless_bitwise_bool.stderr index b1fc1a7a9585..6f2c99758f60 100644 --- a/tests/ui/needless_bitwise_bool.stderr +++ b/tests/ui/needless_bitwise_bool.stderr @@ -1,5 +1,5 @@ error: use of bitwise operator instead of lazy operator between booleans - --> $DIR/needless_bitwise_bool.rs:22:8 + --> $DIR/needless_bitwise_bool.rs:23:8 | LL | if y & !x { | ^^^^^^ help: try: `y && !x` diff --git a/tests/ui/needless_bool/fixable.fixed b/tests/ui/needless_bool/fixable.fixed index 3059de8f89c4..ce1a4c781959 100644 --- a/tests/ui/needless_bool/fixable.fixed +++ b/tests/ui/needless_bool/fixable.fixed @@ -38,17 +38,26 @@ macro_rules! bool_comparison_trigger { fn main() { let x = true; let y = false; + //~v needless_bool x; + //~v needless_bool !x; + //~v needless_bool !(x && y); let a = 0; let b = 1; + //~v needless_bool a != b; + //~v needless_bool a == b; + //~v needless_bool a >= b; + //~v needless_bool a > b; + //~v needless_bool a <= b; + //~v needless_bool a < b; if x { x @@ -73,27 +82,31 @@ fn main() { } fn bool_ret3(x: bool) -> bool { + //~v needless_bool return x; } fn bool_ret4(x: bool) -> bool { + //~v needless_bool return !x; } fn bool_ret5(x: bool, y: bool) -> bool { + //~v needless_bool return x && y; } fn bool_ret6(x: bool, y: bool) -> bool { + //~v needless_bool return !(x && y); } fn needless_bool(x: bool) { - if x {}; + if x {}; //~ bool_comparison } fn needless_bool2(x: bool) { - if !x {}; + if !x {}; //~ bool_comparison } fn needless_bool3(x: bool) { @@ -103,8 +116,8 @@ fn needless_bool3(x: bool) { test_two: true, true; } - if x {}; - if !x {}; + if x {}; //~ bool_comparison + if !x {}; //~ bool_comparison } fn needless_bool_in_the_suggestion_wraps_the_predicate_of_if_else_statement_in_brackets() { @@ -113,6 +126,7 @@ fn needless_bool_in_the_suggestion_wraps_the_predicate_of_if_else_statement_in_b let x = if b { true + //~v needless_bool } else { !returns_bool() }; } @@ -122,11 +136,14 @@ unsafe fn no(v: u8) -> u8 { #[allow(clippy::unnecessary_operation)] fn needless_bool_condition() -> bool { + //~v needless_bool (unsafe { no(4) } & 1 != 0); let _brackets_unneeded = unsafe { no(4) } & 1 != 0; + //~^ needless_bool fn foo() -> bool { // parentheses are needed here (unsafe { no(4) } & 1 != 0) + //~^ needless_bool } foo() diff --git a/tests/ui/needless_bool/fixable.rs b/tests/ui/needless_bool/fixable.rs index b2cbe86e2235..e50899828e27 100644 --- a/tests/ui/needless_bool/fixable.rs +++ b/tests/ui/needless_bool/fixable.rs @@ -38,16 +38,19 @@ macro_rules! bool_comparison_trigger { fn main() { let x = true; let y = false; + //~v needless_bool if x { true } else { false }; + //~v needless_bool if x { false } else { true }; + //~v needless_bool if x && y { false } else { @@ -56,31 +59,37 @@ fn main() { let a = 0; let b = 1; + //~v needless_bool if a == b { false } else { true }; + //~v needless_bool if a != b { false } else { true }; + //~v needless_bool if a < b { false } else { true }; + //~v needless_bool if a <= b { false } else { true }; + //~v needless_bool if a > b { false } else { true }; + //~v needless_bool if a >= b { false } else { @@ -109,6 +118,7 @@ fn main() { } fn bool_ret3(x: bool) -> bool { + //~v needless_bool if x { return true; } else { @@ -117,6 +127,7 @@ fn bool_ret3(x: bool) -> bool { } fn bool_ret4(x: bool) -> bool { + //~v needless_bool if x { return false; } else { @@ -125,6 +136,7 @@ fn bool_ret4(x: bool) -> bool { } fn bool_ret5(x: bool, y: bool) -> bool { + //~v needless_bool if x && y { return true; } else { @@ -133,6 +145,7 @@ fn bool_ret5(x: bool, y: bool) -> bool { } fn bool_ret6(x: bool, y: bool) -> bool { + //~v needless_bool if x && y { return false; } else { @@ -141,11 +154,11 @@ fn bool_ret6(x: bool, y: bool) -> bool { } fn needless_bool(x: bool) { - if x == true {}; + if x == true {}; //~ bool_comparison } fn needless_bool2(x: bool) { - if x == false {}; + if x == false {}; //~ bool_comparison } fn needless_bool3(x: bool) { @@ -155,8 +168,8 @@ fn needless_bool3(x: bool) { test_two: true, true; } - if x == true {}; - if x == false {}; + if x == true {}; //~ bool_comparison + if x == false {}; //~ bool_comparison } fn needless_bool_in_the_suggestion_wraps_the_predicate_of_if_else_statement_in_brackets() { @@ -165,6 +178,7 @@ fn needless_bool_in_the_suggestion_wraps_the_predicate_of_if_else_statement_in_b let x = if b { true + //~v needless_bool } else if returns_bool() { false } else { @@ -178,15 +192,18 @@ unsafe fn no(v: u8) -> u8 { #[allow(clippy::unnecessary_operation)] fn needless_bool_condition() -> bool { + //~v needless_bool if unsafe { no(4) } & 1 != 0 { true } else { false }; let _brackets_unneeded = if unsafe { no(4) } & 1 != 0 { true } else { false }; + //~^ needless_bool fn foo() -> bool { // parentheses are needed here if unsafe { no(4) } & 1 != 0 { true } else { false } + //~^ needless_bool } foo() diff --git a/tests/ui/needless_bool/fixable.stderr b/tests/ui/needless_bool/fixable.stderr index 67018d8d7063..fc3308efc91e 100644 --- a/tests/ui/needless_bool/fixable.stderr +++ b/tests/ui/needless_bool/fixable.stderr @@ -1,5 +1,5 @@ error: this if-then-else expression returns a bool literal - --> $DIR/needless_bool/fixable.rs:41:5 + --> $DIR/needless_bool/fixable.rs:42:5 | LL | / if x { LL | | true @@ -12,7 +12,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::needless_bool)]` error: this if-then-else expression returns a bool literal - --> $DIR/needless_bool/fixable.rs:46:5 + --> $DIR/needless_bool/fixable.rs:48:5 | LL | / if x { LL | | false @@ -22,7 +22,7 @@ LL | | }; | |_____^ help: you can reduce it to: `!x` error: this if-then-else expression returns a bool literal - --> $DIR/needless_bool/fixable.rs:51:5 + --> $DIR/needless_bool/fixable.rs:54:5 | LL | / if x && y { LL | | false @@ -32,7 +32,7 @@ LL | | }; | |_____^ help: you can reduce it to: `!(x && y)` error: this if-then-else expression returns a bool literal - --> $DIR/needless_bool/fixable.rs:59:5 + --> $DIR/needless_bool/fixable.rs:63:5 | LL | / if a == b { LL | | false @@ -42,7 +42,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a != b` error: this if-then-else expression returns a bool literal - --> $DIR/needless_bool/fixable.rs:64:5 + --> $DIR/needless_bool/fixable.rs:69:5 | LL | / if a != b { LL | | false @@ -52,7 +52,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a == b` error: this if-then-else expression returns a bool literal - --> $DIR/needless_bool/fixable.rs:69:5 + --> $DIR/needless_bool/fixable.rs:75:5 | LL | / if a < b { LL | | false @@ -62,7 +62,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a >= b` error: this if-then-else expression returns a bool literal - --> $DIR/needless_bool/fixable.rs:74:5 + --> $DIR/needless_bool/fixable.rs:81:5 | LL | / if a <= b { LL | | false @@ -72,7 +72,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a > b` error: this if-then-else expression returns a bool literal - --> $DIR/needless_bool/fixable.rs:79:5 + --> $DIR/needless_bool/fixable.rs:87:5 | LL | / if a > b { LL | | false @@ -82,7 +82,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a <= b` error: this if-then-else expression returns a bool literal - --> $DIR/needless_bool/fixable.rs:84:5 + --> $DIR/needless_bool/fixable.rs:93:5 | LL | / if a >= b { LL | | false @@ -92,7 +92,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a < b` error: this if-then-else expression returns a bool literal - --> $DIR/needless_bool/fixable.rs:112:5 + --> $DIR/needless_bool/fixable.rs:122:5 | LL | / if x { LL | | return true; @@ -102,7 +102,7 @@ LL | | }; | |_____^ help: you can reduce it to: `return x` error: this if-then-else expression returns a bool literal - --> $DIR/needless_bool/fixable.rs:120:5 + --> $DIR/needless_bool/fixable.rs:131:5 | LL | / if x { LL | | return false; @@ -112,7 +112,7 @@ LL | | }; | |_____^ help: you can reduce it to: `return !x` error: this if-then-else expression returns a bool literal - --> $DIR/needless_bool/fixable.rs:128:5 + --> $DIR/needless_bool/fixable.rs:140:5 | LL | / if x && y { LL | | return true; @@ -122,7 +122,7 @@ LL | | }; | |_____^ help: you can reduce it to: `return x && y` error: this if-then-else expression returns a bool literal - --> $DIR/needless_bool/fixable.rs:136:5 + --> $DIR/needless_bool/fixable.rs:149:5 | LL | / if x && y { LL | | return false; @@ -132,7 +132,7 @@ LL | | }; | |_____^ help: you can reduce it to: `return !(x && y)` error: equality checks against true are unnecessary - --> $DIR/needless_bool/fixable.rs:144:8 + --> $DIR/needless_bool/fixable.rs:157:8 | LL | if x == true {}; | ^^^^^^^^^ help: try simplifying it as shown: `x` @@ -141,25 +141,25 @@ LL | if x == true {}; = help: to override `-D warnings` add `#[allow(clippy::bool_comparison)]` error: equality checks against false can be replaced by a negation - --> $DIR/needless_bool/fixable.rs:148:8 + --> $DIR/needless_bool/fixable.rs:161:8 | LL | if x == false {}; | ^^^^^^^^^^ help: try simplifying it as shown: `!x` error: equality checks against true are unnecessary - --> $DIR/needless_bool/fixable.rs:158:8 + --> $DIR/needless_bool/fixable.rs:171:8 | LL | if x == true {}; | ^^^^^^^^^ help: try simplifying it as shown: `x` error: equality checks against false can be replaced by a negation - --> $DIR/needless_bool/fixable.rs:159:8 + --> $DIR/needless_bool/fixable.rs:172:8 | LL | if x == false {}; | ^^^^^^^^^^ help: try simplifying it as shown: `!x` error: this if-then-else expression returns a bool literal - --> $DIR/needless_bool/fixable.rs:168:12 + --> $DIR/needless_bool/fixable.rs:182:12 | LL | } else if returns_bool() { | ____________^ @@ -170,7 +170,7 @@ LL | | }; | |_____^ help: you can reduce it to: `{ !returns_bool() }` error: this if-then-else expression returns a bool literal - --> $DIR/needless_bool/fixable.rs:181:5 + --> $DIR/needless_bool/fixable.rs:196:5 | LL | / if unsafe { no(4) } & 1 != 0 { LL | | true @@ -180,13 +180,13 @@ LL | | }; | |_____^ help: you can reduce it to: `(unsafe { no(4) } & 1 != 0)` error: this if-then-else expression returns a bool literal - --> $DIR/needless_bool/fixable.rs:186:30 + --> $DIR/needless_bool/fixable.rs:201:30 | LL | let _brackets_unneeded = if unsafe { no(4) } & 1 != 0 { true } else { false }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `unsafe { no(4) } & 1 != 0` error: this if-then-else expression returns a bool literal - --> $DIR/needless_bool/fixable.rs:189:9 + --> $DIR/needless_bool/fixable.rs:205:9 | LL | if unsafe { no(4) } & 1 != 0 { true } else { false } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `(unsafe { no(4) } & 1 != 0)` diff --git a/tests/ui/needless_bool/simple.rs b/tests/ui/needless_bool/simple.rs index 588bb88f4461..20c3bc7ab30c 100644 --- a/tests/ui/needless_bool/simple.rs +++ b/tests/ui/needless_bool/simple.rs @@ -11,11 +11,13 @@ fn main() { let x = true; let y = false; + //~v needless_bool if x { true } else { true }; + //~v needless_bool if x { false } else { @@ -31,6 +33,7 @@ fn main() { } fn bool_ret(x: bool) -> bool { + //~v needless_bool if x { return true; } else { @@ -39,6 +42,7 @@ fn bool_ret(x: bool) -> bool { } fn bool_ret2(x: bool) -> bool { + //~v needless_bool if x { return false; } else { diff --git a/tests/ui/needless_bool/simple.stderr b/tests/ui/needless_bool/simple.stderr index 6846565b68e1..32343e9b49fb 100644 --- a/tests/ui/needless_bool/simple.stderr +++ b/tests/ui/needless_bool/simple.stderr @@ -1,5 +1,5 @@ error: this if-then-else expression will always return true - --> $DIR/needless_bool/simple.rs:14:5 + --> $DIR/needless_bool/simple.rs:15:5 | LL | / if x { LL | | true @@ -12,7 +12,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::needless_bool)]` error: this if-then-else expression will always return false - --> $DIR/needless_bool/simple.rs:19:5 + --> $DIR/needless_bool/simple.rs:21:5 | LL | / if x { LL | | false @@ -22,7 +22,7 @@ LL | | }; | |_____^ error: this if-then-else expression will always return true - --> $DIR/needless_bool/simple.rs:34:5 + --> $DIR/needless_bool/simple.rs:37:5 | LL | / if x { LL | | return true; @@ -32,7 +32,7 @@ LL | | }; | |_____^ error: this if-then-else expression will always return false - --> $DIR/needless_bool/simple.rs:42:5 + --> $DIR/needless_bool/simple.rs:46:5 | LL | / if x { LL | | return false; diff --git a/tests/ui/needless_bool_assign.fixed b/tests/ui/needless_bool_assign.fixed index 7b10fe78c681..693d957ee89b 100644 --- a/tests/ui/needless_bool_assign.fixed +++ b/tests/ui/needless_bool_assign.fixed @@ -10,7 +10,9 @@ fn main() { field: bool, }; let mut a = Data { field: false }; + //~v needless_bool_assign a.field = random() && random(); + //~v needless_bool_assign a.field = !(random() && random()); // Do not lint… if random() { @@ -21,6 +23,8 @@ fn main() { } // This one also triggers lint `clippy::if_same_then_else` // which does not suggest a rewrite. + //~| needless_bool_assign + //~v if_same_then_else random(); a.field = true; let mut b = false; if random() { diff --git a/tests/ui/needless_bool_assign.rs b/tests/ui/needless_bool_assign.rs index 85c0a5777fee..8522b6e5b296 100644 --- a/tests/ui/needless_bool_assign.rs +++ b/tests/ui/needless_bool_assign.rs @@ -10,11 +10,13 @@ fn main() { field: bool, }; let mut a = Data { field: false }; + //~v needless_bool_assign if random() && random() { a.field = true; } else { a.field = false } + //~v needless_bool_assign if random() && random() { a.field = false; } else { @@ -29,6 +31,8 @@ fn main() { } // This one also triggers lint `clippy::if_same_then_else` // which does not suggest a rewrite. + //~| needless_bool_assign + //~v if_same_then_else if random() { a.field = true; } else { diff --git a/tests/ui/needless_bool_assign.stderr b/tests/ui/needless_bool_assign.stderr index 244a88e6691f..733af7ae839b 100644 --- a/tests/ui/needless_bool_assign.stderr +++ b/tests/ui/needless_bool_assign.stderr @@ -1,5 +1,5 @@ error: this if-then-else expression assigns a bool literal - --> $DIR/needless_bool_assign.rs:13:5 + --> $DIR/needless_bool_assign.rs:14:5 | LL | / if random() && random() { LL | | a.field = true; @@ -12,7 +12,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::needless_bool_assign)]` error: this if-then-else expression assigns a bool literal - --> $DIR/needless_bool_assign.rs:18:5 + --> $DIR/needless_bool_assign.rs:20:5 | LL | / if random() && random() { LL | | a.field = false; @@ -22,7 +22,7 @@ LL | | } | |_____^ help: you can reduce it to: `a.field = !(random() && random());` error: this if-then-else expression assigns a bool literal - --> $DIR/needless_bool_assign.rs:32:5 + --> $DIR/needless_bool_assign.rs:36:5 | LL | / if random() { LL | | a.field = true; @@ -32,7 +32,7 @@ LL | | } | |_____^ help: you can reduce it to: `random(); a.field = true;` error: this `if` has identical blocks - --> $DIR/needless_bool_assign.rs:32:17 + --> $DIR/needless_bool_assign.rs:36:17 | LL | if random() { | _________________^ @@ -41,7 +41,7 @@ LL | | } else { | |_____^ | note: same as this - --> $DIR/needless_bool_assign.rs:34:12 + --> $DIR/needless_bool_assign.rs:38:12 | LL | } else { | ____________^ diff --git a/tests/ui/needless_borrow.fixed b/tests/ui/needless_borrow.fixed index 23e8bf8a468f..b26da0a3c6b1 100644 --- a/tests/ui/needless_borrow.fixed +++ b/tests/ui/needless_borrow.fixed @@ -12,10 +12,14 @@ fn main() { let a = 5; let ref_a = &a; let _ = x(&a); // no warning + + //~v needless_borrow let _ = x(&a); // warn let mut b = 5; mut_ref(&mut b); // no warning + + //~v needless_borrow mut_ref(&mut b); // warn let s = &String::from("hi"); @@ -28,38 +32,38 @@ fn main() { 44 => &a, 45 => { println!("foo"); - &a + &a //~ needless_borrow }, - 46 => &a, + 46 => &a, //~ needless_borrow 47 => { println!("foo"); loop { println!("{}", a); if a == 25 { - break ref_a; + break ref_a; //~ needless_borrow } } }, _ => panic!(), }; - let _ = x(&a); - let _ = x(&a); - let _ = x(&mut b); - let _ = x(ref_a); + let _ = x(&a); //~ needless_borrow + let _ = x(&a); //~ needless_borrow + let _ = x(&mut b); //~ needless_borrow + let _ = x(ref_a); //~ needless_borrow { let b = &mut b; - x(b); + x(b); //~ needless_borrow } // Issue #8191 let mut x = 5; let mut x = &mut x; - mut_ref(x); - mut_ref(x); - let y: &mut i32 = x; - let y: &mut i32 = x; + mut_ref(x); //~ needless_borrow + mut_ref(x); //~ needless_borrow + let y: &mut i32 = x; //~ needless_borrow + let y: &mut i32 = x; //~ needless_borrow let y = match 0 { // Don't lint. Removing the borrow would move 'x' @@ -68,13 +72,13 @@ fn main() { }; let y: &mut i32 = match 0 { // Lint here. The type given above triggers auto-borrow. - 0 => x, + 0 => x, //~ needless_borrow _ => &mut *x, }; fn ref_mut_i32(_: &mut i32) {} ref_mut_i32(match 0 { // Lint here. The type given above triggers auto-borrow. - 0 => x, + 0 => x, //~ needless_borrow _ => &mut *x, }); // use 'x' after to make sure it's still usable in the fixed code. @@ -86,9 +90,9 @@ fn main() { // let _ = (&&s).capacity(); let x = (1, 2); - let _ = x.0; + let _ = x.0; //~ needless_borrow let x = &x as *const (i32, i32); - let _ = unsafe { (*x).0 }; + let _ = unsafe { (*x).0 }; //~ needless_borrow // Issue #8367 trait Foo { @@ -98,7 +102,7 @@ fn main() { fn foo(self) {} } (&()).foo(); // Don't lint. `()` doesn't implement `Foo` - (&()).foo(); + (&()).foo(); //~ needless_borrow impl Foo for i32 { fn foo(self) {} @@ -107,7 +111,7 @@ fn main() { fn foo(self) {} } (&5).foo(); // Don't lint. `5` will call `::foo` - (&5).foo(); + (&5).foo(); //~ needless_borrow trait FooRef { fn foo_ref(&self); @@ -133,7 +137,7 @@ fn main() { } // issue #11786 - let x: (&str,) = ("",); + let x: (&str,) = ("",); //~ needless_borrow } #[allow(clippy::needless_borrowed_reference)] @@ -175,7 +179,7 @@ mod issue9160 { F: Fn() -> T, { fn calls_field(&self) -> T { - (self.f)() + (self.f)() //~ needless_borrow } } @@ -184,7 +188,7 @@ mod issue9160 { F: FnMut() -> T, { fn calls_mut_field(&mut self) -> T { - (self.f)() + (self.f)() //~ needless_borrow } } } @@ -221,19 +225,19 @@ fn issue9383() { u: ManuallyDrop::new(Foo { x: 0 }), }; let _ = &mut (&mut x.u).x; - let _ = &mut { x.u }.x; + let _ = &mut { x.u }.x; //~ needless_borrow let _ = &mut ({ &mut x.u }).x; let mut x = U { u: Wrap(ManuallyDrop::new(Foo { x: 0 })), }; let _ = &mut (&mut x.u).x; - let _ = &mut { x.u }.x; + let _ = &mut { x.u }.x; //~ needless_borrow let _ = &mut ({ &mut x.u }).x; let mut x = U { u: Wrap(Foo { x: 0 }) }; - let _ = &mut x.u.x; - let _ = &mut { x.u }.x; + let _ = &mut x.u.x; //~ needless_borrow + let _ = &mut { x.u }.x; //~ needless_borrow let _ = &mut ({ &mut x.u }).x; } } diff --git a/tests/ui/needless_borrow.rs b/tests/ui/needless_borrow.rs index 27771a8f15b3..7af533daf6cc 100644 --- a/tests/ui/needless_borrow.rs +++ b/tests/ui/needless_borrow.rs @@ -12,10 +12,14 @@ fn main() { let a = 5; let ref_a = &a; let _ = x(&a); // no warning + + //~v needless_borrow let _ = x(&&a); // warn let mut b = 5; mut_ref(&mut b); // no warning + + //~v needless_borrow mut_ref(&mut &mut b); // warn let s = &String::from("hi"); @@ -28,38 +32,38 @@ fn main() { 44 => &a, 45 => { println!("foo"); - &&a + &&a //~ needless_borrow }, - 46 => &&a, + 46 => &&a, //~ needless_borrow 47 => { println!("foo"); loop { println!("{}", a); if a == 25 { - break &ref_a; + break &ref_a; //~ needless_borrow } } }, _ => panic!(), }; - let _ = x(&&&a); - let _ = x(&mut &&a); - let _ = x(&&&mut b); - let _ = x(&&ref_a); + let _ = x(&&&a); //~ needless_borrow + let _ = x(&mut &&a); //~ needless_borrow + let _ = x(&&&mut b); //~ needless_borrow + let _ = x(&&ref_a); //~ needless_borrow { let b = &mut b; - x(&b); + x(&b); //~ needless_borrow } // Issue #8191 let mut x = 5; let mut x = &mut x; - mut_ref(&mut x); - mut_ref(&mut &mut x); - let y: &mut i32 = &mut x; - let y: &mut i32 = &mut &mut x; + mut_ref(&mut x); //~ needless_borrow + mut_ref(&mut &mut x); //~ needless_borrow + let y: &mut i32 = &mut x; //~ needless_borrow + let y: &mut i32 = &mut &mut x; //~ needless_borrow let y = match 0 { // Don't lint. Removing the borrow would move 'x' @@ -68,13 +72,13 @@ fn main() { }; let y: &mut i32 = match 0 { // Lint here. The type given above triggers auto-borrow. - 0 => &mut x, + 0 => &mut x, //~ needless_borrow _ => &mut *x, }; fn ref_mut_i32(_: &mut i32) {} ref_mut_i32(match 0 { // Lint here. The type given above triggers auto-borrow. - 0 => &mut x, + 0 => &mut x, //~ needless_borrow _ => &mut *x, }); // use 'x' after to make sure it's still usable in the fixed code. @@ -86,9 +90,9 @@ fn main() { // let _ = (&&s).capacity(); let x = (1, 2); - let _ = (&x).0; + let _ = (&x).0; //~ needless_borrow let x = &x as *const (i32, i32); - let _ = unsafe { (&*x).0 }; + let _ = unsafe { (&*x).0 }; //~ needless_borrow // Issue #8367 trait Foo { @@ -98,7 +102,7 @@ fn main() { fn foo(self) {} } (&()).foo(); // Don't lint. `()` doesn't implement `Foo` - (&&()).foo(); + (&&()).foo(); //~ needless_borrow impl Foo for i32 { fn foo(self) {} @@ -107,7 +111,7 @@ fn main() { fn foo(self) {} } (&5).foo(); // Don't lint. `5` will call `::foo` - (&&5).foo(); + (&&5).foo(); //~ needless_borrow trait FooRef { fn foo_ref(&self); @@ -133,7 +137,7 @@ fn main() { } // issue #11786 - let x: (&str,) = (&"",); + let x: (&str,) = (&"",); //~ needless_borrow } #[allow(clippy::needless_borrowed_reference)] @@ -175,7 +179,7 @@ mod issue9160 { F: Fn() -> T, { fn calls_field(&self) -> T { - (&self.f)() + (&self.f)() //~ needless_borrow } } @@ -184,7 +188,7 @@ mod issue9160 { F: FnMut() -> T, { fn calls_mut_field(&mut self) -> T { - (&mut self.f)() + (&mut self.f)() //~ needless_borrow } } } @@ -221,19 +225,19 @@ fn issue9383() { u: ManuallyDrop::new(Foo { x: 0 }), }; let _ = &mut (&mut x.u).x; - let _ = &mut (&mut { x.u }).x; + let _ = &mut (&mut { x.u }).x; //~ needless_borrow let _ = &mut ({ &mut x.u }).x; let mut x = U { u: Wrap(ManuallyDrop::new(Foo { x: 0 })), }; let _ = &mut (&mut x.u).x; - let _ = &mut (&mut { x.u }).x; + let _ = &mut (&mut { x.u }).x; //~ needless_borrow let _ = &mut ({ &mut x.u }).x; let mut x = U { u: Wrap(Foo { x: 0 }) }; - let _ = &mut (&mut x.u).x; - let _ = &mut (&mut { x.u }).x; + let _ = &mut (&mut x.u).x; //~ needless_borrow + let _ = &mut (&mut { x.u }).x; //~ needless_borrow let _ = &mut ({ &mut x.u }).x; } } diff --git a/tests/ui/needless_borrow.stderr b/tests/ui/needless_borrow.stderr index a21ed8382c14..c056925b48e9 100644 --- a/tests/ui/needless_borrow.stderr +++ b/tests/ui/needless_borrow.stderr @@ -1,5 +1,5 @@ error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:15:15 + --> $DIR/needless_borrow.rs:17:15 | LL | let _ = x(&&a); // warn | ^^^ help: change this to: `&a` @@ -8,157 +8,157 @@ LL | let _ = x(&&a); // warn = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:19:13 + --> $DIR/needless_borrow.rs:23:13 | LL | mut_ref(&mut &mut b); // warn | ^^^^^^^^^^^ help: change this to: `&mut b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:31:13 + --> $DIR/needless_borrow.rs:35:13 | LL | &&a | ^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:33:15 + --> $DIR/needless_borrow.rs:37:15 | LL | 46 => &&a, | ^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:39:27 + --> $DIR/needless_borrow.rs:43:27 | LL | break &ref_a; | ^^^^^^ help: change this to: `ref_a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:46:15 + --> $DIR/needless_borrow.rs:50:15 | LL | let _ = x(&&&a); | ^^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:47:15 + --> $DIR/needless_borrow.rs:51:15 | LL | let _ = x(&mut &&a); | ^^^^^^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:48:15 + --> $DIR/needless_borrow.rs:52:15 | LL | let _ = x(&&&mut b); | ^^^^^^^^ help: change this to: `&mut b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:49:15 + --> $DIR/needless_borrow.rs:53:15 | LL | let _ = x(&&ref_a); | ^^^^^^^ help: change this to: `ref_a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:52:11 + --> $DIR/needless_borrow.rs:56:11 | LL | x(&b); | ^^ help: change this to: `b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:59:13 + --> $DIR/needless_borrow.rs:63:13 | LL | mut_ref(&mut x); | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:60:13 + --> $DIR/needless_borrow.rs:64:13 | LL | mut_ref(&mut &mut x); | ^^^^^^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:61:23 + --> $DIR/needless_borrow.rs:65:23 | LL | let y: &mut i32 = &mut x; | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:62:23 + --> $DIR/needless_borrow.rs:66:23 | LL | let y: &mut i32 = &mut &mut x; | ^^^^^^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:71:14 + --> $DIR/needless_borrow.rs:75:14 | LL | 0 => &mut x, | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:77:14 + --> $DIR/needless_borrow.rs:81:14 | LL | 0 => &mut x, | ^^^^^^ help: change this to: `x` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:89:13 + --> $DIR/needless_borrow.rs:93:13 | LL | let _ = (&x).0; | ^^^^ help: change this to: `x` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:91:22 + --> $DIR/needless_borrow.rs:95:22 | LL | let _ = unsafe { (&*x).0 }; | ^^^^^ help: change this to: `(*x)` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:101:5 + --> $DIR/needless_borrow.rs:105:5 | LL | (&&()).foo(); | ^^^^^^ help: change this to: `(&())` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:110:5 + --> $DIR/needless_borrow.rs:114:5 | LL | (&&5).foo(); | ^^^^^ help: change this to: `(&5)` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:136:23 + --> $DIR/needless_borrow.rs:140:23 | LL | let x: (&str,) = (&"",); | ^^^ help: change this to: `""` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:178:13 + --> $DIR/needless_borrow.rs:182:13 | LL | (&self.f)() | ^^^^^^^^^ help: change this to: `(self.f)` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:187:13 + --> $DIR/needless_borrow.rs:191:13 | LL | (&mut self.f)() | ^^^^^^^^^^^^^ help: change this to: `(self.f)` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:224:22 + --> $DIR/needless_borrow.rs:228:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:231:22 + --> $DIR/needless_borrow.rs:235:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:235:22 + --> $DIR/needless_borrow.rs:239:22 | LL | let _ = &mut (&mut x.u).x; | ^^^^^^^^^^ help: change this to: `x.u` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:236:22 + --> $DIR/needless_borrow.rs:240:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` diff --git a/tests/ui/needless_borrowed_ref.fixed b/tests/ui/needless_borrowed_ref.fixed index 5d2fd0950ee4..a01395079876 100644 --- a/tests/ui/needless_borrowed_ref.fixed +++ b/tests/ui/needless_borrowed_ref.fixed @@ -28,31 +28,43 @@ fn should_lint( ) { let mut v = Vec::::new(); let _ = v.iter_mut().filter(|a| a.is_empty()); + //~^ needless_borrowed_reference let var = 3; let thingy = Some(&var); - if let Some(v) = thingy {} + if let Some(v) = thingy {} //~ needless_borrowed_reference if let &[a, ref b] = slice_of_refs {} + //~^ needless_borrowed_reference - let [a, ..] = &array; + let [a, ..] = &array; //~ needless_borrowed_reference let [a, b, ..] = &array; + //~^ needless_borrowed_reference if let [a, b] = slice {} + //~^ needless_borrowed_reference if let [a, b] = &vec[..] {} + //~^ needless_borrowed_reference if let [a, b, ..] = slice {} + //~^ needless_borrowed_reference if let [a, .., b] = slice {} + //~^ needless_borrowed_reference if let [.., a, b] = slice {} + //~^ needless_borrowed_reference - if let [a, _] = slice {} + if let [a, _] = slice {} //~ needless_borrowed_reference if let (a, b, c) = &tuple {} + //~^ needless_borrowed_reference if let (a, _, c) = &tuple {} - if let (a, ..) = &tuple {} + //~^ needless_borrowed_reference + if let (a, ..) = &tuple {} //~ needless_borrowed_reference if let TupleStruct(a, ..) = &tuple_struct {} + //~^ needless_borrowed_reference + //~v needless_borrowed_reference if let Struct { a, b: b, @@ -61,6 +73,7 @@ fn should_lint( {} if let Struct { a, b: _, .. } = &s {} + //~^ needless_borrowed_reference } fn should_not_lint( diff --git a/tests/ui/needless_borrowed_ref.rs b/tests/ui/needless_borrowed_ref.rs index 556fd3a35427..0f7e06fdee4d 100644 --- a/tests/ui/needless_borrowed_ref.rs +++ b/tests/ui/needless_borrowed_ref.rs @@ -28,31 +28,43 @@ fn should_lint( ) { let mut v = Vec::::new(); let _ = v.iter_mut().filter(|&ref a| a.is_empty()); + //~^ needless_borrowed_reference let var = 3; let thingy = Some(&var); - if let Some(&ref v) = thingy {} + if let Some(&ref v) = thingy {} //~ needless_borrowed_reference if let &[&ref a, ref b] = slice_of_refs {} + //~^ needless_borrowed_reference - let &[ref a, ..] = &array; + let &[ref a, ..] = &array; //~ needless_borrowed_reference let &[ref a, ref b, ..] = &array; + //~^ needless_borrowed_reference if let &[ref a, ref b] = slice {} + //~^ needless_borrowed_reference if let &[ref a, ref b] = &vec[..] {} + //~^ needless_borrowed_reference if let &[ref a, ref b, ..] = slice {} + //~^ needless_borrowed_reference if let &[ref a, .., ref b] = slice {} + //~^ needless_borrowed_reference if let &[.., ref a, ref b] = slice {} + //~^ needless_borrowed_reference - if let &[ref a, _] = slice {} + if let &[ref a, _] = slice {} //~ needless_borrowed_reference if let &(ref a, ref b, ref c) = &tuple {} + //~^ needless_borrowed_reference if let &(ref a, _, ref c) = &tuple {} - if let &(ref a, ..) = &tuple {} + //~^ needless_borrowed_reference + if let &(ref a, ..) = &tuple {} //~ needless_borrowed_reference if let &TupleStruct(ref a, ..) = &tuple_struct {} + //~^ needless_borrowed_reference + //~v needless_borrowed_reference if let &Struct { ref a, b: ref b, @@ -61,6 +73,7 @@ fn should_lint( {} if let &Struct { ref a, b: _, .. } = &s {} + //~^ needless_borrowed_reference } fn should_not_lint( diff --git a/tests/ui/needless_borrowed_ref.stderr b/tests/ui/needless_borrowed_ref.stderr index 15261cfce0c3..e522b77a694f 100644 --- a/tests/ui/needless_borrowed_ref.stderr +++ b/tests/ui/needless_borrowed_ref.stderr @@ -13,7 +13,7 @@ LL + let _ = v.iter_mut().filter(|a| a.is_empty()); | error: this pattern takes a reference on something that is being dereferenced - --> $DIR/needless_borrowed_ref.rs:34:17 + --> $DIR/needless_borrowed_ref.rs:35:17 | LL | if let Some(&ref v) = thingy {} | ^^^^^^ @@ -25,7 +25,7 @@ LL + if let Some(v) = thingy {} | error: this pattern takes a reference on something that is being dereferenced - --> $DIR/needless_borrowed_ref.rs:36:14 + --> $DIR/needless_borrowed_ref.rs:37:14 | LL | if let &[&ref a, ref b] = slice_of_refs {} | ^^^^^^ @@ -37,7 +37,7 @@ LL + if let &[a, ref b] = slice_of_refs {} | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:38:9 + --> $DIR/needless_borrowed_ref.rs:40:9 | LL | let &[ref a, ..] = &array; | ^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + let [a, ..] = &array; | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:39:9 + --> $DIR/needless_borrowed_ref.rs:41:9 | LL | let &[ref a, ref b, ..] = &array; | ^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + let [a, b, ..] = &array; | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:41:12 + --> $DIR/needless_borrowed_ref.rs:44:12 | LL | if let &[ref a, ref b] = slice {} | ^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + if let [a, b] = slice {} | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:42:12 + --> $DIR/needless_borrowed_ref.rs:46:12 | LL | if let &[ref a, ref b] = &vec[..] {} | ^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + if let [a, b] = &vec[..] {} | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:44:12 + --> $DIR/needless_borrowed_ref.rs:49:12 | LL | if let &[ref a, ref b, ..] = slice {} | ^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + if let [a, b, ..] = slice {} | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:45:12 + --> $DIR/needless_borrowed_ref.rs:51:12 | LL | if let &[ref a, .., ref b] = slice {} | ^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + if let [a, .., b] = slice {} | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:46:12 + --> $DIR/needless_borrowed_ref.rs:53:12 | LL | if let &[.., ref a, ref b] = slice {} | ^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + if let [.., a, b] = slice {} | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:48:12 + --> $DIR/needless_borrowed_ref.rs:56:12 | LL | if let &[ref a, _] = slice {} | ^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + if let [a, _] = slice {} | error: dereferencing a tuple pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:50:12 + --> $DIR/needless_borrowed_ref.rs:58:12 | LL | if let &(ref a, ref b, ref c) = &tuple {} | ^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + if let (a, b, c) = &tuple {} | error: dereferencing a tuple pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:51:12 + --> $DIR/needless_borrowed_ref.rs:60:12 | LL | if let &(ref a, _, ref c) = &tuple {} | ^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + if let (a, _, c) = &tuple {} | error: dereferencing a tuple pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:52:12 + --> $DIR/needless_borrowed_ref.rs:62:12 | LL | if let &(ref a, ..) = &tuple {} | ^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + if let (a, ..) = &tuple {} | error: dereferencing a tuple pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:54:12 + --> $DIR/needless_borrowed_ref.rs:64:12 | LL | if let &TupleStruct(ref a, ..) = &tuple_struct {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + if let TupleStruct(a, ..) = &tuple_struct {} | error: dereferencing a struct pattern where every field's pattern takes a reference - --> $DIR/needless_borrowed_ref.rs:56:12 + --> $DIR/needless_borrowed_ref.rs:68:12 | LL | if let &Struct { | ____________^ @@ -200,7 +200,7 @@ LL ~ c: renamed, | error: dereferencing a struct pattern where every field's pattern takes a reference - --> $DIR/needless_borrowed_ref.rs:63:12 + --> $DIR/needless_borrowed_ref.rs:75:12 | LL | if let &Struct { ref a, b: _, .. } = &s {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/needless_borrows_for_generic_args.fixed b/tests/ui/needless_borrows_for_generic_args.fixed index bd7a9a0b9840..866aa33d8781 100644 --- a/tests/ui/needless_borrows_for_generic_args.fixed +++ b/tests/ui/needless_borrows_for_generic_args.fixed @@ -14,11 +14,14 @@ use std::process::Command; fn main() { let _ = Command::new("ls").args(["-a", "-l"]).status().unwrap(); + //~^ needless_borrows_for_generic_args let _ = Path::new(".").join("."); + //~^ needless_borrows_for_generic_args let _ = Any::type_id(&""); // Don't lint. `Any` is only bound let _ = Box::new(&""); // Don't lint. Type parameter appears in return type let _ = Some("").unwrap_or(&""); let _ = std::fs::write("x", "".to_string()); + //~^ needless_borrows_for_generic_args { #[derive(Clone, Copy)] @@ -33,7 +36,7 @@ fn main() { fn deref_target_is_x>(_: T) {} - deref_target_is_x(X); + deref_target_is_x(X); //~ needless_borrows_for_generic_args } { fn multiple_constraints(_: T) @@ -47,6 +50,7 @@ fn main() { } multiple_constraints([[""]]); + //~^ needless_borrows_for_generic_args } { #[derive(Clone, Copy)] @@ -67,6 +71,7 @@ fn main() { } multiple_constraints_normalizes_to_same(X, X); + //~^ needless_borrows_for_generic_args } { fn only_sized(_: T) {} @@ -124,7 +129,7 @@ fn main() { } #[allow(unused_mut)] fn warn(mut x: &mut Iter) { - takes_iter(x) + takes_iter(x) //~ needless_borrows_for_generic_args } } #[clippy::msrv = "1.52.0"] @@ -134,6 +139,7 @@ fn main() { #[clippy::msrv = "1.53.0"] { let _ = Command::new("ls").args(["-a", "-l"]).status().unwrap(); + //~^ needless_borrows_for_generic_args }; { let env = "env".to_owned(); @@ -142,7 +148,9 @@ fn main() { let loc = "loc".to_owned(); let _ = std::fs::write("x", &env); // Don't lint. In environment let _ = std::fs::write("x", arg); + //~^ needless_borrows_for_generic_args let _ = std::fs::write("x", loc); + //~^ needless_borrows_for_generic_args }; let _ = std::fs::write("x", &env); // Don't lint. Borrowed by `f` f(arg); @@ -164,7 +172,7 @@ fn main() { fn f(_: impl AsRef) {} let x = String::new(); - f(x); + f(x); //~ needless_borrows_for_generic_args } { fn f(_: impl AsRef) {} @@ -244,7 +252,7 @@ fn main() { // 8 foo::<&[u8; 100]>(&a); - foo(a); + foo(a); //~ needless_borrows_for_generic_args } { struct S; diff --git a/tests/ui/needless_borrows_for_generic_args.rs b/tests/ui/needless_borrows_for_generic_args.rs index 5cfd4ce30cc5..7e3eae1be8d2 100644 --- a/tests/ui/needless_borrows_for_generic_args.rs +++ b/tests/ui/needless_borrows_for_generic_args.rs @@ -14,11 +14,14 @@ use std::process::Command; fn main() { let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap(); + //~^ needless_borrows_for_generic_args let _ = Path::new(".").join(&&"."); + //~^ needless_borrows_for_generic_args let _ = Any::type_id(&""); // Don't lint. `Any` is only bound let _ = Box::new(&""); // Don't lint. Type parameter appears in return type let _ = Some("").unwrap_or(&""); let _ = std::fs::write("x", &"".to_string()); + //~^ needless_borrows_for_generic_args { #[derive(Clone, Copy)] @@ -33,7 +36,7 @@ fn main() { fn deref_target_is_x>(_: T) {} - deref_target_is_x(&X); + deref_target_is_x(&X); //~ needless_borrows_for_generic_args } { fn multiple_constraints(_: T) @@ -47,6 +50,7 @@ fn main() { } multiple_constraints(&[[""]]); + //~^ needless_borrows_for_generic_args } { #[derive(Clone, Copy)] @@ -67,6 +71,7 @@ fn main() { } multiple_constraints_normalizes_to_same(&X, X); + //~^ needless_borrows_for_generic_args } { fn only_sized(_: T) {} @@ -124,7 +129,7 @@ fn main() { } #[allow(unused_mut)] fn warn(mut x: &mut Iter) { - takes_iter(&mut x) + takes_iter(&mut x) //~ needless_borrows_for_generic_args } } #[clippy::msrv = "1.52.0"] @@ -134,6 +139,7 @@ fn main() { #[clippy::msrv = "1.53.0"] { let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap(); + //~^ needless_borrows_for_generic_args }; { let env = "env".to_owned(); @@ -142,7 +148,9 @@ fn main() { let loc = "loc".to_owned(); let _ = std::fs::write("x", &env); // Don't lint. In environment let _ = std::fs::write("x", &arg); + //~^ needless_borrows_for_generic_args let _ = std::fs::write("x", &loc); + //~^ needless_borrows_for_generic_args }; let _ = std::fs::write("x", &env); // Don't lint. Borrowed by `f` f(arg); @@ -164,7 +172,7 @@ fn main() { fn f(_: impl AsRef) {} let x = String::new(); - f(&x); + f(&x); //~ needless_borrows_for_generic_args } { fn f(_: impl AsRef) {} @@ -244,7 +252,7 @@ fn main() { // 8 foo::<&[u8; 100]>(&a); - foo(&a); + foo(&a); //~ needless_borrows_for_generic_args } { struct S; diff --git a/tests/ui/needless_borrows_for_generic_args.stderr b/tests/ui/needless_borrows_for_generic_args.stderr index e2cde2c59a6e..3e5f1bab9208 100644 --- a/tests/ui/needless_borrows_for_generic_args.stderr +++ b/tests/ui/needless_borrows_for_generic_args.stderr @@ -8,67 +8,67 @@ LL | let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap(); = help: to override `-D warnings` add `#[allow(clippy::needless_borrows_for_generic_args)]` error: the borrowed expression implements the required traits - --> $DIR/needless_borrows_for_generic_args.rs:17:33 + --> $DIR/needless_borrows_for_generic_args.rs:18:33 | LL | let _ = Path::new(".").join(&&"."); | ^^^^^ help: change this to: `"."` error: the borrowed expression implements the required traits - --> $DIR/needless_borrows_for_generic_args.rs:21:33 + --> $DIR/needless_borrows_for_generic_args.rs:23:33 | LL | let _ = std::fs::write("x", &"".to_string()); | ^^^^^^^^^^^^^^^ help: change this to: `"".to_string()` error: the borrowed expression implements the required traits - --> $DIR/needless_borrows_for_generic_args.rs:36:27 + --> $DIR/needless_borrows_for_generic_args.rs:39:27 | LL | deref_target_is_x(&X); | ^^ help: change this to: `X` error: the borrowed expression implements the required traits - --> $DIR/needless_borrows_for_generic_args.rs:49:30 + --> $DIR/needless_borrows_for_generic_args.rs:52:30 | LL | multiple_constraints(&[[""]]); | ^^^^^^^ help: change this to: `[[""]]` error: the borrowed expression implements the required traits - --> $DIR/needless_borrows_for_generic_args.rs:69:49 + --> $DIR/needless_borrows_for_generic_args.rs:73:49 | LL | multiple_constraints_normalizes_to_same(&X, X); | ^^ help: change this to: `X` error: the borrowed expression implements the required traits - --> $DIR/needless_borrows_for_generic_args.rs:127:24 + --> $DIR/needless_borrows_for_generic_args.rs:132:24 | LL | takes_iter(&mut x) | ^^^^^^ help: change this to: `x` error: the borrowed expression implements the required traits - --> $DIR/needless_borrows_for_generic_args.rs:136:41 + --> $DIR/needless_borrows_for_generic_args.rs:141:41 | LL | let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap(); | ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]` error: the borrowed expression implements the required traits - --> $DIR/needless_borrows_for_generic_args.rs:144:41 + --> $DIR/needless_borrows_for_generic_args.rs:150:41 | LL | let _ = std::fs::write("x", &arg); | ^^^^ help: change this to: `arg` error: the borrowed expression implements the required traits - --> $DIR/needless_borrows_for_generic_args.rs:145:41 + --> $DIR/needless_borrows_for_generic_args.rs:152:41 | LL | let _ = std::fs::write("x", &loc); | ^^^^ help: change this to: `loc` error: the borrowed expression implements the required traits - --> $DIR/needless_borrows_for_generic_args.rs:167:11 + --> $DIR/needless_borrows_for_generic_args.rs:175:11 | LL | f(&x); | ^^ help: change this to: `x` error: the borrowed expression implements the required traits - --> $DIR/needless_borrows_for_generic_args.rs:247:13 + --> $DIR/needless_borrows_for_generic_args.rs:255:13 | LL | foo(&a); | ^^ help: change this to: `a` diff --git a/tests/ui/needless_collect.fixed b/tests/ui/needless_collect.fixed index bd83581bdd97..ea57b4f3a9de 100644 --- a/tests/ui/needless_collect.fixed +++ b/tests/ui/needless_collect.fixed @@ -7,16 +7,22 @@ use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedL fn main() { let sample = [1; 5]; let len = sample.iter().count(); + //~^ needless_collect + + //~v needless_collect if sample.iter().next().is_none() { // Empty } sample.iter().cloned().any(|x| x == 1); + //~^ needless_collect // #7164 HashMap's and BTreeMap's `len` usage should not be linted sample.iter().map(|x| (x, x)).collect::>().len(); sample.iter().map(|x| (x, x)).collect::>().len(); sample.iter().map(|x| (x, x)).next().is_none(); + //~^ needless_collect sample.iter().map(|x| (x, x)).next().is_none(); + //~^ needless_collect // Notice the `HashSet`--this should not be linted sample.iter().collect::>().len(); @@ -24,19 +30,27 @@ fn main() { sample.iter().collect::>().len(); sample.iter().count(); + //~^ needless_collect sample.iter().next().is_none(); + //~^ needless_collect sample.iter().cloned().any(|x| x == 1); + //~^ needless_collect sample.iter().any(|x| x == &1); + //~^ needless_collect // `BinaryHeap` doesn't have `contains` method sample.iter().count(); + //~^ needless_collect sample.iter().next().is_none(); + //~^ needless_collect // Don't lint string from str let _ = ["", ""].into_iter().collect::().is_empty(); let _ = sample.iter().next().is_none(); + //~^ needless_collect let _ = sample.iter().any(|x| x == &0); + //~^ needless_collect struct VecWrapper(Vec); impl core::ops::Deref for VecWrapper { @@ -59,14 +73,19 @@ fn main() { } let _ = sample.iter().next().is_none(); + //~^ needless_collect let _ = sample.iter().any(|x| x == &0); + //~^ needless_collect #[allow(clippy::double_parens)] { Vec::::new().extend((0..10)); - foo((0..10)); + //~^ needless_collect + foo((0..10)); //~ needless_collect bar((0..10).collect::>(), (0..10)); + //~^ needless_collect baz((0..10), (), ('a'..='z')) + //~^ needless_collect } let values = [1, 2, 3, 4]; diff --git a/tests/ui/needless_collect.rs b/tests/ui/needless_collect.rs index 6a81a767bbb6..8ca42af2d3df 100644 --- a/tests/ui/needless_collect.rs +++ b/tests/ui/needless_collect.rs @@ -7,16 +7,22 @@ use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedL fn main() { let sample = [1; 5]; let len = sample.iter().collect::>().len(); + //~^ needless_collect + + //~v needless_collect if sample.iter().collect::>().is_empty() { // Empty } sample.iter().cloned().collect::>().contains(&1); + //~^ needless_collect // #7164 HashMap's and BTreeMap's `len` usage should not be linted sample.iter().map(|x| (x, x)).collect::>().len(); sample.iter().map(|x| (x, x)).collect::>().len(); sample.iter().map(|x| (x, x)).collect::>().is_empty(); + //~^ needless_collect sample.iter().map(|x| (x, x)).collect::>().is_empty(); + //~^ needless_collect // Notice the `HashSet`--this should not be linted sample.iter().collect::>().len(); @@ -24,19 +30,27 @@ fn main() { sample.iter().collect::>().len(); sample.iter().collect::>().len(); + //~^ needless_collect sample.iter().collect::>().is_empty(); + //~^ needless_collect sample.iter().cloned().collect::>().contains(&1); + //~^ needless_collect sample.iter().collect::>().contains(&&1); + //~^ needless_collect // `BinaryHeap` doesn't have `contains` method sample.iter().collect::>().len(); + //~^ needless_collect sample.iter().collect::>().is_empty(); + //~^ needless_collect // Don't lint string from str let _ = ["", ""].into_iter().collect::().is_empty(); let _ = sample.iter().collect::>().is_empty(); + //~^ needless_collect let _ = sample.iter().collect::>().contains(&&0); + //~^ needless_collect struct VecWrapper(Vec); impl core::ops::Deref for VecWrapper { @@ -59,14 +73,19 @@ fn main() { } let _ = sample.iter().collect::>().is_empty(); + //~^ needless_collect let _ = sample.iter().collect::>().contains(&&0); + //~^ needless_collect #[allow(clippy::double_parens)] { Vec::::new().extend((0..10).collect::>()); - foo((0..10).collect::>()); + //~^ needless_collect + foo((0..10).collect::>()); //~ needless_collect bar((0..10).collect::>(), (0..10).collect::>()); + //~^ needless_collect baz((0..10), (), ('a'..='z').collect::>()) + //~^ needless_collect } let values = [1, 2, 3, 4]; diff --git a/tests/ui/needless_collect.stderr b/tests/ui/needless_collect.stderr index 2c21fc5965d5..0e402c923406 100644 --- a/tests/ui/needless_collect.stderr +++ b/tests/ui/needless_collect.stderr @@ -8,109 +8,109 @@ LL | let len = sample.iter().collect::>().len(); = help: to override `-D warnings` add `#[allow(clippy::needless_collect)]` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:10:22 + --> $DIR/needless_collect.rs:13:22 | LL | if sample.iter().collect::>().is_empty() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:13:28 + --> $DIR/needless_collect.rs:16:28 | LL | sample.iter().cloned().collect::>().contains(&1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == 1)` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:18:35 + --> $DIR/needless_collect.rs:22:35 | LL | sample.iter().map(|x| (x, x)).collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:19:35 + --> $DIR/needless_collect.rs:24:35 | LL | sample.iter().map(|x| (x, x)).collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:26:19 + --> $DIR/needless_collect.rs:32:19 | LL | sample.iter().collect::>().len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:27:19 + --> $DIR/needless_collect.rs:34:19 | LL | sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:28:28 + --> $DIR/needless_collect.rs:36:28 | LL | sample.iter().cloned().collect::>().contains(&1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == 1)` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:29:19 + --> $DIR/needless_collect.rs:38:19 | LL | sample.iter().collect::>().contains(&&1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &1)` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:32:19 + --> $DIR/needless_collect.rs:42:19 | LL | sample.iter().collect::>().len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:33:19 + --> $DIR/needless_collect.rs:44:19 | LL | sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:38:27 + --> $DIR/needless_collect.rs:50:27 | LL | let _ = sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:39:27 + --> $DIR/needless_collect.rs:52:27 | LL | let _ = sample.iter().collect::>().contains(&&0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &0)` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:61:27 + --> $DIR/needless_collect.rs:75:27 | LL | let _ = sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:62:27 + --> $DIR/needless_collect.rs:77:27 | LL | let _ = sample.iter().collect::>().contains(&&0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &0)` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:66:40 + --> $DIR/needless_collect.rs:82:40 | LL | Vec::::new().extend((0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:67:20 + --> $DIR/needless_collect.rs:84:20 | LL | foo((0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:68:49 + --> $DIR/needless_collect.rs:85:49 | LL | bar((0..10).collect::>(), (0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:69:37 + --> $DIR/needless_collect.rs:87:37 | LL | baz((0..10), (), ('a'..='z').collect::>()) | ^^^^^^^^^^^^^^^^^^^^ help: remove this call diff --git a/tests/ui/needless_else.fixed b/tests/ui/needless_else.fixed index 240b79bae13c..3865fbd5ddf6 100644 --- a/tests/ui/needless_else.fixed +++ b/tests/ui/needless_else.fixed @@ -20,6 +20,7 @@ fn main() { if b { println!("Foobar"); + //~v needless_else } if b { diff --git a/tests/ui/needless_else.rs b/tests/ui/needless_else.rs index ad84da170535..638fc8849984 100644 --- a/tests/ui/needless_else.rs +++ b/tests/ui/needless_else.rs @@ -20,6 +20,7 @@ fn main() { if b { println!("Foobar"); + //~v needless_else } else { } diff --git a/tests/ui/needless_else.stderr b/tests/ui/needless_else.stderr index 66552109c48e..72962aace83e 100644 --- a/tests/ui/needless_else.stderr +++ b/tests/ui/needless_else.stderr @@ -1,5 +1,5 @@ error: this `else` branch is empty - --> $DIR/needless_else.rs:23:7 + --> $DIR/needless_else.rs:24:7 | LL | } else { | _______^ diff --git a/tests/ui/needless_for_each_fixable.fixed b/tests/ui/needless_for_each_fixable.fixed index 8c0e7ba76278..f8064fd35e0e 100644 --- a/tests/ui/needless_for_each_fixable.fixed +++ b/tests/ui/needless_for_each_fixable.fixed @@ -12,27 +12,34 @@ use std::collections::HashMap; fn should_lint() { let v: Vec = Vec::new(); let mut acc = 0; + //~v needless_for_each for elem in v.iter() { acc += elem; } + //~v needless_for_each for elem in v.into_iter() { acc += elem; } + //~v needless_for_each for elem in [1, 2, 3].iter() { acc += elem; } let mut hash_map: HashMap = HashMap::new(); + //~v needless_for_each for (k, v) in hash_map.iter() { acc += k + v; } + //~v needless_for_each for (k, v) in hash_map.iter_mut() { acc += *k + *v; } + //~v needless_for_each for k in hash_map.keys() { acc += k; } + //~v needless_for_each for v in hash_map.values() { acc += v; } @@ -40,6 +47,7 @@ fn should_lint() { fn my_vec() -> Vec { Vec::new() } + //~v needless_for_each for elem in my_vec().iter() { acc += elem; } diff --git a/tests/ui/needless_for_each_fixable.rs b/tests/ui/needless_for_each_fixable.rs index cdc903a636c9..a9b6bcd2a646 100644 --- a/tests/ui/needless_for_each_fixable.rs +++ b/tests/ui/needless_for_each_fixable.rs @@ -12,27 +12,34 @@ use std::collections::HashMap; fn should_lint() { let v: Vec = Vec::new(); let mut acc = 0; + //~v needless_for_each v.iter().for_each(|elem| { acc += elem; }); + //~v needless_for_each v.into_iter().for_each(|elem| { acc += elem; }); + //~v needless_for_each [1, 2, 3].iter().for_each(|elem| { acc += elem; }); let mut hash_map: HashMap = HashMap::new(); + //~v needless_for_each hash_map.iter().for_each(|(k, v)| { acc += k + v; }); + //~v needless_for_each hash_map.iter_mut().for_each(|(k, v)| { acc += *k + *v; }); + //~v needless_for_each hash_map.keys().for_each(|k| { acc += k; }); + //~v needless_for_each hash_map.values().for_each(|v| { acc += v; }); @@ -40,6 +47,7 @@ fn should_lint() { fn my_vec() -> Vec { Vec::new() } + //~v needless_for_each my_vec().iter().for_each(|elem| { acc += elem; }); diff --git a/tests/ui/needless_for_each_fixable.stderr b/tests/ui/needless_for_each_fixable.stderr index 3b5163b0171a..e78d8634be65 100644 --- a/tests/ui/needless_for_each_fixable.stderr +++ b/tests/ui/needless_for_each_fixable.stderr @@ -1,5 +1,5 @@ error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:15:5 + --> $DIR/needless_for_each_fixable.rs:16:5 | LL | / v.iter().for_each(|elem| { LL | | acc += elem; @@ -16,7 +16,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:18:5 + --> $DIR/needless_for_each_fixable.rs:20:5 | LL | / v.into_iter().for_each(|elem| { LL | | acc += elem; @@ -31,7 +31,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:22:5 + --> $DIR/needless_for_each_fixable.rs:25:5 | LL | / [1, 2, 3].iter().for_each(|elem| { LL | | acc += elem; @@ -46,7 +46,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:27:5 + --> $DIR/needless_for_each_fixable.rs:31:5 | LL | / hash_map.iter().for_each(|(k, v)| { LL | | acc += k + v; @@ -61,7 +61,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:30:5 + --> $DIR/needless_for_each_fixable.rs:35:5 | LL | / hash_map.iter_mut().for_each(|(k, v)| { LL | | acc += *k + *v; @@ -76,7 +76,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:33:5 + --> $DIR/needless_for_each_fixable.rs:39:5 | LL | / hash_map.keys().for_each(|k| { LL | | acc += k; @@ -91,7 +91,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:36:5 + --> $DIR/needless_for_each_fixable.rs:43:5 | LL | / hash_map.values().for_each(|v| { LL | | acc += v; @@ -106,7 +106,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:43:5 + --> $DIR/needless_for_each_fixable.rs:51:5 | LL | / my_vec().iter().for_each(|elem| { LL | | acc += elem; diff --git a/tests/ui/needless_if.fixed b/tests/ui/needless_if.fixed index 79e33a7218b7..7bd124700869 100644 --- a/tests/ui/needless_if.fixed +++ b/tests/ui/needless_if.fixed @@ -24,13 +24,14 @@ fn maybe_side_effect() -> bool { fn main() { // Lint - + //~ needless_if // Do not remove the condition - maybe_side_effect(); + maybe_side_effect(); //~ needless_if // Do not lint if (true) { } else { } + //~v needless_if ({ return; }); @@ -47,6 +48,7 @@ fn main() { && let true = true {} // Can lint nested `if let`s + //~v needless_if ({ if let true = true && true @@ -90,13 +92,13 @@ fn main() { empty_repetition!(); // Must be placed into an expression context to not be interpreted as a block - ({ maybe_side_effect() }); + ({ maybe_side_effect() }); //~ needless_if // Would be a block followed by `&&true` - a double reference to `true` - ({ maybe_side_effect() } && true); + ({ maybe_side_effect() } && true); //~ needless_if // Don't leave trailing attributes #[allow(unused)] - true; + true; //~ needless_if let () = if maybe_side_effect() {}; } diff --git a/tests/ui/needless_if.rs b/tests/ui/needless_if.rs index 2c135fb22bf8..95fca96b176a 100644 --- a/tests/ui/needless_if.rs +++ b/tests/ui/needless_if.rs @@ -24,13 +24,14 @@ fn maybe_side_effect() -> bool { fn main() { // Lint - if (true) {} + if (true) {} //~ needless_if // Do not remove the condition - if maybe_side_effect() {} + if maybe_side_effect() {} //~ needless_if // Do not lint if (true) { } else { } + //~v needless_if if { return; } {} @@ -47,6 +48,7 @@ fn main() { && let true = true {} // Can lint nested `if let`s + //~v needless_if if { if let true = true && true @@ -91,13 +93,13 @@ fn main() { empty_repetition!(); // Must be placed into an expression context to not be interpreted as a block - if { maybe_side_effect() } {} + if { maybe_side_effect() } {} //~ needless_if // Would be a block followed by `&&true` - a double reference to `true` - if { maybe_side_effect() } && true {} + if { maybe_side_effect() } && true {} //~ needless_if // Don't leave trailing attributes #[allow(unused)] - if true {} + if true {} //~ needless_if let () = if maybe_side_effect() {}; } diff --git a/tests/ui/needless_if.stderr b/tests/ui/needless_if.stderr index 9a911b4dbacc..210029b95b69 100644 --- a/tests/ui/needless_if.stderr +++ b/tests/ui/needless_if.stderr @@ -14,7 +14,7 @@ LL | if maybe_side_effect() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `maybe_side_effect();` error: this `if` branch is empty - --> $DIR/needless_if.rs:34:5 + --> $DIR/needless_if.rs:35:5 | LL | / if { LL | | return; @@ -29,7 +29,7 @@ LL + }); | error: this `if` branch is empty - --> $DIR/needless_if.rs:50:5 + --> $DIR/needless_if.rs:52:5 | LL | / if { LL | | if let true = true @@ -54,19 +54,19 @@ LL + } && true); | error: this `if` branch is empty - --> $DIR/needless_if.rs:94:5 + --> $DIR/needless_if.rs:96:5 | LL | if { maybe_side_effect() } {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `({ maybe_side_effect() });` error: this `if` branch is empty - --> $DIR/needless_if.rs:96:5 + --> $DIR/needless_if.rs:98:5 | LL | if { maybe_side_effect() } && true {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `({ maybe_side_effect() } && true);` error: this `if` branch is empty - --> $DIR/needless_if.rs:100:5 + --> $DIR/needless_if.rs:102:5 | LL | if true {} | ^^^^^^^^^^ help: you can remove it: `true;` diff --git a/tests/ui/needless_late_init.fixed b/tests/ui/needless_late_init.fixed index 6db870490445..2f417eb0240d 100644 --- a/tests/ui/needless_late_init.fixed +++ b/tests/ui/needless_late_init.fixed @@ -24,23 +24,23 @@ impl std::ops::Drop for SignificantDrop { } fn simple() { - + //~ needless_late_init let a = "zero"; - - + //~ needless_late_init + //~ needless_late_init let b = 1; let c = 2; - + //~ needless_late_init let d: usize = 1; - + //~ needless_late_init let e = format!("{}", d); } fn main() { - + //~ needless_late_init let n = 1; let a = match n { 1 => "one", @@ -49,14 +49,14 @@ fn main() { }, }; - + //~ needless_late_init let b = if n == 3 { "four" } else { "five" }; - + //~ needless_late_init let d = if true { let temp = 5; temp @@ -64,20 +64,20 @@ fn main() { 15 }; - + //~ needless_late_init let e = if true { format!("{} {}", a, b) } else { format!("{}", n) }; - + //~ needless_late_init let f = match 1 { 1 => "three", _ => return, }; // has semi - + //~ needless_late_init let g: usize = if true { 5 } else { @@ -85,15 +85,15 @@ fn main() { }; // Drop order only matters if both are significant - + //~ needless_late_init let y = SignificantDrop; let x = 1; - + //~ needless_late_init let y = 1; let x = SignificantDrop; - + //~ needless_late_init // types that should be considered insignificant let y = 1; let y = "2"; @@ -112,7 +112,7 @@ async fn in_async() -> &'static str { "one" } - + //~ needless_late_init let n = 1; let a = match n { 1 => f().await, @@ -129,7 +129,7 @@ const fn in_const() -> &'static str { "one" } - + //~ needless_late_init let n = 1; let a = match n { 1 => f(), diff --git a/tests/ui/needless_late_init.rs b/tests/ui/needless_late_init.rs index c1e86212a08b..0098f610125c 100644 --- a/tests/ui/needless_late_init.rs +++ b/tests/ui/needless_late_init.rs @@ -24,23 +24,23 @@ impl std::ops::Drop for SignificantDrop { } fn simple() { - let a; + let a; //~ needless_late_init a = "zero"; - let b; - let c; + let b; //~ needless_late_init + let c; //~ needless_late_init b = 1; c = 2; - let d: usize; + let d: usize; //~ needless_late_init d = 1; - let e; + let e; //~ needless_late_init e = format!("{}", d); } fn main() { - let a; + let a; //~ needless_late_init let n = 1; match n { 1 => a = "one", @@ -49,14 +49,14 @@ fn main() { }, } - let b; + let b; //~ needless_late_init if n == 3 { b = "four"; } else { b = "five" } - let d; + let d; //~ needless_late_init if true { let temp = 5; d = temp; @@ -64,20 +64,20 @@ fn main() { d = 15; } - let e; + let e; //~ needless_late_init if true { e = format!("{} {}", a, b); } else { e = format!("{}", n); } - let f; + let f; //~ needless_late_init match 1 { 1 => f = "three", _ => return, }; // has semi - let g: usize; + let g: usize; //~ needless_late_init if true { g = 5; } else { @@ -85,15 +85,15 @@ fn main() { } // Drop order only matters if both are significant - let x; + let x; //~ needless_late_init let y = SignificantDrop; x = 1; - let x; + let x; //~ needless_late_init let y = 1; x = SignificantDrop; - let x; + let x; //~ needless_late_init // types that should be considered insignificant let y = 1; let y = "2"; @@ -112,7 +112,7 @@ async fn in_async() -> &'static str { "one" } - let a; + let a; //~ needless_late_init let n = 1; match n { 1 => a = f().await, @@ -129,7 +129,7 @@ const fn in_const() -> &'static str { "one" } - let a; + let a; //~ needless_late_init let n = 1; match n { 1 => a = f(), diff --git a/tests/ui/needless_lifetimes.fixed b/tests/ui/needless_lifetimes.fixed index d1787b35abd2..ae4fddbdc3c2 100644 --- a/tests/ui/needless_lifetimes.fixed +++ b/tests/ui/needless_lifetimes.fixed @@ -15,8 +15,10 @@ extern crate proc_macros; use proc_macros::inline_macros; fn distinct_lifetimes(_x: &u8, _y: &u8, _z: u8) {} +//~^ needless_lifetimes fn distinct_and_static(_x: &u8, _y: &u8, _z: &'static u8) {} +//~^ needless_lifetimes // No error; same lifetime on two params. fn same_lifetime_on_input<'a>(_x: &'a u8, _y: &'a u8) {} @@ -26,6 +28,7 @@ fn only_static_on_input(_x: &u8, _y: &u8, _z: &'static u8) {} fn mut_and_static_input(_x: &mut u8, _y: &'static str) {} +//~v needless_lifetimes fn in_and_out(x: &u8, _y: u8) -> &u8 { x } @@ -38,6 +41,7 @@ fn multiple_in_and_out_1<'a>(x: &'a u8, _y: &'a u8) -> &'a u8 { // Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid: // fn multiple_in_and_out_2a<'a>(x: &'a u8, _y: &u8) -> &'a u8 // ^^^ +//~v needless_lifetimes fn multiple_in_and_out_2a<'a>(x: &'a u8, _y: &u8) -> &'a u8 { x } @@ -45,6 +49,7 @@ fn multiple_in_and_out_2a<'a>(x: &'a u8, _y: &u8) -> &'a u8 { // Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid: // fn multiple_in_and_out_2b<'b>(_x: &u8, y: &'b u8) -> &'b u8 // ^^^ +//~v needless_lifetimes fn multiple_in_and_out_2b<'b>(_x: &u8, y: &'b u8) -> &'b u8 { y } @@ -62,6 +67,7 @@ fn in_static_and_out<'a>(x: &'a u8, _y: &'static u8) -> &'a u8 { // Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid: // fn deep_reference_1a<'a>(x: &'a u8, _y: &u8) -> Result<&'a u8, ()> // ^^^ +//~v needless_lifetimes fn deep_reference_1a<'a>(x: &'a u8, _y: &u8) -> Result<&'a u8, ()> { Ok(x) } @@ -69,6 +75,7 @@ fn deep_reference_1a<'a>(x: &'a u8, _y: &u8) -> Result<&'a u8, ()> { // Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid: // fn deep_reference_1b<'b>(_x: &u8, y: &'b u8) -> Result<&'b u8, ()> // ^^^ +//~v needless_lifetimes fn deep_reference_1b<'b>(_x: &u8, y: &'b u8) -> Result<&'b u8, ()> { Ok(y) } @@ -78,12 +85,14 @@ fn deep_reference_2<'a>(x: Result<&'a u8, &'a u8>) -> &'a u8 { x.unwrap() } +//~v needless_lifetimes fn deep_reference_3(x: &u8, _y: u8) -> Result<&u8, ()> { Ok(x) } // Where-clause, but without lifetimes. fn where_clause_without_lt(x: &u8, _y: u8) -> Result<&u8, ()> +//~^ needless_lifetimes where T: Copy, { @@ -96,6 +105,7 @@ type Ref<'r> = &'r u8; fn lifetime_param_1<'a>(_x: Ref<'a>, _y: &'a u8) {} fn lifetime_param_2(_x: Ref<'_>, _y: &u8) {} +//~^ needless_lifetimes // No error; bounded lifetime. fn lifetime_param_3<'a, 'b: 'a>(_x: Ref<'a>, _y: &'b u8) {} @@ -120,6 +130,7 @@ where } fn fn_bound_2(_m: Lt<'_, I>, _f: F) -> Lt<'_, I> +//~^ needless_lifetimes where for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>, { @@ -149,6 +160,7 @@ struct X { } impl X { + //~v needless_lifetimes fn self_and_out(&self) -> &u8 { &self.x } @@ -156,6 +168,7 @@ impl X { // Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid: // fn self_and_in_out_1<'s>(&'s self, _x: &u8) -> &'s u8 // ^^^ + //~v needless_lifetimes fn self_and_in_out_1<'s>(&'s self, _x: &u8) -> &'s u8 { &self.x } @@ -163,11 +176,13 @@ impl X { // Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid: // fn self_and_in_out_2<'t>(&self, x: &'t u8) -> &'t u8 // ^^^^^ + //~v needless_lifetimes fn self_and_in_out_2<'t>(&self, x: &'t u8) -> &'t u8 { x } fn distinct_self_and_in(&self, _x: &u8) {} + //~^ needless_lifetimes // No error; same lifetimes on two params. fn self_and_same_in<'s>(&'s self, _x: &'s u8) {} @@ -186,6 +201,7 @@ fn already_elided<'a>(_: &u8, _: &'a u8) -> &'a u8 { unimplemented!() } +//~v needless_lifetimes fn struct_with_lt(_foo: Foo<'_>) -> &str { unimplemented!() } @@ -204,6 +220,7 @@ fn struct_with_lt3<'a>(_foo: &Foo<'a>) -> &'a str { // valid: // fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str // ^^ +//~v needless_lifetimes fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str { unimplemented!() } @@ -212,6 +229,7 @@ fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str { // valid: // fn struct_with_lt4b<'b>(_foo: &Foo<'b>) -> &'b str // ^^^^ +//~v needless_lifetimes fn struct_with_lt4b<'b>(_foo: &Foo<'b>) -> &'b str { unimplemented!() } @@ -227,12 +245,14 @@ fn trait_obj_elided<'a>(_arg: &'a dyn WithLifetime) -> &'a str { // Should warn because there is no lifetime on `Drop`, so this would be // unambiguous if we elided the lifetime. +//~v needless_lifetimes fn trait_obj_elided2(_arg: &dyn Drop) -> &str { unimplemented!() } type FooAlias<'a> = Foo<'a>; +//~v needless_lifetimes fn alias_with_lt(_foo: FooAlias<'_>) -> &str { unimplemented!() } @@ -251,6 +271,7 @@ fn alias_with_lt3<'a>(_foo: &FooAlias<'a>) -> &'a str { // valid: // fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str // ^^ +//~v needless_lifetimes fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str { unimplemented!() } @@ -259,10 +280,12 @@ fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str { // valid: // fn alias_with_lt4b<'b>(_foo: &FooAlias<'b>) -> &'b str // ^^^^^^^^^ +//~v needless_lifetimes fn alias_with_lt4b<'b>(_foo: &FooAlias<'b>) -> &'b str { unimplemented!() } +//~v needless_lifetimes fn named_input_elided_output(_arg: &str) -> &str { unimplemented!() } @@ -271,6 +294,7 @@ fn elided_input_named_output<'a>(_arg: &str) -> &'a str { unimplemented!() } +//~v needless_lifetimes fn trait_bound_ok>(_: &u8, _: T) { unimplemented!() } @@ -307,6 +331,7 @@ fn test<'a>(x: &'a [u8]) -> u8 { struct Cow<'a> { x: &'a str, } +//~v needless_lifetimes fn out_return_type_lts(e: &str) -> Cow<'_> { unimplemented!() } @@ -314,11 +339,11 @@ fn out_return_type_lts(e: &str) -> Cow<'_> { // Make sure we still warn on implementations mod issue4291 { trait BadTrait { - fn needless_lt(x: &u8) {} + fn needless_lt(x: &u8) {} //~ needless_lifetimes } impl BadTrait for () { - fn needless_lt(_x: &u8) {} + fn needless_lt(_x: &u8) {} //~ needless_lifetimes } } @@ -331,6 +356,7 @@ mod issue2944 { impl<'a> Foo for Baz<'a> {} impl Bar { + //~v needless_lifetimes fn baz(&self) -> impl Foo + '_ { Baz { bar: self } } @@ -363,6 +389,7 @@ mod nested_elision_sites { fn impl_trait_elidable_nested_named_lifetimes<'a>(i: &'a i32, f: impl for<'b> Fn(&'b i32) -> &'b i32) -> &'a i32 { f(i) } + //~v needless_lifetimes fn impl_trait_elidable_nested_anonymous_lifetimes(i: &i32, f: impl Fn(&i32) -> &i32) -> &i32 { f(i) } @@ -372,6 +399,7 @@ mod nested_elision_sites { f() } // lint + //~v needless_lifetimes fn generics_elidable &i32>(i: &i32, f: T) -> &i32 { f(i) } @@ -385,6 +413,7 @@ mod nested_elision_sites { } // lint fn where_clause_elidadable(i: &i32, f: T) -> &i32 + //~^ needless_lifetimes where T: Fn(&i32) -> &i32, { @@ -399,6 +428,7 @@ mod nested_elision_sites { |i| i } // lint + //~v needless_lifetimes fn pointer_fn_elidable(i: &i32, f: fn(&i32) -> &i32) -> &i32 { f(i) } @@ -412,9 +442,11 @@ mod nested_elision_sites { } // lint + //~v needless_lifetimes fn nested_fn_pointer_3(_: &i32) -> fn(fn(&i32) -> &i32) -> i32 { |f| 42 } + //~v needless_lifetimes fn nested_fn_pointer_4(_: &i32) -> impl Fn(fn(&i32)) { |f| () } @@ -437,9 +469,11 @@ mod issue7296 { struct Foo; impl Foo { + //~v needless_lifetimes fn implicit(&self) -> &() { &() } + //~v needless_lifetimes fn implicit_mut(&mut self) -> &() { &() } @@ -451,13 +485,16 @@ mod issue7296 { &() } + //~v needless_lifetimes fn lifetime_elsewhere(self: Box, here: &()) -> &() { &() } } trait Bar { - fn implicit(&self) -> &(); + fn implicit(&self) -> &(); //~ needless_lifetimes + + //~v needless_lifetimes fn implicit_provided(&self) -> &() { &() } @@ -468,6 +505,9 @@ mod issue7296 { } fn lifetime_elsewhere(self: Box, here: &()) -> &(); + //~^ needless_lifetimes + + //~v needless_lifetimes fn lifetime_elsewhere_provided(self: Box, here: &()) -> &() { &() } @@ -477,20 +517,23 @@ mod issue7296 { mod pr_9743_false_negative_fix { #![allow(unused)] - fn foo(x: &u8, y: &'_ u8) {} + fn foo(x: &u8, y: &'_ u8) {} //~ needless_lifetimes fn bar(x: &u8, y: &'_ u8, z: &'_ u8) {} + //~^ needless_lifetimes } mod pr_9743_output_lifetime_checks { #![allow(unused)] // lint: only one input + //~v needless_lifetimes fn one_input(x: &u8) -> &u8 { unimplemented!() } // lint: multiple inputs, output would not be elided + //~v needless_lifetimes fn multiple_inputs_output_not_elided<'b>(x: &u8, y: &'b u8, z: &'b u8) -> &'b u8 { unimplemented!() } @@ -507,6 +550,7 @@ mod in_macro { // lint local macro expands to function with needless lifetimes inline! { + //~v needless_lifetimes fn one_input(x: &u8) -> &u8 { unimplemented!() } diff --git a/tests/ui/needless_lifetimes.rs b/tests/ui/needless_lifetimes.rs index 03d6f2013586..705f3ac1df03 100644 --- a/tests/ui/needless_lifetimes.rs +++ b/tests/ui/needless_lifetimes.rs @@ -15,8 +15,10 @@ extern crate proc_macros; use proc_macros::inline_macros; fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {} +//~^ needless_lifetimes fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) {} +//~^ needless_lifetimes // No error; same lifetime on two params. fn same_lifetime_on_input<'a>(_x: &'a u8, _y: &'a u8) {} @@ -26,6 +28,7 @@ fn only_static_on_input(_x: &u8, _y: &u8, _z: &'static u8) {} fn mut_and_static_input(_x: &mut u8, _y: &'static str) {} +//~v needless_lifetimes fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { x } @@ -38,6 +41,7 @@ fn multiple_in_and_out_1<'a>(x: &'a u8, _y: &'a u8) -> &'a u8 { // Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid: // fn multiple_in_and_out_2a<'a>(x: &'a u8, _y: &u8) -> &'a u8 // ^^^ +//~v needless_lifetimes fn multiple_in_and_out_2a<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 { x } @@ -45,6 +49,7 @@ fn multiple_in_and_out_2a<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 { // Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid: // fn multiple_in_and_out_2b<'b>(_x: &u8, y: &'b u8) -> &'b u8 // ^^^ +//~v needless_lifetimes fn multiple_in_and_out_2b<'a, 'b>(_x: &'a u8, y: &'b u8) -> &'b u8 { y } @@ -62,6 +67,7 @@ fn in_static_and_out<'a>(x: &'a u8, _y: &'static u8) -> &'a u8 { // Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid: // fn deep_reference_1a<'a>(x: &'a u8, _y: &u8) -> Result<&'a u8, ()> // ^^^ +//~v needless_lifetimes fn deep_reference_1a<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> { Ok(x) } @@ -69,6 +75,7 @@ fn deep_reference_1a<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> { // Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid: // fn deep_reference_1b<'b>(_x: &u8, y: &'b u8) -> Result<&'b u8, ()> // ^^^ +//~v needless_lifetimes fn deep_reference_1b<'a, 'b>(_x: &'a u8, y: &'b u8) -> Result<&'b u8, ()> { Ok(y) } @@ -78,12 +85,14 @@ fn deep_reference_2<'a>(x: Result<&'a u8, &'a u8>) -> &'a u8 { x.unwrap() } +//~v needless_lifetimes fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> { Ok(x) } // Where-clause, but without lifetimes. fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> +//~^ needless_lifetimes where T: Copy, { @@ -96,6 +105,7 @@ type Ref<'r> = &'r u8; fn lifetime_param_1<'a>(_x: Ref<'a>, _y: &'a u8) {} fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {} +//~^ needless_lifetimes // No error; bounded lifetime. fn lifetime_param_3<'a, 'b: 'a>(_x: Ref<'a>, _y: &'b u8) {} @@ -120,6 +130,7 @@ where } fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> +//~^ needless_lifetimes where for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>, { @@ -149,6 +160,7 @@ struct X { } impl X { + //~v needless_lifetimes fn self_and_out<'s>(&'s self) -> &'s u8 { &self.x } @@ -156,6 +168,7 @@ impl X { // Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid: // fn self_and_in_out_1<'s>(&'s self, _x: &u8) -> &'s u8 // ^^^ + //~v needless_lifetimes fn self_and_in_out_1<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 { &self.x } @@ -163,11 +176,13 @@ impl X { // Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid: // fn self_and_in_out_2<'t>(&self, x: &'t u8) -> &'t u8 // ^^^^^ + //~v needless_lifetimes fn self_and_in_out_2<'s, 't>(&'s self, x: &'t u8) -> &'t u8 { x } fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {} + //~^ needless_lifetimes // No error; same lifetimes on two params. fn self_and_same_in<'s>(&'s self, _x: &'s u8) {} @@ -186,6 +201,7 @@ fn already_elided<'a>(_: &u8, _: &'a u8) -> &'a u8 { unimplemented!() } +//~v needless_lifetimes fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { unimplemented!() } @@ -204,6 +220,7 @@ fn struct_with_lt3<'a>(_foo: &Foo<'a>) -> &'a str { // valid: // fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str // ^^ +//~v needless_lifetimes fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { unimplemented!() } @@ -212,6 +229,7 @@ fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { // valid: // fn struct_with_lt4b<'b>(_foo: &Foo<'b>) -> &'b str // ^^^^ +//~v needless_lifetimes fn struct_with_lt4b<'a, 'b>(_foo: &'a Foo<'b>) -> &'b str { unimplemented!() } @@ -227,12 +245,14 @@ fn trait_obj_elided<'a>(_arg: &'a dyn WithLifetime) -> &'a str { // Should warn because there is no lifetime on `Drop`, so this would be // unambiguous if we elided the lifetime. +//~v needless_lifetimes fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str { unimplemented!() } type FooAlias<'a> = Foo<'a>; +//~v needless_lifetimes fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { unimplemented!() } @@ -251,6 +271,7 @@ fn alias_with_lt3<'a>(_foo: &FooAlias<'a>) -> &'a str { // valid: // fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str // ^^ +//~v needless_lifetimes fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { unimplemented!() } @@ -259,10 +280,12 @@ fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { // valid: // fn alias_with_lt4b<'b>(_foo: &FooAlias<'b>) -> &'b str // ^^^^^^^^^ +//~v needless_lifetimes fn alias_with_lt4b<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'b str { unimplemented!() } +//~v needless_lifetimes fn named_input_elided_output<'a>(_arg: &'a str) -> &str { unimplemented!() } @@ -271,6 +294,7 @@ fn elided_input_named_output<'a>(_arg: &str) -> &'a str { unimplemented!() } +//~v needless_lifetimes fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { unimplemented!() } @@ -307,6 +331,7 @@ fn test<'a>(x: &'a [u8]) -> u8 { struct Cow<'a> { x: &'a str, } +//~v needless_lifetimes fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { unimplemented!() } @@ -314,11 +339,11 @@ fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { // Make sure we still warn on implementations mod issue4291 { trait BadTrait { - fn needless_lt<'a>(x: &'a u8) {} + fn needless_lt<'a>(x: &'a u8) {} //~ needless_lifetimes } impl BadTrait for () { - fn needless_lt<'a>(_x: &'a u8) {} + fn needless_lt<'a>(_x: &'a u8) {} //~ needless_lifetimes } } @@ -331,6 +356,7 @@ mod issue2944 { impl<'a> Foo for Baz<'a> {} impl Bar { + //~v needless_lifetimes fn baz<'a>(&'a self) -> impl Foo + 'a { Baz { bar: self } } @@ -363,6 +389,7 @@ mod nested_elision_sites { fn impl_trait_elidable_nested_named_lifetimes<'a>(i: &'a i32, f: impl for<'b> Fn(&'b i32) -> &'b i32) -> &'a i32 { f(i) } + //~v needless_lifetimes fn impl_trait_elidable_nested_anonymous_lifetimes<'a>(i: &'a i32, f: impl Fn(&i32) -> &i32) -> &'a i32 { f(i) } @@ -372,6 +399,7 @@ mod nested_elision_sites { f() } // lint + //~v needless_lifetimes fn generics_elidable<'a, T: Fn(&i32) -> &i32>(i: &'a i32, f: T) -> &'a i32 { f(i) } @@ -385,6 +413,7 @@ mod nested_elision_sites { } // lint fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32 + //~^ needless_lifetimes where T: Fn(&i32) -> &i32, { @@ -399,6 +428,7 @@ mod nested_elision_sites { |i| i } // lint + //~v needless_lifetimes fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 { f(i) } @@ -412,9 +442,11 @@ mod nested_elision_sites { } // lint + //~v needless_lifetimes fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 { |f| 42 } + //~v needless_lifetimes fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) { |f| () } @@ -437,9 +469,11 @@ mod issue7296 { struct Foo; impl Foo { + //~v needless_lifetimes fn implicit<'a>(&'a self) -> &'a () { &() } + //~v needless_lifetimes fn implicit_mut<'a>(&'a mut self) -> &'a () { &() } @@ -451,13 +485,16 @@ mod issue7296 { &() } + //~v needless_lifetimes fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a () { &() } } trait Bar { - fn implicit<'a>(&'a self) -> &'a (); + fn implicit<'a>(&'a self) -> &'a (); //~ needless_lifetimes + + //~v needless_lifetimes fn implicit_provided<'a>(&'a self) -> &'a () { &() } @@ -468,6 +505,9 @@ mod issue7296 { } fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a (); + //~^ needless_lifetimes + + //~v needless_lifetimes fn lifetime_elsewhere_provided<'a>(self: Box, here: &'a ()) -> &'a () { &() } @@ -477,20 +517,23 @@ mod issue7296 { mod pr_9743_false_negative_fix { #![allow(unused)] - fn foo<'a>(x: &'a u8, y: &'_ u8) {} + fn foo<'a>(x: &'a u8, y: &'_ u8) {} //~ needless_lifetimes fn bar<'a>(x: &'a u8, y: &'_ u8, z: &'_ u8) {} + //~^ needless_lifetimes } mod pr_9743_output_lifetime_checks { #![allow(unused)] // lint: only one input + //~v needless_lifetimes fn one_input<'a>(x: &'a u8) -> &'a u8 { unimplemented!() } // lint: multiple inputs, output would not be elided + //~v needless_lifetimes fn multiple_inputs_output_not_elided<'a, 'b>(x: &'a u8, y: &'b u8, z: &'b u8) -> &'b u8 { unimplemented!() } @@ -507,6 +550,7 @@ mod in_macro { // lint local macro expands to function with needless lifetimes inline! { + //~v needless_lifetimes fn one_input<'a>(x: &'a u8) -> &'a u8 { unimplemented!() } diff --git a/tests/ui/needless_lifetimes.stderr b/tests/ui/needless_lifetimes.stderr index 7051a2604b91..e4ccd1baac58 100644 --- a/tests/ui/needless_lifetimes.stderr +++ b/tests/ui/needless_lifetimes.stderr @@ -13,7 +13,7 @@ LL + fn distinct_lifetimes(_x: &u8, _y: &u8, _z: u8) {} | error: the following explicit lifetimes could be elided: 'a, 'b - --> $DIR/needless_lifetimes.rs:19:24 + --> $DIR/needless_lifetimes.rs:20:24 | LL | fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) {} | ^^ ^^ ^^ ^^ @@ -25,7 +25,7 @@ LL + fn distinct_and_static(_x: &u8, _y: &u8, _z: &'static u8) {} | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:29:15 + --> $DIR/needless_lifetimes.rs:32:15 | LL | fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { | ^^ ^^ ^^ @@ -37,7 +37,7 @@ LL + fn in_and_out(x: &u8, _y: u8) -> &u8 { | error: the following explicit lifetimes could be elided: 'b - --> $DIR/needless_lifetimes.rs:41:31 + --> $DIR/needless_lifetimes.rs:45:31 | LL | fn multiple_in_and_out_2a<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 { | ^^ ^^ @@ -49,7 +49,7 @@ LL + fn multiple_in_and_out_2a<'a>(x: &'a u8, _y: &u8) -> &'a u8 { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:48:27 + --> $DIR/needless_lifetimes.rs:53:27 | LL | fn multiple_in_and_out_2b<'a, 'b>(_x: &'a u8, y: &'b u8) -> &'b u8 { | ^^ ^^ @@ -61,7 +61,7 @@ LL + fn multiple_in_and_out_2b<'b>(_x: &u8, y: &'b u8) -> &'b u8 { | error: the following explicit lifetimes could be elided: 'b - --> $DIR/needless_lifetimes.rs:65:26 + --> $DIR/needless_lifetimes.rs:71:26 | LL | fn deep_reference_1a<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> { | ^^ ^^ @@ -73,7 +73,7 @@ LL + fn deep_reference_1a<'a>(x: &'a u8, _y: &u8) -> Result<&'a u8, ()> { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:72:22 + --> $DIR/needless_lifetimes.rs:79:22 | LL | fn deep_reference_1b<'a, 'b>(_x: &'a u8, y: &'b u8) -> Result<&'b u8, ()> { | ^^ ^^ @@ -85,7 +85,7 @@ LL + fn deep_reference_1b<'b>(_x: &u8, y: &'b u8) -> Result<&'b u8, ()> { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:81:21 + --> $DIR/needless_lifetimes.rs:89:21 | LL | fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> { | ^^ ^^ ^^ @@ -97,7 +97,7 @@ LL + fn deep_reference_3(x: &u8, _y: u8) -> Result<&u8, ()> { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:86:28 + --> $DIR/needless_lifetimes.rs:94:28 | LL | fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> | ^^ ^^ ^^ @@ -109,7 +109,7 @@ LL + fn where_clause_without_lt(x: &u8, _y: u8) -> Result<&u8, ()> | error: the following explicit lifetimes could be elided: 'a, 'b - --> $DIR/needless_lifetimes.rs:98:21 + --> $DIR/needless_lifetimes.rs:107:21 | LL | fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {} | ^^ ^^ ^^ ^^ @@ -121,7 +121,7 @@ LL + fn lifetime_param_2(_x: Ref<'_>, _y: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:122:15 + --> $DIR/needless_lifetimes.rs:132:15 | LL | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> | ^^ ^^ ^^ @@ -133,7 +133,7 @@ LL + fn fn_bound_2(_m: Lt<'_, I>, _f: F) -> Lt<'_, I> | error: the following explicit lifetimes could be elided: 's - --> $DIR/needless_lifetimes.rs:152:21 + --> $DIR/needless_lifetimes.rs:164:21 | LL | fn self_and_out<'s>(&'s self) -> &'s u8 { | ^^ ^^ ^^ @@ -145,7 +145,7 @@ LL + fn self_and_out(&self) -> &u8 { | error: the following explicit lifetimes could be elided: 't - --> $DIR/needless_lifetimes.rs:159:30 + --> $DIR/needless_lifetimes.rs:172:30 | LL | fn self_and_in_out_1<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 { | ^^ ^^ @@ -157,7 +157,7 @@ LL + fn self_and_in_out_1<'s>(&'s self, _x: &u8) -> &'s u8 { | error: the following explicit lifetimes could be elided: 's - --> $DIR/needless_lifetimes.rs:166:26 + --> $DIR/needless_lifetimes.rs:180:26 | LL | fn self_and_in_out_2<'s, 't>(&'s self, x: &'t u8) -> &'t u8 { | ^^ ^^ @@ -169,7 +169,7 @@ LL + fn self_and_in_out_2<'t>(&self, x: &'t u8) -> &'t u8 { | error: the following explicit lifetimes could be elided: 's, 't - --> $DIR/needless_lifetimes.rs:170:29 + --> $DIR/needless_lifetimes.rs:184:29 | LL | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {} | ^^ ^^ ^^ ^^ @@ -181,7 +181,7 @@ LL + fn distinct_self_and_in(&self, _x: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:189:19 + --> $DIR/needless_lifetimes.rs:205:19 | LL | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { | ^^ ^^ ^^ @@ -193,7 +193,7 @@ LL + fn struct_with_lt(_foo: Foo<'_>) -> &str { | error: the following explicit lifetimes could be elided: 'b - --> $DIR/needless_lifetimes.rs:207:25 + --> $DIR/needless_lifetimes.rs:224:25 | LL | fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { | ^^ ^^ @@ -205,7 +205,7 @@ LL + fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:215:21 + --> $DIR/needless_lifetimes.rs:233:21 | LL | fn struct_with_lt4b<'a, 'b>(_foo: &'a Foo<'b>) -> &'b str { | ^^ ^^ @@ -217,7 +217,7 @@ LL + fn struct_with_lt4b<'b>(_foo: &Foo<'b>) -> &'b str { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:230:22 + --> $DIR/needless_lifetimes.rs:249:22 | LL | fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str { | ^^ ^^ ^^ @@ -229,7 +229,7 @@ LL + fn trait_obj_elided2(_arg: &dyn Drop) -> &str { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:236:18 + --> $DIR/needless_lifetimes.rs:256:18 | LL | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { | ^^ ^^ ^^ @@ -241,7 +241,7 @@ LL + fn alias_with_lt(_foo: FooAlias<'_>) -> &str { | error: the following explicit lifetimes could be elided: 'b - --> $DIR/needless_lifetimes.rs:254:24 + --> $DIR/needless_lifetimes.rs:275:24 | LL | fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { | ^^ ^^ @@ -253,7 +253,7 @@ LL + fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:262:20 + --> $DIR/needless_lifetimes.rs:284:20 | LL | fn alias_with_lt4b<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'b str { | ^^ ^^ @@ -265,7 +265,7 @@ LL + fn alias_with_lt4b<'b>(_foo: &FooAlias<'b>) -> &'b str { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:266:30 + --> $DIR/needless_lifetimes.rs:289:30 | LL | fn named_input_elided_output<'a>(_arg: &'a str) -> &str { | ^^ ^^ ^ @@ -277,7 +277,7 @@ LL + fn named_input_elided_output(_arg: &str) -> &str { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:274:19 + --> $DIR/needless_lifetimes.rs:298:19 | LL | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { | ^^ ^^ @@ -289,7 +289,7 @@ LL + fn trait_bound_ok>(_: &u8, _: T) { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:310:24 + --> $DIR/needless_lifetimes.rs:335:24 | LL | fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { | ^^ ^^ ^^ @@ -301,7 +301,7 @@ LL + fn out_return_type_lts(e: &str) -> Cow<'_> { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:317:24 + --> $DIR/needless_lifetimes.rs:342:24 | LL | fn needless_lt<'a>(x: &'a u8) {} | ^^ ^^ @@ -313,7 +313,7 @@ LL + fn needless_lt(x: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:321:24 + --> $DIR/needless_lifetimes.rs:346:24 | LL | fn needless_lt<'a>(_x: &'a u8) {} | ^^ ^^ @@ -325,7 +325,7 @@ LL + fn needless_lt(_x: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:334:16 + --> $DIR/needless_lifetimes.rs:360:16 | LL | fn baz<'a>(&'a self) -> impl Foo + 'a { | ^^ ^^ ^^ @@ -337,7 +337,7 @@ LL + fn baz(&self) -> impl Foo + '_ { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:366:55 + --> $DIR/needless_lifetimes.rs:393:55 | LL | fn impl_trait_elidable_nested_anonymous_lifetimes<'a>(i: &'a i32, f: impl Fn(&i32) -> &i32) -> &'a i32 { | ^^ ^^ ^^ @@ -349,7 +349,7 @@ LL + fn impl_trait_elidable_nested_anonymous_lifetimes(i: &i32, f: impl Fn(& | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:375:26 + --> $DIR/needless_lifetimes.rs:403:26 | LL | fn generics_elidable<'a, T: Fn(&i32) -> &i32>(i: &'a i32, f: T) -> &'a i32 { | ^^ ^^ ^^ @@ -361,7 +361,7 @@ LL + fn generics_elidable &i32>(i: &i32, f: T) -> &i32 { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:387:32 + --> $DIR/needless_lifetimes.rs:415:32 | LL | fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32 | ^^ ^^ ^^ @@ -373,7 +373,7 @@ LL + fn where_clause_elidadable(i: &i32, f: T) -> &i32 | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:402:28 + --> $DIR/needless_lifetimes.rs:432:28 | LL | fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 { | ^^ ^^ ^^ @@ -385,7 +385,7 @@ LL + fn pointer_fn_elidable(i: &i32, f: fn(&i32) -> &i32) -> &i32 { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:415:28 + --> $DIR/needless_lifetimes.rs:446:28 | LL | fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 { | ^^ ^^ @@ -397,7 +397,7 @@ LL + fn nested_fn_pointer_3(_: &i32) -> fn(fn(&i32) -> &i32) -> i32 { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:418:28 + --> $DIR/needless_lifetimes.rs:450:28 | LL | fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) { | ^^ ^^ @@ -409,7 +409,7 @@ LL + fn nested_fn_pointer_4(_: &i32) -> impl Fn(fn(&i32)) { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:440:21 + --> $DIR/needless_lifetimes.rs:473:21 | LL | fn implicit<'a>(&'a self) -> &'a () { | ^^ ^^ ^^ @@ -421,7 +421,7 @@ LL + fn implicit(&self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:443:25 + --> $DIR/needless_lifetimes.rs:477:25 | LL | fn implicit_mut<'a>(&'a mut self) -> &'a () { | ^^ ^^ ^^ @@ -433,7 +433,7 @@ LL + fn implicit_mut(&mut self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:454:31 + --> $DIR/needless_lifetimes.rs:489:31 | LL | fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a () { | ^^ ^^ ^^ @@ -445,7 +445,7 @@ LL + fn lifetime_elsewhere(self: Box, here: &()) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:460:21 + --> $DIR/needless_lifetimes.rs:495:21 | LL | fn implicit<'a>(&'a self) -> &'a (); | ^^ ^^ ^^ @@ -457,7 +457,7 @@ LL + fn implicit(&self) -> &(); | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:461:30 + --> $DIR/needless_lifetimes.rs:498:30 | LL | fn implicit_provided<'a>(&'a self) -> &'a () { | ^^ ^^ ^^ @@ -469,7 +469,7 @@ LL + fn implicit_provided(&self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:470:31 + --> $DIR/needless_lifetimes.rs:507:31 | LL | fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a (); | ^^ ^^ ^^ @@ -481,7 +481,7 @@ LL + fn lifetime_elsewhere(self: Box, here: &()) -> &(); | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:471:40 + --> $DIR/needless_lifetimes.rs:511:40 | LL | fn lifetime_elsewhere_provided<'a>(self: Box, here: &'a ()) -> &'a () { | ^^ ^^ ^^ @@ -493,7 +493,7 @@ LL + fn lifetime_elsewhere_provided(self: Box, here: &()) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:480:12 + --> $DIR/needless_lifetimes.rs:520:12 | LL | fn foo<'a>(x: &'a u8, y: &'_ u8) {} | ^^ ^^ @@ -505,7 +505,7 @@ LL + fn foo(x: &u8, y: &'_ u8) {} | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:482:12 + --> $DIR/needless_lifetimes.rs:522:12 | LL | fn bar<'a>(x: &'a u8, y: &'_ u8, z: &'_ u8) {} | ^^ ^^ @@ -517,7 +517,7 @@ LL + fn bar(x: &u8, y: &'_ u8, z: &'_ u8) {} | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:489:18 + --> $DIR/needless_lifetimes.rs:531:18 | LL | fn one_input<'a>(x: &'a u8) -> &'a u8 { | ^^ ^^ ^^ @@ -529,7 +529,7 @@ LL + fn one_input(x: &u8) -> &u8 { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:494:42 + --> $DIR/needless_lifetimes.rs:537:42 | LL | fn multiple_inputs_output_not_elided<'a, 'b>(x: &'a u8, y: &'b u8, z: &'b u8) -> &'b u8 { | ^^ ^^ @@ -541,7 +541,7 @@ LL + fn multiple_inputs_output_not_elided<'b>(x: &u8, y: &'b u8, z: &'b u8) | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:510:22 + --> $DIR/needless_lifetimes.rs:554:22 | LL | fn one_input<'a>(x: &'a u8) -> &'a u8 { | ^^ ^^ ^^ diff --git a/tests/ui/needless_match.fixed b/tests/ui/needless_match.fixed index a936eb463f96..e334321d9e4e 100644 --- a/tests/ui/needless_match.fixed +++ b/tests/ui/needless_match.fixed @@ -12,13 +12,16 @@ enum Simple { fn useless_match() { let i = 10; + //~v needless_match let _: i32 = i; let s = "test"; + //~v needless_match let _: &str = s; } fn custom_type_match() { let se = Simple::A; + //~v needless_match let _: Simple = se; // Don't trigger let _: Simple = match se { @@ -36,6 +39,7 @@ fn custom_type_match() { } fn option_match(x: Option) { + //~v needless_match let _: Option = x; // Don't trigger, this is the case for manual_map_option let _: Option = match x { @@ -49,7 +53,9 @@ fn func_ret_err(err: T) -> Result { } fn result_match() { + //~v needless_match let _: Result = Ok(1); + //~v needless_match let _: Result = func_ret_err(0_i32); // as ref, don't trigger let res = &func_ret_err(0_i32); @@ -61,6 +67,7 @@ fn result_match() { fn if_let_option() { let _ = Some(1); + //~^ needless_match fn do_something() {} @@ -96,13 +103,16 @@ fn if_let_option_result() -> Result<(), ()> { fn if_let_result() { let x: Result = Ok(1); let _: Result = x; + //~^ needless_match let _: Result = x; + //~^ needless_match // Input type mismatch, don't trigger #[allow(clippy::question_mark)] let _: Result = if let Err(e) = Ok(1) { Err(e) } else { x }; } fn if_let_custom_enum(x: Simple) { + //~v needless_match let _: Simple = x; // Don't trigger @@ -134,6 +144,7 @@ mod issue8542 { let aa = 0_u8; let bb = false; + //~v needless_match let _: Complex = ce; // Don't trigger @@ -212,9 +223,11 @@ mod issue9084 { let e = Some(1); // should lint + //~v needless_match let _ = e; // should lint + //~v needless_match let _ = e; // should not lint diff --git a/tests/ui/needless_match.rs b/tests/ui/needless_match.rs index b1dd6ff075d8..535b1d7bb9e7 100644 --- a/tests/ui/needless_match.rs +++ b/tests/ui/needless_match.rs @@ -12,6 +12,7 @@ enum Simple { fn useless_match() { let i = 10; + //~v needless_match let _: i32 = match i { 0 => 0, 1 => 1, @@ -19,6 +20,7 @@ fn useless_match() { _ => i, }; let s = "test"; + //~v needless_match let _: &str = match s { "a" => "a", "b" => "b", @@ -28,6 +30,7 @@ fn useless_match() { fn custom_type_match() { let se = Simple::A; + //~v needless_match let _: Simple = match se { Simple::A => Simple::A, Simple::B => Simple::B, @@ -50,6 +53,7 @@ fn custom_type_match() { } fn option_match(x: Option) { + //~v needless_match let _: Option = match x { Some(a) => Some(a), None => None, @@ -66,10 +70,12 @@ fn func_ret_err(err: T) -> Result { } fn result_match() { + //~v needless_match let _: Result = match Ok(1) { Ok(a) => Ok(a), Err(err) => Err(err), }; + //~v needless_match let _: Result = match func_ret_err(0_i32) { Err(err) => Err(err), Ok(a) => Ok(a), @@ -84,6 +90,7 @@ fn result_match() { fn if_let_option() { let _ = if let Some(a) = Some(1) { Some(a) } else { None }; + //~^ needless_match fn do_something() {} @@ -119,13 +126,16 @@ fn if_let_option_result() -> Result<(), ()> { fn if_let_result() { let x: Result = Ok(1); let _: Result = if let Err(e) = x { Err(e) } else { x }; + //~^ needless_match let _: Result = if let Ok(val) = x { Ok(val) } else { x }; + //~^ needless_match // Input type mismatch, don't trigger #[allow(clippy::question_mark)] let _: Result = if let Err(e) = Ok(1) { Err(e) } else { x }; } fn if_let_custom_enum(x: Simple) { + //~v needless_match let _: Simple = if let Simple::A = x { Simple::A } else if let Simple::B = x { @@ -165,6 +175,7 @@ mod issue8542 { let aa = 0_u8; let bb = false; + //~v needless_match let _: Complex = match ce { Complex::A(a) => Complex::A(a), Complex::B(a, b) => Complex::B(a, b), @@ -249,12 +260,14 @@ mod issue9084 { let e = Some(1); // should lint + //~v needless_match let _ = match e { _ if some_bool => e, _ => e, }; // should lint + //~v needless_match let _ = match e { Some(i) => Some(i), _ if some_bool => e, diff --git a/tests/ui/needless_match.stderr b/tests/ui/needless_match.stderr index 736926b4415b..68647f2c8420 100644 --- a/tests/ui/needless_match.stderr +++ b/tests/ui/needless_match.stderr @@ -1,5 +1,5 @@ error: this match expression is unnecessary - --> $DIR/needless_match.rs:15:18 + --> $DIR/needless_match.rs:16:18 | LL | let _: i32 = match i { | __________________^ @@ -14,7 +14,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::needless_match)]` error: this match expression is unnecessary - --> $DIR/needless_match.rs:22:19 + --> $DIR/needless_match.rs:24:19 | LL | let _: &str = match s { | ___________________^ @@ -25,7 +25,7 @@ LL | | }; | |_____^ help: replace it with: `s` error: this match expression is unnecessary - --> $DIR/needless_match.rs:31:21 + --> $DIR/needless_match.rs:34:21 | LL | let _: Simple = match se { | _____________________^ @@ -37,7 +37,7 @@ LL | | }; | |_____^ help: replace it with: `se` error: this match expression is unnecessary - --> $DIR/needless_match.rs:53:26 + --> $DIR/needless_match.rs:57:26 | LL | let _: Option = match x { | __________________________^ @@ -47,7 +47,7 @@ LL | | }; | |_____^ help: replace it with: `x` error: this match expression is unnecessary - --> $DIR/needless_match.rs:69:31 + --> $DIR/needless_match.rs:74:31 | LL | let _: Result = match Ok(1) { | _______________________________^ @@ -57,7 +57,7 @@ LL | | }; | |_____^ help: replace it with: `Ok(1)` error: this match expression is unnecessary - --> $DIR/needless_match.rs:73:31 + --> $DIR/needless_match.rs:79:31 | LL | let _: Result = match func_ret_err(0_i32) { | _______________________________^ @@ -67,25 +67,25 @@ LL | | }; | |_____^ help: replace it with: `func_ret_err(0_i32)` error: this if-let expression is unnecessary - --> $DIR/needless_match.rs:86:13 + --> $DIR/needless_match.rs:92:13 | LL | let _ = if let Some(a) = Some(1) { Some(a) } else { None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `Some(1)` error: this if-let expression is unnecessary - --> $DIR/needless_match.rs:121:31 + --> $DIR/needless_match.rs:128:31 | LL | let _: Result = if let Err(e) = x { Err(e) } else { x }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x` error: this if-let expression is unnecessary - --> $DIR/needless_match.rs:122:31 + --> $DIR/needless_match.rs:130:31 | LL | let _: Result = if let Ok(val) = x { Ok(val) } else { x }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x` error: this if-let expression is unnecessary - --> $DIR/needless_match.rs:129:21 + --> $DIR/needless_match.rs:139:21 | LL | let _: Simple = if let Simple::A = x { | _____________________^ @@ -98,7 +98,7 @@ LL | | }; | |_____^ help: replace it with: `x` error: this match expression is unnecessary - --> $DIR/needless_match.rs:168:26 + --> $DIR/needless_match.rs:179:26 | LL | let _: Complex = match ce { | __________________________^ @@ -111,7 +111,7 @@ LL | | }; | |_________^ help: replace it with: `ce` error: this match expression is unnecessary - --> $DIR/needless_match.rs:252:17 + --> $DIR/needless_match.rs:264:17 | LL | let _ = match e { | _________________^ @@ -121,7 +121,7 @@ LL | | }; | |_________^ help: replace it with: `e` error: this match expression is unnecessary - --> $DIR/needless_match.rs:258:17 + --> $DIR/needless_match.rs:271:17 | LL | let _ = match e { | _________________^ diff --git a/tests/ui/needless_option_as_deref.fixed b/tests/ui/needless_option_as_deref.fixed index 58f56eba0f53..c2d586816b60 100644 --- a/tests/ui/needless_option_as_deref.fixed +++ b/tests/ui/needless_option_as_deref.fixed @@ -5,11 +5,13 @@ fn main() { // should lint let _: Option<&usize> = Some(&1); + //~^ needless_option_as_deref let _: Option<&mut usize> = Some(&mut 1); + //~^ needless_option_as_deref let mut y = 0; let mut x = Some(&mut y); - let _ = x; + let _ = x; //~ needless_option_as_deref // should not lint let _ = Some(Box::new(1)).as_deref(); diff --git a/tests/ui/needless_option_as_deref.rs b/tests/ui/needless_option_as_deref.rs index 842e025f669b..674414331116 100644 --- a/tests/ui/needless_option_as_deref.rs +++ b/tests/ui/needless_option_as_deref.rs @@ -5,11 +5,13 @@ fn main() { // should lint let _: Option<&usize> = Some(&1).as_deref(); + //~^ needless_option_as_deref let _: Option<&mut usize> = Some(&mut 1).as_deref_mut(); + //~^ needless_option_as_deref let mut y = 0; let mut x = Some(&mut y); - let _ = x.as_deref_mut(); + let _ = x.as_deref_mut(); //~ needless_option_as_deref // should not lint let _ = Some(Box::new(1)).as_deref(); diff --git a/tests/ui/needless_option_as_deref.stderr b/tests/ui/needless_option_as_deref.stderr index 024d30c1717c..a64014f87fd7 100644 --- a/tests/ui/needless_option_as_deref.stderr +++ b/tests/ui/needless_option_as_deref.stderr @@ -8,13 +8,13 @@ LL | let _: Option<&usize> = Some(&1).as_deref(); = help: to override `-D warnings` add `#[allow(clippy::needless_option_as_deref)]` error: derefed type is same as origin - --> $DIR/needless_option_as_deref.rs:8:33 + --> $DIR/needless_option_as_deref.rs:9:33 | LL | let _: Option<&mut usize> = Some(&mut 1).as_deref_mut(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(&mut 1)` error: derefed type is same as origin - --> $DIR/needless_option_as_deref.rs:12:13 + --> $DIR/needless_option_as_deref.rs:14:13 | LL | let _ = x.as_deref_mut(); | ^^^^^^^^^^^^^^^^ help: try: `x` diff --git a/tests/ui/needless_option_take.fixed b/tests/ui/needless_option_take.fixed index d732a2686cb9..8519ae63e11a 100644 --- a/tests/ui/needless_option_take.fixed +++ b/tests/ui/needless_option_take.fixed @@ -9,5 +9,5 @@ fn main() { println!("Testing erroneous option_take_on_temporary"); let x = Some(3); - x.as_ref(); + x.as_ref(); //~ needless_option_take } diff --git a/tests/ui/needless_option_take.rs b/tests/ui/needless_option_take.rs index f947d874e064..cb24175cd26a 100644 --- a/tests/ui/needless_option_take.rs +++ b/tests/ui/needless_option_take.rs @@ -9,5 +9,5 @@ fn main() { println!("Testing erroneous option_take_on_temporary"); let x = Some(3); - x.as_ref().take(); + x.as_ref().take(); //~ needless_option_take } diff --git a/tests/ui/needless_parens_on_range_literals.fixed b/tests/ui/needless_parens_on_range_literals.fixed index b4d9e3297c49..cb14808bfbab 100644 --- a/tests/ui/needless_parens_on_range_literals.fixed +++ b/tests/ui/needless_parens_on_range_literals.fixed @@ -5,9 +5,11 @@ fn main() { let _ = 'a'..='z'; - let _ = 'a'..'z'; + //~^ needless_parens_on_range_literals + //~| needless_parens_on_range_literals + let _ = 'a'..'z'; //~ needless_parens_on_range_literals let _ = (1.)..2.; - let _ = (1.)..2.; - let _ = 'a'..; - let _ = ..'z'; + let _ = (1.)..2.; //~ needless_parens_on_range_literals + let _ = 'a'..; //~ needless_parens_on_range_literals + let _ = ..'z'; //~ needless_parens_on_range_literals } diff --git a/tests/ui/needless_parens_on_range_literals.rs b/tests/ui/needless_parens_on_range_literals.rs index 2f0e54f80d85..899f79225c9e 100644 --- a/tests/ui/needless_parens_on_range_literals.rs +++ b/tests/ui/needless_parens_on_range_literals.rs @@ -5,9 +5,11 @@ fn main() { let _ = ('a')..=('z'); - let _ = 'a'..('z'); + //~^ needless_parens_on_range_literals + //~| needless_parens_on_range_literals + let _ = 'a'..('z'); //~ needless_parens_on_range_literals let _ = (1.)..2.; - let _ = (1.)..(2.); - let _ = ('a')..; - let _ = ..('z'); + let _ = (1.)..(2.); //~ needless_parens_on_range_literals + let _ = ('a')..; //~ needless_parens_on_range_literals + let _ = ..('z'); //~ needless_parens_on_range_literals } diff --git a/tests/ui/needless_parens_on_range_literals.stderr b/tests/ui/needless_parens_on_range_literals.stderr index c73564e210c0..8ec305138c94 100644 --- a/tests/ui/needless_parens_on_range_literals.stderr +++ b/tests/ui/needless_parens_on_range_literals.stderr @@ -14,25 +14,25 @@ LL | let _ = ('a')..=('z'); | ^^^^^ help: try: `'z'` error: needless parenthesis on range literals can be removed - --> $DIR/needless_parens_on_range_literals.rs:8:18 + --> $DIR/needless_parens_on_range_literals.rs:10:18 | LL | let _ = 'a'..('z'); | ^^^^^ help: try: `'z'` error: needless parenthesis on range literals can be removed - --> $DIR/needless_parens_on_range_literals.rs:10:19 + --> $DIR/needless_parens_on_range_literals.rs:12:19 | LL | let _ = (1.)..(2.); | ^^^^ help: try: `2.` error: needless parenthesis on range literals can be removed - --> $DIR/needless_parens_on_range_literals.rs:11:13 + --> $DIR/needless_parens_on_range_literals.rs:13:13 | LL | let _ = ('a')..; | ^^^^^ help: try: `'a'` error: needless parenthesis on range literals can be removed - --> $DIR/needless_parens_on_range_literals.rs:12:15 + --> $DIR/needless_parens_on_range_literals.rs:14:15 | LL | let _ = ..('z'); | ^^^^^ help: try: `'z'` diff --git a/tests/ui/needless_pass_by_ref_mut.rs b/tests/ui/needless_pass_by_ref_mut.rs index a92197fb0af5..0dfebf9f8057 100644 --- a/tests/ui/needless_pass_by_ref_mut.rs +++ b/tests/ui/needless_pass_by_ref_mut.rs @@ -157,6 +157,7 @@ async fn a7(x: i32, y: i32, z: &mut i32) { //~^ ERROR: this argument is a mutable reference, but not used mutably println!("{:?}", z); } +//~v needless_pass_by_ref_mut async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) { //~^ ERROR: this argument is a mutable reference, but not used mutably println!("{:?}", z); @@ -238,6 +239,7 @@ async fn async_vec2(b: &mut Vec) { } fn non_mut(n: &str) {} //Should warn +//~v needless_pass_by_ref_mut pub async fn call_in_closure1(n: &mut str) { (|| non_mut(n))() } @@ -250,6 +252,7 @@ pub async fn call_in_closure2(str: &mut String) { } // Should not warn. +//~v needless_pass_by_ref_mut pub async fn closure(n: &mut usize) -> impl '_ + FnMut() { || { *n += 1; @@ -308,17 +311,22 @@ fn filter_copy(predicate: &mut impl FnMut(T) -> bool) -> impl FnMut(&T) } // `is_from_proc_macro` stress tests -fn _empty_tup(x: &mut (())) {} -fn _single_tup(x: &mut ((i32,))) {} -fn _multi_tup(x: &mut ((i32, u32))) {} -fn _fn(x: &mut (fn())) {} +fn _empty_tup(x: &mut (())) {} //~ needless_pass_by_ref_mut +fn _single_tup(x: &mut ((i32,))) {} //~ needless_pass_by_ref_mut +fn _multi_tup(x: &mut ((i32, u32))) {} //~ needless_pass_by_ref_mut +fn _fn(x: &mut (fn())) {} //~ needless_pass_by_ref_mut #[rustfmt::skip] fn _extern_rust_fn(x: &mut extern "Rust" fn()) {} +//~^ needless_pass_by_ref_mut fn _extern_c_fn(x: &mut extern "C" fn()) {} -fn _unsafe_fn(x: &mut unsafe fn()) {} +//~^ needless_pass_by_ref_mut +fn _unsafe_fn(x: &mut unsafe fn()) {} //~ needless_pass_by_ref_mut fn _unsafe_extern_fn(x: &mut unsafe extern "C" fn()) {} +//~^ needless_pass_by_ref_mut fn _fn_with_arg(x: &mut unsafe extern "C" fn(i32)) {} +//~^ needless_pass_by_ref_mut fn _fn_with_ret(x: &mut unsafe extern "C" fn() -> (i32)) {} +//~^ needless_pass_by_ref_mut fn main() { let mut u = 0; diff --git a/tests/ui/needless_pass_by_ref_mut.stderr b/tests/ui/needless_pass_by_ref_mut.stderr index 5d1e9515de12..0a8e4476af7d 100644 --- a/tests/ui/needless_pass_by_ref_mut.stderr +++ b/tests/ui/needless_pass_by_ref_mut.stderr @@ -68,19 +68,19 @@ LL | async fn a7(x: i32, y: i32, z: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:160:24 + --> $DIR/needless_pass_by_ref_mut.rs:161:24 | LL | async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:160:45 + --> $DIR/needless_pass_by_ref_mut.rs:161:45 | LL | async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:194:16 + --> $DIR/needless_pass_by_ref_mut.rs:195:16 | LL | fn cfg_warn(s: &mut u32) {} | ^^^^^^^^ help: consider changing to: `&u32` @@ -88,7 +88,7 @@ LL | fn cfg_warn(s: &mut u32) {} = note: this is cfg-gated and may require further changes error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:200:20 + --> $DIR/needless_pass_by_ref_mut.rs:201:20 | LL | fn cfg_warn(s: &mut u32) {} | ^^^^^^^^ help: consider changing to: `&u32` @@ -96,19 +96,19 @@ LL | fn cfg_warn(s: &mut u32) {} = note: this is cfg-gated and may require further changes error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:214:39 + --> $DIR/needless_pass_by_ref_mut.rs:215:39 | LL | async fn inner_async2(x: &mut i32, y: &mut u32) { | ^^^^^^^^ help: consider changing to: `&u32` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:222:26 + --> $DIR/needless_pass_by_ref_mut.rs:223:26 | LL | async fn inner_async3(x: &mut i32, y: &mut u32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:241:34 + --> $DIR/needless_pass_by_ref_mut.rs:243:34 | LL | pub async fn call_in_closure1(n: &mut str) { | ^^^^^^^^ help: consider changing to: `&str` @@ -116,7 +116,7 @@ LL | pub async fn call_in_closure1(n: &mut str) { = warning: changing this function will impact semver compatibility error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:253:25 + --> $DIR/needless_pass_by_ref_mut.rs:256:25 | LL | pub async fn closure(n: &mut usize) -> impl '_ + FnMut() { | ^^^^^^^^^^ help: consider changing to: `&usize` @@ -124,7 +124,7 @@ LL | pub async fn closure(n: &mut usize) -> impl '_ + FnMut() { = warning: changing this function will impact semver compatibility error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:260:20 + --> $DIR/needless_pass_by_ref_mut.rs:263:20 | LL | pub fn closure2(n: &mut usize) -> impl '_ + FnMut() -> usize { | ^^^^^^^^^^ help: consider changing to: `&usize` @@ -132,7 +132,7 @@ LL | pub fn closure2(n: &mut usize) -> impl '_ + FnMut() -> usize { = warning: changing this function will impact semver compatibility error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:271:26 + --> $DIR/needless_pass_by_ref_mut.rs:274:26 | LL | pub async fn closure4(n: &mut usize) { | ^^^^^^^^^^ help: consider changing to: `&usize` @@ -140,61 +140,61 @@ LL | pub async fn closure4(n: &mut usize) { = warning: changing this function will impact semver compatibility error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:311:18 + --> $DIR/needless_pass_by_ref_mut.rs:314:18 | LL | fn _empty_tup(x: &mut (())) {} | ^^^^^^^^^ help: consider changing to: `&()` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:312:19 + --> $DIR/needless_pass_by_ref_mut.rs:315:19 | LL | fn _single_tup(x: &mut ((i32,))) {} | ^^^^^^^^^^^^^ help: consider changing to: `&(i32,)` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:313:18 + --> $DIR/needless_pass_by_ref_mut.rs:316:18 | LL | fn _multi_tup(x: &mut ((i32, u32))) {} | ^^^^^^^^^^^^^^^^^ help: consider changing to: `&(i32, u32)` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:314:11 + --> $DIR/needless_pass_by_ref_mut.rs:317:11 | LL | fn _fn(x: &mut (fn())) {} | ^^^^^^^^^^^ help: consider changing to: `&fn()` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:316:23 + --> $DIR/needless_pass_by_ref_mut.rs:319:23 | LL | fn _extern_rust_fn(x: &mut extern "Rust" fn()) {} | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&extern "Rust" fn()` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:317:20 + --> $DIR/needless_pass_by_ref_mut.rs:321:20 | LL | fn _extern_c_fn(x: &mut extern "C" fn()) {} | ^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&extern "C" fn()` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:318:18 + --> $DIR/needless_pass_by_ref_mut.rs:323:18 | LL | fn _unsafe_fn(x: &mut unsafe fn()) {} | ^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe fn()` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:319:25 + --> $DIR/needless_pass_by_ref_mut.rs:324:25 | LL | fn _unsafe_extern_fn(x: &mut unsafe extern "C" fn()) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe extern "C" fn()` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:320:20 + --> $DIR/needless_pass_by_ref_mut.rs:326:20 | LL | fn _fn_with_arg(x: &mut unsafe extern "C" fn(i32)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe extern "C" fn(i32)` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:321:20 + --> $DIR/needless_pass_by_ref_mut.rs:328:20 | LL | fn _fn_with_ret(x: &mut unsafe extern "C" fn() -> (i32)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe extern "C" fn() -> (i32)` diff --git a/tests/ui/needless_pub_self.fixed b/tests/ui/needless_pub_self.fixed index d9f7b92d0901..6bbc0782c147 100644 --- a/tests/ui/needless_pub_self.fixed +++ b/tests/ui/needless_pub_self.fixed @@ -10,14 +10,14 @@ #[macro_use] extern crate proc_macros; - fn a() {} - fn b() {} + fn a() {} //~ needless_pub_self + fn b() {} //~ needless_pub_self pub fn c() {} mod a { pub(in super) fn d() {} pub(super) fn e() {} - fn f() {} + fn f() {} //~ needless_pub_self } external! { diff --git a/tests/ui/needless_pub_self.rs b/tests/ui/needless_pub_self.rs index 9f0ec76477e6..4cec5b32b337 100644 --- a/tests/ui/needless_pub_self.rs +++ b/tests/ui/needless_pub_self.rs @@ -10,14 +10,14 @@ #[macro_use] extern crate proc_macros; -pub(self) fn a() {} -pub(in self) fn b() {} +pub(self) fn a() {} //~ needless_pub_self +pub(in self) fn b() {} //~ needless_pub_self pub fn c() {} mod a { pub(in super) fn d() {} pub(super) fn e() {} - pub(self) fn f() {} + pub(self) fn f() {} //~ needless_pub_self } external! { diff --git a/tests/ui/needless_question_mark.fixed b/tests/ui/needless_question_mark.fixed index 92f01c217c1c..65bee6c586f1 100644 --- a/tests/ui/needless_question_mark.fixed +++ b/tests/ui/needless_question_mark.fixed @@ -17,7 +17,7 @@ struct TR { fn simple_option_bad1(to: TO) -> Option { // return as a statement - return to.magic; + return to.magic; //~ needless_question_mark } // formatting will add a semi-colon, which would make @@ -25,17 +25,17 @@ fn simple_option_bad1(to: TO) -> Option { #[rustfmt::skip] fn simple_option_bad2(to: TO) -> Option { // return as an expression - return to.magic + return to.magic //~ needless_question_mark } fn simple_option_bad3(to: TO) -> Option { // block value "return" - to.magic + to.magic //~ needless_question_mark } fn simple_option_bad4(to: Option) -> Option { // single line closure - to.and_then(|t| t.magic) + to.and_then(|t| t.magic) //~ needless_question_mark } // formatting this will remove the block brackets, making @@ -44,27 +44,27 @@ fn simple_option_bad4(to: Option) -> Option { fn simple_option_bad5(to: Option) -> Option { // closure with body to.and_then(|t| { - t.magic + t.magic //~ needless_question_mark }) } fn simple_result_bad1(tr: TR) -> Result { - return tr.magic; + return tr.magic; //~ needless_question_mark } // formatting will add a semi-colon, which would make // this identical to the test case above #[rustfmt::skip] fn simple_result_bad2(tr: TR) -> Result { - return tr.magic + return tr.magic //~ needless_question_mark } fn simple_result_bad3(tr: TR) -> Result { - tr.magic + tr.magic //~ needless_question_mark } fn simple_result_bad4(tr: Result) -> Result { - tr.and_then(|t| t.magic) + tr.and_then(|t| t.magic) //~ needless_question_mark } // formatting this will remove the block brackets, making @@ -72,14 +72,14 @@ fn simple_result_bad4(tr: Result) -> Result { #[rustfmt::skip] fn simple_result_bad5(tr: Result) -> Result { tr.and_then(|t| { - t.magic + t.magic //~ needless_question_mark }) } fn also_bad(tr: Result) -> Result { if tr.is_ok() { let t = tr.unwrap(); - return t.magic; + return t.magic; //~ needless_question_mark } Err(false) } @@ -115,6 +115,7 @@ pub fn test1() { macro_rules! some_and_qmark_in_macro { ($expr:expr) => { || -> Option<_> { Some($expr) }() + //~^ needless_question_mark }; } @@ -125,7 +126,7 @@ pub fn test2() { async fn async_option_bad(to: TO) -> Option { let _ = Some(3); - to.magic + to.magic //~ needless_question_mark } async fn async_deref_ref(s: Option<&String>) -> Option<&str> { @@ -133,9 +134,9 @@ async fn async_deref_ref(s: Option<&String>) -> Option<&str> { } async fn async_result_bad(s: TR) -> Result { - s.magic + s.magic //~ needless_question_mark } async fn async_wrapped(a: Option) -> Option { - { a } + { a } //~ needless_question_mark } diff --git a/tests/ui/needless_question_mark.rs b/tests/ui/needless_question_mark.rs index 21c858c291ff..a6e20a37ddde 100644 --- a/tests/ui/needless_question_mark.rs +++ b/tests/ui/needless_question_mark.rs @@ -17,7 +17,7 @@ struct TR { fn simple_option_bad1(to: TO) -> Option { // return as a statement - return Some(to.magic?); + return Some(to.magic?); //~ needless_question_mark } // formatting will add a semi-colon, which would make @@ -25,17 +25,17 @@ fn simple_option_bad1(to: TO) -> Option { #[rustfmt::skip] fn simple_option_bad2(to: TO) -> Option { // return as an expression - return Some(to.magic?) + return Some(to.magic?) //~ needless_question_mark } fn simple_option_bad3(to: TO) -> Option { // block value "return" - Some(to.magic?) + Some(to.magic?) //~ needless_question_mark } fn simple_option_bad4(to: Option) -> Option { // single line closure - to.and_then(|t| Some(t.magic?)) + to.and_then(|t| Some(t.magic?)) //~ needless_question_mark } // formatting this will remove the block brackets, making @@ -44,27 +44,27 @@ fn simple_option_bad4(to: Option) -> Option { fn simple_option_bad5(to: Option) -> Option { // closure with body to.and_then(|t| { - Some(t.magic?) + Some(t.magic?) //~ needless_question_mark }) } fn simple_result_bad1(tr: TR) -> Result { - return Ok(tr.magic?); + return Ok(tr.magic?); //~ needless_question_mark } // formatting will add a semi-colon, which would make // this identical to the test case above #[rustfmt::skip] fn simple_result_bad2(tr: TR) -> Result { - return Ok(tr.magic?) + return Ok(tr.magic?) //~ needless_question_mark } fn simple_result_bad3(tr: TR) -> Result { - Ok(tr.magic?) + Ok(tr.magic?) //~ needless_question_mark } fn simple_result_bad4(tr: Result) -> Result { - tr.and_then(|t| Ok(t.magic?)) + tr.and_then(|t| Ok(t.magic?)) //~ needless_question_mark } // formatting this will remove the block brackets, making @@ -72,14 +72,14 @@ fn simple_result_bad4(tr: Result) -> Result { #[rustfmt::skip] fn simple_result_bad5(tr: Result) -> Result { tr.and_then(|t| { - Ok(t.magic?) + Ok(t.magic?) //~ needless_question_mark }) } fn also_bad(tr: Result) -> Result { if tr.is_ok() { let t = tr.unwrap(); - return Ok(t.magic?); + return Ok(t.magic?); //~ needless_question_mark } Err(false) } @@ -115,6 +115,7 @@ pub fn test1() { macro_rules! some_and_qmark_in_macro { ($expr:expr) => { || -> Option<_> { Some(Some($expr)?) }() + //~^ needless_question_mark }; } @@ -125,7 +126,7 @@ pub fn test2() { async fn async_option_bad(to: TO) -> Option { let _ = Some(3); - Some(to.magic?) + Some(to.magic?) //~ needless_question_mark } async fn async_deref_ref(s: Option<&String>) -> Option<&str> { @@ -133,9 +134,9 @@ async fn async_deref_ref(s: Option<&String>) -> Option<&str> { } async fn async_result_bad(s: TR) -> Result { - Ok(s.magic?) + Ok(s.magic?) //~ needless_question_mark } async fn async_wrapped(a: Option) -> Option { - { Some(a?) } + { Some(a?) } //~ needless_question_mark } diff --git a/tests/ui/needless_question_mark.stderr b/tests/ui/needless_question_mark.stderr index bf090302ef7e..7170727fda56 100644 --- a/tests/ui/needless_question_mark.stderr +++ b/tests/ui/needless_question_mark.stderr @@ -79,19 +79,19 @@ LL | let _x = some_and_qmark_in_macro!(x?); = note: this error originates in the macro `some_and_qmark_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info) error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:128:5 + --> $DIR/needless_question_mark.rs:129:5 | LL | Some(to.magic?) | ^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `to.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:136:5 + --> $DIR/needless_question_mark.rs:137:5 | LL | Ok(s.magic?) | ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `s.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:140:7 + --> $DIR/needless_question_mark.rs:141:7 | LL | { Some(a?) } | ^^^^^^^^ help: try removing question mark and `Some()`: `a` diff --git a/tests/ui/needless_raw_string.fixed b/tests/ui/needless_raw_string.fixed index 1a9c601c462b..5a5debbec000 100644 --- a/tests/ui/needless_raw_string.fixed +++ b/tests/ui/needless_raw_string.fixed @@ -2,23 +2,24 @@ #![warn(clippy::needless_raw_strings)] fn main() { - "aaa"; + "aaa"; //~ needless_raw_strings r#""aaa""#; r#"\s"#; - b"aaa"; + b"aaa"; //~ needless_raw_strings br#""aaa""#; br#"\s"#; - c"aaa"; + c"aaa"; //~ needless_raw_strings cr#""aaa""#; cr#"\s"#; + //~v needless_raw_strings " a multiline string "; - "no hashes"; - b"no hashes"; - c"no hashes"; + "no hashes"; //~ needless_raw_strings + b"no hashes"; //~ needless_raw_strings + c"no hashes"; //~ needless_raw_strings } diff --git a/tests/ui/needless_raw_string.rs b/tests/ui/needless_raw_string.rs index 1126ea5aa303..d64f7db9c9b8 100644 --- a/tests/ui/needless_raw_string.rs +++ b/tests/ui/needless_raw_string.rs @@ -2,23 +2,24 @@ #![warn(clippy::needless_raw_strings)] fn main() { - r#"aaa"#; + r#"aaa"#; //~ needless_raw_strings r#""aaa""#; r#"\s"#; - br#"aaa"#; + br#"aaa"#; //~ needless_raw_strings br#""aaa""#; br#"\s"#; - cr#"aaa"#; + cr#"aaa"#; //~ needless_raw_strings cr#""aaa""#; cr#"\s"#; + //~v needless_raw_strings r#" a multiline string "#; - r"no hashes"; - br"no hashes"; - cr"no hashes"; + r"no hashes"; //~ needless_raw_strings + br"no hashes"; //~ needless_raw_strings + cr"no hashes"; //~ needless_raw_strings } diff --git a/tests/ui/needless_raw_string.stderr b/tests/ui/needless_raw_string.stderr index b2188698564f..9205a1d5126b 100644 --- a/tests/ui/needless_raw_string.stderr +++ b/tests/ui/needless_raw_string.stderr @@ -37,7 +37,7 @@ LL + c"aaa"; | error: unnecessary raw string literal - --> $DIR/needless_raw_string.rs:15:5 + --> $DIR/needless_raw_string.rs:16:5 | LL | / r#" LL | | a @@ -56,7 +56,7 @@ LL ~ "; | error: unnecessary raw string literal - --> $DIR/needless_raw_string.rs:21:5 + --> $DIR/needless_raw_string.rs:22:5 | LL | r"no hashes"; | ^^^^^^^^^^^^ @@ -68,7 +68,7 @@ LL + "no hashes"; | error: unnecessary raw string literal - --> $DIR/needless_raw_string.rs:22:5 + --> $DIR/needless_raw_string.rs:23:5 | LL | br"no hashes"; | ^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL + b"no hashes"; | error: unnecessary raw string literal - --> $DIR/needless_raw_string.rs:23:5 + --> $DIR/needless_raw_string.rs:24:5 | LL | cr"no hashes"; | ^^^^^^^^^^^^^ diff --git a/tests/ui/needless_raw_string_hashes.fixed b/tests/ui/needless_raw_string_hashes.fixed index b2ad657d6b29..1fbce6247421 100644 --- a/tests/ui/needless_raw_string_hashes.fixed +++ b/tests/ui/needless_raw_string_hashes.fixed @@ -2,25 +2,26 @@ #![warn(clippy::needless_raw_string_hashes)] fn main() { - r"\aaa"; - r#"Hello "world"!"#; - r####" "### "## "# "####; - r###" "aa" "# "## "###; - br"\aaa"; - br#"Hello "world"!"#; - br####" "### "## "# "####; - br###" "aa" "# "## "###; - cr"\aaa"; - cr#"Hello "world"!"#; - cr####" "### "## "# "####; - cr###" "aa" "# "## "###; + r"\aaa"; //~ needless_raw_string_hashes + r#"Hello "world"!"#; //~ needless_raw_string_hashes + r####" "### "## "# "####; //~ needless_raw_string_hashes + r###" "aa" "# "## "###; //~ needless_raw_string_hashes + br"\aaa"; //~ needless_raw_string_hashes + br#"Hello "world"!"#; //~ needless_raw_string_hashes + br####" "### "## "# "####; //~ needless_raw_string_hashes + br###" "aa" "# "## "###; //~ needless_raw_string_hashes + cr"\aaa"; //~ needless_raw_string_hashes + cr#"Hello "world"!"#; //~ needless_raw_string_hashes + cr####" "### "## "# "####; //~ needless_raw_string_hashes + cr###" "aa" "# "## "###; //~ needless_raw_string_hashes + //~v needless_raw_string_hashes r" \a multiline string "; - r"rust"; - r"hello world"; + r"rust"; //~ needless_raw_string_hashes + r"hello world"; //~ needless_raw_string_hashes } diff --git a/tests/ui/needless_raw_string_hashes.rs b/tests/ui/needless_raw_string_hashes.rs index 54d8ed76d475..0ea9c8678744 100644 --- a/tests/ui/needless_raw_string_hashes.rs +++ b/tests/ui/needless_raw_string_hashes.rs @@ -2,25 +2,26 @@ #![warn(clippy::needless_raw_string_hashes)] fn main() { - r#"\aaa"#; - r##"Hello "world"!"##; - r######" "### "## "# "######; - r######" "aa" "# "## "######; - br#"\aaa"#; - br##"Hello "world"!"##; - br######" "### "## "# "######; - br######" "aa" "# "## "######; - cr#"\aaa"#; - cr##"Hello "world"!"##; - cr######" "### "## "# "######; - cr######" "aa" "# "## "######; + r#"\aaa"#; //~ needless_raw_string_hashes + r##"Hello "world"!"##; //~ needless_raw_string_hashes + r######" "### "## "# "######; //~ needless_raw_string_hashes + r######" "aa" "# "## "######; //~ needless_raw_string_hashes + br#"\aaa"#; //~ needless_raw_string_hashes + br##"Hello "world"!"##; //~ needless_raw_string_hashes + br######" "### "## "# "######; //~ needless_raw_string_hashes + br######" "aa" "# "## "######; //~ needless_raw_string_hashes + cr#"\aaa"#; //~ needless_raw_string_hashes + cr##"Hello "world"!"##; //~ needless_raw_string_hashes + cr######" "### "## "# "######; //~ needless_raw_string_hashes + cr######" "aa" "# "## "######; //~ needless_raw_string_hashes + //~v needless_raw_string_hashes r#" \a multiline string "#; - r###"rust"###; - r#"hello world"#; + r###"rust"###; //~ needless_raw_string_hashes + r#"hello world"#; //~ needless_raw_string_hashes } diff --git a/tests/ui/needless_raw_string_hashes.stderr b/tests/ui/needless_raw_string_hashes.stderr index c74eff8161e9..e3e2ad36517a 100644 --- a/tests/ui/needless_raw_string_hashes.stderr +++ b/tests/ui/needless_raw_string_hashes.stderr @@ -145,7 +145,7 @@ LL + cr###" "aa" "# "## "###; | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:18:5 + --> $DIR/needless_raw_string_hashes.rs:19:5 | LL | / r#" LL | | \a @@ -164,7 +164,7 @@ LL ~ "; | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:24:5 + --> $DIR/needless_raw_string_hashes.rs:25:5 | LL | r###"rust"###; | ^^^^^^^^^^^^^ @@ -176,7 +176,7 @@ LL + r"rust"; | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:25:5 + --> $DIR/needless_raw_string_hashes.rs:26:5 | LL | r#"hello world"#; | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/needless_return.fixed b/tests/ui/needless_return.fixed index f9eb39d49382..456f29943366 100644 --- a/tests/ui/needless_return.fixed +++ b/tests/ui/needless_return.fixed @@ -23,56 +23,59 @@ fn test_end_of_fn() -> bool { // no error! return true; } - true + true//~ needless_return } fn test_no_semicolon() -> bool { - true + true//~ needless_return } #[rustfmt::skip] fn test_multiple_semicolon() -> bool { - true + true//~ needless_return } #[rustfmt::skip] fn test_multiple_semicolon_with_spaces() -> bool { - true + true//~ needless_return } fn test_if_block() -> bool { if true { - true + true//~ needless_return } else { - false + false//~ needless_return } } fn test_match(x: bool) -> bool { match x { - true => false, + true => false, //~ needless_return false => { - true + true//~ needless_return }, } } fn test_closure() { let _ = || { - true + true//~ needless_return }; - let _ = || true; + let _ = || true; //~ needless_return } fn test_macro_call() -> i32 { - the_answer!() + the_answer!()//~ needless_return } +//~v needless_return fn test_void_fun() { } fn test_void_if_fun(b: bool) { + //~v needless_return if b { + //~v needless_return } else { } } @@ -80,7 +83,7 @@ fn test_void_if_fun(b: bool) { fn test_void_match(x: u32) { match x { 0 => (), - _ => (), + _ => (), //~ needless_return } } @@ -88,9 +91,10 @@ fn test_nested_match(x: u32) { match x { 0 => (), 1 => { + //~v needless_return let _ = 42; }, - _ => (), + _ => (), //~ needless_return } } @@ -103,9 +107,9 @@ fn borrows_but_not_last(value: bool) -> String { if value { let x = RefCell::::default(); let _a = x.borrow().clone(); - String::from("test") + String::from("test")//~ needless_return } else { - String::new() + String::new()//~ needless_return } } @@ -127,19 +131,20 @@ fn test_return_in_macro() { mod issue6501 { #[allow(clippy::unnecessary_lazy_evaluations)] fn foo(bar: Result<(), ()>) { - bar.unwrap_or_else(|_| {}) + bar.unwrap_or_else(|_| {}) //~ needless_return } fn test_closure() { + //~v needless_return let _ = || { }; - let _ = || {}; + let _ = || {}; //~ needless_return } struct Foo; #[allow(clippy::unnecessary_lazy_evaluations)] fn bar(res: Result) -> Foo { - res.unwrap_or_else(|_| Foo) + res.unwrap_or_else(|_| Foo) //~ needless_return } } @@ -148,46 +153,49 @@ async fn async_test_end_of_fn() -> bool { // no error! return true; } - true + true//~ needless_return } async fn async_test_no_semicolon() -> bool { - true + true//~ needless_return } async fn async_test_if_block() -> bool { if true { - true + true//~ needless_return } else { - false + false//~ needless_return } } async fn async_test_match(x: bool) -> bool { match x { - true => false, + true => false, //~ needless_return false => { - true + true//~ needless_return }, } } async fn async_test_closure() { let _ = || { - true + true//~ needless_return }; - let _ = || true; + let _ = || true; //~ needless_return } async fn async_test_macro_call() -> i32 { - the_answer!() + the_answer!()//~ needless_return } +//~v needless_return async fn async_test_void_fun() { } async fn async_test_void_if_fun(b: bool) { + //~v needless_return if b { + //~v needless_return } else { } } @@ -195,7 +203,7 @@ async fn async_test_void_if_fun(b: bool) { async fn async_test_void_match(x: u32) { match x { 0 => (), - _ => (), + _ => (), //~ needless_return } } @@ -208,9 +216,9 @@ async fn async_borrows_but_not_last(value: bool) -> String { if value { let x = RefCell::::default(); let _a = x.borrow().clone(); - String::from("test") + String::from("test")//~ needless_return } else { - String::new() + String::new()//~ needless_return } } @@ -226,7 +234,7 @@ fn let_else() { fn needless_return_macro() -> String { let _ = "foo"; let _ = "bar"; - format!("Hello {}", "world!") + format!("Hello {}", "world!")//~ needless_return } fn issue_9361() -> i32 { @@ -238,19 +246,19 @@ fn issue_9361() -> i32 { fn issue8336(x: i32) -> bool { if x > 0 { println!("something"); - true + true//~ needless_return } else { - false + false//~ needless_return } } fn issue8156(x: u8) -> u64 { match x { 80 => { - 10 + 10//~ needless_return }, _ => { - 100 + 100//~ needless_return }, } } @@ -258,28 +266,29 @@ fn issue8156(x: u8) -> u64 { // Ideally the compiler should throw `unused_braces` in this case fn issue9192() -> i32 { { - 0 + 0//~ needless_return } } fn issue9503(x: usize) -> isize { unsafe { if x > 12 { - *(x as *const isize) + *(x as *const isize)//~ needless_return } else { - !*(x as *const isize) + !*(x as *const isize)//~ needless_return } } } mod issue9416 { pub fn with_newline() { + //~v needless_return let _ = 42; } #[rustfmt::skip] pub fn oneline() { - let _ = 42; + let _ = 42;//~ needless_return } } @@ -291,19 +300,20 @@ fn issue9947() -> Result<(), String> { #[expect(clippy::useless_format)] fn issue10051() -> Result { if true { - Ok(format!("ok!")) + Ok(format!("ok!"))//~ needless_return } else { - Err(format!("err!")) + Err(format!("err!"))//~ needless_return } } mod issue10049 { fn single() -> u32 { - if true { 1 } else { 2 } + if true { 1 } else { 2 }//~ needless_return } fn multiple(b1: bool, b2: bool, b3: bool) -> u32 { (if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 }) + //~^ needless_return } } diff --git a/tests/ui/needless_return.rs b/tests/ui/needless_return.rs index 4dd2e22ea9fe..f5eb90a96355 100644 --- a/tests/ui/needless_return.rs +++ b/tests/ui/needless_return.rs @@ -23,58 +23,61 @@ fn test_end_of_fn() -> bool { // no error! return true; } - return true; + return true; //~ needless_return } fn test_no_semicolon() -> bool { - return true; + return true; //~ needless_return } #[rustfmt::skip] fn test_multiple_semicolon() -> bool { - return true;;; + return true;;; //~ needless_return } #[rustfmt::skip] fn test_multiple_semicolon_with_spaces() -> bool { - return true;; ; ; + return true;; ; ; //~ needless_return } fn test_if_block() -> bool { if true { - return true; + return true; //~ needless_return } else { - return false; + return false; //~ needless_return } } fn test_match(x: bool) -> bool { match x { - true => return false, + true => return false, //~ needless_return false => { - return true; + return true; //~ needless_return }, } } fn test_closure() { let _ = || { - return true; + return true; //~ needless_return }; - let _ = || return true; + let _ = || return true; //~ needless_return } fn test_macro_call() -> i32 { - return the_answer!(); + return the_answer!(); //~ needless_return } +//~v needless_return fn test_void_fun() { return; } fn test_void_if_fun(b: bool) { + //~v needless_return if b { return; + //~v needless_return } else { return; } @@ -83,7 +86,7 @@ fn test_void_if_fun(b: bool) { fn test_void_match(x: u32) { match x { 0 => (), - _ => return, + _ => return, //~ needless_return } } @@ -91,10 +94,11 @@ fn test_nested_match(x: u32) { match x { 0 => (), 1 => { + //~v needless_return let _ = 42; return; }, - _ => return, + _ => return, //~ needless_return } } @@ -107,9 +111,9 @@ fn borrows_but_not_last(value: bool) -> String { if value { let x = RefCell::::default(); let _a = x.borrow().clone(); - return String::from("test"); + return String::from("test"); //~ needless_return } else { - return String::new(); + return String::new(); //~ needless_return } } @@ -131,20 +135,21 @@ fn test_return_in_macro() { mod issue6501 { #[allow(clippy::unnecessary_lazy_evaluations)] fn foo(bar: Result<(), ()>) { - bar.unwrap_or_else(|_| return) + bar.unwrap_or_else(|_| return) //~ needless_return } fn test_closure() { + //~v needless_return let _ = || { return; }; - let _ = || return; + let _ = || return; //~ needless_return } struct Foo; #[allow(clippy::unnecessary_lazy_evaluations)] fn bar(res: Result) -> Foo { - res.unwrap_or_else(|_| return Foo) + res.unwrap_or_else(|_| return Foo) //~ needless_return } } @@ -153,48 +158,51 @@ async fn async_test_end_of_fn() -> bool { // no error! return true; } - return true; + return true; //~ needless_return } async fn async_test_no_semicolon() -> bool { - return true; + return true; //~ needless_return } async fn async_test_if_block() -> bool { if true { - return true; + return true; //~ needless_return } else { - return false; + return false; //~ needless_return } } async fn async_test_match(x: bool) -> bool { match x { - true => return false, + true => return false, //~ needless_return false => { - return true; + return true; //~ needless_return }, } } async fn async_test_closure() { let _ = || { - return true; + return true; //~ needless_return }; - let _ = || return true; + let _ = || return true; //~ needless_return } async fn async_test_macro_call() -> i32 { - return the_answer!(); + return the_answer!(); //~ needless_return } +//~v needless_return async fn async_test_void_fun() { return; } async fn async_test_void_if_fun(b: bool) { + //~v needless_return if b { return; + //~v needless_return } else { return; } @@ -203,7 +211,7 @@ async fn async_test_void_if_fun(b: bool) { async fn async_test_void_match(x: u32) { match x { 0 => (), - _ => return, + _ => return, //~ needless_return } } @@ -216,9 +224,9 @@ async fn async_borrows_but_not_last(value: bool) -> String { if value { let x = RefCell::::default(); let _a = x.borrow().clone(); - return String::from("test"); + return String::from("test"); //~ needless_return } else { - return String::new(); + return String::new(); //~ needless_return } } @@ -234,7 +242,7 @@ fn let_else() { fn needless_return_macro() -> String { let _ = "foo"; let _ = "bar"; - return format!("Hello {}", "world!"); + return format!("Hello {}", "world!"); //~ needless_return } fn issue_9361() -> i32 { @@ -246,19 +254,19 @@ fn issue_9361() -> i32 { fn issue8336(x: i32) -> bool { if x > 0 { println!("something"); - return true; + return true; //~ needless_return } else { - return false; + return false; //~ needless_return }; } fn issue8156(x: u8) -> u64 { match x { 80 => { - return 10; + return 10; //~ needless_return }, _ => { - return 100; + return 100; //~ needless_return }, }; } @@ -266,22 +274,23 @@ fn issue8156(x: u8) -> u64 { // Ideally the compiler should throw `unused_braces` in this case fn issue9192() -> i32 { { - return 0; + return 0; //~ needless_return }; } fn issue9503(x: usize) -> isize { unsafe { if x > 12 { - return *(x as *const isize); + return *(x as *const isize); //~ needless_return } else { - return !*(x as *const isize); + return !*(x as *const isize); //~ needless_return }; }; } mod issue9416 { pub fn with_newline() { + //~v needless_return let _ = 42; return; @@ -289,7 +298,7 @@ mod issue9416 { #[rustfmt::skip] pub fn oneline() { - let _ = 42; return; + let _ = 42; return; //~ needless_return } } @@ -301,19 +310,20 @@ fn issue9947() -> Result<(), String> { #[expect(clippy::useless_format)] fn issue10051() -> Result { if true { - return Ok(format!("ok!")); + return Ok(format!("ok!")); //~ needless_return } else { - return Err(format!("err!")); + return Err(format!("err!")); //~ needless_return } } mod issue10049 { fn single() -> u32 { - return if true { 1 } else { 2 }; + return if true { 1 } else { 2 }; //~ needless_return } fn multiple(b1: bool, b2: bool, b3: bool) -> u32 { return if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 }; + //~^ needless_return } } diff --git a/tests/ui/needless_return.stderr b/tests/ui/needless_return.stderr index cc48831115d9..81c18862f671 100644 --- a/tests/ui/needless_return.stderr +++ b/tests/ui/needless_return.stderr @@ -131,7 +131,7 @@ LL + the_answer!() | error: unneeded `return` statement - --> $DIR/needless_return.rs:71:21 + --> $DIR/needless_return.rs:72:21 | LL | fn test_void_fun() { | _____________________^ @@ -146,7 +146,7 @@ LL + fn test_void_fun() { | error: unneeded `return` statement - --> $DIR/needless_return.rs:76:11 + --> $DIR/needless_return.rs:78:11 | LL | if b { | ___________^ @@ -161,7 +161,7 @@ LL + if b { | error: unneeded `return` statement - --> $DIR/needless_return.rs:78:13 + --> $DIR/needless_return.rs:81:13 | LL | } else { | _____________^ @@ -176,7 +176,7 @@ LL + } else { | error: unneeded `return` statement - --> $DIR/needless_return.rs:86:14 + --> $DIR/needless_return.rs:89:14 | LL | _ => return, | ^^^^^^ @@ -187,7 +187,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:94:24 + --> $DIR/needless_return.rs:98:24 | LL | let _ = 42; | ________________________^ @@ -202,7 +202,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> $DIR/needless_return.rs:97:14 + --> $DIR/needless_return.rs:101:14 | LL | _ => return, | ^^^^^^ @@ -213,7 +213,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:110:9 + --> $DIR/needless_return.rs:114:9 | LL | return String::from("test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -225,7 +225,7 @@ LL + String::from("test") | error: unneeded `return` statement - --> $DIR/needless_return.rs:112:9 + --> $DIR/needless_return.rs:116:9 | LL | return String::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -237,7 +237,7 @@ LL + String::new() | error: unneeded `return` statement - --> $DIR/needless_return.rs:134:32 + --> $DIR/needless_return.rs:138:32 | LL | bar.unwrap_or_else(|_| return) | ^^^^^^ @@ -248,7 +248,7 @@ LL | bar.unwrap_or_else(|_| {}) | ~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:138:21 + --> $DIR/needless_return.rs:143:21 | LL | let _ = || { | _____________________^ @@ -263,7 +263,7 @@ LL + let _ = || { | error: unneeded `return` statement - --> $DIR/needless_return.rs:141:20 + --> $DIR/needless_return.rs:146:20 | LL | let _ = || return; | ^^^^^^ @@ -274,7 +274,7 @@ LL | let _ = || {}; | ~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:147:32 + --> $DIR/needless_return.rs:152:32 | LL | res.unwrap_or_else(|_| return Foo) | ^^^^^^^^^^ @@ -285,7 +285,7 @@ LL | res.unwrap_or_else(|_| Foo) | ~~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:156:5 + --> $DIR/needless_return.rs:161:5 | LL | return true; | ^^^^^^^^^^^ @@ -297,7 +297,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:160:5 + --> $DIR/needless_return.rs:165:5 | LL | return true; | ^^^^^^^^^^^ @@ -309,7 +309,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:165:9 + --> $DIR/needless_return.rs:170:9 | LL | return true; | ^^^^^^^^^^^ @@ -321,7 +321,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:167:9 + --> $DIR/needless_return.rs:172:9 | LL | return false; | ^^^^^^^^^^^^ @@ -333,7 +333,7 @@ LL + false | error: unneeded `return` statement - --> $DIR/needless_return.rs:173:17 + --> $DIR/needless_return.rs:178:17 | LL | true => return false, | ^^^^^^^^^^^^ @@ -344,7 +344,7 @@ LL | true => false, | ~~~~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:175:13 + --> $DIR/needless_return.rs:180:13 | LL | return true; | ^^^^^^^^^^^ @@ -356,7 +356,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:182:9 + --> $DIR/needless_return.rs:187:9 | LL | return true; | ^^^^^^^^^^^ @@ -368,7 +368,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:184:16 + --> $DIR/needless_return.rs:189:16 | LL | let _ = || return true; | ^^^^^^^^^^^ @@ -379,7 +379,7 @@ LL | let _ = || true; | ~~~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:188:5 + --> $DIR/needless_return.rs:193:5 | LL | return the_answer!(); | ^^^^^^^^^^^^^^^^^^^^ @@ -391,7 +391,7 @@ LL + the_answer!() | error: unneeded `return` statement - --> $DIR/needless_return.rs:191:33 + --> $DIR/needless_return.rs:197:33 | LL | async fn async_test_void_fun() { | _________________________________^ @@ -406,7 +406,7 @@ LL + async fn async_test_void_fun() { | error: unneeded `return` statement - --> $DIR/needless_return.rs:196:11 + --> $DIR/needless_return.rs:203:11 | LL | if b { | ___________^ @@ -421,7 +421,7 @@ LL + if b { | error: unneeded `return` statement - --> $DIR/needless_return.rs:198:13 + --> $DIR/needless_return.rs:206:13 | LL | } else { | _____________^ @@ -436,7 +436,7 @@ LL + } else { | error: unneeded `return` statement - --> $DIR/needless_return.rs:206:14 + --> $DIR/needless_return.rs:214:14 | LL | _ => return, | ^^^^^^ @@ -447,7 +447,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:219:9 + --> $DIR/needless_return.rs:227:9 | LL | return String::from("test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -459,7 +459,7 @@ LL + String::from("test") | error: unneeded `return` statement - --> $DIR/needless_return.rs:221:9 + --> $DIR/needless_return.rs:229:9 | LL | return String::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -471,7 +471,7 @@ LL + String::new() | error: unneeded `return` statement - --> $DIR/needless_return.rs:237:5 + --> $DIR/needless_return.rs:245:5 | LL | return format!("Hello {}", "world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -483,7 +483,7 @@ LL + format!("Hello {}", "world!") | error: unneeded `return` statement - --> $DIR/needless_return.rs:249:9 + --> $DIR/needless_return.rs:257:9 | LL | return true; | ^^^^^^^^^^^ @@ -497,7 +497,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:251:9 + --> $DIR/needless_return.rs:259:9 | LL | return false; | ^^^^^^^^^^^^ @@ -509,7 +509,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:258:13 + --> $DIR/needless_return.rs:266:13 | LL | return 10; | ^^^^^^^^^ @@ -524,7 +524,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:261:13 + --> $DIR/needless_return.rs:269:13 | LL | return 100; | ^^^^^^^^^^ @@ -537,7 +537,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:269:9 + --> $DIR/needless_return.rs:277:9 | LL | return 0; | ^^^^^^^^ @@ -549,7 +549,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:276:13 + --> $DIR/needless_return.rs:284:13 | LL | return *(x as *const isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -564,7 +564,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:278:13 + --> $DIR/needless_return.rs:286:13 | LL | return !*(x as *const isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -577,7 +577,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:285:20 + --> $DIR/needless_return.rs:294:20 | LL | let _ = 42; | ____________________^ @@ -594,7 +594,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> $DIR/needless_return.rs:292:20 + --> $DIR/needless_return.rs:301:20 | LL | let _ = 42; return; | ^^^^^^^ @@ -606,7 +606,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> $DIR/needless_return.rs:304:9 + --> $DIR/needless_return.rs:313:9 | LL | return Ok(format!("ok!")); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -618,7 +618,7 @@ LL + Ok(format!("ok!")) | error: unneeded `return` statement - --> $DIR/needless_return.rs:306:9 + --> $DIR/needless_return.rs:315:9 | LL | return Err(format!("err!")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -630,7 +630,7 @@ LL + Err(format!("err!")) | error: unneeded `return` statement - --> $DIR/needless_return.rs:312:9 + --> $DIR/needless_return.rs:321:9 | LL | return if true { 1 } else { 2 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -642,7 +642,7 @@ LL + if true { 1 } else { 2 } | error: unneeded `return` statement - --> $DIR/needless_return.rs:316:9 + --> $DIR/needless_return.rs:325:9 | LL | return if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/needless_return_with_question_mark.fixed b/tests/ui/needless_return_with_question_mark.fixed index 9b7da8526631..d416cd6f89d7 100644 --- a/tests/ui/needless_return_with_question_mark.fixed +++ b/tests/ui/needless_return_with_question_mark.fixed @@ -26,7 +26,7 @@ fn c() -> Option<()> { } fn main() -> Result<(), ()> { - Err(())?; + Err(())?; //~ needless_return_with_question_mark return Ok::<(), ()>(()); Err(())?; Ok::<(), ()>(()); diff --git a/tests/ui/needless_return_with_question_mark.rs b/tests/ui/needless_return_with_question_mark.rs index 68e76d2b6402..1c23920f91e9 100644 --- a/tests/ui/needless_return_with_question_mark.rs +++ b/tests/ui/needless_return_with_question_mark.rs @@ -26,7 +26,7 @@ fn c() -> Option<()> { } fn main() -> Result<(), ()> { - return Err(())?; + return Err(())?; //~ needless_return_with_question_mark return Ok::<(), ()>(()); Err(())?; Ok::<(), ()>(()); diff --git a/tests/ui/needless_splitn.fixed b/tests/ui/needless_splitn.fixed index efc47533e233..33472091634c 100644 --- a/tests/ui/needless_splitn.fixed +++ b/tests/ui/needless_splitn.fixed @@ -10,30 +10,32 @@ use itertools::Itertools; fn main() { let str = "key=value=end"; - let _ = str.split('=').next(); - let _ = str.split('=').nth(0); + let _ = str.split('=').next(); //~ needless_splitn + let _ = str.split('=').nth(0); //~ needless_splitn let _ = str.splitn(2, '=').nth(1); let (_, _) = str.splitn(2, '=').next_tuple().unwrap(); let (_, _) = str.split('=').next_tuple().unwrap(); + //~^ needless_splitn let _: Vec<&str> = str.splitn(3, '=').collect(); - let _ = str.rsplit('=').next(); - let _ = str.rsplit('=').nth(0); + let _ = str.rsplit('=').next(); //~ needless_splitn + let _ = str.rsplit('=').nth(0); //~ needless_splitn let _ = str.rsplitn(2, '=').nth(1); let (_, _) = str.rsplitn(2, '=').next_tuple().unwrap(); let (_, _) = str.rsplit('=').next_tuple().unwrap(); + //~^ needless_splitn - let _ = str.split('=').next(); - let _ = str.split('=').nth(3); + let _ = str.split('=').next(); //~ needless_splitn + let _ = str.split('=').nth(3); //~ needless_splitn let _ = str.splitn(5, '=').nth(4); let _ = str.splitn(5, '=').nth(5); } fn _question_mark(s: &str) -> Option<()> { - let _ = s.split('=').next()?; - let _ = s.split('=').nth(0)?; - let _ = s.rsplit('=').next()?; - let _ = s.rsplit('=').nth(0)?; + let _ = s.split('=').next()?; //~ needless_splitn + let _ = s.split('=').nth(0)?; //~ needless_splitn + let _ = s.rsplit('=').next()?; //~ needless_splitn + let _ = s.rsplit('=').nth(0)?; //~ needless_splitn Some(()) } @@ -42,4 +44,5 @@ fn _question_mark(s: &str) -> Option<()> { fn _test_msrv() { // `manual_split_once` MSRV shouldn't apply to `needless_splitn` let _ = "key=value".split('=').nth(0).unwrap(); + //~^ needless_splitn } diff --git a/tests/ui/needless_splitn.rs b/tests/ui/needless_splitn.rs index a4a3736eea2f..6b67ffbe45b9 100644 --- a/tests/ui/needless_splitn.rs +++ b/tests/ui/needless_splitn.rs @@ -10,30 +10,32 @@ use itertools::Itertools; fn main() { let str = "key=value=end"; - let _ = str.splitn(2, '=').next(); - let _ = str.splitn(2, '=').nth(0); + let _ = str.splitn(2, '=').next(); //~ needless_splitn + let _ = str.splitn(2, '=').nth(0); //~ needless_splitn let _ = str.splitn(2, '=').nth(1); let (_, _) = str.splitn(2, '=').next_tuple().unwrap(); let (_, _) = str.splitn(3, '=').next_tuple().unwrap(); + //~^ needless_splitn let _: Vec<&str> = str.splitn(3, '=').collect(); - let _ = str.rsplitn(2, '=').next(); - let _ = str.rsplitn(2, '=').nth(0); + let _ = str.rsplitn(2, '=').next(); //~ needless_splitn + let _ = str.rsplitn(2, '=').nth(0); //~ needless_splitn let _ = str.rsplitn(2, '=').nth(1); let (_, _) = str.rsplitn(2, '=').next_tuple().unwrap(); let (_, _) = str.rsplitn(3, '=').next_tuple().unwrap(); + //~^ needless_splitn - let _ = str.splitn(5, '=').next(); - let _ = str.splitn(5, '=').nth(3); + let _ = str.splitn(5, '=').next(); //~ needless_splitn + let _ = str.splitn(5, '=').nth(3); //~ needless_splitn let _ = str.splitn(5, '=').nth(4); let _ = str.splitn(5, '=').nth(5); } fn _question_mark(s: &str) -> Option<()> { - let _ = s.splitn(2, '=').next()?; - let _ = s.splitn(2, '=').nth(0)?; - let _ = s.rsplitn(2, '=').next()?; - let _ = s.rsplitn(2, '=').nth(0)?; + let _ = s.splitn(2, '=').next()?; //~ needless_splitn + let _ = s.splitn(2, '=').nth(0)?; //~ needless_splitn + let _ = s.rsplitn(2, '=').next()?; //~ needless_splitn + let _ = s.rsplitn(2, '=').nth(0)?; //~ needless_splitn Some(()) } @@ -42,4 +44,5 @@ fn _question_mark(s: &str) -> Option<()> { fn _test_msrv() { // `manual_split_once` MSRV shouldn't apply to `needless_splitn` let _ = "key=value".splitn(2, '=').nth(0).unwrap(); + //~^ needless_splitn } diff --git a/tests/ui/needless_splitn.stderr b/tests/ui/needless_splitn.stderr index f347ca760dbe..c7a7ebec20cd 100644 --- a/tests/ui/needless_splitn.stderr +++ b/tests/ui/needless_splitn.stderr @@ -20,61 +20,61 @@ LL | let (_, _) = str.splitn(3, '=').next_tuple().unwrap(); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `rsplitn` - --> $DIR/needless_splitn.rs:20:13 + --> $DIR/needless_splitn.rs:21:13 | LL | let _ = str.rsplitn(2, '=').next(); | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')` error: unnecessary use of `rsplitn` - --> $DIR/needless_splitn.rs:21:13 + --> $DIR/needless_splitn.rs:22:13 | LL | let _ = str.rsplitn(2, '=').nth(0); | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')` error: unnecessary use of `rsplitn` - --> $DIR/needless_splitn.rs:24:18 + --> $DIR/needless_splitn.rs:25:18 | LL | let (_, _) = str.rsplitn(3, '=').next_tuple().unwrap(); | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:26:13 + --> $DIR/needless_splitn.rs:28:13 | LL | let _ = str.splitn(5, '=').next(); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:27:13 + --> $DIR/needless_splitn.rs:29:13 | LL | let _ = str.splitn(5, '=').nth(3); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:33:13 + --> $DIR/needless_splitn.rs:35:13 | LL | let _ = s.splitn(2, '=').next()?; | ^^^^^^^^^^^^^^^^ help: try: `s.split('=')` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:34:13 + --> $DIR/needless_splitn.rs:36:13 | LL | let _ = s.splitn(2, '=').nth(0)?; | ^^^^^^^^^^^^^^^^ help: try: `s.split('=')` error: unnecessary use of `rsplitn` - --> $DIR/needless_splitn.rs:35:13 + --> $DIR/needless_splitn.rs:37:13 | LL | let _ = s.rsplitn(2, '=').next()?; | ^^^^^^^^^^^^^^^^^ help: try: `s.rsplit('=')` error: unnecessary use of `rsplitn` - --> $DIR/needless_splitn.rs:36:13 + --> $DIR/needless_splitn.rs:38:13 | LL | let _ = s.rsplitn(2, '=').nth(0)?; | ^^^^^^^^^^^^^^^^^ help: try: `s.rsplit('=')` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:44:13 + --> $DIR/needless_splitn.rs:46:13 | LL | let _ = "key=value".splitn(2, '=').nth(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split('=')` diff --git a/tests/ui/neg_multiply.fixed b/tests/ui/neg_multiply.fixed index 52edea73afbb..bfa24f6ea9c4 100644 --- a/tests/ui/neg_multiply.fixed +++ b/tests/ui/neg_multiply.fixed @@ -25,20 +25,20 @@ impl Mul for isize { fn main() { let x = 0; - -x; + -x; //~ neg_multiply - -x; + -x; //~ neg_multiply - 100 + -x; + 100 + -x; //~ neg_multiply - -(100 + x); + -(100 + x); //~ neg_multiply - -17; + -17; //~ neg_multiply - 0xcafe | -0xff00; + 0xcafe | -0xff00; //~ neg_multiply - -(3_usize as i32); - -(3_usize as i32); + -(3_usize as i32); //~ neg_multiply + -(3_usize as i32); //~ neg_multiply -1 * -1; // should be ok diff --git a/tests/ui/neg_multiply.rs b/tests/ui/neg_multiply.rs index 23092a35e606..5580673c8e75 100644 --- a/tests/ui/neg_multiply.rs +++ b/tests/ui/neg_multiply.rs @@ -25,20 +25,20 @@ impl Mul for isize { fn main() { let x = 0; - x * -1; + x * -1; //~ neg_multiply - -1 * x; + -1 * x; //~ neg_multiply - 100 + x * -1; + 100 + x * -1; //~ neg_multiply - (100 + x) * -1; + (100 + x) * -1; //~ neg_multiply - -1 * 17; + -1 * 17; //~ neg_multiply - 0xcafe | 0xff00 * -1; + 0xcafe | 0xff00 * -1; //~ neg_multiply - 3_usize as i32 * -1; - (3_usize as i32) * -1; + 3_usize as i32 * -1; //~ neg_multiply + (3_usize as i32) * -1; //~ neg_multiply -1 * -1; // should be ok diff --git a/tests/ui/new_without_default.fixed b/tests/ui/new_without_default.fixed index 85408c4e17f4..9d2c65933de3 100644 --- a/tests/ui/new_without_default.fixed +++ b/tests/ui/new_without_default.fixed @@ -141,6 +141,7 @@ impl Default for Const { } impl Const { + //~v new_without_default pub const fn new() -> Const { Const } // While Default is not const, it can still call const functions, so we should lint this @@ -309,6 +310,7 @@ impl MyStruct where K: std::hash::Hash + Eq + PartialEq, { + //~v new_without_default pub fn new() -> Self { Self { _kv: None } } diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs index 3ac7292c2362..06ca34e491da 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -117,6 +117,7 @@ impl PrivateItem { pub struct Const; impl Const { + //~v new_without_default pub const fn new() -> Const { Const } // While Default is not const, it can still call const functions, so we should lint this @@ -252,6 +253,7 @@ impl MyStruct where K: std::hash::Hash + Eq + PartialEq, { + //~v new_without_default pub fn new() -> Self { Self { _kv: None } } diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index 6652a2642051..679c037d15dd 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -56,7 +56,7 @@ LL + } | error: you should consider adding a `Default` implementation for `Const` - --> $DIR/new_without_default.rs:120:5 + --> $DIR/new_without_default.rs:121:5 | LL | / pub const fn new() -> Const { LL | | Const @@ -73,7 +73,7 @@ LL + } | error: you should consider adding a `Default` implementation for `NewNotEqualToDerive` - --> $DIR/new_without_default.rs:180:5 + --> $DIR/new_without_default.rs:181:5 | LL | / pub fn new() -> Self { LL | | @@ -91,7 +91,7 @@ LL + } | error: you should consider adding a `Default` implementation for `FooGenerics` - --> $DIR/new_without_default.rs:189:5 + --> $DIR/new_without_default.rs:190:5 | LL | / pub fn new() -> Self { LL | | @@ -109,7 +109,7 @@ LL + } | error: you should consider adding a `Default` implementation for `BarGenerics` - --> $DIR/new_without_default.rs:197:5 + --> $DIR/new_without_default.rs:198:5 | LL | / pub fn new() -> Self { LL | | @@ -127,7 +127,7 @@ LL + } | error: you should consider adding a `Default` implementation for `Foo` - --> $DIR/new_without_default.rs:209:9 + --> $DIR/new_without_default.rs:210:9 | LL | / pub fn new() -> Self { LL | | @@ -147,7 +147,7 @@ LL ~ impl Foo { | error: you should consider adding a `Default` implementation for `MyStruct` - --> $DIR/new_without_default.rs:255:5 + --> $DIR/new_without_default.rs:257:5 | LL | / pub fn new() -> Self { LL | | Self { _kv: None } diff --git a/tests/ui/non_canonical_clone_impl.fixed b/tests/ui/non_canonical_clone_impl.fixed index 165702b30411..ec929e508f97 100644 --- a/tests/ui/non_canonical_clone_impl.fixed +++ b/tests/ui/non_canonical_clone_impl.fixed @@ -6,8 +6,10 @@ struct A(u32); impl Clone for A { + //~v non_canonical_clone_impl fn clone(&self) -> Self { *self } + //~v non_canonical_clone_impl } @@ -72,8 +74,10 @@ impl Copy for E {} struct F(u32); impl Clone for F { + //~v non_canonical_clone_impl fn clone(&self) -> Self { *self } + //~v non_canonical_clone_impl } diff --git a/tests/ui/non_canonical_clone_impl.rs b/tests/ui/non_canonical_clone_impl.rs index 3b07dd5ce62f..6978e369c4e2 100644 --- a/tests/ui/non_canonical_clone_impl.rs +++ b/tests/ui/non_canonical_clone_impl.rs @@ -6,10 +6,12 @@ struct A(u32); impl Clone for A { + //~v non_canonical_clone_impl fn clone(&self) -> Self { Self(self.0) } + //~v non_canonical_clone_impl fn clone_from(&mut self, source: &Self) { source.clone(); *self = source.clone(); @@ -77,10 +79,12 @@ impl Copy for E {} struct F(u32); impl Clone for F { + //~v non_canonical_clone_impl fn clone(&self) -> Self { Self(self.0) } + //~v non_canonical_clone_impl fn clone_from(&mut self, source: &Self) { source.clone(); *self = source.clone(); diff --git a/tests/ui/non_canonical_clone_impl.stderr b/tests/ui/non_canonical_clone_impl.stderr index 44196751b053..e4c3059c5e0d 100644 --- a/tests/ui/non_canonical_clone_impl.stderr +++ b/tests/ui/non_canonical_clone_impl.stderr @@ -1,5 +1,5 @@ error: non-canonical implementation of `clone` on a `Copy` type - --> $DIR/non_canonical_clone_impl.rs:9:29 + --> $DIR/non_canonical_clone_impl.rs:10:29 | LL | fn clone(&self) -> Self { | _____________________________^ @@ -11,7 +11,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::non_canonical_clone_impl)]` error: unnecessary implementation of `clone_from` on a `Copy` type - --> $DIR/non_canonical_clone_impl.rs:13:5 + --> $DIR/non_canonical_clone_impl.rs:15:5 | LL | / fn clone_from(&mut self, source: &Self) { LL | | source.clone(); @@ -20,7 +20,7 @@ LL | | } | |_____^ help: remove it error: non-canonical implementation of `clone` on a `Copy` type - --> $DIR/non_canonical_clone_impl.rs:80:29 + --> $DIR/non_canonical_clone_impl.rs:83:29 | LL | fn clone(&self) -> Self { | _____________________________^ @@ -29,7 +29,7 @@ LL | | } | |_____^ help: change this to: `{ *self }` error: unnecessary implementation of `clone_from` on a `Copy` type - --> $DIR/non_canonical_clone_impl.rs:84:5 + --> $DIR/non_canonical_clone_impl.rs:88:5 | LL | / fn clone_from(&mut self, source: &Self) { LL | | source.clone(); diff --git a/tests/ui/non_canonical_partial_ord_impl.fixed b/tests/ui/non_canonical_partial_ord_impl.fixed index db55cc094e3a..ace61fd10f99 100644 --- a/tests/ui/non_canonical_partial_ord_impl.fixed +++ b/tests/ui/non_canonical_partial_ord_impl.fixed @@ -13,6 +13,7 @@ impl Ord for A { } } +//~v non_canonical_partial_ord_impl impl PartialOrd for A { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } @@ -45,6 +46,7 @@ impl Ord for C { } } +//~v non_canonical_partial_ord_impl impl PartialOrd for C { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } diff --git a/tests/ui/non_canonical_partial_ord_impl.rs b/tests/ui/non_canonical_partial_ord_impl.rs index 52f4b85b9172..3c7ca44ac6f4 100644 --- a/tests/ui/non_canonical_partial_ord_impl.rs +++ b/tests/ui/non_canonical_partial_ord_impl.rs @@ -13,6 +13,7 @@ impl Ord for A { } } +//~v non_canonical_partial_ord_impl impl PartialOrd for A { fn partial_cmp(&self, other: &Self) -> Option { todo!(); @@ -47,6 +48,7 @@ impl Ord for C { } } +//~v non_canonical_partial_ord_impl impl PartialOrd for C { fn partial_cmp(&self, _: &Self) -> Option { todo!(); diff --git a/tests/ui/non_canonical_partial_ord_impl.stderr b/tests/ui/non_canonical_partial_ord_impl.stderr index 05cc717b9ba1..034f1b50881c 100644 --- a/tests/ui/non_canonical_partial_ord_impl.stderr +++ b/tests/ui/non_canonical_partial_ord_impl.stderr @@ -1,5 +1,5 @@ error: non-canonical implementation of `partial_cmp` on an `Ord` type - --> $DIR/non_canonical_partial_ord_impl.rs:16:1 + --> $DIR/non_canonical_partial_ord_impl.rs:17:1 | LL | / impl PartialOrd for A { LL | | fn partial_cmp(&self, other: &Self) -> Option { @@ -14,7 +14,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::non_canonical_partial_ord_impl)]` error: non-canonical implementation of `partial_cmp` on an `Ord` type - --> $DIR/non_canonical_partial_ord_impl.rs:50:1 + --> $DIR/non_canonical_partial_ord_impl.rs:52:1 | LL | / impl PartialOrd for C { LL | | fn partial_cmp(&self, _: &Self) -> Option { diff --git a/tests/ui/non_canonical_partial_ord_impl_fully_qual.rs b/tests/ui/non_canonical_partial_ord_impl_fully_qual.rs index 2f8d5cf30c77..added8109d12 100644 --- a/tests/ui/non_canonical_partial_ord_impl_fully_qual.rs +++ b/tests/ui/non_canonical_partial_ord_impl_fully_qual.rs @@ -20,6 +20,7 @@ impl cmp::Ord for A { } } +//~v non_canonical_partial_ord_impl impl PartialOrd for A { fn partial_cmp(&self, other: &Self) -> Option { // NOTE: This suggestion is wrong, as `Ord` is not in scope. But this should be fine as it isn't @@ -43,6 +44,7 @@ impl cmp::Ord for B { } } +//~v non_canonical_partial_ord_impl impl PartialOrd for B { fn partial_cmp(&self, other: &Self) -> Option { // This calls `B.cmp`, not `Ord::cmp`! diff --git a/tests/ui/non_canonical_partial_ord_impl_fully_qual.stderr b/tests/ui/non_canonical_partial_ord_impl_fully_qual.stderr index 4978d7a87396..4e95de698287 100644 --- a/tests/ui/non_canonical_partial_ord_impl_fully_qual.stderr +++ b/tests/ui/non_canonical_partial_ord_impl_fully_qual.stderr @@ -1,5 +1,5 @@ error: non-canonical implementation of `partial_cmp` on an `Ord` type - --> $DIR/non_canonical_partial_ord_impl_fully_qual.rs:23:1 + --> $DIR/non_canonical_partial_ord_impl_fully_qual.rs:24:1 | LL | / impl PartialOrd for A { LL | | fn partial_cmp(&self, other: &Self) -> Option { @@ -16,7 +16,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::non_canonical_partial_ord_impl)]` error: non-canonical implementation of `partial_cmp` on an `Ord` type - --> $DIR/non_canonical_partial_ord_impl_fully_qual.rs:46:1 + --> $DIR/non_canonical_partial_ord_impl_fully_qual.rs:48:1 | LL | / impl PartialOrd for B { LL | | fn partial_cmp(&self, other: &Self) -> Option { diff --git a/tests/ui/non_minimal_cfg.fixed b/tests/ui/non_minimal_cfg.fixed index 2fcecab452b8..d6810cd67439 100644 --- a/tests/ui/non_minimal_cfg.fixed +++ b/tests/ui/non_minimal_cfg.fixed @@ -1,12 +1,14 @@ #![allow(unused)] -#[cfg(windows)] +#[cfg(windows)] //~ non_minimal_cfg fn hermit() {} -#[cfg(windows)] +#[cfg(windows)] //~ non_minimal_cfg fn wasi() {} #[cfg(all(unix, not(windows)))] +//~^ non_minimal_cfg +//~| non_minimal_cfg fn the_end() {} #[cfg(any())] diff --git a/tests/ui/non_minimal_cfg.rs b/tests/ui/non_minimal_cfg.rs index e3ce11b73336..42b67d9e9392 100644 --- a/tests/ui/non_minimal_cfg.rs +++ b/tests/ui/non_minimal_cfg.rs @@ -1,12 +1,14 @@ #![allow(unused)] -#[cfg(all(windows))] +#[cfg(all(windows))] //~ non_minimal_cfg fn hermit() {} -#[cfg(any(windows))] +#[cfg(any(windows))] //~ non_minimal_cfg fn wasi() {} #[cfg(all(any(unix), all(not(windows))))] +//~^ non_minimal_cfg +//~| non_minimal_cfg fn the_end() {} #[cfg(any())] diff --git a/tests/ui/nonminimal_bool.rs b/tests/ui/nonminimal_bool.rs index 908ef6cb2a02..0e8e63165866 100644 --- a/tests/ui/nonminimal_bool.rs +++ b/tests/ui/nonminimal_bool.rs @@ -166,9 +166,18 @@ fn issue_5794() { let b = true; let c = false; + //~| bool_comparison + //~v bool_comparison if !b == true {} //~ ERROR: this boolean expression can be simplified + + //~v bool_comparison if !b != true {} //~ ERROR: this boolean expression can be simplified + + //~| bool_comparison + //~v bool_comparison if true == !b {} //~ ERROR: this boolean expression can be simplified + + //~v bool_comparison if true != !b {} //~ ERROR: this boolean expression can be simplified if !b == !c {} //~ ERROR: this boolean expression can be simplified if !b != !c {} //~ ERROR: this boolean expression can be simplified diff --git a/tests/ui/nonminimal_bool.stderr b/tests/ui/nonminimal_bool.stderr index a317c8328d94..2c4f79def43c 100644 --- a/tests/ui/nonminimal_bool.stderr +++ b/tests/ui/nonminimal_bool.stderr @@ -139,13 +139,13 @@ LL | if !(a != 12) {} | ^^^^^^^^^^ help: try: `a == 12` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:169:8 + --> $DIR/nonminimal_bool.rs:171:8 | LL | if !b == true {} | ^^^^^^^^^^ help: try: `b != true` error: this comparison might be written more concisely - --> $DIR/nonminimal_bool.rs:169:8 + --> $DIR/nonminimal_bool.rs:171:8 | LL | if !b == true {} | ^^^^^^^^^^ help: try simplifying it as shown: `b != true` @@ -154,61 +154,61 @@ LL | if !b == true {} = help: to override `-D warnings` add `#[allow(clippy::bool_comparison)]` error: equality checks against true are unnecessary - --> $DIR/nonminimal_bool.rs:169:8 + --> $DIR/nonminimal_bool.rs:171:8 | LL | if !b == true {} | ^^^^^^^^^^ help: try simplifying it as shown: `!b` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:170:8 + --> $DIR/nonminimal_bool.rs:174:8 | LL | if !b != true {} | ^^^^^^^^^^ help: try: `b == true` error: inequality checks against true can be replaced by a negation - --> $DIR/nonminimal_bool.rs:170:8 + --> $DIR/nonminimal_bool.rs:174:8 | LL | if !b != true {} | ^^^^^^^^^^ help: try simplifying it as shown: `!(!b)` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:171:8 + --> $DIR/nonminimal_bool.rs:178:8 | LL | if true == !b {} | ^^^^^^^^^^ help: try: `true != b` error: this comparison might be written more concisely - --> $DIR/nonminimal_bool.rs:171:8 + --> $DIR/nonminimal_bool.rs:178:8 | LL | if true == !b {} | ^^^^^^^^^^ help: try simplifying it as shown: `true != b` error: equality checks against true are unnecessary - --> $DIR/nonminimal_bool.rs:171:8 + --> $DIR/nonminimal_bool.rs:178:8 | LL | if true == !b {} | ^^^^^^^^^^ help: try simplifying it as shown: `!b` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:172:8 + --> $DIR/nonminimal_bool.rs:181:8 | LL | if true != !b {} | ^^^^^^^^^^ help: try: `true == b` error: inequality checks against true can be replaced by a negation - --> $DIR/nonminimal_bool.rs:172:8 + --> $DIR/nonminimal_bool.rs:181:8 | LL | if true != !b {} | ^^^^^^^^^^ help: try simplifying it as shown: `!(!b)` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:173:8 + --> $DIR/nonminimal_bool.rs:182:8 | LL | if !b == !c {} | ^^^^^^^^ help: try: `b == c` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:174:8 + --> $DIR/nonminimal_bool.rs:183:8 | LL | if !b != !c {} | ^^^^^^^^ help: try: `b != c` diff --git a/tests/ui/nonminimal_bool_methods.fixed b/tests/ui/nonminimal_bool_methods.fixed index e27c0350d49e..3d522526c2af 100644 --- a/tests/ui/nonminimal_bool_methods.fixed +++ b/tests/ui/nonminimal_bool_methods.fixed @@ -5,19 +5,19 @@ fn methods_with_negation() { let a: Option = unimplemented!(); let b: Result = unimplemented!(); let _ = a.is_some(); + let _ = a.is_none(); //~ nonminimal_bool let _ = a.is_none(); - let _ = a.is_none(); - let _ = a.is_some(); + let _ = a.is_some(); //~ nonminimal_bool let _ = b.is_err(); + let _ = b.is_ok(); //~ nonminimal_bool let _ = b.is_ok(); - let _ = b.is_ok(); - let _ = b.is_err(); + let _ = b.is_err(); //~ nonminimal_bool let c = false; - let _ = a.is_none() || c; - let _ = a.is_none() && c; - let _ = !(!c ^ c) || a.is_none(); - let _ = (!c ^ c) || a.is_none(); - let _ = !c ^ c || a.is_none(); + let _ = a.is_none() || c; //~ nonminimal_bool + let _ = a.is_none() && c; //~ nonminimal_bool + let _ = !(!c ^ c) || a.is_none(); //~ nonminimal_bool + let _ = (!c ^ c) || a.is_none(); //~ nonminimal_bool + let _ = !c ^ c || a.is_none(); //~ nonminimal_bool } // Simplified versions of https://github.com/rust-lang/rust-clippy/issues/2638 @@ -89,12 +89,12 @@ fn dont_warn_for_custom_methods_with_negation() { // Only Built-in Result and Some types should suggest the negated alternative fn warn_for_built_in_methods_with_negation() { let res: Result = Ok(1); - if res.is_err() {} - if res.is_ok() {} + if res.is_err() {} //~ nonminimal_bool + if res.is_ok() {} //~ nonminimal_bool let res = Some(1); - if res.is_none() {} - if res.is_some() {} + if res.is_none() {} //~ nonminimal_bool + if res.is_some() {} //~ nonminimal_bool } #[allow(clippy::neg_cmp_op_on_partial_ord)] diff --git a/tests/ui/nonminimal_bool_methods.rs b/tests/ui/nonminimal_bool_methods.rs index 040a6e920a17..0ca06a67b2cf 100644 --- a/tests/ui/nonminimal_bool_methods.rs +++ b/tests/ui/nonminimal_bool_methods.rs @@ -5,19 +5,19 @@ fn methods_with_negation() { let a: Option = unimplemented!(); let b: Result = unimplemented!(); let _ = a.is_some(); - let _ = !a.is_some(); + let _ = !a.is_some(); //~ nonminimal_bool let _ = a.is_none(); - let _ = !a.is_none(); + let _ = !a.is_none(); //~ nonminimal_bool let _ = b.is_err(); - let _ = !b.is_err(); + let _ = !b.is_err(); //~ nonminimal_bool let _ = b.is_ok(); - let _ = !b.is_ok(); + let _ = !b.is_ok(); //~ nonminimal_bool let c = false; - let _ = !(a.is_some() && !c); - let _ = !(a.is_some() || !c); - let _ = !(!c ^ c) || !a.is_some(); - let _ = (!c ^ c) || !a.is_some(); - let _ = !c ^ c || !a.is_some(); + let _ = !(a.is_some() && !c); //~ nonminimal_bool + let _ = !(a.is_some() || !c); //~ nonminimal_bool + let _ = !(!c ^ c) || !a.is_some(); //~ nonminimal_bool + let _ = (!c ^ c) || !a.is_some(); //~ nonminimal_bool + let _ = !c ^ c || !a.is_some(); //~ nonminimal_bool } // Simplified versions of https://github.com/rust-lang/rust-clippy/issues/2638 @@ -89,12 +89,12 @@ fn dont_warn_for_custom_methods_with_negation() { // Only Built-in Result and Some types should suggest the negated alternative fn warn_for_built_in_methods_with_negation() { let res: Result = Ok(1); - if !res.is_ok() {} - if !res.is_err() {} + if !res.is_ok() {} //~ nonminimal_bool + if !res.is_err() {} //~ nonminimal_bool let res = Some(1); - if !res.is_some() {} - if !res.is_none() {} + if !res.is_some() {} //~ nonminimal_bool + if !res.is_none() {} //~ nonminimal_bool } #[allow(clippy::neg_cmp_op_on_partial_ord)] diff --git a/tests/ui/numbered_fields.fixed b/tests/ui/numbered_fields.fixed index dc88081ba0a7..fcdb9e4fa605 100644 --- a/tests/ui/numbered_fields.fixed +++ b/tests/ui/numbered_fields.fixed @@ -14,9 +14,11 @@ fn main() { let tuple_struct = TupleStruct::default(); // This should lint + //~v init_numbered_fields let _ = TupleStruct(1u32, 42, 23u8); // This should also lint and order the fields correctly + //~v init_numbered_fields let _ = TupleStruct(1u32, 3u32, 2u8); // Ok because of default initializer diff --git a/tests/ui/numbered_fields.rs b/tests/ui/numbered_fields.rs index e8fa652e3c1d..8de2054b7d2d 100644 --- a/tests/ui/numbered_fields.rs +++ b/tests/ui/numbered_fields.rs @@ -14,6 +14,7 @@ fn main() { let tuple_struct = TupleStruct::default(); // This should lint + //~v init_numbered_fields let _ = TupleStruct { 0: 1u32, 1: 42, @@ -21,6 +22,7 @@ fn main() { }; // This should also lint and order the fields correctly + //~v init_numbered_fields let _ = TupleStruct { 0: 1u32, 2: 2u8, diff --git a/tests/ui/numbered_fields.stderr b/tests/ui/numbered_fields.stderr index 76f5e082f326..8faec4786b45 100644 --- a/tests/ui/numbered_fields.stderr +++ b/tests/ui/numbered_fields.stderr @@ -1,5 +1,5 @@ error: used a field initializer for a tuple struct - --> $DIR/numbered_fields.rs:17:13 + --> $DIR/numbered_fields.rs:18:13 | LL | let _ = TupleStruct { | _____________^ @@ -13,7 +13,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::init_numbered_fields)]` error: used a field initializer for a tuple struct - --> $DIR/numbered_fields.rs:24:13 + --> $DIR/numbered_fields.rs:26:13 | LL | let _ = TupleStruct { | _____________^ diff --git a/tests/ui/obfuscated_if_else.fixed b/tests/ui/obfuscated_if_else.fixed index c5ee569800ab..f6355cf20947 100644 --- a/tests/ui/obfuscated_if_else.fixed +++ b/tests/ui/obfuscated_if_else.fixed @@ -1,5 +1,5 @@ #![warn(clippy::obfuscated_if_else)] fn main() { - if true { "a" } else { "b" }; + if true { "a" } else { "b" }; //~ obfuscated_if_else } diff --git a/tests/ui/obfuscated_if_else.rs b/tests/ui/obfuscated_if_else.rs index 2b60c855a555..51f3bd08a777 100644 --- a/tests/ui/obfuscated_if_else.rs +++ b/tests/ui/obfuscated_if_else.rs @@ -1,5 +1,5 @@ #![warn(clippy::obfuscated_if_else)] fn main() { - true.then_some("a").unwrap_or("b"); + true.then_some("a").unwrap_or("b"); //~ obfuscated_if_else } diff --git a/tests/ui/option_as_ref_cloned.fixed b/tests/ui/option_as_ref_cloned.fixed index 394dad219f77..cf21d1c0176e 100644 --- a/tests/ui/option_as_ref_cloned.fixed +++ b/tests/ui/option_as_ref_cloned.fixed @@ -5,10 +5,13 @@ fn main() { let mut x = Some(String::new()); let _: Option = x.clone(); + //~^ option_as_ref_cloned let _: Option = x.clone(); + //~^ option_as_ref_cloned let y = x.as_ref(); let _: Option<&String> = y.clone(); + //~^ option_as_ref_cloned macro_rules! cloned_recv { () => { diff --git a/tests/ui/option_as_ref_cloned.rs b/tests/ui/option_as_ref_cloned.rs index 7243957927b2..354638c4c380 100644 --- a/tests/ui/option_as_ref_cloned.rs +++ b/tests/ui/option_as_ref_cloned.rs @@ -5,10 +5,13 @@ fn main() { let mut x = Some(String::new()); let _: Option = x.as_ref().cloned(); + //~^ option_as_ref_cloned let _: Option = x.as_mut().cloned(); + //~^ option_as_ref_cloned let y = x.as_ref(); let _: Option<&String> = y.as_ref().cloned(); + //~^ option_as_ref_cloned macro_rules! cloned_recv { () => { diff --git a/tests/ui/option_as_ref_cloned.stderr b/tests/ui/option_as_ref_cloned.stderr index ea03da3b69fa..c5d3ef39e699 100644 --- a/tests/ui/option_as_ref_cloned.stderr +++ b/tests/ui/option_as_ref_cloned.stderr @@ -12,7 +12,7 @@ LL | let _: Option = x.clone(); | ~~~~~ error: cloning an `Option<_>` using `.as_mut().cloned()` - --> $DIR/option_as_ref_cloned.rs:8:31 + --> $DIR/option_as_ref_cloned.rs:9:31 | LL | let _: Option = x.as_mut().cloned(); | ^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _: Option = x.clone(); | ~~~~~ error: cloning an `Option<_>` using `.as_ref().cloned()` - --> $DIR/option_as_ref_cloned.rs:11:32 + --> $DIR/option_as_ref_cloned.rs:13:32 | LL | let _: Option<&String> = y.as_ref().cloned(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/option_as_ref_deref.fixed b/tests/ui/option_as_ref_deref.fixed index c5a959ba566d..c5de941e2ffd 100644 --- a/tests/ui/option_as_ref_deref.fixed +++ b/tests/ui/option_as_ref_deref.fixed @@ -9,36 +9,50 @@ fn main() { let mut opt = Some(String::from("123")); let _ = opt.clone().as_deref().map(str::len); + //~^ option_as_ref_deref #[rustfmt::skip] + //~v option_as_ref_deref let _ = opt.clone().as_deref() .map(str::len); let _ = opt.as_deref_mut(); + //~^ option_as_ref_deref let _ = opt.as_deref(); + //~^ option_as_ref_deref let _ = opt.as_deref(); + //~^ option_as_ref_deref let _ = opt.as_deref_mut(); + //~^ option_as_ref_deref let _ = opt.as_deref_mut(); + //~^ option_as_ref_deref let _ = Some(CString::new(vec![]).unwrap()).as_deref(); + //~^ option_as_ref_deref let _ = Some(OsString::new()).as_deref(); + //~^ option_as_ref_deref let _ = Some(PathBuf::new()).as_deref(); + //~^ option_as_ref_deref let _ = Some(Vec::<()>::new()).as_deref(); + //~^ option_as_ref_deref let _ = Some(Vec::<()>::new()).as_deref_mut(); + //~^ option_as_ref_deref - let _ = opt.as_deref(); + let _ = opt.as_deref(); //~ option_as_ref_deref let _ = opt.clone().as_deref_mut().map(|x| x.len()); + //~^ option_as_ref_deref let vc = vec![String::new()]; let _ = Some(1_usize).as_ref().map(|x| vc[*x].as_str()); // should not be linted let _: Option<&str> = Some(&String::new()).as_ref().map(|x| x.as_str()); // should not be linted - let _ = opt.as_deref(); - let _ = opt.as_deref_mut(); + let _ = opt.as_deref(); //~ option_as_ref_deref + let _ = opt.as_deref_mut(); //~ option_as_ref_deref // Issue #5927 let _ = opt.as_deref(); + //~^ option_as_ref_deref } #[clippy::msrv = "1.39"] @@ -51,4 +65,5 @@ fn msrv_1_39() { fn msrv_1_40() { let opt = Some(String::from("123")); let _ = opt.as_deref(); + //~^ option_as_ref_deref } diff --git a/tests/ui/option_as_ref_deref.rs b/tests/ui/option_as_ref_deref.rs index 1aeedf211fe2..ae87a33af541 100644 --- a/tests/ui/option_as_ref_deref.rs +++ b/tests/ui/option_as_ref_deref.rs @@ -9,8 +9,10 @@ fn main() { let mut opt = Some(String::from("123")); let _ = opt.clone().as_ref().map(Deref::deref).map(str::len); + //~^ option_as_ref_deref #[rustfmt::skip] + //~v option_as_ref_deref let _ = opt.clone() .as_ref().map( Deref::deref @@ -18,30 +20,42 @@ fn main() { .map(str::len); let _ = opt.as_mut().map(DerefMut::deref_mut); + //~^ option_as_ref_deref let _ = opt.as_ref().map(String::as_str); + //~^ option_as_ref_deref let _ = opt.as_ref().map(|x| x.as_str()); + //~^ option_as_ref_deref let _ = opt.as_mut().map(String::as_mut_str); + //~^ option_as_ref_deref let _ = opt.as_mut().map(|x| x.as_mut_str()); + //~^ option_as_ref_deref let _ = Some(CString::new(vec![]).unwrap()).as_ref().map(CString::as_c_str); + //~^ option_as_ref_deref let _ = Some(OsString::new()).as_ref().map(OsString::as_os_str); + //~^ option_as_ref_deref let _ = Some(PathBuf::new()).as_ref().map(PathBuf::as_path); + //~^ option_as_ref_deref let _ = Some(Vec::<()>::new()).as_ref().map(Vec::as_slice); + //~^ option_as_ref_deref let _ = Some(Vec::<()>::new()).as_mut().map(Vec::as_mut_slice); + //~^ option_as_ref_deref - let _ = opt.as_ref().map(|x| x.deref()); + let _ = opt.as_ref().map(|x| x.deref()); //~ option_as_ref_deref let _ = opt.clone().as_mut().map(|x| x.deref_mut()).map(|x| x.len()); + //~^ option_as_ref_deref let vc = vec![String::new()]; let _ = Some(1_usize).as_ref().map(|x| vc[*x].as_str()); // should not be linted let _: Option<&str> = Some(&String::new()).as_ref().map(|x| x.as_str()); // should not be linted - let _ = opt.as_ref().map(|x| &**x); - let _ = opt.as_mut().map(|x| &mut **x); + let _ = opt.as_ref().map(|x| &**x); //~ option_as_ref_deref + let _ = opt.as_mut().map(|x| &mut **x); //~ option_as_ref_deref // Issue #5927 let _ = opt.as_ref().map(std::ops::Deref::deref); + //~^ option_as_ref_deref } #[clippy::msrv = "1.39"] @@ -54,4 +68,5 @@ fn msrv_1_39() { fn msrv_1_40() { let opt = Some(String::from("123")); let _ = opt.as_ref().map(String::as_str); + //~^ option_as_ref_deref } diff --git a/tests/ui/option_as_ref_deref.stderr b/tests/ui/option_as_ref_deref.stderr index 036b8c749e41..449fc42cb64c 100644 --- a/tests/ui/option_as_ref_deref.stderr +++ b/tests/ui/option_as_ref_deref.stderr @@ -8,7 +8,7 @@ LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len); = help: to override `-D warnings` add `#[allow(clippy::option_as_ref_deref)]` error: called `.as_ref().map(Deref::deref)` on an `Option` value - --> $DIR/option_as_ref_deref.rs:14:13 + --> $DIR/option_as_ref_deref.rs:16:13 | LL | let _ = opt.clone() | _____________^ @@ -18,97 +18,97 @@ LL | | ) | |_________^ help: consider using as_deref: `opt.clone().as_deref()` error: called `.as_mut().map(DerefMut::deref_mut)` on an `Option` value - --> $DIR/option_as_ref_deref.rs:20:13 + --> $DIR/option_as_ref_deref.rs:22:13 | LL | let _ = opt.as_mut().map(DerefMut::deref_mut); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref_mut: `opt.as_deref_mut()` error: called `.as_ref().map(String::as_str)` on an `Option` value - --> $DIR/option_as_ref_deref.rs:22:13 + --> $DIR/option_as_ref_deref.rs:25:13 | LL | let _ = opt.as_ref().map(String::as_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `opt.as_deref()` error: called `.as_ref().map(|x| x.as_str())` on an `Option` value - --> $DIR/option_as_ref_deref.rs:23:13 + --> $DIR/option_as_ref_deref.rs:27:13 | LL | let _ = opt.as_ref().map(|x| x.as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `opt.as_deref()` error: called `.as_mut().map(String::as_mut_str)` on an `Option` value - --> $DIR/option_as_ref_deref.rs:24:13 + --> $DIR/option_as_ref_deref.rs:29:13 | LL | let _ = opt.as_mut().map(String::as_mut_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref_mut: `opt.as_deref_mut()` error: called `.as_mut().map(|x| x.as_mut_str())` on an `Option` value - --> $DIR/option_as_ref_deref.rs:25:13 + --> $DIR/option_as_ref_deref.rs:31:13 | LL | let _ = opt.as_mut().map(|x| x.as_mut_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref_mut: `opt.as_deref_mut()` error: called `.as_ref().map(CString::as_c_str)` on an `Option` value - --> $DIR/option_as_ref_deref.rs:26:13 + --> $DIR/option_as_ref_deref.rs:33:13 | LL | let _ = Some(CString::new(vec![]).unwrap()).as_ref().map(CString::as_c_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `Some(CString::new(vec![]).unwrap()).as_deref()` error: called `.as_ref().map(OsString::as_os_str)` on an `Option` value - --> $DIR/option_as_ref_deref.rs:27:13 + --> $DIR/option_as_ref_deref.rs:35:13 | LL | let _ = Some(OsString::new()).as_ref().map(OsString::as_os_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `Some(OsString::new()).as_deref()` error: called `.as_ref().map(PathBuf::as_path)` on an `Option` value - --> $DIR/option_as_ref_deref.rs:28:13 + --> $DIR/option_as_ref_deref.rs:37:13 | LL | let _ = Some(PathBuf::new()).as_ref().map(PathBuf::as_path); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `Some(PathBuf::new()).as_deref()` error: called `.as_ref().map(Vec::as_slice)` on an `Option` value - --> $DIR/option_as_ref_deref.rs:29:13 + --> $DIR/option_as_ref_deref.rs:39:13 | LL | let _ = Some(Vec::<()>::new()).as_ref().map(Vec::as_slice); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `Some(Vec::<()>::new()).as_deref()` error: called `.as_mut().map(Vec::as_mut_slice)` on an `Option` value - --> $DIR/option_as_ref_deref.rs:30:13 + --> $DIR/option_as_ref_deref.rs:41:13 | LL | let _ = Some(Vec::<()>::new()).as_mut().map(Vec::as_mut_slice); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref_mut: `Some(Vec::<()>::new()).as_deref_mut()` error: called `.as_ref().map(|x| x.deref())` on an `Option` value - --> $DIR/option_as_ref_deref.rs:32:13 + --> $DIR/option_as_ref_deref.rs:44:13 | LL | let _ = opt.as_ref().map(|x| x.deref()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `opt.as_deref()` error: called `.as_mut().map(|x| x.deref_mut())` on an `Option` value - --> $DIR/option_as_ref_deref.rs:33:13 + --> $DIR/option_as_ref_deref.rs:45:13 | LL | let _ = opt.clone().as_mut().map(|x| x.deref_mut()).map(|x| x.len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref_mut: `opt.clone().as_deref_mut()` error: called `.as_ref().map(|x| &**x)` on an `Option` value - --> $DIR/option_as_ref_deref.rs:40:13 + --> $DIR/option_as_ref_deref.rs:53:13 | LL | let _ = opt.as_ref().map(|x| &**x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `opt.as_deref()` error: called `.as_mut().map(|x| &mut **x)` on an `Option` value - --> $DIR/option_as_ref_deref.rs:41:13 + --> $DIR/option_as_ref_deref.rs:54:13 | LL | let _ = opt.as_mut().map(|x| &mut **x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref_mut: `opt.as_deref_mut()` error: called `.as_ref().map(std::ops::Deref::deref)` on an `Option` value - --> $DIR/option_as_ref_deref.rs:44:13 + --> $DIR/option_as_ref_deref.rs:57:13 | LL | let _ = opt.as_ref().map(std::ops::Deref::deref); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `opt.as_deref()` error: called `.as_ref().map(String::as_str)` on an `Option` value - --> $DIR/option_as_ref_deref.rs:56:13 + --> $DIR/option_as_ref_deref.rs:70:13 | LL | let _ = opt.as_ref().map(String::as_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `opt.as_deref()` diff --git a/tests/ui/option_env_unwrap.rs b/tests/ui/option_env_unwrap.rs index f8d382340f2f..e5f78cb011e3 100644 --- a/tests/ui/option_env_unwrap.rs +++ b/tests/ui/option_env_unwrap.rs @@ -7,11 +7,18 @@ use proc_macros::{external, inline_macros}; #[inline_macros] fn main() { - let _ = option_env!("PATH").unwrap(); + let _ = option_env!("PATH").unwrap(); //~ option_env_unwrap let _ = option_env!("PATH").expect("environment variable PATH isn't set"); + //~^ option_env_unwrap + + //~v option_env_unwrap let _ = option_env!("__Y__do_not_use").unwrap(); // This test only works if you don't have a __Y__do_not_use env variable in your environment. let _ = inline!(option_env!($"PATH").unwrap()); + //~^ option_env_unwrap let _ = inline!(option_env!($"PATH").expect($"environment variable PATH isn't set")); + //~^ option_env_unwrap let _ = external!(option_env!($"PATH").unwrap()); + //~^ option_env_unwrap let _ = external!(option_env!($"PATH").expect($"environment variable PATH isn't set")); + //~^ option_env_unwrap } diff --git a/tests/ui/option_env_unwrap.stderr b/tests/ui/option_env_unwrap.stderr index de31d0c7f095..736130f3990f 100644 --- a/tests/ui/option_env_unwrap.stderr +++ b/tests/ui/option_env_unwrap.stderr @@ -17,7 +17,7 @@ LL | let _ = option_env!("PATH").expect("environment variable PATH isn't set = help: consider using the `env!` macro instead error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:12:13 + --> $DIR/option_env_unwrap.rs:15:13 | LL | let _ = option_env!("__Y__do_not_use").unwrap(); // This test only works if you don't have a __Y__do_not_use env variable in your env... | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = option_env!("__Y__do_not_use").unwrap(); // This test only work = help: consider using the `env!` macro instead error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:13:21 + --> $DIR/option_env_unwrap.rs:16:21 | LL | let _ = inline!(option_env!($"PATH").unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = inline!(option_env!($"PATH").unwrap()); = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:14:21 + --> $DIR/option_env_unwrap.rs:18:21 | LL | let _ = inline!(option_env!($"PATH").expect($"environment variable PATH isn't set")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -43,7 +43,7 @@ LL | let _ = inline!(option_env!($"PATH").expect($"environment variable PATH = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:15:13 + --> $DIR/option_env_unwrap.rs:20:13 | LL | let _ = external!(option_env!($"PATH").unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,7 +52,7 @@ LL | let _ = external!(option_env!($"PATH").unwrap()); = note: this error originates in the macro `external` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:16:13 + --> $DIR/option_env_unwrap.rs:22:13 | LL | let _ = external!(option_env!($"PATH").expect($"environment variable PATH isn't set")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/option_if_let_else.fixed b/tests/ui/option_if_let_else.fixed index d443334bb059..e64a1e26db0b 100644 --- a/tests/ui/option_if_let_else.fixed +++ b/tests/ui/option_if_let_else.fixed @@ -7,6 +7,7 @@ )] fn bad1(string: Option<&str>) -> (bool, &str) { + //~v option_if_let_else string.map_or((false, "hello"), |x| (true, x)) } @@ -22,16 +23,24 @@ fn else_if_option(string: Option<&str>) -> Option<(bool, &str)> { fn unop_bad(string: &Option<&str>, mut num: Option) { let _ = string.map_or(0, |s| s.len()); + //~^ option_if_let_else let _ = num.as_ref().map_or(&0, |s| s); + //~^ option_if_let_else + + //~v option_if_let_else let _ = num.as_mut().map_or(&0, |s| { *s += 1; s }); let _ = num.as_ref().map_or(&0, |s| s); + //~^ option_if_let_else + + //~v option_if_let_else let _ = num.map_or(0, |mut s| { s += 1; s }); + //~v option_if_let_else let _ = num.as_mut().map_or(&0, |s| { *s += 1; s @@ -39,6 +48,7 @@ fn unop_bad(string: &Option<&str>, mut num: Option) { } fn longer_body(arg: Option) -> u32 { + //~v option_if_let_else arg.map_or(13, |x| { let y = x * x; y * y @@ -50,10 +60,12 @@ fn impure_else(arg: Option) { println!("return 1"); 1 }; + //~v option_if_let_else let _ = arg.map_or_else(side_effect, |x| x); } fn test_map_or_else(arg: Option) { + //~v option_if_let_else let _ = arg.map_or_else(|| { let mut y = 1; y = (y + 2 / y) / 2; @@ -85,6 +97,7 @@ fn pattern_to_vec(pattern: &str) -> Vec { .trim_matches('/') .split('/') .flat_map(|s| { + //~v option_if_let_else s.find('.').map_or_else(|| vec![s.to_string()], |idx| vec![s[..idx].to_string(), s[idx..].to_string()]) }) .collect::>() @@ -92,6 +105,7 @@ fn pattern_to_vec(pattern: &str) -> Vec { // #10335 fn test_result_impure_else(variable: Result) -> bool { + //~v option_if_let_else variable.map_or_else(|_| { println!("Err"); false @@ -117,6 +131,7 @@ fn complex_subpat() -> DummyEnum { fn main() { let optional = Some(5); let _ = optional.map_or(5, |x| x + 2); + //~^ option_if_let_else let _ = bad1(None); let _ = else_if_option(None); unop_bad(&None, None); @@ -126,6 +141,7 @@ fn main() { let _ = negative_tests(None); let _ = impure_else(None); + //~v option_if_let_else let _ = Some(0).map_or(0, |x| loop { if x == 0 { break x; @@ -151,9 +167,11 @@ fn main() { let s = String::new(); // Lint, both branches immutably borrow `s`. let _ = Some(0).map_or(s.len(), |x| s.len() + x); + //~^ option_if_let_else let s = String::new(); // Lint, `Some` branch consumes `s`, but else branch doesn't use `s`. + //~v option_if_let_else let _ = Some(0).map_or(1, |x| { let s = s; s.len() + x @@ -191,13 +209,18 @@ fn main() { let _ = complex_subpat(); // issue #8492 + //~v option_if_let_else let _ = s.map_or(1, |string| string.len()); + //~v option_if_let_else let _ = Some(10).map_or(5, |a| a + 1); let res: Result = Ok(5); + //~v option_if_let_else let _ = res.map_or(1, |a| a + 1); + //~v option_if_let_else let _ = res.map_or(1, |a| a + 1); let _ = res.map_or(5, |a| a + 1); + //~^ option_if_let_else } #[allow(dead_code)] @@ -214,10 +237,12 @@ mod issue10729 { pub fn reproduce(initial: &Option) { // 👇 needs `.as_ref()` because initial is an `&Option<_>` + //~v option_if_let_else let _ = initial.as_ref().map_or(42, |value| do_something(value)); } pub fn reproduce2(initial: &mut Option) { + //~v option_if_let_else let _ = initial.as_mut().map_or(42, |value| do_something2(value)); } @@ -238,9 +263,11 @@ fn issue11429() { let opt: Option> = None; + //~v option_if_let_else let mut _hashmap = opt.as_ref().map_or_else(HashMap::new, |hm| hm.clone()); let mut _hm = opt.as_ref().map_or_else(|| new_map!(), |hm| hm.clone()); + //~^ option_if_let_else } fn issue11893() { diff --git a/tests/ui/option_if_let_else.rs b/tests/ui/option_if_let_else.rs index 317c35bf8427..a9543a64e69d 100644 --- a/tests/ui/option_if_let_else.rs +++ b/tests/ui/option_if_let_else.rs @@ -7,6 +7,7 @@ )] fn bad1(string: Option<&str>) -> (bool, &str) { + //~v option_if_let_else if let Some(x) = string { (true, x) } else { @@ -26,7 +27,11 @@ fn else_if_option(string: Option<&str>) -> Option<(bool, &str)> { fn unop_bad(string: &Option<&str>, mut num: Option) { let _ = if let Some(s) = *string { s.len() } else { 0 }; + //~^ option_if_let_else let _ = if let Some(s) = &num { s } else { &0 }; + //~^ option_if_let_else + + //~v option_if_let_else let _ = if let Some(s) = &mut num { *s += 1; s @@ -34,12 +39,16 @@ fn unop_bad(string: &Option<&str>, mut num: Option) { &0 }; let _ = if let Some(ref s) = num { s } else { &0 }; + //~^ option_if_let_else + + //~v option_if_let_else let _ = if let Some(mut s) = num { s += 1; s } else { 0 }; + //~v option_if_let_else let _ = if let Some(ref mut s) = num { *s += 1; s @@ -49,6 +58,7 @@ fn unop_bad(string: &Option<&str>, mut num: Option) { } fn longer_body(arg: Option) -> u32 { + //~v option_if_let_else if let Some(x) = arg { let y = x * x; y * y @@ -62,6 +72,7 @@ fn impure_else(arg: Option) { println!("return 1"); 1 }; + //~v option_if_let_else let _ = if let Some(x) = arg { x } else { @@ -71,6 +82,7 @@ fn impure_else(arg: Option) { } fn test_map_or_else(arg: Option) { + //~v option_if_let_else let _ = if let Some(x) = arg { x * x * x * x } else { @@ -104,6 +116,7 @@ fn pattern_to_vec(pattern: &str) -> Vec { .trim_matches('/') .split('/') .flat_map(|s| { + //~v option_if_let_else if let Some(idx) = s.find('.') { vec![s[..idx].to_string(), s[idx..].to_string()] } else { @@ -115,6 +128,7 @@ fn pattern_to_vec(pattern: &str) -> Vec { // #10335 fn test_result_impure_else(variable: Result) -> bool { + //~v option_if_let_else if let Ok(binding) = variable { println!("Ok {binding}"); true @@ -140,6 +154,7 @@ fn complex_subpat() -> DummyEnum { fn main() { let optional = Some(5); let _ = if let Some(x) = optional { x + 2 } else { 5 }; + //~^ option_if_let_else let _ = bad1(None); let _ = else_if_option(None); unop_bad(&None, None); @@ -149,6 +164,7 @@ fn main() { let _ = negative_tests(None); let _ = impure_else(None); + //~v option_if_let_else let _ = if let Some(x) = Some(0) { loop { if x == 0 { @@ -178,9 +194,11 @@ fn main() { let s = String::new(); // Lint, both branches immutably borrow `s`. let _ = if let Some(x) = Some(0) { s.len() + x } else { s.len() }; + //~^ option_if_let_else let s = String::new(); // Lint, `Some` branch consumes `s`, but else branch doesn't use `s`. + //~v option_if_let_else let _ = if let Some(x) = Some(0) { let s = s; s.len() + x @@ -220,25 +238,30 @@ fn main() { let _ = complex_subpat(); // issue #8492 + //~v option_if_let_else let _ = match s { Some(string) => string.len(), None => 1, }; + //~v option_if_let_else let _ = match Some(10) { Some(a) => a + 1, None => 5, }; let res: Result = Ok(5); + //~v option_if_let_else let _ = match res { Ok(a) => a + 1, _ => 1, }; + //~v option_if_let_else let _ = match res { Err(_) => 1, Ok(a) => a + 1, }; let _ = if let Ok(a) = res { a + 1 } else { 5 }; + //~^ option_if_let_else } #[allow(dead_code)] @@ -255,6 +278,7 @@ mod issue10729 { pub fn reproduce(initial: &Option) { // 👇 needs `.as_ref()` because initial is an `&Option<_>` + //~v option_if_let_else let _ = match initial { Some(value) => do_something(value), None => 42, @@ -262,6 +286,7 @@ mod issue10729 { } pub fn reproduce2(initial: &mut Option) { + //~v option_if_let_else let _ = match initial { Some(value) => do_something2(value), None => 42, @@ -285,6 +310,7 @@ fn issue11429() { let opt: Option> = None; + //~v option_if_let_else let mut _hashmap = if let Some(hm) = &opt { hm.clone() } else { @@ -292,6 +318,7 @@ fn issue11429() { }; let mut _hm = if let Some(hm) = &opt { hm.clone() } else { new_map!() }; + //~^ option_if_let_else } fn issue11893() { diff --git a/tests/ui/option_if_let_else.stderr b/tests/ui/option_if_let_else.stderr index e053d356ff24..9b0520f7379b 100644 --- a/tests/ui/option_if_let_else.stderr +++ b/tests/ui/option_if_let_else.stderr @@ -1,5 +1,5 @@ error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:10:5 + --> $DIR/option_if_let_else.rs:11:5 | LL | / if let Some(x) = string { LL | | (true, x) @@ -12,19 +12,19 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::option_if_let_else)]` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:28:13 + --> $DIR/option_if_let_else.rs:29:13 | LL | let _ = if let Some(s) = *string { s.len() } else { 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.map_or(0, |s| s.len())` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:29:13 + --> $DIR/option_if_let_else.rs:31:13 | LL | let _ = if let Some(s) = &num { s } else { &0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:30:13 + --> $DIR/option_if_let_else.rs:35:13 | LL | let _ = if let Some(s) = &mut num { | _____________^ @@ -44,13 +44,13 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:36:13 + --> $DIR/option_if_let_else.rs:41:13 | LL | let _ = if let Some(ref s) = num { s } else { &0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:37:13 + --> $DIR/option_if_let_else.rs:45:13 | LL | let _ = if let Some(mut s) = num { | _____________^ @@ -70,7 +70,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:43:13 + --> $DIR/option_if_let_else.rs:52:13 | LL | let _ = if let Some(ref mut s) = num { | _____________^ @@ -90,7 +90,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:52:5 + --> $DIR/option_if_let_else.rs:62:5 | LL | / if let Some(x) = arg { LL | | let y = x * x; @@ -109,7 +109,7 @@ LL + }) | error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:65:13 + --> $DIR/option_if_let_else.rs:76:13 | LL | let _ = if let Some(x) = arg { | _____________^ @@ -121,7 +121,7 @@ LL | | }; | |_____^ help: try: `arg.map_or_else(side_effect, |x| x)` error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:74:13 + --> $DIR/option_if_let_else.rs:86:13 | LL | let _ = if let Some(x) = arg { | _____________^ @@ -144,7 +144,7 @@ LL ~ }, |x| x * x * x * x); | error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:107:13 + --> $DIR/option_if_let_else.rs:120:13 | LL | / if let Some(idx) = s.find('.') { LL | | vec![s[..idx].to_string(), s[idx..].to_string()] @@ -154,7 +154,7 @@ LL | | } | |_____________^ help: try: `s.find('.').map_or_else(|| vec![s.to_string()], |idx| vec![s[..idx].to_string(), s[idx..].to_string()])` error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:118:5 + --> $DIR/option_if_let_else.rs:132:5 | LL | / if let Ok(binding) = variable { LL | | println!("Ok {binding}"); @@ -177,13 +177,13 @@ LL + }) | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:142:13 + --> $DIR/option_if_let_else.rs:156:13 | LL | let _ = if let Some(x) = optional { x + 2 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:152:13 + --> $DIR/option_if_let_else.rs:168:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ @@ -205,13 +205,13 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:180:13 + --> $DIR/option_if_let_else.rs:196:13 | LL | let _ = if let Some(x) = Some(0) { s.len() + x } else { s.len() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(0).map_or(s.len(), |x| s.len() + x)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:184:13 + --> $DIR/option_if_let_else.rs:202:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ @@ -231,7 +231,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:223:13 + --> $DIR/option_if_let_else.rs:242:13 | LL | let _ = match s { | _____________^ @@ -241,7 +241,7 @@ LL | | }; | |_____^ help: try: `s.map_or(1, |string| string.len())` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:227:13 + --> $DIR/option_if_let_else.rs:247:13 | LL | let _ = match Some(10) { | _____________^ @@ -251,7 +251,7 @@ LL | | }; | |_____^ help: try: `Some(10).map_or(5, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:233:13 + --> $DIR/option_if_let_else.rs:254:13 | LL | let _ = match res { | _____________^ @@ -261,7 +261,7 @@ LL | | }; | |_____^ help: try: `res.map_or(1, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:237:13 + --> $DIR/option_if_let_else.rs:259:13 | LL | let _ = match res { | _____________^ @@ -271,13 +271,13 @@ LL | | }; | |_____^ help: try: `res.map_or(1, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:241:13 + --> $DIR/option_if_let_else.rs:263:13 | LL | let _ = if let Ok(a) = res { a + 1 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `res.map_or(5, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:258:17 + --> $DIR/option_if_let_else.rs:282:17 | LL | let _ = match initial { | _________________^ @@ -287,7 +287,7 @@ LL | | }; | |_________^ help: try: `initial.as_ref().map_or(42, |value| do_something(value))` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:265:17 + --> $DIR/option_if_let_else.rs:290:17 | LL | let _ = match initial { | _________________^ @@ -297,7 +297,7 @@ LL | | }; | |_________^ help: try: `initial.as_mut().map_or(42, |value| do_something2(value))` error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:288:24 + --> $DIR/option_if_let_else.rs:314:24 | LL | let mut _hashmap = if let Some(hm) = &opt { | ________________________^ @@ -308,7 +308,7 @@ LL | | }; | |_____^ help: try: `opt.as_ref().map_or_else(HashMap::new, |hm| hm.clone())` error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:294:19 + --> $DIR/option_if_let_else.rs:320:19 | LL | let mut _hm = if let Some(hm) = &opt { hm.clone() } else { new_map!() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.as_ref().map_or_else(|| new_map!(), |hm| hm.clone())` diff --git a/tests/ui/option_map_or_none.fixed b/tests/ui/option_map_or_none.fixed index 5f0ef34d231c..f30765c9ca0d 100644 --- a/tests/ui/option_map_or_none.fixed +++ b/tests/ui/option_map_or_none.fixed @@ -8,11 +8,16 @@ fn main() { // Check `OPTION_MAP_OR_NONE`. // Single line case. let _: Option = opt.map(|x| x + 1); + //~^ option_map_or_none // Multi-line case. #[rustfmt::skip] + //~v option_map_or_none let _: Option = opt.map(|x| x + 1); // function returning `Option` let _: Option = opt.and_then(bar); + //~^ option_map_or_none + + //~v option_map_or_none let _: Option = opt.and_then(|x| { let offset = 0; let height = x; @@ -21,4 +26,5 @@ fn main() { // Check `RESULT_MAP_OR_INTO_OPTION`. let _: Option = r.ok(); + //~^ result_map_or_into_option } diff --git a/tests/ui/option_map_or_none.rs b/tests/ui/option_map_or_none.rs index 56b1f61212d0..6bffc1c1ec8d 100644 --- a/tests/ui/option_map_or_none.rs +++ b/tests/ui/option_map_or_none.rs @@ -8,13 +8,18 @@ fn main() { // Check `OPTION_MAP_OR_NONE`. // Single line case. let _: Option = opt.map_or(None, |x| Some(x + 1)); + //~^ option_map_or_none // Multi-line case. #[rustfmt::skip] + //~v option_map_or_none let _: Option = opt.map_or(None, |x| { Some(x + 1) }); // function returning `Option` let _: Option = opt.map_or(None, bar); + //~^ option_map_or_none + + //~v option_map_or_none let _: Option = opt.map_or(None, |x| { let offset = 0; let height = x; @@ -23,4 +28,5 @@ fn main() { // Check `RESULT_MAP_OR_INTO_OPTION`. let _: Option = r.map_or(None, Some); + //~^ result_map_or_into_option } diff --git a/tests/ui/option_map_or_none.stderr b/tests/ui/option_map_or_none.stderr index d58ff83c3da2..358db1b3e0fc 100644 --- a/tests/ui/option_map_or_none.stderr +++ b/tests/ui/option_map_or_none.stderr @@ -8,7 +8,7 @@ LL | let _: Option = opt.map_or(None, |x| Some(x + 1)); = help: to override `-D warnings` add `#[allow(clippy::option_map_or_none)]` error: called `map_or(None, ..)` on an `Option` value - --> $DIR/option_map_or_none.rs:13:26 + --> $DIR/option_map_or_none.rs:15:26 | LL | let _: Option = opt.map_or(None, |x| { | __________________________^ @@ -17,13 +17,13 @@ LL | | }); | |_________________________^ help: consider using `map`: `opt.map(|x| x + 1)` error: called `map_or(None, ..)` on an `Option` value - --> $DIR/option_map_or_none.rs:17:26 + --> $DIR/option_map_or_none.rs:19:26 | LL | let _: Option = opt.map_or(None, bar); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `and_then`: `opt.and_then(bar)` error: called `map_or(None, ..)` on an `Option` value - --> $DIR/option_map_or_none.rs:18:26 + --> $DIR/option_map_or_none.rs:23:26 | LL | let _: Option = opt.map_or(None, |x| { | __________________________^ @@ -43,7 +43,7 @@ LL ~ }); | error: called `map_or(None, Some)` on a `Result` value - --> $DIR/option_map_or_none.rs:25:26 + --> $DIR/option_map_or_none.rs:30:26 | LL | let _: Option = r.map_or(None, Some); | ^^^^^^^^^^^^^^^^^^^^ help: consider using `ok`: `r.ok()` diff --git a/tests/ui/option_map_unit_fn_fixable.fixed b/tests/ui/option_map_unit_fn_fixable.fixed index 5dcc6464ff5f..c35cb43c4f74 100644 --- a/tests/ui/option_map_unit_fn_fixable.fixed +++ b/tests/ui/option_map_unit_fn_fixable.fixed @@ -34,53 +34,68 @@ fn option_map_unit_fn() { x.field.map(plus_one); let _ : Option<()> = x.field.map(do_nothing); - if let Some(x_field) = x.field { do_nothing(x_field) } + if let Some(x_field) = x.field { do_nothing(x_field) } //~ option_map_unit_fn - if let Some(x_field) = x.field { do_nothing(x_field) } + if let Some(x_field) = x.field { do_nothing(x_field) } //~ option_map_unit_fn - if let Some(x_field) = x.field { diverge(x_field) } + if let Some(x_field) = x.field { diverge(x_field) } //~ option_map_unit_fn let captured = 10; if let Some(value) = x.field { do_nothing(value + captured) }; let _ : Option<()> = x.field.map(|value| do_nothing(value + captured)); if let Some(value) = x.field { x.do_option_nothing(value + captured) } + //~^ option_map_unit_fn if let Some(value) = x.field { x.do_option_plus_one(value + captured); } + //~^ option_map_unit_fn if let Some(value) = x.field { do_nothing(value + captured) } + //~^ option_map_unit_fn if let Some(value) = x.field { do_nothing(value + captured) } + //~^ option_map_unit_fn if let Some(value) = x.field { do_nothing(value + captured); } + //~^ option_map_unit_fn if let Some(value) = x.field { do_nothing(value + captured); } + //~^ option_map_unit_fn if let Some(value) = x.field { diverge(value + captured) } + //~^ option_map_unit_fn if let Some(value) = x.field { diverge(value + captured) } + //~^ option_map_unit_fn if let Some(value) = x.field { diverge(value + captured); } + //~^ option_map_unit_fn if let Some(value) = x.field { diverge(value + captured); } + //~^ option_map_unit_fn x.field.map(|value| plus_one(value + captured)); x.field.map(|value| { plus_one(value + captured) }); if let Some(value) = x.field { let y = plus_one(value + captured); } + //~^ option_map_unit_fn if let Some(value) = x.field { plus_one(value + captured); } + //~^ option_map_unit_fn if let Some(value) = x.field { plus_one(value + captured); } + //~^ option_map_unit_fn if let Some(ref value) = x.field { do_nothing(value + captured) } + //~^ option_map_unit_fn - if let Some(a) = option() { do_nothing(a) } + if let Some(a) = option() { do_nothing(a) } //~ option_map_unit_fn if let Some(value) = option() { println!("{:?}", value) } + //~^ option_map_unit_fn } fn main() {} diff --git a/tests/ui/option_map_unit_fn_fixable.rs b/tests/ui/option_map_unit_fn_fixable.rs index 5489545fe3d9..4abbb72065a8 100644 --- a/tests/ui/option_map_unit_fn_fixable.rs +++ b/tests/ui/option_map_unit_fn_fixable.rs @@ -34,53 +34,68 @@ fn option_map_unit_fn() { x.field.map(plus_one); let _ : Option<()> = x.field.map(do_nothing); - x.field.map(do_nothing); + x.field.map(do_nothing); //~ option_map_unit_fn - x.field.map(do_nothing); + x.field.map(do_nothing); //~ option_map_unit_fn - x.field.map(diverge); + x.field.map(diverge); //~ option_map_unit_fn let captured = 10; if let Some(value) = x.field { do_nothing(value + captured) }; let _ : Option<()> = x.field.map(|value| do_nothing(value + captured)); x.field.map(|value| x.do_option_nothing(value + captured)); + //~^ option_map_unit_fn x.field.map(|value| { x.do_option_plus_one(value + captured); }); + //~^ option_map_unit_fn x.field.map(|value| do_nothing(value + captured)); + //~^ option_map_unit_fn x.field.map(|value| { do_nothing(value + captured) }); + //~^ option_map_unit_fn x.field.map(|value| { do_nothing(value + captured); }); + //~^ option_map_unit_fn x.field.map(|value| { { do_nothing(value + captured); } }); + //~^ option_map_unit_fn x.field.map(|value| diverge(value + captured)); + //~^ option_map_unit_fn x.field.map(|value| { diverge(value + captured) }); + //~^ option_map_unit_fn x.field.map(|value| { diverge(value + captured); }); + //~^ option_map_unit_fn x.field.map(|value| { { diverge(value + captured); } }); + //~^ option_map_unit_fn x.field.map(|value| plus_one(value + captured)); x.field.map(|value| { plus_one(value + captured) }); x.field.map(|value| { let y = plus_one(value + captured); }); + //~^ option_map_unit_fn x.field.map(|value| { plus_one(value + captured); }); + //~^ option_map_unit_fn x.field.map(|value| { { plus_one(value + captured); } }); + //~^ option_map_unit_fn x.field.map(|ref value| { do_nothing(value + captured) }); + //~^ option_map_unit_fn - option().map(do_nothing); + option().map(do_nothing); //~ option_map_unit_fn option().map(|value| println!("{:?}", value)); + //~^ option_map_unit_fn } fn main() {} diff --git a/tests/ui/option_map_unit_fn_fixable.stderr b/tests/ui/option_map_unit_fn_fixable.stderr index 34aca31e95c9..8fe24fcdd104 100644 --- a/tests/ui/option_map_unit_fn_fixable.stderr +++ b/tests/ui/option_map_unit_fn_fixable.stderr @@ -34,7 +34,7 @@ LL | x.field.map(|value| x.do_option_nothing(value + captured)); | help: try: `if let Some(value) = x.field { x.do_option_nothing(value + captured) }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:49:5 + --> $DIR/option_map_unit_fn_fixable.rs:50:5 | LL | x.field.map(|value| { x.do_option_plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -42,7 +42,7 @@ LL | x.field.map(|value| { x.do_option_plus_one(value + captured); }); | help: try: `if let Some(value) = x.field { x.do_option_plus_one(value + captured); }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:52:5 + --> $DIR/option_map_unit_fn_fixable.rs:54:5 | LL | x.field.map(|value| do_nothing(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -50,7 +50,7 @@ LL | x.field.map(|value| do_nothing(value + captured)); | help: try: `if let Some(value) = x.field { do_nothing(value + captured) }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:54:5 + --> $DIR/option_map_unit_fn_fixable.rs:57:5 | LL | x.field.map(|value| { do_nothing(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -58,7 +58,7 @@ LL | x.field.map(|value| { do_nothing(value + captured) }); | help: try: `if let Some(value) = x.field { do_nothing(value + captured) }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:56:5 + --> $DIR/option_map_unit_fn_fixable.rs:60:5 | LL | x.field.map(|value| { do_nothing(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -66,7 +66,7 @@ LL | x.field.map(|value| { do_nothing(value + captured); }); | help: try: `if let Some(value) = x.field { do_nothing(value + captured); }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:58:5 + --> $DIR/option_map_unit_fn_fixable.rs:63:5 | LL | x.field.map(|value| { { do_nothing(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -74,7 +74,7 @@ LL | x.field.map(|value| { { do_nothing(value + captured); } }); | help: try: `if let Some(value) = x.field { do_nothing(value + captured); }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:61:5 + --> $DIR/option_map_unit_fn_fixable.rs:67:5 | LL | x.field.map(|value| diverge(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -82,7 +82,7 @@ LL | x.field.map(|value| diverge(value + captured)); | help: try: `if let Some(value) = x.field { diverge(value + captured) }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:63:5 + --> $DIR/option_map_unit_fn_fixable.rs:70:5 | LL | x.field.map(|value| { diverge(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -90,7 +90,7 @@ LL | x.field.map(|value| { diverge(value + captured) }); | help: try: `if let Some(value) = x.field { diverge(value + captured) }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:65:5 + --> $DIR/option_map_unit_fn_fixable.rs:73:5 | LL | x.field.map(|value| { diverge(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -98,7 +98,7 @@ LL | x.field.map(|value| { diverge(value + captured); }); | help: try: `if let Some(value) = x.field { diverge(value + captured); }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:67:5 + --> $DIR/option_map_unit_fn_fixable.rs:76:5 | LL | x.field.map(|value| { { diverge(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -106,7 +106,7 @@ LL | x.field.map(|value| { { diverge(value + captured); } }); | help: try: `if let Some(value) = x.field { diverge(value + captured); }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:72:5 + --> $DIR/option_map_unit_fn_fixable.rs:82:5 | LL | x.field.map(|value| { let y = plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -114,7 +114,7 @@ LL | x.field.map(|value| { let y = plus_one(value + captured); }); | help: try: `if let Some(value) = x.field { let y = plus_one(value + captured); }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:74:5 + --> $DIR/option_map_unit_fn_fixable.rs:85:5 | LL | x.field.map(|value| { plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -122,7 +122,7 @@ LL | x.field.map(|value| { plus_one(value + captured); }); | help: try: `if let Some(value) = x.field { plus_one(value + captured); }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:76:5 + --> $DIR/option_map_unit_fn_fixable.rs:88:5 | LL | x.field.map(|value| { { plus_one(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -130,7 +130,7 @@ LL | x.field.map(|value| { { plus_one(value + captured); } }); | help: try: `if let Some(value) = x.field { plus_one(value + captured); }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:79:5 + --> $DIR/option_map_unit_fn_fixable.rs:92:5 | LL | x.field.map(|ref value| { do_nothing(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -138,7 +138,7 @@ LL | x.field.map(|ref value| { do_nothing(value + captured) }); | help: try: `if let Some(ref value) = x.field { do_nothing(value + captured) }` error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:81:5 + --> $DIR/option_map_unit_fn_fixable.rs:95:5 | LL | option().map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^^- @@ -146,7 +146,7 @@ LL | option().map(do_nothing); | help: try: `if let Some(a) = option() { do_nothing(a) }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:83:5 + --> $DIR/option_map_unit_fn_fixable.rs:97:5 | LL | option().map(|value| println!("{:?}", value)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed index e7ba54864ab0..3c0c9035f8cc 100644 --- a/tests/ui/or_fun_call.fixed +++ b/tests/ui/or_fun_call.fixed @@ -49,52 +49,57 @@ fn or_fun_call() { with_const_fn.unwrap_or(Duration::from_secs(5)); let with_constructor = Some(vec![1]); - with_constructor.unwrap_or_else(make); + with_constructor.unwrap_or_else(make); //~ or_fun_call let with_new = Some(vec![1]); - with_new.unwrap_or_default(); + with_new.unwrap_or_default(); //~ unwrap_or_default let with_const_args = Some(vec![1]); with_const_args.unwrap_or_else(|| Vec::with_capacity(12)); + //~^ or_fun_call let with_err: Result<_, ()> = Ok(vec![1]); - with_err.unwrap_or_else(|_| make()); + with_err.unwrap_or_else(|_| make()); //~ or_fun_call let with_err_args: Result<_, ()> = Ok(vec![1]); - with_err_args.unwrap_or_else(|_| Vec::with_capacity(12)); + with_err_args.unwrap_or_else(|_| Vec::with_capacity(12)); //~ or_fun_call let with_default_trait = Some(1); with_default_trait.unwrap_or_default(); + //~^ unwrap_or_default let with_default_type = Some(1); with_default_type.unwrap_or_default(); + //~^ unwrap_or_default let self_default = None::; self_default.unwrap_or_else(::default); + //~^ or_fun_call let real_default = None::; real_default.unwrap_or_default(); + //~^ unwrap_or_default let with_vec = Some(vec![1]); - with_vec.unwrap_or_default(); + with_vec.unwrap_or_default(); //~ unwrap_or_default let without_default = Some(Foo); - without_default.unwrap_or_else(Foo::new); + without_default.unwrap_or_else(Foo::new); //~ or_fun_call let mut map = HashMap::::new(); - map.entry(42).or_default(); + map.entry(42).or_default(); //~ unwrap_or_default let mut map_vec = HashMap::>::new(); - map_vec.entry(42).or_default(); + map_vec.entry(42).or_default(); //~ unwrap_or_default let mut btree = BTreeMap::::new(); - btree.entry(42).or_default(); + btree.entry(42).or_default(); //~ unwrap_or_default let mut btree_vec = BTreeMap::>::new(); - btree_vec.entry(42).or_default(); + btree_vec.entry(42).or_default(); //~ unwrap_or_default let stringy = Some(String::new()); - let _ = stringy.unwrap_or_default(); + let _ = stringy.unwrap_or_default(); //~ unwrap_or_default let opt = Some(1); let hello = "Hello"; @@ -102,9 +107,9 @@ fn or_fun_call() { // index let map = HashMap::::new(); - let _ = Some(1).unwrap_or_else(|| map[&1]); + let _ = Some(1).unwrap_or_else(|| map[&1]); //~ or_fun_call let map = BTreeMap::::new(); - let _ = Some(1).unwrap_or_else(|| map[&1]); + let _ = Some(1).unwrap_or_else(|| map[&1]); //~ or_fun_call // don't lint index vec let vec = vec![1]; let _ = Some(1).unwrap_or(vec[1]); @@ -129,6 +134,7 @@ fn test_or_with_ctors() { let _ = opt.or(Some(two)); let _ = Some("a".to_string()).or_else(|| Some("b".to_string())); + //~^ or_fun_call let b = "b".to_string(); let _ = Some(Bar("a".to_string(), Duration::from_secs(1))) @@ -167,15 +173,16 @@ mod issue6675 { unsafe fn foo() { let s = "test".to_owned(); let s = &s as *const _; - None.unwrap_or_else(|| ptr_to_ref(s)); + None.unwrap_or_else(|| ptr_to_ref(s)); //~ or_fun_call } fn bar() { let s = "test".to_owned(); let s = &s as *const _; - None.unwrap_or_else(|| unsafe { ptr_to_ref(s) }); + None.unwrap_or_else(|| unsafe { ptr_to_ref(s) }); //~ or_fun_call #[rustfmt::skip] None.unwrap_or_else(|| unsafe { ptr_to_ref(s) }); + //~^ or_fun_call } } @@ -250,8 +257,8 @@ mod issue8993 { } fn test_map_or() { - let _ = Some(4).map_or_else(g, |v| v); - let _ = Some(4).map_or_else(g, f); + let _ = Some(4).map_or_else(g, |v| v); //~ or_fun_call + let _ = Some(4).map_or_else(g, f); //~ or_fun_call let _ = Some(4).map_or(0, f); } } @@ -282,25 +289,31 @@ mod lazy { } let with_new = Some(vec![1]); - with_new.unwrap_or_default(); + with_new.unwrap_or_default(); //~ unwrap_or_default let with_default_trait = Some(1); with_default_trait.unwrap_or_default(); + //~^ unwrap_or_default let with_default_type = Some(1); with_default_type.unwrap_or_default(); + //~^ unwrap_or_default let real_default = None::; real_default.unwrap_or_default(); + //~^ unwrap_or_default let mut map = HashMap::::new(); map.entry(42).or_default(); + //~^ unwrap_or_default let mut btree = BTreeMap::::new(); btree.entry(42).or_default(); + //~^ unwrap_or_default let stringy = Some(String::new()); let _ = stringy.unwrap_or_default(); + //~^ unwrap_or_default // negative tests let self_default = None::; diff --git a/tests/ui/or_fun_call.rs b/tests/ui/or_fun_call.rs index 196632133d52..217e2bfc84ee 100644 --- a/tests/ui/or_fun_call.rs +++ b/tests/ui/or_fun_call.rs @@ -49,52 +49,57 @@ fn or_fun_call() { with_const_fn.unwrap_or(Duration::from_secs(5)); let with_constructor = Some(vec![1]); - with_constructor.unwrap_or(make()); + with_constructor.unwrap_or(make()); //~ or_fun_call let with_new = Some(vec![1]); - with_new.unwrap_or(Vec::new()); + with_new.unwrap_or(Vec::new()); //~ unwrap_or_default let with_const_args = Some(vec![1]); with_const_args.unwrap_or(Vec::with_capacity(12)); + //~^ or_fun_call let with_err: Result<_, ()> = Ok(vec![1]); - with_err.unwrap_or(make()); + with_err.unwrap_or(make()); //~ or_fun_call let with_err_args: Result<_, ()> = Ok(vec![1]); - with_err_args.unwrap_or(Vec::with_capacity(12)); + with_err_args.unwrap_or(Vec::with_capacity(12)); //~ or_fun_call let with_default_trait = Some(1); with_default_trait.unwrap_or(Default::default()); + //~^ unwrap_or_default let with_default_type = Some(1); with_default_type.unwrap_or(u64::default()); + //~^ unwrap_or_default let self_default = None::; self_default.unwrap_or(::default()); + //~^ or_fun_call let real_default = None::; real_default.unwrap_or(::default()); + //~^ unwrap_or_default let with_vec = Some(vec![1]); - with_vec.unwrap_or(vec![]); + with_vec.unwrap_or(vec![]); //~ unwrap_or_default let without_default = Some(Foo); - without_default.unwrap_or(Foo::new()); + without_default.unwrap_or(Foo::new()); //~ or_fun_call let mut map = HashMap::::new(); - map.entry(42).or_insert(String::new()); + map.entry(42).or_insert(String::new()); //~ unwrap_or_default let mut map_vec = HashMap::>::new(); - map_vec.entry(42).or_insert(vec![]); + map_vec.entry(42).or_insert(vec![]); //~ unwrap_or_default let mut btree = BTreeMap::::new(); - btree.entry(42).or_insert(String::new()); + btree.entry(42).or_insert(String::new()); //~ unwrap_or_default let mut btree_vec = BTreeMap::>::new(); - btree_vec.entry(42).or_insert(vec![]); + btree_vec.entry(42).or_insert(vec![]); //~ unwrap_or_default let stringy = Some(String::new()); - let _ = stringy.unwrap_or(String::new()); + let _ = stringy.unwrap_or(String::new()); //~ unwrap_or_default let opt = Some(1); let hello = "Hello"; @@ -102,9 +107,9 @@ fn or_fun_call() { // index let map = HashMap::::new(); - let _ = Some(1).unwrap_or(map[&1]); + let _ = Some(1).unwrap_or(map[&1]); //~ or_fun_call let map = BTreeMap::::new(); - let _ = Some(1).unwrap_or(map[&1]); + let _ = Some(1).unwrap_or(map[&1]); //~ or_fun_call // don't lint index vec let vec = vec![1]; let _ = Some(1).unwrap_or(vec[1]); @@ -129,6 +134,7 @@ fn test_or_with_ctors() { let _ = opt.or(Some(two)); let _ = Some("a".to_string()).or(Some("b".to_string())); + //~^ or_fun_call let b = "b".to_string(); let _ = Some(Bar("a".to_string(), Duration::from_secs(1))) @@ -167,15 +173,16 @@ mod issue6675 { unsafe fn foo() { let s = "test".to_owned(); let s = &s as *const _; - None.unwrap_or(ptr_to_ref(s)); + None.unwrap_or(ptr_to_ref(s)); //~ or_fun_call } fn bar() { let s = "test".to_owned(); let s = &s as *const _; - None.unwrap_or(unsafe { ptr_to_ref(s) }); + None.unwrap_or(unsafe { ptr_to_ref(s) }); //~ or_fun_call #[rustfmt::skip] None.unwrap_or( unsafe { ptr_to_ref(s) } ); + //~^ or_fun_call } } @@ -250,8 +257,8 @@ mod issue8993 { } fn test_map_or() { - let _ = Some(4).map_or(g(), |v| v); - let _ = Some(4).map_or(g(), f); + let _ = Some(4).map_or(g(), |v| v); //~ or_fun_call + let _ = Some(4).map_or(g(), f); //~ or_fun_call let _ = Some(4).map_or(0, f); } } @@ -282,25 +289,31 @@ mod lazy { } let with_new = Some(vec![1]); - with_new.unwrap_or_else(Vec::new); + with_new.unwrap_or_else(Vec::new); //~ unwrap_or_default let with_default_trait = Some(1); with_default_trait.unwrap_or_else(Default::default); + //~^ unwrap_or_default let with_default_type = Some(1); with_default_type.unwrap_or_else(u64::default); + //~^ unwrap_or_default let real_default = None::; real_default.unwrap_or_else(::default); + //~^ unwrap_or_default let mut map = HashMap::::new(); map.entry(42).or_insert_with(String::new); + //~^ unwrap_or_default let mut btree = BTreeMap::::new(); btree.entry(42).or_insert_with(String::new); + //~^ unwrap_or_default let stringy = Some(String::new()); let _ = stringy.unwrap_or_else(String::new); + //~^ unwrap_or_default // negative tests let self_default = None::; diff --git a/tests/ui/or_fun_call.stderr b/tests/ui/or_fun_call.stderr index afa4b7628112..74e81be42d84 100644 --- a/tests/ui/or_fun_call.stderr +++ b/tests/ui/or_fun_call.stderr @@ -23,169 +23,169 @@ LL | with_const_args.unwrap_or(Vec::with_capacity(12)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Vec::with_capacity(12))` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:61:14 + --> $DIR/or_fun_call.rs:62:14 | LL | with_err.unwrap_or(make()); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| make())` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:64:19 + --> $DIR/or_fun_call.rs:65:19 | LL | with_err_args.unwrap_or(Vec::with_capacity(12)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| Vec::with_capacity(12))` error: use of `unwrap_or` to construct default value - --> $DIR/or_fun_call.rs:67:24 + --> $DIR/or_fun_call.rs:68:24 | LL | with_default_trait.unwrap_or(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or` to construct default value - --> $DIR/or_fun_call.rs:70:23 + --> $DIR/or_fun_call.rs:72:23 | LL | with_default_type.unwrap_or(u64::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:73:18 + --> $DIR/or_fun_call.rs:76:18 | LL | self_default.unwrap_or(::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(::default)` error: use of `unwrap_or` to construct default value - --> $DIR/or_fun_call.rs:76:18 + --> $DIR/or_fun_call.rs:80:18 | LL | real_default.unwrap_or(::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or` to construct default value - --> $DIR/or_fun_call.rs:79:14 + --> $DIR/or_fun_call.rs:84:14 | LL | with_vec.unwrap_or(vec![]); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:82:21 + --> $DIR/or_fun_call.rs:87:21 | LL | without_default.unwrap_or(Foo::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(Foo::new)` error: use of `or_insert` to construct default value - --> $DIR/or_fun_call.rs:85:19 + --> $DIR/or_fun_call.rs:90:19 | LL | map.entry(42).or_insert(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert` to construct default value - --> $DIR/or_fun_call.rs:88:23 + --> $DIR/or_fun_call.rs:93:23 | LL | map_vec.entry(42).or_insert(vec![]); | ^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert` to construct default value - --> $DIR/or_fun_call.rs:91:21 + --> $DIR/or_fun_call.rs:96:21 | LL | btree.entry(42).or_insert(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert` to construct default value - --> $DIR/or_fun_call.rs:94:25 + --> $DIR/or_fun_call.rs:99:25 | LL | btree_vec.entry(42).or_insert(vec![]); | ^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `unwrap_or` to construct default value - --> $DIR/or_fun_call.rs:97:21 + --> $DIR/or_fun_call.rs:102:21 | LL | let _ = stringy.unwrap_or(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:105:21 + --> $DIR/or_fun_call.rs:110:21 | LL | let _ = Some(1).unwrap_or(map[&1]); | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| map[&1])` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:107:21 + --> $DIR/or_fun_call.rs:112:21 | LL | let _ = Some(1).unwrap_or(map[&1]); | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| map[&1])` error: use of `or` followed by a function call - --> $DIR/or_fun_call.rs:131:35 + --> $DIR/or_fun_call.rs:136:35 | LL | let _ = Some("a".to_string()).or(Some("b".to_string())); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_else(|| Some("b".to_string()))` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:170:14 + --> $DIR/or_fun_call.rs:176:14 | LL | None.unwrap_or(ptr_to_ref(s)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| ptr_to_ref(s))` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:176:14 + --> $DIR/or_fun_call.rs:182:14 | LL | None.unwrap_or(unsafe { ptr_to_ref(s) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:178:14 + --> $DIR/or_fun_call.rs:184:14 | LL | None.unwrap_or( unsafe { ptr_to_ref(s) } ); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })` error: use of `map_or` followed by a function call - --> $DIR/or_fun_call.rs:253:25 + --> $DIR/or_fun_call.rs:260:25 | LL | let _ = Some(4).map_or(g(), |v| v); | ^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(g, |v| v)` error: use of `map_or` followed by a function call - --> $DIR/or_fun_call.rs:254:25 + --> $DIR/or_fun_call.rs:261:25 | LL | let _ = Some(4).map_or(g(), f); | ^^^^^^^^^^^^^^ help: try: `map_or_else(g, f)` error: use of `unwrap_or_else` to construct default value - --> $DIR/or_fun_call.rs:285:18 + --> $DIR/or_fun_call.rs:292:18 | LL | with_new.unwrap_or_else(Vec::new); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/or_fun_call.rs:288:28 + --> $DIR/or_fun_call.rs:295:28 | LL | with_default_trait.unwrap_or_else(Default::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/or_fun_call.rs:291:27 + --> $DIR/or_fun_call.rs:299:27 | LL | with_default_type.unwrap_or_else(u64::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/or_fun_call.rs:294:22 + --> $DIR/or_fun_call.rs:303:22 | LL | real_default.unwrap_or_else(::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `or_insert_with` to construct default value - --> $DIR/or_fun_call.rs:297:23 + --> $DIR/or_fun_call.rs:307:23 | LL | map.entry(42).or_insert_with(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert_with` to construct default value - --> $DIR/or_fun_call.rs:300:25 + --> $DIR/or_fun_call.rs:311:25 | LL | btree.entry(42).or_insert_with(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/or_fun_call.rs:303:25 + --> $DIR/or_fun_call.rs:315:25 | LL | let _ = stringy.unwrap_or_else(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` diff --git a/tests/ui/or_then_unwrap.fixed b/tests/ui/or_then_unwrap.fixed index c94478614352..a10f75d8f21f 100644 --- a/tests/ui/or_then_unwrap.fixed +++ b/tests/ui/or_then_unwrap.fixed @@ -19,13 +19,16 @@ impl SomeOtherStruct { fn main() { let option: Option<&str> = None; + //~v or_then_unwrap let _ = option.unwrap_or("fallback"); // should trigger lint let result: Result<&str, &str> = Err("Error"); + //~v or_then_unwrap let _ = result.unwrap_or("fallback"); // should trigger lint // as part of a method chain let option: Option<&str> = None; + //~v or_then_unwrap let _ = option.map(|v| v).unwrap_or("fallback").to_string().chars(); // should trigger lint // Not Option/Result diff --git a/tests/ui/or_then_unwrap.rs b/tests/ui/or_then_unwrap.rs index 10e43e1d1896..9a693d71ad7f 100644 --- a/tests/ui/or_then_unwrap.rs +++ b/tests/ui/or_then_unwrap.rs @@ -19,13 +19,16 @@ impl SomeOtherStruct { fn main() { let option: Option<&str> = None; + //~v or_then_unwrap let _ = option.or(Some("fallback")).unwrap(); // should trigger lint let result: Result<&str, &str> = Err("Error"); + //~v or_then_unwrap let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint // as part of a method chain let option: Option<&str> = None; + //~v or_then_unwrap let _ = option.map(|v| v).or(Some("fallback")).unwrap().to_string().chars(); // should trigger lint // Not Option/Result diff --git a/tests/ui/or_then_unwrap.stderr b/tests/ui/or_then_unwrap.stderr index 99e4488c040d..df29614f2171 100644 --- a/tests/ui/or_then_unwrap.stderr +++ b/tests/ui/or_then_unwrap.stderr @@ -1,5 +1,5 @@ error: found `.or(Some(…)).unwrap()` - --> $DIR/or_then_unwrap.rs:22:20 + --> $DIR/or_then_unwrap.rs:23:20 | LL | let _ = option.or(Some("fallback")).unwrap(); // should trigger lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or("fallback")` @@ -8,13 +8,13 @@ LL | let _ = option.or(Some("fallback")).unwrap(); // should trigger lint = help: to override `-D warnings` add `#[allow(clippy::or_then_unwrap)]` error: found `.or(Ok(…)).unwrap()` - --> $DIR/or_then_unwrap.rs:25:20 + --> $DIR/or_then_unwrap.rs:27:20 | LL | let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or("fallback")` error: found `.or(Some(…)).unwrap()` - --> $DIR/or_then_unwrap.rs:29:31 + --> $DIR/or_then_unwrap.rs:32:31 | LL | let _ = option.map(|v| v).or(Some("fallback")).unwrap().to_string().chars(); // should trigger lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or("fallback")` diff --git a/tests/ui/partialeq_to_none.fixed b/tests/ui/partialeq_to_none.fixed index 87adbca39484..a6cb6e48ce13 100644 --- a/tests/ui/partialeq_to_none.fixed +++ b/tests/ui/partialeq_to_none.fixed @@ -11,7 +11,7 @@ impl PartialEq> for Foobar { #[allow(dead_code)] fn foo(f: Option) -> &'static str { - if f.is_some() { "yay" } else { "nay" } + if f.is_some() { "yay" } else { "nay" } //~ partialeq_to_none } fn foobar() -> Option<()> { @@ -41,19 +41,20 @@ pub fn macro_expansion() { fn main() { let x = Some(0); - let _ = x.is_none(); - let _ = x.is_some(); - let _ = x.is_none(); - let _ = x.is_some(); + let _ = x.is_none(); //~ partialeq_to_none + let _ = x.is_some(); //~ partialeq_to_none + let _ = x.is_none(); //~ partialeq_to_none + let _ = x.is_some(); //~ partialeq_to_none - if foobar().is_none() {} + if foobar().is_none() {} //~ partialeq_to_none - if bar().ok().is_some() {} + if bar().ok().is_some() {} //~ partialeq_to_none - let _ = Some(1 + 2).is_some(); + let _ = Some(1 + 2).is_some(); //~ partialeq_to_none - let _ = { Some(0) }.is_none(); + let _ = { Some(0) }.is_none(); //~ partialeq_to_none + //~v partialeq_to_none let _ = { /* This comment runs long @@ -64,11 +65,11 @@ fn main() { // Should not trigger, as `Foobar` is not an `Option` and has no `is_none` let _ = Foobar == None; - let _ = optref().is_none(); - let _ = optref().is_some(); - let _ = optref().is_none(); - let _ = optref().is_some(); + let _ = optref().is_none(); //~ partialeq_to_none + let _ = optref().is_some(); //~ partialeq_to_none + let _ = optref().is_none(); //~ partialeq_to_none + let _ = optref().is_some(); //~ partialeq_to_none let x = Box::new(Option::<()>::None); - let _ = (*x).is_some(); + let _ = (*x).is_some(); //~ partialeq_to_none } diff --git a/tests/ui/partialeq_to_none.rs b/tests/ui/partialeq_to_none.rs index b623e6a66268..3f851f037815 100644 --- a/tests/ui/partialeq_to_none.rs +++ b/tests/ui/partialeq_to_none.rs @@ -11,7 +11,7 @@ impl PartialEq> for Foobar { #[allow(dead_code)] fn foo(f: Option) -> &'static str { - if f != None { "yay" } else { "nay" } + if f != None { "yay" } else { "nay" } //~ partialeq_to_none } fn foobar() -> Option<()> { @@ -41,19 +41,20 @@ pub fn macro_expansion() { fn main() { let x = Some(0); - let _ = x == None; - let _ = x != None; - let _ = None == x; - let _ = None != x; + let _ = x == None; //~ partialeq_to_none + let _ = x != None; //~ partialeq_to_none + let _ = None == x; //~ partialeq_to_none + let _ = None != x; //~ partialeq_to_none - if foobar() == None {} + if foobar() == None {} //~ partialeq_to_none - if bar().ok() != None {} + if bar().ok() != None {} //~ partialeq_to_none - let _ = Some(1 + 2) != None; + let _ = Some(1 + 2) != None; //~ partialeq_to_none - let _ = { Some(0) } == None; + let _ = { Some(0) } == None; //~ partialeq_to_none + //~v partialeq_to_none let _ = { /* This comment runs long @@ -64,11 +65,11 @@ fn main() { // Should not trigger, as `Foobar` is not an `Option` and has no `is_none` let _ = Foobar == None; - let _ = optref() == &&None; - let _ = &&None != optref(); - let _ = **optref() == None; - let _ = &None != *optref(); + let _ = optref() == &&None; //~ partialeq_to_none + let _ = &&None != optref(); //~ partialeq_to_none + let _ = **optref() == None; //~ partialeq_to_none + let _ = &None != *optref(); //~ partialeq_to_none let x = Box::new(Option::<()>::None); - let _ = None != *x; + let _ = None != *x; //~ partialeq_to_none } diff --git a/tests/ui/partialeq_to_none.stderr b/tests/ui/partialeq_to_none.stderr index 50ce15001f40..889573f50757 100644 --- a/tests/ui/partialeq_to_none.stderr +++ b/tests/ui/partialeq_to_none.stderr @@ -56,7 +56,7 @@ LL | let _ = { Some(0) } == None; | ^^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `{ Some(0) }.is_none()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:57:13 + --> $DIR/partialeq_to_none.rs:58:13 | LL | let _ = { | _____________^ @@ -78,31 +78,31 @@ LL ~ }.is_some(); | error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:67:13 + --> $DIR/partialeq_to_none.rs:68:13 | LL | let _ = optref() == &&None; | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `optref().is_none()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:68:13 + --> $DIR/partialeq_to_none.rs:69:13 | LL | let _ = &&None != optref(); | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `optref().is_some()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:69:13 + --> $DIR/partialeq_to_none.rs:70:13 | LL | let _ = **optref() == None; | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `optref().is_none()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:70:13 + --> $DIR/partialeq_to_none.rs:71:13 | LL | let _ = &None != *optref(); | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `optref().is_some()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:73:13 + --> $DIR/partialeq_to_none.rs:74:13 | LL | let _ = None != *x; | ^^^^^^^^^^ help: use `Option::is_some()` instead: `(*x).is_some()` diff --git a/tests/ui/path_buf_push_overwrite.fixed b/tests/ui/path_buf_push_overwrite.fixed index 86e3e5bbdafd..acdb30241efe 100644 --- a/tests/ui/path_buf_push_overwrite.fixed +++ b/tests/ui/path_buf_push_overwrite.fixed @@ -3,5 +3,5 @@ use std::path::PathBuf; #[warn(clippy::all, clippy::path_buf_push_overwrite)] fn main() { let mut x = PathBuf::from("/foo"); - x.push("bar"); + x.push("bar"); //~ path_buf_push_overwrite } diff --git a/tests/ui/path_buf_push_overwrite.rs b/tests/ui/path_buf_push_overwrite.rs index 460cc254e942..fffb37f0af00 100644 --- a/tests/ui/path_buf_push_overwrite.rs +++ b/tests/ui/path_buf_push_overwrite.rs @@ -3,5 +3,5 @@ use std::path::PathBuf; #[warn(clippy::all, clippy::path_buf_push_overwrite)] fn main() { let mut x = PathBuf::from("/foo"); - x.push("/bar"); + x.push("/bar"); //~ path_buf_push_overwrite } diff --git a/tests/ui/pattern_type_mismatch/syntax.rs b/tests/ui/pattern_type_mismatch/syntax.rs index dbc7c3f31061..44e22f3bdcde 100644 --- a/tests/ui/pattern_type_mismatch/syntax.rs +++ b/tests/ui/pattern_type_mismatch/syntax.rs @@ -133,7 +133,7 @@ fn macro_expansion() { ($e:expr) => { // not ok match $e { - Some(_) => (), + Some(_) => (), //~ pattern_type_mismatch _ => (), } diff --git a/tests/ui/patterns.fixed b/tests/ui/patterns.fixed index 332cba971557..d8e52550e276 100644 --- a/tests/ui/patterns.fixed +++ b/tests/ui/patterns.fixed @@ -11,7 +11,7 @@ fn main() { let s = [0, 1, 2, 3, 4]; match v { Some(x) => (), - y => (), + y => (), //~ redundant_pattern } match v { Some(x) => (), @@ -26,6 +26,7 @@ fn main() { // required "ref" left out in suggestion: #5271 match mutv { + //~v redundant_pattern ref mut x => { x.push(4); println!("vec: {:?}", x); @@ -34,7 +35,7 @@ fn main() { } match mutv { - ref x => println!("vec: {:?}", x), + ref x => println!("vec: {:?}", x), //~ redundant_pattern ref y if y == &vec![0] => (), } external! { diff --git a/tests/ui/patterns.rs b/tests/ui/patterns.rs index 45d907688e37..1dc23e2f40db 100644 --- a/tests/ui/patterns.rs +++ b/tests/ui/patterns.rs @@ -11,7 +11,7 @@ fn main() { let s = [0, 1, 2, 3, 4]; match v { Some(x) => (), - y @ _ => (), + y @ _ => (), //~ redundant_pattern } match v { Some(x) => (), @@ -26,6 +26,7 @@ fn main() { // required "ref" left out in suggestion: #5271 match mutv { + //~v redundant_pattern ref mut x @ _ => { x.push(4); println!("vec: {:?}", x); @@ -34,7 +35,7 @@ fn main() { } match mutv { - ref x @ _ => println!("vec: {:?}", x), + ref x @ _ => println!("vec: {:?}", x), //~ redundant_pattern ref y if y == &vec![0] => (), } external! { diff --git a/tests/ui/patterns.stderr b/tests/ui/patterns.stderr index 2f608bbc18fa..d7f484aaf116 100644 --- a/tests/ui/patterns.stderr +++ b/tests/ui/patterns.stderr @@ -8,13 +8,13 @@ LL | y @ _ => (), = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern)]` error: the `x @ _` pattern can be written as just `x` - --> $DIR/patterns.rs:29:9 + --> $DIR/patterns.rs:30:9 | LL | ref mut x @ _ => { | ^^^^^^^^^^^^^ help: try: `ref mut x` error: the `x @ _` pattern can be written as just `x` - --> $DIR/patterns.rs:37:9 + --> $DIR/patterns.rs:38:9 | LL | ref x @ _ => println!("vec: {:?}", x), | ^^^^^^^^^ help: try: `ref x` diff --git a/tests/ui/precedence.fixed b/tests/ui/precedence.fixed index cc87de0d90f1..11e538b869ad 100644 --- a/tests/ui/precedence.fixed +++ b/tests/ui/precedence.fixed @@ -13,15 +13,15 @@ macro_rules! trip { } fn main() { - 1 << (2 + 3); - (1 + 2) << 3; - 4 >> (1 + 1); - (1 + 3) >> 2; - 1 ^ (1 - 1); - 3 | (2 - 1); - 3 & (5 - 2); - -(1i32.abs()); - -(1f32.abs()); + 1 << (2 + 3); //~ precedence + (1 + 2) << 3; //~ precedence + 4 >> (1 + 1); //~ precedence + (1 + 3) >> 2; //~ precedence + 1 ^ (1 - 1); //~ precedence + 3 | (2 - 1); //~ precedence + 3 & (5 - 2); //~ precedence + -(1i32.abs()); //~ precedence + -(1f32.abs()); //~ precedence // These should not trigger an error let _ = (-1i32).abs(); @@ -48,9 +48,9 @@ fn main() { let _ = -1f64.to_radians(); // Chains containing any non-odd function should trigger (issue #5924) - let _ = -(1.0_f64.cos().cos()); - let _ = -(1.0_f64.cos().sin()); - let _ = -(1.0_f64.sin().cos()); + let _ = -(1.0_f64.cos().cos()); //~ precedence + let _ = -(1.0_f64.cos().sin()); //~ precedence + let _ = -(1.0_f64.sin().cos()); //~ precedence // Chains of odd functions shouldn't trigger let _ = -1f64.sin().sin(); diff --git a/tests/ui/precedence.rs b/tests/ui/precedence.rs index 00c18d92b5fb..78d3abc69a7d 100644 --- a/tests/ui/precedence.rs +++ b/tests/ui/precedence.rs @@ -13,15 +13,15 @@ macro_rules! trip { } fn main() { - 1 << 2 + 3; - 1 + 2 << 3; - 4 >> 1 + 1; - 1 + 3 >> 2; - 1 ^ 1 - 1; - 3 | 2 - 1; - 3 & 5 - 2; - -1i32.abs(); - -1f32.abs(); + 1 << 2 + 3; //~ precedence + 1 + 2 << 3; //~ precedence + 4 >> 1 + 1; //~ precedence + 1 + 3 >> 2; //~ precedence + 1 ^ 1 - 1; //~ precedence + 3 | 2 - 1; //~ precedence + 3 & 5 - 2; //~ precedence + -1i32.abs(); //~ precedence + -1f32.abs(); //~ precedence // These should not trigger an error let _ = (-1i32).abs(); @@ -48,9 +48,9 @@ fn main() { let _ = -1f64.to_radians(); // Chains containing any non-odd function should trigger (issue #5924) - let _ = -1.0_f64.cos().cos(); - let _ = -1.0_f64.cos().sin(); - let _ = -1.0_f64.sin().cos(); + let _ = -1.0_f64.cos().cos(); //~ precedence + let _ = -1.0_f64.cos().sin(); //~ precedence + let _ = -1.0_f64.sin().cos(); //~ precedence // Chains of odd functions shouldn't trigger let _ = -1f64.sin().sin(); diff --git a/tests/ui/print_literal.fixed b/tests/ui/print_literal.fixed index a7157c07f8a9..14f7f3f14311 100644 --- a/tests/ui/print_literal.fixed +++ b/tests/ui/print_literal.fixed @@ -54,15 +54,16 @@ fn main() { // Braces in unicode escapes should not be escaped println!("{{}} \x00 \u{ab123} \\\u{ab123} {{:?}}"); - println!("\\\u{1234}"); + //~^ print_literal + println!("\\\u{1234}"); //~ print_literal // This does not lint because it would have to suggest unescaping the character println!(r"{}", "\u{ab123}"); // These are not unicode escapes - println!("\\u{{ab123}} \\u{{{{"); - println!(r"\u{{ab123}} \u{{{{"); - println!("\\{{ab123}} \\u{{{{"); - println!("\\u{{ab123}}"); - println!("\\\\u{{1234}}"); + println!("\\u{{ab123}} \\u{{{{"); //~ print_literal + println!(r"\u{{ab123}} \u{{{{"); //~ print_literal + println!("\\{{ab123}} \\u{{{{"); //~ print_literal + println!("\\u{{ab123}}"); //~ print_literal + println!("\\\\u{{1234}}"); //~ print_literal - println!("mixed: {{hello}} {world}"); + println!("mixed: {{hello}} {world}"); //~ print_literal } diff --git a/tests/ui/print_literal.rs b/tests/ui/print_literal.rs index 4b04b42744cc..8979af48e650 100644 --- a/tests/ui/print_literal.rs +++ b/tests/ui/print_literal.rs @@ -54,15 +54,16 @@ fn main() { // Braces in unicode escapes should not be escaped println!("{}", "{} \x00 \u{ab123} \\\u{ab123} {:?}"); - println!("{}", "\\\u{1234}"); + //~^ print_literal + println!("{}", "\\\u{1234}"); //~ print_literal // This does not lint because it would have to suggest unescaping the character println!(r"{}", "\u{ab123}"); // These are not unicode escapes - println!("{}", r"\u{ab123} \u{{"); - println!(r"{}", r"\u{ab123} \u{{"); - println!("{}", r"\{ab123} \u{{"); - println!("{}", "\\u{ab123}"); - println!("{}", "\\\\u{1234}"); + println!("{}", r"\u{ab123} \u{{"); //~ print_literal + println!(r"{}", r"\u{ab123} \u{{"); //~ print_literal + println!("{}", r"\{ab123} \u{{"); //~ print_literal + println!("{}", "\\u{ab123}"); //~ print_literal + println!("{}", "\\\\u{1234}"); //~ print_literal - println!("mixed: {} {world}", "{hello}"); + println!("mixed: {} {world}", "{hello}"); //~ print_literal } diff --git a/tests/ui/print_literal.stderr b/tests/ui/print_literal.stderr index 8c011d7bc0a6..90afaad20556 100644 --- a/tests/ui/print_literal.stderr +++ b/tests/ui/print_literal.stderr @@ -109,7 +109,7 @@ LL + println!("{{}} \x00 \u{ab123} \\\u{ab123} {{:?}}"); | error: literal with an empty format string - --> $DIR/print_literal.rs:57:20 + --> $DIR/print_literal.rs:58:20 | LL | println!("{}", "\\\u{1234}"); | ^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + println!("\\\u{1234}"); | error: literal with an empty format string - --> $DIR/print_literal.rs:61:20 + --> $DIR/print_literal.rs:62:20 | LL | println!("{}", r"\u{ab123} \u{{"); | ^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + println!("\\u{{ab123}} \\u{{{{"); | error: literal with an empty format string - --> $DIR/print_literal.rs:62:21 + --> $DIR/print_literal.rs:63:21 | LL | println!(r"{}", r"\u{ab123} \u{{"); | ^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + println!(r"\u{{ab123}} \u{{{{"); | error: literal with an empty format string - --> $DIR/print_literal.rs:63:20 + --> $DIR/print_literal.rs:64:20 | LL | println!("{}", r"\{ab123} \u{{"); | ^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + println!("\\{{ab123}} \\u{{{{"); | error: literal with an empty format string - --> $DIR/print_literal.rs:64:20 + --> $DIR/print_literal.rs:65:20 | LL | println!("{}", "\\u{ab123}"); | ^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + println!("\\u{{ab123}}"); | error: literal with an empty format string - --> $DIR/print_literal.rs:65:20 + --> $DIR/print_literal.rs:66:20 | LL | println!("{}", "\\\\u{1234}"); | ^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + println!("\\\\u{{1234}}"); | error: literal with an empty format string - --> $DIR/print_literal.rs:67:35 + --> $DIR/print_literal.rs:68:35 | LL | println!("mixed: {} {world}", "{hello}"); | ^^^^^^^^^ diff --git a/tests/ui/println_empty_string.fixed b/tests/ui/println_empty_string.fixed index 20811fc75323..d34320bb22d3 100644 --- a/tests/ui/println_empty_string.fixed +++ b/tests/ui/println_empty_string.fixed @@ -2,16 +2,16 @@ fn main() { println!(); - println!(); + println!(); //~ println_empty_string match "a" { - _ => println!(), + _ => println!(), //~ println_empty_string } eprintln!(); - eprintln!(); + eprintln!(); //~ println_empty_string match "a" { - _ => eprintln!(), + _ => eprintln!(), //~ println_empty_string } } diff --git a/tests/ui/println_empty_string.rs b/tests/ui/println_empty_string.rs index 47f7277dce79..f132faefb3a9 100644 --- a/tests/ui/println_empty_string.rs +++ b/tests/ui/println_empty_string.rs @@ -2,16 +2,16 @@ fn main() { println!(); - println!(""); + println!(""); //~ println_empty_string match "a" { - _ => println!(""), + _ => println!(""), //~ println_empty_string } eprintln!(); - eprintln!(""); + eprintln!(""); //~ println_empty_string match "a" { - _ => eprintln!(""), + _ => eprintln!(""), //~ println_empty_string } } diff --git a/tests/ui/ptr_as_ptr.fixed b/tests/ui/ptr_as_ptr.fixed index fa15c323540f..61a5e5e8cf0a 100644 --- a/tests/ui/ptr_as_ptr.fixed +++ b/tests/ui/ptr_as_ptr.fixed @@ -16,6 +16,7 @@ mod issue_11278_b { pub fn f(o: &mut super::issue_11278_a::T) -> super::issue_11278_a::T { // Retain `super` *unsafe { Box::from_raw(Box::into_raw(Box::new(o)).cast::>()) } + //~^ ptr_as_ptr } } @@ -24,13 +25,13 @@ fn main() { let ptr: *const u32 = &42_u32; let mut_ptr: *mut u32 = &mut 42_u32; - let _ = ptr.cast::(); - let _ = mut_ptr.cast::(); + let _ = ptr.cast::(); //~ ptr_as_ptr + let _ = mut_ptr.cast::(); //~ ptr_as_ptr // Make sure the lint can handle the difference in their operator precedences. unsafe { let ptr_ptr: *const *const u32 = &ptr; - let _ = (*ptr_ptr).cast::(); + let _ = (*ptr_ptr).cast::(); //~ ptr_as_ptr } // Changes in mutability. Do not lint this. @@ -43,11 +44,11 @@ fn main() { let _ = ptr_of_array as *const dyn std::fmt::Debug; // Ensure the lint doesn't produce unnecessary turbofish for inferred types. - let _: *const i32 = ptr.cast(); - let _: *mut i32 = mut_ptr.cast(); + let _: *const i32 = ptr.cast(); //~ ptr_as_ptr + let _: *mut i32 = mut_ptr.cast(); //~ ptr_as_ptr // Make sure the lint is triggered inside a macro - let _ = inline!($ptr.cast::()); + let _ = inline!($ptr.cast::()); //~ ptr_as_ptr // Do not lint inside macros from external crates let _ = external!($ptr as *const i32); @@ -68,121 +69,121 @@ fn _msrv_1_38() { let ptr: *const u32 = &42_u32; let mut_ptr: *mut u32 = &mut 42_u32; - let _ = ptr.cast::(); - let _ = mut_ptr.cast::(); + let _ = ptr.cast::(); //~ ptr_as_ptr + let _ = mut_ptr.cast::(); //~ ptr_as_ptr } #[allow(clippy::unnecessary_cast)] mod null { fn use_path_mut() -> *mut u32 { use std::ptr; - ptr::null_mut::() + ptr::null_mut::() //~ ptr_as_ptr } fn full_path_mut() -> *mut u32 { - std::ptr::null_mut::() + std::ptr::null_mut::() //~ ptr_as_ptr } fn core_path_mut() -> *mut u32 { use core::ptr; - ptr::null_mut::() + ptr::null_mut::() //~ ptr_as_ptr } fn full_core_path_mut() -> *mut u32 { - core::ptr::null_mut::() + core::ptr::null_mut::() //~ ptr_as_ptr } fn use_path() -> *const u32 { use std::ptr; - ptr::null::() + ptr::null::() //~ ptr_as_ptr } fn full_path() -> *const u32 { - std::ptr::null::() + std::ptr::null::() //~ ptr_as_ptr } fn core_path() -> *const u32 { use core::ptr; - ptr::null::() + ptr::null::() //~ ptr_as_ptr } fn full_core_path() -> *const u32 { - core::ptr::null::() + core::ptr::null::() //~ ptr_as_ptr } } mod null_ptr_infer { fn use_path_mut() -> *mut u32 { use std::ptr; - ptr::null_mut() + ptr::null_mut() //~ ptr_as_ptr } fn full_path_mut() -> *mut u32 { - std::ptr::null_mut() + std::ptr::null_mut() //~ ptr_as_ptr } fn core_path_mut() -> *mut u32 { use core::ptr; - ptr::null_mut() + ptr::null_mut() //~ ptr_as_ptr } fn full_core_path_mut() -> *mut u32 { - core::ptr::null_mut() + core::ptr::null_mut() //~ ptr_as_ptr } fn use_path() -> *const u32 { use std::ptr; - ptr::null() + ptr::null() //~ ptr_as_ptr } fn full_path() -> *const u32 { - std::ptr::null() + std::ptr::null() //~ ptr_as_ptr } fn core_path() -> *const u32 { use core::ptr; - ptr::null() + ptr::null() //~ ptr_as_ptr } fn full_core_path() -> *const u32 { - core::ptr::null() + core::ptr::null() //~ ptr_as_ptr } } mod null_entire_infer { fn use_path_mut() -> *mut u32 { use std::ptr; - ptr::null_mut() + ptr::null_mut() //~ ptr_as_ptr } fn full_path_mut() -> *mut u32 { - std::ptr::null_mut() + std::ptr::null_mut() //~ ptr_as_ptr } fn core_path_mut() -> *mut u32 { use core::ptr; - ptr::null_mut() + ptr::null_mut() //~ ptr_as_ptr } fn full_core_path_mut() -> *mut u32 { - core::ptr::null_mut() + core::ptr::null_mut() //~ ptr_as_ptr } fn use_path() -> *const u32 { use std::ptr; - ptr::null() + ptr::null() //~ ptr_as_ptr } fn full_path() -> *const u32 { - std::ptr::null() + std::ptr::null() //~ ptr_as_ptr } fn core_path() -> *const u32 { use core::ptr; - ptr::null() + ptr::null() //~ ptr_as_ptr } fn full_core_path() -> *const u32 { - core::ptr::null() + core::ptr::null() //~ ptr_as_ptr } } diff --git a/tests/ui/ptr_as_ptr.rs b/tests/ui/ptr_as_ptr.rs index 7ab52e63da55..4d1b2627dc29 100644 --- a/tests/ui/ptr_as_ptr.rs +++ b/tests/ui/ptr_as_ptr.rs @@ -16,6 +16,7 @@ mod issue_11278_b { pub fn f(o: &mut super::issue_11278_a::T) -> super::issue_11278_a::T { // Retain `super` *unsafe { Box::from_raw(Box::into_raw(Box::new(o)) as *mut super::issue_11278_a::T) } + //~^ ptr_as_ptr } } @@ -24,13 +25,13 @@ fn main() { let ptr: *const u32 = &42_u32; let mut_ptr: *mut u32 = &mut 42_u32; - let _ = ptr as *const i32; - let _ = mut_ptr as *mut i32; + let _ = ptr as *const i32; //~ ptr_as_ptr + let _ = mut_ptr as *mut i32; //~ ptr_as_ptr // Make sure the lint can handle the difference in their operator precedences. unsafe { let ptr_ptr: *const *const u32 = &ptr; - let _ = *ptr_ptr as *const i32; + let _ = *ptr_ptr as *const i32; //~ ptr_as_ptr } // Changes in mutability. Do not lint this. @@ -43,11 +44,11 @@ fn main() { let _ = ptr_of_array as *const dyn std::fmt::Debug; // Ensure the lint doesn't produce unnecessary turbofish for inferred types. - let _: *const i32 = ptr as *const _; - let _: *mut i32 = mut_ptr as _; + let _: *const i32 = ptr as *const _; //~ ptr_as_ptr + let _: *mut i32 = mut_ptr as _; //~ ptr_as_ptr // Make sure the lint is triggered inside a macro - let _ = inline!($ptr as *const i32); + let _ = inline!($ptr as *const i32); //~ ptr_as_ptr // Do not lint inside macros from external crates let _ = external!($ptr as *const i32); @@ -68,121 +69,121 @@ fn _msrv_1_38() { let ptr: *const u32 = &42_u32; let mut_ptr: *mut u32 = &mut 42_u32; - let _ = ptr as *const i32; - let _ = mut_ptr as *mut i32; + let _ = ptr as *const i32; //~ ptr_as_ptr + let _ = mut_ptr as *mut i32; //~ ptr_as_ptr } #[allow(clippy::unnecessary_cast)] mod null { fn use_path_mut() -> *mut u32 { use std::ptr; - ptr::null_mut() as *mut u32 + ptr::null_mut() as *mut u32 //~ ptr_as_ptr } fn full_path_mut() -> *mut u32 { - std::ptr::null_mut() as *mut u32 + std::ptr::null_mut() as *mut u32 //~ ptr_as_ptr } fn core_path_mut() -> *mut u32 { use core::ptr; - ptr::null_mut() as *mut u32 + ptr::null_mut() as *mut u32 //~ ptr_as_ptr } fn full_core_path_mut() -> *mut u32 { - core::ptr::null_mut() as *mut u32 + core::ptr::null_mut() as *mut u32 //~ ptr_as_ptr } fn use_path() -> *const u32 { use std::ptr; - ptr::null() as *const u32 + ptr::null() as *const u32 //~ ptr_as_ptr } fn full_path() -> *const u32 { - std::ptr::null() as *const u32 + std::ptr::null() as *const u32 //~ ptr_as_ptr } fn core_path() -> *const u32 { use core::ptr; - ptr::null() as *const u32 + ptr::null() as *const u32 //~ ptr_as_ptr } fn full_core_path() -> *const u32 { - core::ptr::null() as *const u32 + core::ptr::null() as *const u32 //~ ptr_as_ptr } } mod null_ptr_infer { fn use_path_mut() -> *mut u32 { use std::ptr; - ptr::null_mut() as *mut _ + ptr::null_mut() as *mut _ //~ ptr_as_ptr } fn full_path_mut() -> *mut u32 { - std::ptr::null_mut() as *mut _ + std::ptr::null_mut() as *mut _ //~ ptr_as_ptr } fn core_path_mut() -> *mut u32 { use core::ptr; - ptr::null_mut() as *mut _ + ptr::null_mut() as *mut _ //~ ptr_as_ptr } fn full_core_path_mut() -> *mut u32 { - core::ptr::null_mut() as *mut _ + core::ptr::null_mut() as *mut _ //~ ptr_as_ptr } fn use_path() -> *const u32 { use std::ptr; - ptr::null() as *const _ + ptr::null() as *const _ //~ ptr_as_ptr } fn full_path() -> *const u32 { - std::ptr::null() as *const _ + std::ptr::null() as *const _ //~ ptr_as_ptr } fn core_path() -> *const u32 { use core::ptr; - ptr::null() as *const _ + ptr::null() as *const _ //~ ptr_as_ptr } fn full_core_path() -> *const u32 { - core::ptr::null() as *const _ + core::ptr::null() as *const _ //~ ptr_as_ptr } } mod null_entire_infer { fn use_path_mut() -> *mut u32 { use std::ptr; - ptr::null_mut() as _ + ptr::null_mut() as _ //~ ptr_as_ptr } fn full_path_mut() -> *mut u32 { - std::ptr::null_mut() as _ + std::ptr::null_mut() as _ //~ ptr_as_ptr } fn core_path_mut() -> *mut u32 { use core::ptr; - ptr::null_mut() as _ + ptr::null_mut() as _ //~ ptr_as_ptr } fn full_core_path_mut() -> *mut u32 { - core::ptr::null_mut() as _ + core::ptr::null_mut() as _ //~ ptr_as_ptr } fn use_path() -> *const u32 { use std::ptr; - ptr::null() as _ + ptr::null() as _ //~ ptr_as_ptr } fn full_path() -> *const u32 { - std::ptr::null() as _ + std::ptr::null() as _ //~ ptr_as_ptr } fn core_path() -> *const u32 { use core::ptr; - ptr::null() as _ + ptr::null() as _ //~ ptr_as_ptr } fn full_core_path() -> *const u32 { - core::ptr::null() as _ + core::ptr::null() as _ //~ ptr_as_ptr } } diff --git a/tests/ui/ptr_as_ptr.stderr b/tests/ui/ptr_as_ptr.stderr index ef64347e9350..4b99332438ad 100644 --- a/tests/ui/ptr_as_ptr.stderr +++ b/tests/ui/ptr_as_ptr.stderr @@ -8,37 +8,37 @@ LL | *unsafe { Box::from_raw(Box::into_raw(Box::new(o)) as *mut super::i = help: to override `-D warnings` add `#[allow(clippy::ptr_as_ptr)]` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:27:13 + --> $DIR/ptr_as_ptr.rs:28:13 | LL | let _ = ptr as *const i32; | ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:28:13 + --> $DIR/ptr_as_ptr.rs:29:13 | LL | let _ = mut_ptr as *mut i32; | ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:33:17 + --> $DIR/ptr_as_ptr.rs:34:17 | LL | let _ = *ptr_ptr as *const i32; | ^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `(*ptr_ptr).cast::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:46:25 + --> $DIR/ptr_as_ptr.rs:47:25 | LL | let _: *const i32 = ptr as *const _; | ^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:47:23 + --> $DIR/ptr_as_ptr.rs:48:23 | LL | let _: *mut i32 = mut_ptr as _; | ^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:50:21 + --> $DIR/ptr_as_ptr.rs:51:21 | LL | let _ = inline!($ptr as *const i32); | ^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `$ptr.cast::()` @@ -46,157 +46,157 @@ LL | let _ = inline!($ptr as *const i32); = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:71:13 + --> $DIR/ptr_as_ptr.rs:72:13 | LL | let _ = ptr as *const i32; | ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:72:13 + --> $DIR/ptr_as_ptr.rs:73:13 | LL | let _ = mut_ptr as *mut i32; | ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:79:9 + --> $DIR/ptr_as_ptr.rs:80:9 | LL | ptr::null_mut() as *mut u32 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:83:9 + --> $DIR/ptr_as_ptr.rs:84:9 | LL | std::ptr::null_mut() as *mut u32 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null_mut::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:88:9 + --> $DIR/ptr_as_ptr.rs:89:9 | LL | ptr::null_mut() as *mut u32 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:92:9 + --> $DIR/ptr_as_ptr.rs:93:9 | LL | core::ptr::null_mut() as *mut u32 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null_mut::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:97:9 + --> $DIR/ptr_as_ptr.rs:98:9 | LL | ptr::null() as *const u32 | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:101:9 + --> $DIR/ptr_as_ptr.rs:102:9 | LL | std::ptr::null() as *const u32 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:106:9 + --> $DIR/ptr_as_ptr.rs:107:9 | LL | ptr::null() as *const u32 | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:110:9 + --> $DIR/ptr_as_ptr.rs:111:9 | LL | core::ptr::null() as *const u32 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:117:9 + --> $DIR/ptr_as_ptr.rs:118:9 | LL | ptr::null_mut() as *mut _ | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:121:9 + --> $DIR/ptr_as_ptr.rs:122:9 | LL | std::ptr::null_mut() as *mut _ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null_mut()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:126:9 + --> $DIR/ptr_as_ptr.rs:127:9 | LL | ptr::null_mut() as *mut _ | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:130:9 + --> $DIR/ptr_as_ptr.rs:131:9 | LL | core::ptr::null_mut() as *mut _ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null_mut()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:135:9 + --> $DIR/ptr_as_ptr.rs:136:9 | LL | ptr::null() as *const _ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:139:9 + --> $DIR/ptr_as_ptr.rs:140:9 | LL | std::ptr::null() as *const _ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:144:9 + --> $DIR/ptr_as_ptr.rs:145:9 | LL | ptr::null() as *const _ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:148:9 + --> $DIR/ptr_as_ptr.rs:149:9 | LL | core::ptr::null() as *const _ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:155:9 + --> $DIR/ptr_as_ptr.rs:156:9 | LL | ptr::null_mut() as _ | ^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:159:9 + --> $DIR/ptr_as_ptr.rs:160:9 | LL | std::ptr::null_mut() as _ | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null_mut()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:164:9 + --> $DIR/ptr_as_ptr.rs:165:9 | LL | ptr::null_mut() as _ | ^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:168:9 + --> $DIR/ptr_as_ptr.rs:169:9 | LL | core::ptr::null_mut() as _ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null_mut()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:173:9 + --> $DIR/ptr_as_ptr.rs:174:9 | LL | ptr::null() as _ | ^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:177:9 + --> $DIR/ptr_as_ptr.rs:178:9 | LL | std::ptr::null() as _ | ^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:182:9 + --> $DIR/ptr_as_ptr.rs:183:9 | LL | ptr::null() as _ | ^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:186:9 + --> $DIR/ptr_as_ptr.rs:187:9 | LL | core::ptr::null() as _ | ^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null()` diff --git a/tests/ui/ptr_cast_constness.fixed b/tests/ui/ptr_cast_constness.fixed index c410a660dc42..36894770e42a 100644 --- a/tests/ui/ptr_cast_constness.fixed +++ b/tests/ui/ptr_cast_constness.fixed @@ -8,7 +8,8 @@ use proc_macros::{external, inline_macros}; unsafe fn ptr_to_ref(p: *const T, om: *mut U) { let _: &mut T = std::mem::transmute(p.cast_mut()); - let _ = &mut *p.cast_mut(); + //~^ ptr_cast_constness + let _ = &mut *p.cast_mut(); //~ ptr_cast_constness let _: &T = &*(om as *const T); } @@ -23,11 +24,11 @@ fn main() { // Make sure the lint can handle the difference in their operator precedences. unsafe { let ptr_ptr: *const *const u32 = &ptr; - let _ = (*ptr_ptr).cast_mut(); + let _ = (*ptr_ptr).cast_mut(); //~ ptr_cast_constness } - let _ = ptr.cast_mut(); - let _ = mut_ptr.cast_const(); + let _ = ptr.cast_mut(); //~ ptr_cast_constness + let _ = mut_ptr.cast_const(); //~ ptr_cast_constness // Lint this, since pointer::cast_mut and pointer::cast_const have ?Sized let ptr_of_array: *const [u32; 4] = &[1, 2, 3, 4]; @@ -56,6 +57,6 @@ fn _msrv_1_65() { let ptr: *const u32 = &42_u32; let mut_ptr: *mut u32 = &mut 42_u32; - let _ = ptr.cast_mut(); - let _ = mut_ptr.cast_const(); + let _ = ptr.cast_mut(); //~ ptr_cast_constness + let _ = mut_ptr.cast_const(); //~ ptr_cast_constness } diff --git a/tests/ui/ptr_cast_constness.rs b/tests/ui/ptr_cast_constness.rs index 6025b857b8f4..1e4da34a17a5 100644 --- a/tests/ui/ptr_cast_constness.rs +++ b/tests/ui/ptr_cast_constness.rs @@ -8,7 +8,8 @@ use proc_macros::{external, inline_macros}; unsafe fn ptr_to_ref(p: *const T, om: *mut U) { let _: &mut T = std::mem::transmute(p as *mut T); - let _ = &mut *(p as *mut T); + //~^ ptr_cast_constness + let _ = &mut *(p as *mut T); //~ ptr_cast_constness let _: &T = &*(om as *const T); } @@ -23,11 +24,11 @@ fn main() { // Make sure the lint can handle the difference in their operator precedences. unsafe { let ptr_ptr: *const *const u32 = &ptr; - let _ = *ptr_ptr as *mut u32; + let _ = *ptr_ptr as *mut u32; //~ ptr_cast_constness } - let _ = ptr as *mut u32; - let _ = mut_ptr as *const u32; + let _ = ptr as *mut u32; //~ ptr_cast_constness + let _ = mut_ptr as *const u32; //~ ptr_cast_constness // Lint this, since pointer::cast_mut and pointer::cast_const have ?Sized let ptr_of_array: *const [u32; 4] = &[1, 2, 3, 4]; @@ -56,6 +57,6 @@ fn _msrv_1_65() { let ptr: *const u32 = &42_u32; let mut_ptr: *mut u32 = &mut 42_u32; - let _ = ptr as *mut u32; - let _ = mut_ptr as *const u32; + let _ = ptr as *mut u32; //~ ptr_cast_constness + let _ = mut_ptr as *const u32; //~ ptr_cast_constness } diff --git a/tests/ui/ptr_cast_constness.stderr b/tests/ui/ptr_cast_constness.stderr index a4bf778ad19d..d6f6b301a496 100644 --- a/tests/ui/ptr_cast_constness.stderr +++ b/tests/ui/ptr_cast_constness.stderr @@ -8,37 +8,37 @@ LL | let _: &mut T = std::mem::transmute(p as *mut T); = help: to override `-D warnings` add `#[allow(clippy::ptr_cast_constness)]` error: `as` casting between raw pointers while changing only its constness - --> $DIR/ptr_cast_constness.rs:11:19 + --> $DIR/ptr_cast_constness.rs:12:19 | LL | let _ = &mut *(p as *mut T); | ^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `p.cast_mut()` error: `as` casting between raw pointers while changing only its constness - --> $DIR/ptr_cast_constness.rs:26:17 + --> $DIR/ptr_cast_constness.rs:27:17 | LL | let _ = *ptr_ptr as *mut u32; | ^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `(*ptr_ptr).cast_mut()` error: `as` casting between raw pointers while changing only its constness - --> $DIR/ptr_cast_constness.rs:29:13 + --> $DIR/ptr_cast_constness.rs:30:13 | LL | let _ = ptr as *mut u32; | ^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `ptr.cast_mut()` error: `as` casting between raw pointers while changing only its constness - --> $DIR/ptr_cast_constness.rs:30:13 + --> $DIR/ptr_cast_constness.rs:31:13 | LL | let _ = mut_ptr as *const u32; | ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()` error: `as` casting between raw pointers while changing only its constness - --> $DIR/ptr_cast_constness.rs:59:13 + --> $DIR/ptr_cast_constness.rs:60:13 | LL | let _ = ptr as *mut u32; | ^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `ptr.cast_mut()` error: `as` casting between raw pointers while changing only its constness - --> $DIR/ptr_cast_constness.rs:60:13 + --> $DIR/ptr_cast_constness.rs:61:13 | LL | let _ = mut_ptr as *const u32; | ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()` diff --git a/tests/ui/ptr_eq.fixed b/tests/ui/ptr_eq.fixed index 3ae6df18c0a0..39939a102d17 100644 --- a/tests/ui/ptr_eq.fixed +++ b/tests/ui/ptr_eq.fixed @@ -17,7 +17,8 @@ fn main() { let b = &[1, 2, 3]; let _ = std::ptr::eq(a, b); - let _ = std::ptr::eq(a, b); + //~^ ptr_eq + let _ = std::ptr::eq(a, b); //~ ptr_eq let _ = a.as_ptr() == b as *const _; let _ = a.as_ptr() == b.as_ptr(); diff --git a/tests/ui/ptr_eq.rs b/tests/ui/ptr_eq.rs index 440d5d94a831..3cfe329da849 100644 --- a/tests/ui/ptr_eq.rs +++ b/tests/ui/ptr_eq.rs @@ -17,7 +17,8 @@ fn main() { let b = &[1, 2, 3]; let _ = a as *const _ as usize == b as *const _ as usize; - let _ = a as *const _ == b as *const _; + //~^ ptr_eq + let _ = a as *const _ == b as *const _; //~ ptr_eq let _ = a.as_ptr() == b as *const _; let _ = a.as_ptr() == b.as_ptr(); diff --git a/tests/ui/ptr_eq.stderr b/tests/ui/ptr_eq.stderr index 2a384accac57..69b4953bad55 100644 --- a/tests/ui/ptr_eq.stderr +++ b/tests/ui/ptr_eq.stderr @@ -8,7 +8,7 @@ LL | let _ = a as *const _ as usize == b as *const _ as usize; = help: to override `-D warnings` add `#[allow(clippy::ptr_eq)]` error: use `std::ptr::eq` when comparing raw pointers - --> $DIR/ptr_eq.rs:20:13 + --> $DIR/ptr_eq.rs:21:13 | LL | let _ = a as *const _ == b as *const _; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(a, b)` diff --git a/tests/ui/ptr_eq_no_std.fixed b/tests/ui/ptr_eq_no_std.fixed index 97c8c394c03d..cca985eeb04d 100644 --- a/tests/ui/ptr_eq_no_std.fixed +++ b/tests/ui/ptr_eq_no_std.fixed @@ -29,7 +29,8 @@ fn main() { let b = &[1, 2, 3]; let _ = core::ptr::eq(a, b); - let _ = core::ptr::eq(a, b); + //~^ ptr_eq + let _ = core::ptr::eq(a, b); //~ ptr_eq let _ = a.as_ptr() == b as *const _; let _ = a.as_ptr() == b.as_ptr(); diff --git a/tests/ui/ptr_eq_no_std.rs b/tests/ui/ptr_eq_no_std.rs index a7ba9b4d8174..b63fca16715a 100644 --- a/tests/ui/ptr_eq_no_std.rs +++ b/tests/ui/ptr_eq_no_std.rs @@ -29,7 +29,8 @@ fn main() { let b = &[1, 2, 3]; let _ = a as *const _ as usize == b as *const _ as usize; - let _ = a as *const _ == b as *const _; + //~^ ptr_eq + let _ = a as *const _ == b as *const _; //~ ptr_eq let _ = a.as_ptr() == b as *const _; let _ = a.as_ptr() == b.as_ptr(); diff --git a/tests/ui/ptr_eq_no_std.stderr b/tests/ui/ptr_eq_no_std.stderr index 3e289f5be613..c1dd8b66c89f 100644 --- a/tests/ui/ptr_eq_no_std.stderr +++ b/tests/ui/ptr_eq_no_std.stderr @@ -8,7 +8,7 @@ LL | let _ = a as *const _ as usize == b as *const _ as usize; = help: to override `-D warnings` add `#[allow(clippy::ptr_eq)]` error: use `core::ptr::eq` when comparing raw pointers - --> $DIR/ptr_eq_no_std.rs:32:13 + --> $DIR/ptr_eq_no_std.rs:33:13 | LL | let _ = a as *const _ == b as *const _; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `core::ptr::eq(a, b)` diff --git a/tests/ui/ptr_offset_with_cast.fixed b/tests/ui/ptr_offset_with_cast.fixed index 929512be63d4..4fe9dcf46c35 100644 --- a/tests/ui/ptr_offset_with_cast.fixed +++ b/tests/ui/ptr_offset_with_cast.fixed @@ -10,10 +10,12 @@ fn main() { unsafe { let _ = ptr.add(offset_usize); + //~^ ptr_offset_with_cast let _ = ptr.offset(offset_isize as isize); let _ = ptr.offset(offset_u8 as isize); let _ = ptr.wrapping_add(offset_usize); + //~^ ptr_offset_with_cast let _ = ptr.wrapping_offset(offset_isize as isize); let _ = ptr.wrapping_offset(offset_u8 as isize); } diff --git a/tests/ui/ptr_offset_with_cast.rs b/tests/ui/ptr_offset_with_cast.rs index 146bc27765ad..a1fb892733d3 100644 --- a/tests/ui/ptr_offset_with_cast.rs +++ b/tests/ui/ptr_offset_with_cast.rs @@ -10,10 +10,12 @@ fn main() { unsafe { let _ = ptr.offset(offset_usize as isize); + //~^ ptr_offset_with_cast let _ = ptr.offset(offset_isize as isize); let _ = ptr.offset(offset_u8 as isize); let _ = ptr.wrapping_offset(offset_usize as isize); + //~^ ptr_offset_with_cast let _ = ptr.wrapping_offset(offset_isize as isize); let _ = ptr.wrapping_offset(offset_u8 as isize); } diff --git a/tests/ui/ptr_offset_with_cast.stderr b/tests/ui/ptr_offset_with_cast.stderr index e99053846795..ecbfc39a9983 100644 --- a/tests/ui/ptr_offset_with_cast.stderr +++ b/tests/ui/ptr_offset_with_cast.stderr @@ -8,7 +8,7 @@ LL | let _ = ptr.offset(offset_usize as isize); = help: to override `-D warnings` add `#[allow(clippy::ptr_offset_with_cast)]` error: use of `wrapping_offset` with a `usize` casted to an `isize` - --> $DIR/ptr_offset_with_cast.rs:16:17 + --> $DIR/ptr_offset_with_cast.rs:17:17 | LL | let _ = ptr.wrapping_offset(offset_usize as isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.wrapping_add(offset_usize)` diff --git a/tests/ui/pub_with_shorthand.fixed b/tests/ui/pub_with_shorthand.fixed index 028209de0666..f001a22c289c 100644 --- a/tests/ui/pub_with_shorthand.fixed +++ b/tests/ui/pub_with_shorthand.fixed @@ -10,15 +10,15 @@ #[macro_use] extern crate proc_macros; -pub(in self) fn a() {} +pub(in self) fn a() {} //~ pub_with_shorthand pub(in self) fn b() {} pub fn c() {} mod a { pub(in super) fn d() {} - pub(in super) fn e() {} - pub(in self) fn f() {} - pub(in crate) fn k() {} + pub(in super) fn e() {} //~ pub_with_shorthand + pub(in self) fn f() {} //~ pub_with_shorthand + pub(in crate) fn k() {} //~ pub_with_shorthand pub(in crate) fn m() {} mod b { pub(in crate::a) fn l() {} diff --git a/tests/ui/pub_with_shorthand.rs b/tests/ui/pub_with_shorthand.rs index 8578e3e0c434..a446a7c260be 100644 --- a/tests/ui/pub_with_shorthand.rs +++ b/tests/ui/pub_with_shorthand.rs @@ -10,15 +10,15 @@ #[macro_use] extern crate proc_macros; -pub(self) fn a() {} +pub(self) fn a() {} //~ pub_with_shorthand pub(in self) fn b() {} pub fn c() {} mod a { pub(in super) fn d() {} - pub(super) fn e() {} - pub(self) fn f() {} - pub(crate) fn k() {} + pub(super) fn e() {} //~ pub_with_shorthand + pub(self) fn f() {} //~ pub_with_shorthand + pub(crate) fn k() {} //~ pub_with_shorthand pub(in crate) fn m() {} mod b { pub(in crate::a) fn l() {} diff --git a/tests/ui/pub_without_shorthand.fixed b/tests/ui/pub_without_shorthand.fixed index 715e86c17645..4b3732bf137f 100644 --- a/tests/ui/pub_without_shorthand.fixed +++ b/tests/ui/pub_without_shorthand.fixed @@ -11,15 +11,15 @@ extern crate proc_macros; pub(self) fn a() {} -pub(self) fn b() {} +pub(self) fn b() {} //~ pub_without_shorthand pub fn c() {} mod a { - pub(super) fn d() {} + pub(super) fn d() {} //~ pub_without_shorthand pub(super) fn e() {} pub(self) fn f() {} pub(crate) fn k() {} - pub(crate) fn m() {} + pub(crate) fn m() {} //~ pub_without_shorthand mod b { pub(in crate::a) fn l() {} } diff --git a/tests/ui/pub_without_shorthand.rs b/tests/ui/pub_without_shorthand.rs index ed2fd6f0f617..a930385958a8 100644 --- a/tests/ui/pub_without_shorthand.rs +++ b/tests/ui/pub_without_shorthand.rs @@ -11,15 +11,15 @@ extern crate proc_macros; pub(self) fn a() {} -pub(in self) fn b() {} +pub(in self) fn b() {} //~ pub_without_shorthand pub fn c() {} mod a { - pub(in super) fn d() {} + pub(in super) fn d() {} //~ pub_without_shorthand pub(super) fn e() {} pub(self) fn f() {} pub(crate) fn k() {} - pub(in crate) fn m() {} + pub(in crate) fn m() {} //~ pub_without_shorthand mod b { pub(in crate::a) fn l() {} } diff --git a/tests/ui/question_mark.fixed b/tests/ui/question_mark.fixed index 2ef006c14192..6f6dfeeb723f 100644 --- a/tests/ui/question_mark.fixed +++ b/tests/ui/question_mark.fixed @@ -4,6 +4,7 @@ #![allow(clippy::unnecessary_wraps)] fn some_func(a: Option) -> Option { + //~v question_mark a?; a @@ -47,12 +48,16 @@ pub struct CopyStruct { impl CopyStruct { #[rustfmt::skip] pub fn func(&self) -> Option { + //~v question_mark (self.opt)?; + //~v question_mark self.opt?; + //~v question_mark let _ = Some(self.opt?); + //~v question_mark let _ = self.opt?; self.opt @@ -66,29 +71,34 @@ pub struct MoveStruct { impl MoveStruct { pub fn ref_func(&self) -> Option> { + //~v question_mark self.opt.as_ref()?; self.opt.clone() } pub fn mov_func_reuse(self) -> Option> { + //~v question_mark self.opt.as_ref()?; self.opt } pub fn mov_func_no_use(self) -> Option> { + //~v question_mark self.opt.as_ref()?; Some(Vec::new()) } pub fn if_let_ref_func(self) -> Option> { + //~v question_mark let v: &Vec<_> = self.opt.as_ref()?; Some(v.clone()) } pub fn if_let_mov_func(self) -> Option> { + //~v question_mark let v = self.opt?; Some(v) @@ -100,6 +110,7 @@ fn func() -> Option { Some(String::new()) } + //~v question_mark f()?; Some(0) @@ -111,7 +122,9 @@ fn func_returning_result() -> Result { fn result_func(x: Result) -> Result { let _ = x?; + //~^ question_mark + //~v question_mark x?; // No warning @@ -178,11 +191,13 @@ fn f() -> NotOption { fn do_something() {} fn err_immediate_return() -> Result { + //~v question_mark func_returning_result()?; Ok(1) } fn err_immediate_return_and_do_something() -> Result { + //~v question_mark func_returning_result()?; do_something(); Ok(1) @@ -258,6 +273,7 @@ fn issue8628(a: Option) -> Option { fn issue6828_nested_body() -> Option { try { fn f2(a: Option) -> Option { + //~v question_mark a?; Some(32) } diff --git a/tests/ui/question_mark.rs b/tests/ui/question_mark.rs index c170669823f3..ebd3103b9d68 100644 --- a/tests/ui/question_mark.rs +++ b/tests/ui/question_mark.rs @@ -4,6 +4,7 @@ #![allow(clippy::unnecessary_wraps)] fn some_func(a: Option) -> Option { + //~v question_mark if a.is_none() { return None; } @@ -49,20 +50,24 @@ pub struct CopyStruct { impl CopyStruct { #[rustfmt::skip] pub fn func(&self) -> Option { + //~v question_mark if (self.opt).is_none() { return None; } + //~v question_mark if self.opt.is_none() { return None } + //~v question_mark let _ = if self.opt.is_none() { return None; } else { self.opt }; + //~v question_mark let _ = if let Some(x) = self.opt { x } else { @@ -80,6 +85,7 @@ pub struct MoveStruct { impl MoveStruct { pub fn ref_func(&self) -> Option> { + //~v question_mark if self.opt.is_none() { return None; } @@ -88,6 +94,7 @@ impl MoveStruct { } pub fn mov_func_reuse(self) -> Option> { + //~v question_mark if self.opt.is_none() { return None; } @@ -96,6 +103,7 @@ impl MoveStruct { } pub fn mov_func_no_use(self) -> Option> { + //~v question_mark if self.opt.is_none() { return None; } @@ -103,6 +111,7 @@ impl MoveStruct { } pub fn if_let_ref_func(self) -> Option> { + //~v question_mark let v: &Vec<_> = if let Some(ref v) = self.opt { v } else { @@ -113,6 +122,7 @@ impl MoveStruct { } pub fn if_let_mov_func(self) -> Option> { + //~v question_mark let v = if let Some(v) = self.opt { v } else { @@ -128,6 +138,7 @@ fn func() -> Option { Some(String::new()) } + //~v question_mark if f().is_none() { return None; } @@ -141,7 +152,9 @@ fn func_returning_result() -> Result { fn result_func(x: Result) -> Result { let _ = if let Ok(x) = x { x } else { return x }; + //~^ question_mark + //~v question_mark if x.is_err() { return x; } @@ -210,6 +223,7 @@ fn f() -> NotOption { fn do_something() {} fn err_immediate_return() -> Result { + //~v question_mark if let Err(err) = func_returning_result() { return Err(err); } @@ -217,6 +231,7 @@ fn err_immediate_return() -> Result { } fn err_immediate_return_and_do_something() -> Result { + //~v question_mark if let Err(err) = func_returning_result() { return Err(err); } @@ -294,6 +309,7 @@ fn issue8628(a: Option) -> Option { fn issue6828_nested_body() -> Option { try { fn f2(a: Option) -> Option { + //~v question_mark if a.is_none() { return None; // do lint here, the outer `try` is not relevant here diff --git a/tests/ui/question_mark.stderr b/tests/ui/question_mark.stderr index 7b7b85d08e63..3822d3a882c9 100644 --- a/tests/ui/question_mark.stderr +++ b/tests/ui/question_mark.stderr @@ -1,5 +1,5 @@ error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:7:5 + --> $DIR/question_mark.rs:8:5 | LL | / if a.is_none() { LL | | return None; @@ -10,7 +10,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::question_mark)]` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:52:9 + --> $DIR/question_mark.rs:54:9 | LL | / if (self.opt).is_none() { LL | | return None; @@ -18,7 +18,7 @@ LL | | } | |_________^ help: replace it with: `(self.opt)?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:56:9 + --> $DIR/question_mark.rs:59:9 | LL | / if self.opt.is_none() { LL | | return None @@ -26,7 +26,7 @@ LL | | } | |_________^ help: replace it with: `self.opt?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:60:17 + --> $DIR/question_mark.rs:64:17 | LL | let _ = if self.opt.is_none() { | _________________^ @@ -37,7 +37,7 @@ LL | | }; | |_________^ help: replace it with: `Some(self.opt?)` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:66:17 + --> $DIR/question_mark.rs:71:17 | LL | let _ = if let Some(x) = self.opt { | _________________^ @@ -48,7 +48,7 @@ LL | | }; | |_________^ help: replace it with: `self.opt?` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:83:9 + --> $DIR/question_mark.rs:89:9 | LL | / if self.opt.is_none() { LL | | return None; @@ -56,7 +56,7 @@ LL | | } | |_________^ help: replace it with: `self.opt.as_ref()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:91:9 + --> $DIR/question_mark.rs:98:9 | LL | / if self.opt.is_none() { LL | | return None; @@ -64,7 +64,7 @@ LL | | } | |_________^ help: replace it with: `self.opt.as_ref()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:99:9 + --> $DIR/question_mark.rs:107:9 | LL | / if self.opt.is_none() { LL | | return None; @@ -72,7 +72,7 @@ LL | | } | |_________^ help: replace it with: `self.opt.as_ref()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:106:26 + --> $DIR/question_mark.rs:115:26 | LL | let v: &Vec<_> = if let Some(ref v) = self.opt { | __________________________^ @@ -83,7 +83,7 @@ LL | | }; | |_________^ help: replace it with: `self.opt.as_ref()?` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:116:17 + --> $DIR/question_mark.rs:126:17 | LL | let v = if let Some(v) = self.opt { | _________________^ @@ -94,7 +94,7 @@ LL | | }; | |_________^ help: replace it with: `self.opt?` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:131:5 + --> $DIR/question_mark.rs:142:5 | LL | / if f().is_none() { LL | | return None; @@ -102,13 +102,13 @@ LL | | } | |_____^ help: replace it with: `f()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:143:13 + --> $DIR/question_mark.rs:154:13 | LL | let _ = if let Ok(x) = x { x } else { return x }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x?` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:145:5 + --> $DIR/question_mark.rs:158:5 | LL | / if x.is_err() { LL | | return x; @@ -116,7 +116,7 @@ LL | | } | |_____^ help: replace it with: `x?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:213:5 + --> $DIR/question_mark.rs:227:5 | LL | / if let Err(err) = func_returning_result() { LL | | return Err(err); @@ -124,7 +124,7 @@ LL | | } | |_____^ help: replace it with: `func_returning_result()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:220:5 + --> $DIR/question_mark.rs:235:5 | LL | / if let Err(err) = func_returning_result() { LL | | return Err(err); @@ -132,7 +132,7 @@ LL | | } | |_____^ help: replace it with: `func_returning_result()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:297:13 + --> $DIR/question_mark.rs:313:13 | LL | / if a.is_none() { LL | | return None; diff --git a/tests/ui/range_contains.fixed b/tests/ui/range_contains.fixed index ed248df374d1..a611b2b8d8a3 100644 --- a/tests/ui/range_contains.fixed +++ b/tests/ui/range_contains.fixed @@ -10,24 +10,24 @@ fn main() { let x = 9_i32; // order shouldn't matter - (8..12).contains(&x); - (21..42).contains(&x); - (1..100).contains(&x); + (8..12).contains(&x); //~ manual_range_contains + (21..42).contains(&x); //~ manual_range_contains + (1..100).contains(&x); //~ manual_range_contains // also with inclusive ranges - (9..=99).contains(&x); - (1..=33).contains(&x); - (1..=999).contains(&x); + (9..=99).contains(&x); //~ manual_range_contains + (1..=33).contains(&x); //~ manual_range_contains + (1..=999).contains(&x); //~ manual_range_contains // and the outside - !(8..12).contains(&x); - !(21..42).contains(&x); - !(1..100).contains(&x); + !(8..12).contains(&x); //~ manual_range_contains + !(21..42).contains(&x); //~ manual_range_contains + !(1..100).contains(&x); //~ manual_range_contains // also with the outside of inclusive ranges - !(9..=99).contains(&x); - !(1..=33).contains(&x); - !(1..=999).contains(&x); + !(9..=99).contains(&x); //~ manual_range_contains + !(1..=33).contains(&x); //~ manual_range_contains + !(1..=999).contains(&x); //~ manual_range_contains // not a range.contains x > 8 && x < 12; // lower bound not inclusive @@ -42,19 +42,23 @@ fn main() { // Fix #6315 let y = 3.; - (0. ..1.).contains(&y); - !(0. ..=1.).contains(&y); + (0. ..1.).contains(&y); //~ manual_range_contains + !(0. ..=1.).contains(&y); //~ manual_range_contains // handle negatives #8721 - (-10..=10).contains(&x); + (-10..=10).contains(&x); //~ manual_range_contains x >= 10 && x <= -10; - (-3. ..=3.).contains(&y); + (-3. ..=3.).contains(&y); //~ manual_range_contains y >= 3. && y <= -3.; // Fix #8745 let z = 42; (0..=10).contains(&x) && (0..=10).contains(&z); + //~^ manual_range_contains + //~| manual_range_contains !(0..10).contains(&x) || !(0..10).contains(&z); + //~^ manual_range_contains + //~| manual_range_contains // Make sure operators in parens don't give a breaking suggestion ((x % 2 == 0) || (x < 0)) || (x >= 10); } @@ -73,5 +77,5 @@ fn msrv_1_34() { #[clippy::msrv = "1.35"] fn msrv_1_35() { let x = 5; - (8..35).contains(&x); + (8..35).contains(&x); //~ manual_range_contains } diff --git a/tests/ui/range_contains.rs b/tests/ui/range_contains.rs index c3188ec6d92b..99236229c5eb 100644 --- a/tests/ui/range_contains.rs +++ b/tests/ui/range_contains.rs @@ -10,24 +10,24 @@ fn main() { let x = 9_i32; // order shouldn't matter - x >= 8 && x < 12; - x < 42 && x >= 21; - 100 > x && 1 <= x; + x >= 8 && x < 12; //~ manual_range_contains + x < 42 && x >= 21; //~ manual_range_contains + 100 > x && 1 <= x; //~ manual_range_contains // also with inclusive ranges - x >= 9 && x <= 99; - x <= 33 && x >= 1; - 999 >= x && 1 <= x; + x >= 9 && x <= 99; //~ manual_range_contains + x <= 33 && x >= 1; //~ manual_range_contains + 999 >= x && 1 <= x; //~ manual_range_contains // and the outside - x < 8 || x >= 12; - x >= 42 || x < 21; - 100 <= x || 1 > x; + x < 8 || x >= 12; //~ manual_range_contains + x >= 42 || x < 21; //~ manual_range_contains + 100 <= x || 1 > x; //~ manual_range_contains // also with the outside of inclusive ranges - x < 9 || x > 99; - x > 33 || x < 1; - 999 < x || 1 > x; + x < 9 || x > 99; //~ manual_range_contains + x > 33 || x < 1; //~ manual_range_contains + 999 < x || 1 > x; //~ manual_range_contains // not a range.contains x > 8 && x < 12; // lower bound not inclusive @@ -42,19 +42,23 @@ fn main() { // Fix #6315 let y = 3.; - y >= 0. && y < 1.; - y < 0. || y > 1.; + y >= 0. && y < 1.; //~ manual_range_contains + y < 0. || y > 1.; //~ manual_range_contains // handle negatives #8721 - x >= -10 && x <= 10; + x >= -10 && x <= 10; //~ manual_range_contains x >= 10 && x <= -10; - y >= -3. && y <= 3.; + y >= -3. && y <= 3.; //~ manual_range_contains y >= 3. && y <= -3.; // Fix #8745 let z = 42; (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10); + //~^ manual_range_contains + //~| manual_range_contains (x < 0) || (x >= 10) || (z < 0) || (z >= 10); + //~^ manual_range_contains + //~| manual_range_contains // Make sure operators in parens don't give a breaking suggestion ((x % 2 == 0) || (x < 0)) || (x >= 10); } @@ -73,5 +77,5 @@ fn msrv_1_34() { #[clippy::msrv = "1.35"] fn msrv_1_35() { let x = 5; - x >= 8 && x < 35; + x >= 8 && x < 35; //~ manual_range_contains } diff --git a/tests/ui/range_contains.stderr b/tests/ui/range_contains.stderr index 349adea2193c..25896e97f4f4 100644 --- a/tests/ui/range_contains.stderr +++ b/tests/ui/range_contains.stderr @@ -110,19 +110,19 @@ LL | (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10); | ^^^^^^^^^^^^^^^^^^^^^ help: use: `(0..=10).contains(&x)` error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:57:29 + --> $DIR/range_contains.rs:59:29 | LL | (x < 0) || (x >= 10) || (z < 0) || (z >= 10); | ^^^^^^^^^^^^^^^^^^^^ help: use: `!(0..10).contains(&z)` error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:57:5 + --> $DIR/range_contains.rs:59:5 | LL | (x < 0) || (x >= 10) || (z < 0) || (z >= 10); | ^^^^^^^^^^^^^^^^^^^^ help: use: `!(0..10).contains(&x)` error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:76:5 + --> $DIR/range_contains.rs:80:5 | LL | x >= 8 && x < 35; | ^^^^^^^^^^^^^^^^ help: use: `(8..35).contains(&x)` diff --git a/tests/ui/range_plus_minus_one.fixed b/tests/ui/range_plus_minus_one.fixed index e701dde86933..246f1f1a9730 100644 --- a/tests/ui/range_plus_minus_one.fixed +++ b/tests/ui/range_plus_minus_one.fixed @@ -26,30 +26,30 @@ fn main() { for _ in 0..2 {} for _ in 0..=2 {} - for _ in 0..=3 {} + for _ in 0..=3 {} //~ range_plus_one for _ in 0..=3 + 1 {} - for _ in 0..=5 {} + for _ in 0..=5 {} //~ range_plus_one for _ in 0..=1 + 5 {} - for _ in 1..=1 {} + for _ in 1..=1 {} //~ range_plus_one for _ in 1..=1 + 1 {} for _ in 0..13 + 13 {} for _ in 0..=13 - 7 {} - for _ in 0..=f() {} + for _ in 0..=f() {} //~ range_plus_one for _ in 0..=(1 + f()) {} let _ = ..11 - 1; - let _ = ..11; - let _ = ..11; - let _ = (1..=11); - let _ = ((f() + 1)..=f()); + let _ = ..11; //~ range_minus_one + let _ = ..11; //~ range_minus_one + let _ = (1..=11); //~ range_plus_one + let _ = ((f() + 1)..=f()); //~ range_plus_one const ONE: usize = 1; // integer consts are linted, too - for _ in 1..=ONE {} + for _ in 1..=ONE {} //~ range_plus_one let mut vec: Vec<()> = std::vec::Vec::new(); vec.drain(..); diff --git a/tests/ui/range_plus_minus_one.rs b/tests/ui/range_plus_minus_one.rs index 7057fa8e3f0d..e0785903adcf 100644 --- a/tests/ui/range_plus_minus_one.rs +++ b/tests/ui/range_plus_minus_one.rs @@ -26,30 +26,30 @@ fn main() { for _ in 0..2 {} for _ in 0..=2 {} - for _ in 0..3 + 1 {} + for _ in 0..3 + 1 {} //~ range_plus_one for _ in 0..=3 + 1 {} - for _ in 0..1 + 5 {} + for _ in 0..1 + 5 {} //~ range_plus_one for _ in 0..=1 + 5 {} - for _ in 1..1 + 1 {} + for _ in 1..1 + 1 {} //~ range_plus_one for _ in 1..=1 + 1 {} for _ in 0..13 + 13 {} for _ in 0..=13 - 7 {} - for _ in 0..(1 + f()) {} + for _ in 0..(1 + f()) {} //~ range_plus_one for _ in 0..=(1 + f()) {} let _ = ..11 - 1; - let _ = ..=11 - 1; - let _ = ..=(11 - 1); - let _ = (1..11 + 1); - let _ = (f() + 1)..(f() + 1); + let _ = ..=11 - 1; //~ range_minus_one + let _ = ..=(11 - 1); //~ range_minus_one + let _ = (1..11 + 1); //~ range_plus_one + let _ = (f() + 1)..(f() + 1); //~ range_plus_one const ONE: usize = 1; // integer consts are linted, too - for _ in 1..ONE + ONE {} + for _ in 1..ONE + ONE {} //~ range_plus_one let mut vec: Vec<()> = std::vec::Vec::new(); vec.drain(..); diff --git a/tests/ui/rc_buffer.fixed b/tests/ui/rc_buffer.fixed index 35ac95a76a91..9b9f2f20dc7b 100644 --- a/tests/ui/rc_buffer.fixed +++ b/tests/ui/rc_buffer.fixed @@ -8,19 +8,19 @@ use std::rc::Rc; struct S { // triggers lint - bad1: Rc, - bad2: Rc, - bad3: Rc<[u8]>, - bad4: Rc, + bad1: Rc, //~ rc_buffer + bad2: Rc, //~ rc_buffer + bad3: Rc<[u8]>, //~ rc_buffer + bad4: Rc, //~ rc_buffer // does not trigger lint good1: Rc>, } // triggers lint -fn func_bad1(_: Rc) {} -fn func_bad2(_: Rc) {} -fn func_bad3(_: Rc<[u8]>) {} -fn func_bad4(_: Rc) {} +fn func_bad1(_: Rc) {} //~ rc_buffer +fn func_bad2(_: Rc) {} //~ rc_buffer +fn func_bad3(_: Rc<[u8]>) {} //~ rc_buffer +fn func_bad4(_: Rc) {} //~ rc_buffer // does not trigger lint fn func_good1(_: Rc>) {} diff --git a/tests/ui/rc_buffer.rs b/tests/ui/rc_buffer.rs index e78fb5a6d9d8..9c3de2a27bf9 100644 --- a/tests/ui/rc_buffer.rs +++ b/tests/ui/rc_buffer.rs @@ -8,19 +8,19 @@ use std::rc::Rc; struct S { // triggers lint - bad1: Rc, - bad2: Rc, - bad3: Rc>, - bad4: Rc, + bad1: Rc, //~ rc_buffer + bad2: Rc, //~ rc_buffer + bad3: Rc>, //~ rc_buffer + bad4: Rc, //~ rc_buffer // does not trigger lint good1: Rc>, } // triggers lint -fn func_bad1(_: Rc) {} -fn func_bad2(_: Rc) {} -fn func_bad3(_: Rc>) {} -fn func_bad4(_: Rc) {} +fn func_bad1(_: Rc) {} //~ rc_buffer +fn func_bad2(_: Rc) {} //~ rc_buffer +fn func_bad3(_: Rc>) {} //~ rc_buffer +fn func_bad4(_: Rc) {} //~ rc_buffer // does not trigger lint fn func_good1(_: Rc>) {} diff --git a/tests/ui/rc_buffer_arc.fixed b/tests/ui/rc_buffer_arc.fixed index 0d01c7c476f7..22ea02e9c6ef 100644 --- a/tests/ui/rc_buffer_arc.fixed +++ b/tests/ui/rc_buffer_arc.fixed @@ -7,19 +7,19 @@ use std::sync::{Arc, Mutex}; struct S { // triggers lint - bad1: Arc, - bad2: Arc, - bad3: Arc<[u8]>, - bad4: Arc, + bad1: Arc, //~ rc_buffer + bad2: Arc, //~ rc_buffer + bad3: Arc<[u8]>, //~ rc_buffer + bad4: Arc, //~ rc_buffer // does not trigger lint good1: Arc>, } // triggers lint -fn func_bad1(_: Arc) {} -fn func_bad2(_: Arc) {} -fn func_bad3(_: Arc<[u8]>) {} -fn func_bad4(_: Arc) {} +fn func_bad1(_: Arc) {} //~ rc_buffer +fn func_bad2(_: Arc) {} //~ rc_buffer +fn func_bad3(_: Arc<[u8]>) {} //~ rc_buffer +fn func_bad4(_: Arc) {} //~ rc_buffer // does not trigger lint fn func_good1(_: Arc>) {} diff --git a/tests/ui/rc_buffer_arc.rs b/tests/ui/rc_buffer_arc.rs index 61ab16dc1829..158253e32c82 100644 --- a/tests/ui/rc_buffer_arc.rs +++ b/tests/ui/rc_buffer_arc.rs @@ -7,19 +7,19 @@ use std::sync::{Arc, Mutex}; struct S { // triggers lint - bad1: Arc, - bad2: Arc, - bad3: Arc>, - bad4: Arc, + bad1: Arc, //~ rc_buffer + bad2: Arc, //~ rc_buffer + bad3: Arc>, //~ rc_buffer + bad4: Arc, //~ rc_buffer // does not trigger lint good1: Arc>, } // triggers lint -fn func_bad1(_: Arc) {} -fn func_bad2(_: Arc) {} -fn func_bad3(_: Arc>) {} -fn func_bad4(_: Arc) {} +fn func_bad1(_: Arc) {} //~ rc_buffer +fn func_bad2(_: Arc) {} //~ rc_buffer +fn func_bad3(_: Arc>) {} //~ rc_buffer +fn func_bad4(_: Arc) {} //~ rc_buffer // does not trigger lint fn func_good1(_: Arc>) {} diff --git a/tests/ui/read_line_without_trim.fixed b/tests/ui/read_line_without_trim.fixed index 03a99b17dcee..73a6b9e3c514 100644 --- a/tests/ui/read_line_without_trim.fixed +++ b/tests/ui/read_line_without_trim.fixed @@ -9,23 +9,27 @@ fn main() { let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); - let _x: i32 = input.trim_end().parse().unwrap(); + let _x: i32 = input.trim_end().parse().unwrap(); //~ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x = input.trim_end().parse::().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x = input.trim_end().parse::().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x = input.trim_end().parse::().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x = input.trim_end().parse::().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); diff --git a/tests/ui/read_line_without_trim.rs b/tests/ui/read_line_without_trim.rs index 65510aea0fd0..15d48cab282b 100644 --- a/tests/ui/read_line_without_trim.rs +++ b/tests/ui/read_line_without_trim.rs @@ -9,23 +9,27 @@ fn main() { let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); - let _x: i32 = input.parse().unwrap(); + let _x: i32 = input.parse().unwrap(); //~ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x = input.parse::().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x = input.parse::().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x = input.parse::().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x = input.parse::().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); diff --git a/tests/ui/read_line_without_trim.stderr b/tests/ui/read_line_without_trim.stderr index 8d46e0f79078..b021a671e7b1 100644 --- a/tests/ui/read_line_without_trim.stderr +++ b/tests/ui/read_line_without_trim.stderr @@ -29,7 +29,7 @@ LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `.parse()` without trimming the trailing newline character - --> $DIR/read_line_without_trim.rs:20:20 + --> $DIR/read_line_without_trim.rs:21:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^ @@ -37,13 +37,13 @@ LL | let _x = input.parse::().unwrap(); | help: try: `input.trim_end()` | note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause `.parse()` to fail - --> $DIR/read_line_without_trim.rs:19:5 + --> $DIR/read_line_without_trim.rs:20:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `.parse()` without trimming the trailing newline character - --> $DIR/read_line_without_trim.rs:24:20 + --> $DIR/read_line_without_trim.rs:26:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^ @@ -51,13 +51,13 @@ LL | let _x = input.parse::().unwrap(); | help: try: `input.trim_end()` | note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause `.parse()` to fail - --> $DIR/read_line_without_trim.rs:23:5 + --> $DIR/read_line_without_trim.rs:25:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `.parse()` without trimming the trailing newline character - --> $DIR/read_line_without_trim.rs:28:20 + --> $DIR/read_line_without_trim.rs:31:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | let _x = input.parse::().unwrap(); | help: try: `input.trim_end()` | note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause `.parse()` to fail - --> $DIR/read_line_without_trim.rs:27:5 + --> $DIR/read_line_without_trim.rs:30:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_allocation_fixable.fixed b/tests/ui/redundant_allocation_fixable.fixed index 61c989c67a1a..dd56aea70d92 100644 --- a/tests/ui/redundant_allocation_fixable.fixed +++ b/tests/ui/redundant_allocation_fixable.fixed @@ -20,15 +20,17 @@ mod outer_box { use std::rc::Rc; use std::sync::Arc; - pub fn box_test1(foo: &T) {} + pub fn box_test1(foo: &T) {} //~ redundant_allocation pub fn box_test2(foo: &MyStruct) {} + //~^ redundant_allocation - pub fn box_test3(foo: &MyEnum) {} + pub fn box_test3(foo: &MyEnum) {} //~ redundant_allocation pub fn box_test4_neg(foo: Box>) {} pub fn box_test5(foo: Box) {} + //~^ redundant_allocation } mod outer_rc { @@ -37,15 +39,15 @@ mod outer_rc { use std::rc::Rc; use std::sync::Arc; - pub fn rc_test1(foo: &T) {} + pub fn rc_test1(foo: &T) {} //~ redundant_allocation - pub fn rc_test2(foo: &MyStruct) {} + pub fn rc_test2(foo: &MyStruct) {} //~ redundant_allocation - pub fn rc_test3(foo: &MyEnum) {} + pub fn rc_test3(foo: &MyEnum) {} //~ redundant_allocation pub fn rc_test4_neg(foo: Rc>) {} - pub fn rc_test6(a: Rc) {} + pub fn rc_test6(a: Rc) {} //~ redundant_allocation } mod outer_arc { @@ -54,15 +56,16 @@ mod outer_arc { use std::rc::Rc; use std::sync::Arc; - pub fn arc_test1(foo: &T) {} + pub fn arc_test1(foo: &T) {} //~ redundant_allocation pub fn arc_test2(foo: &MyStruct) {} + //~^ redundant_allocation - pub fn arc_test3(foo: &MyEnum) {} + pub fn arc_test3(foo: &MyEnum) {} //~ redundant_allocation pub fn arc_test4_neg(foo: Arc>) {} - pub fn arc_test7(a: Arc) {} + pub fn arc_test7(a: Arc) {} //~ redundant_allocation } fn main() {} diff --git a/tests/ui/redundant_allocation_fixable.rs b/tests/ui/redundant_allocation_fixable.rs index 3ad1e9a978df..b33f6bd79dd3 100644 --- a/tests/ui/redundant_allocation_fixable.rs +++ b/tests/ui/redundant_allocation_fixable.rs @@ -20,15 +20,17 @@ mod outer_box { use std::rc::Rc; use std::sync::Arc; - pub fn box_test1(foo: Box<&T>) {} + pub fn box_test1(foo: Box<&T>) {} //~ redundant_allocation pub fn box_test2(foo: Box<&MyStruct>) {} + //~^ redundant_allocation - pub fn box_test3(foo: Box<&MyEnum>) {} + pub fn box_test3(foo: Box<&MyEnum>) {} //~ redundant_allocation pub fn box_test4_neg(foo: Box>) {} pub fn box_test5(foo: Box>) {} + //~^ redundant_allocation } mod outer_rc { @@ -37,15 +39,15 @@ mod outer_rc { use std::rc::Rc; use std::sync::Arc; - pub fn rc_test1(foo: Rc<&T>) {} + pub fn rc_test1(foo: Rc<&T>) {} //~ redundant_allocation - pub fn rc_test2(foo: Rc<&MyStruct>) {} + pub fn rc_test2(foo: Rc<&MyStruct>) {} //~ redundant_allocation - pub fn rc_test3(foo: Rc<&MyEnum>) {} + pub fn rc_test3(foo: Rc<&MyEnum>) {} //~ redundant_allocation pub fn rc_test4_neg(foo: Rc>) {} - pub fn rc_test6(a: Rc>) {} + pub fn rc_test6(a: Rc>) {} //~ redundant_allocation } mod outer_arc { @@ -54,15 +56,16 @@ mod outer_arc { use std::rc::Rc; use std::sync::Arc; - pub fn arc_test1(foo: Arc<&T>) {} + pub fn arc_test1(foo: Arc<&T>) {} //~ redundant_allocation pub fn arc_test2(foo: Arc<&MyStruct>) {} + //~^ redundant_allocation - pub fn arc_test3(foo: Arc<&MyEnum>) {} + pub fn arc_test3(foo: Arc<&MyEnum>) {} //~ redundant_allocation pub fn arc_test4_neg(foo: Arc>) {} - pub fn arc_test7(a: Arc>) {} + pub fn arc_test7(a: Arc>) {} //~ redundant_allocation } fn main() {} diff --git a/tests/ui/redundant_allocation_fixable.stderr b/tests/ui/redundant_allocation_fixable.stderr index 603600f30227..cd101b903613 100644 --- a/tests/ui/redundant_allocation_fixable.stderr +++ b/tests/ui/redundant_allocation_fixable.stderr @@ -17,7 +17,7 @@ LL | pub fn box_test2(foo: Box<&MyStruct>) {} = note: `&MyStruct` is already a pointer, `Box<&MyStruct>` allocates a pointer on the heap error: usage of `Box<&MyEnum>` - --> $DIR/redundant_allocation_fixable.rs:27:27 + --> $DIR/redundant_allocation_fixable.rs:28:27 | LL | pub fn box_test3(foo: Box<&MyEnum>) {} | ^^^^^^^^^^^^ help: try: `&MyEnum` @@ -25,7 +25,7 @@ LL | pub fn box_test3(foo: Box<&MyEnum>) {} = note: `&MyEnum` is already a pointer, `Box<&MyEnum>` allocates a pointer on the heap error: usage of `Box>` - --> $DIR/redundant_allocation_fixable.rs:31:30 + --> $DIR/redundant_allocation_fixable.rs:32:30 | LL | pub fn box_test5(foo: Box>) {} | ^^^^^^^^^^^ help: try: `Box` @@ -33,7 +33,7 @@ LL | pub fn box_test5(foo: Box>) {} = note: `Box` is already on the heap, `Box>` makes an extra allocation error: usage of `Rc<&T>` - --> $DIR/redundant_allocation_fixable.rs:40:29 + --> $DIR/redundant_allocation_fixable.rs:42:29 | LL | pub fn rc_test1(foo: Rc<&T>) {} | ^^^^^^ help: try: `&T` @@ -41,7 +41,7 @@ LL | pub fn rc_test1(foo: Rc<&T>) {} = note: `&T` is already a pointer, `Rc<&T>` allocates a pointer on the heap error: usage of `Rc<&MyStruct>` - --> $DIR/redundant_allocation_fixable.rs:42:26 + --> $DIR/redundant_allocation_fixable.rs:44:26 | LL | pub fn rc_test2(foo: Rc<&MyStruct>) {} | ^^^^^^^^^^^^^ help: try: `&MyStruct` @@ -49,7 +49,7 @@ LL | pub fn rc_test2(foo: Rc<&MyStruct>) {} = note: `&MyStruct` is already a pointer, `Rc<&MyStruct>` allocates a pointer on the heap error: usage of `Rc<&MyEnum>` - --> $DIR/redundant_allocation_fixable.rs:44:26 + --> $DIR/redundant_allocation_fixable.rs:46:26 | LL | pub fn rc_test3(foo: Rc<&MyEnum>) {} | ^^^^^^^^^^^ help: try: `&MyEnum` @@ -57,7 +57,7 @@ LL | pub fn rc_test3(foo: Rc<&MyEnum>) {} = note: `&MyEnum` is already a pointer, `Rc<&MyEnum>` allocates a pointer on the heap error: usage of `Rc>` - --> $DIR/redundant_allocation_fixable.rs:48:24 + --> $DIR/redundant_allocation_fixable.rs:50:24 | LL | pub fn rc_test6(a: Rc>) {} | ^^^^^^^^^^^^ help: try: `Rc` @@ -65,7 +65,7 @@ LL | pub fn rc_test6(a: Rc>) {} = note: `Rc` is already on the heap, `Rc>` makes an extra allocation error: usage of `Arc<&T>` - --> $DIR/redundant_allocation_fixable.rs:57:30 + --> $DIR/redundant_allocation_fixable.rs:59:30 | LL | pub fn arc_test1(foo: Arc<&T>) {} | ^^^^^^^ help: try: `&T` @@ -73,7 +73,7 @@ LL | pub fn arc_test1(foo: Arc<&T>) {} = note: `&T` is already a pointer, `Arc<&T>` allocates a pointer on the heap error: usage of `Arc<&MyStruct>` - --> $DIR/redundant_allocation_fixable.rs:59:27 + --> $DIR/redundant_allocation_fixable.rs:61:27 | LL | pub fn arc_test2(foo: Arc<&MyStruct>) {} | ^^^^^^^^^^^^^^ help: try: `&MyStruct` @@ -81,7 +81,7 @@ LL | pub fn arc_test2(foo: Arc<&MyStruct>) {} = note: `&MyStruct` is already a pointer, `Arc<&MyStruct>` allocates a pointer on the heap error: usage of `Arc<&MyEnum>` - --> $DIR/redundant_allocation_fixable.rs:61:27 + --> $DIR/redundant_allocation_fixable.rs:64:27 | LL | pub fn arc_test3(foo: Arc<&MyEnum>) {} | ^^^^^^^^^^^^ help: try: `&MyEnum` @@ -89,7 +89,7 @@ LL | pub fn arc_test3(foo: Arc<&MyEnum>) {} = note: `&MyEnum` is already a pointer, `Arc<&MyEnum>` allocates a pointer on the heap error: usage of `Arc>` - --> $DIR/redundant_allocation_fixable.rs:65:25 + --> $DIR/redundant_allocation_fixable.rs:68:25 | LL | pub fn arc_test7(a: Arc>) {} | ^^^^^^^^^^^^^^ help: try: `Arc` diff --git a/tests/ui/redundant_as_str.fixed b/tests/ui/redundant_as_str.fixed index 4185b402226c..b257ee0b6d20 100644 --- a/tests/ui/redundant_as_str.fixed +++ b/tests/ui/redundant_as_str.fixed @@ -5,7 +5,9 @@ fn main() { // These methods are redundant and the `as_str` can be removed let _redundant = string.as_bytes(); + //~^ redundant_as_str let _redundant = string.is_empty(); + //~^ redundant_as_str // These methods don't use `as_str` when they are redundant let _no_as_str = string.as_bytes(); diff --git a/tests/ui/redundant_as_str.rs b/tests/ui/redundant_as_str.rs index 7a74d8a55ded..849a99db8ac2 100644 --- a/tests/ui/redundant_as_str.rs +++ b/tests/ui/redundant_as_str.rs @@ -5,7 +5,9 @@ fn main() { // These methods are redundant and the `as_str` can be removed let _redundant = string.as_str().as_bytes(); + //~^ redundant_as_str let _redundant = string.as_str().is_empty(); + //~^ redundant_as_str // These methods don't use `as_str` when they are redundant let _no_as_str = string.as_bytes(); diff --git a/tests/ui/redundant_as_str.stderr b/tests/ui/redundant_as_str.stderr index 0ea42a94a81e..2f89bf3a4d3f 100644 --- a/tests/ui/redundant_as_str.stderr +++ b/tests/ui/redundant_as_str.stderr @@ -8,7 +8,7 @@ LL | let _redundant = string.as_str().as_bytes(); = help: to override `-D warnings` add `#[allow(clippy::redundant_as_str)]` error: this `as_str` is redundant and can be removed as the method immediately following exists on `String` too - --> $DIR/redundant_as_str.rs:8:29 + --> $DIR/redundant_as_str.rs:9:29 | LL | let _redundant = string.as_str().is_empty(); | ^^^^^^^^^^^^^^^^^ help: try: `is_empty` diff --git a/tests/ui/redundant_async_block.fixed b/tests/ui/redundant_async_block.fixed index a1875c1c06e1..e11097b892d9 100644 --- a/tests/ui/redundant_async_block.fixed +++ b/tests/ui/redundant_async_block.fixed @@ -10,21 +10,22 @@ async fn func1(n: usize) -> usize { async fn func2() -> String { let s = String::from("some string"); let f = async { (*s).to_owned() }; - let x = f; + let x = f; //~ redundant_async_block x.await } fn main() { let fut1 = async { 17 }; // Lint - let fut2 = fut1; + let fut2 = fut1; //~ redundant_async_block let fut1 = async { 25 }; // Lint - let fut2 = fut1; + let fut2 = fut1; //~ redundant_async_block // Lint let fut = async { 42 }; + //~^ redundant_async_block // Do not lint: not a single expression let fut = async { @@ -40,7 +41,7 @@ fn main() { fn capture_local() -> impl Future { let fut = async { 17 }; // Lint - fut + fut //~ redundant_async_block } fn capture_local_closure(s: &str) -> impl Future { @@ -53,12 +54,12 @@ fn capture_local_closure(s: &str) -> impl Future { fn capture_arg(s: &str) -> impl Future { let fut = async move { s }; // Lint - fut + fut //~ redundant_async_block } fn capture_future_arg(f: impl Future) -> impl Future { // Lint - f + f //~ redundant_async_block } fn capture_func_result(f: FN) -> impl Future @@ -82,6 +83,7 @@ where { // Lint async { f().await + 1 } + //~^ redundant_async_block } #[derive(Debug, Clone)] @@ -144,7 +146,7 @@ fn all_from_macro() -> impl Future { macro_rules! mac { () => { // Lint - async { 42 } + async { 42 } //~ redundant_async_block }; } mac!() @@ -164,7 +166,7 @@ fn safe_parts_from_macro() -> impl Future { macro_rules! mac { ($e: expr) => { // Lint - async { $e } + async { $e } //~ redundant_async_block }; } mac!(42) diff --git a/tests/ui/redundant_async_block.rs b/tests/ui/redundant_async_block.rs index bb43403a043e..66f520a040ff 100644 --- a/tests/ui/redundant_async_block.rs +++ b/tests/ui/redundant_async_block.rs @@ -10,21 +10,22 @@ async fn func1(n: usize) -> usize { async fn func2() -> String { let s = String::from("some string"); let f = async { (*s).to_owned() }; - let x = async { f.await }; + let x = async { f.await }; //~ redundant_async_block x.await } fn main() { let fut1 = async { 17 }; // Lint - let fut2 = async { fut1.await }; + let fut2 = async { fut1.await }; //~ redundant_async_block let fut1 = async { 25 }; // Lint - let fut2 = async move { fut1.await }; + let fut2 = async move { fut1.await }; //~ redundant_async_block // Lint let fut = async { async { 42 }.await }; + //~^ redundant_async_block // Do not lint: not a single expression let fut = async { @@ -40,7 +41,7 @@ fn main() { fn capture_local() -> impl Future { let fut = async { 17 }; // Lint - async move { fut.await } + async move { fut.await } //~ redundant_async_block } fn capture_local_closure(s: &str) -> impl Future { @@ -53,12 +54,12 @@ fn capture_local_closure(s: &str) -> impl Future { fn capture_arg(s: &str) -> impl Future { let fut = async move { s }; // Lint - async move { fut.await } + async move { fut.await } //~ redundant_async_block } fn capture_future_arg(f: impl Future) -> impl Future { // Lint - async { f.await } + async { f.await } //~ redundant_async_block } fn capture_func_result(f: FN) -> impl Future @@ -82,6 +83,7 @@ where { // Lint async { async { f().await + 1 }.await } + //~^ redundant_async_block } #[derive(Debug, Clone)] @@ -144,7 +146,7 @@ fn all_from_macro() -> impl Future { macro_rules! mac { () => { // Lint - async { async { 42 }.await } + async { async { 42 }.await } //~ redundant_async_block }; } mac!() @@ -164,7 +166,7 @@ fn safe_parts_from_macro() -> impl Future { macro_rules! mac { ($e: expr) => { // Lint - async { async { $e }.await } + async { async { $e }.await } //~ redundant_async_block }; } mac!(42) diff --git a/tests/ui/redundant_async_block.stderr b/tests/ui/redundant_async_block.stderr index adb44d7a62ef..5228a67be8a1 100644 --- a/tests/ui/redundant_async_block.stderr +++ b/tests/ui/redundant_async_block.stderr @@ -26,31 +26,31 @@ LL | let fut = async { async { 42 }.await }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `async { 42 }` error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:43:5 + --> $DIR/redundant_async_block.rs:44:5 | LL | async move { fut.await } | ^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `fut` error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:56:5 + --> $DIR/redundant_async_block.rs:57:5 | LL | async move { fut.await } | ^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `fut` error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:61:5 + --> $DIR/redundant_async_block.rs:62:5 | LL | async { f.await } | ^^^^^^^^^^^^^^^^^ help: you can reduce it to: `f` error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:84:5 + --> $DIR/redundant_async_block.rs:85:5 | LL | async { async { f().await + 1 }.await } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `async { f().await + 1 }` error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:147:13 + --> $DIR/redundant_async_block.rs:149:13 | LL | async { async { 42 }.await } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `async { 42 }` @@ -61,7 +61,7 @@ LL | mac!() = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:167:13 + --> $DIR/redundant_async_block.rs:169:13 | LL | async { async { $e }.await } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `async { $e }` diff --git a/tests/ui/redundant_at_rest_pattern.fixed b/tests/ui/redundant_at_rest_pattern.fixed index a7997637372e..7c37aca0f9dd 100644 --- a/tests/ui/redundant_at_rest_pattern.fixed +++ b/tests/ui/redundant_at_rest_pattern.fixed @@ -6,14 +6,14 @@ extern crate proc_macros; fn main() { - if let a = [()] {} - if let ref a = [()] {} - if let mut a = [()] {} - if let ref mut a = [()] {} + if let a = [()] {} //~ redundant_at_rest_pattern + if let ref a = [()] {} //~ redundant_at_rest_pattern + if let mut a = [()] {} //~ redundant_at_rest_pattern + if let ref mut a = [()] {} //~ redundant_at_rest_pattern let v = vec![()]; - if let a = &*v {} + if let a = &*v {} //~ redundant_at_rest_pattern let s = &[()]; - if let a = s {} + if let a = s {} //~ redundant_at_rest_pattern // Don't lint if let [..] = &*v {} if let [a] = &*v {} diff --git a/tests/ui/redundant_at_rest_pattern.rs b/tests/ui/redundant_at_rest_pattern.rs index f103d1f1a179..34d522cdfb78 100644 --- a/tests/ui/redundant_at_rest_pattern.rs +++ b/tests/ui/redundant_at_rest_pattern.rs @@ -6,14 +6,14 @@ extern crate proc_macros; fn main() { - if let [a @ ..] = [()] {} - if let [ref a @ ..] = [()] {} - if let [mut a @ ..] = [()] {} - if let [ref mut a @ ..] = [()] {} + if let [a @ ..] = [()] {} //~ redundant_at_rest_pattern + if let [ref a @ ..] = [()] {} //~ redundant_at_rest_pattern + if let [mut a @ ..] = [()] {} //~ redundant_at_rest_pattern + if let [ref mut a @ ..] = [()] {} //~ redundant_at_rest_pattern let v = vec![()]; - if let [a @ ..] = &*v {} + if let [a @ ..] = &*v {} //~ redundant_at_rest_pattern let s = &[()]; - if let [a @ ..] = s {} + if let [a @ ..] = s {} //~ redundant_at_rest_pattern // Don't lint if let [..] = &*v {} if let [a] = &*v {} diff --git a/tests/ui/redundant_clone.fixed b/tests/ui/redundant_clone.fixed index 867f5b210171..b5d2499a1639 100644 --- a/tests/ui/redundant_clone.fixed +++ b/tests/ui/redundant_clone.fixed @@ -13,23 +13,26 @@ use std::path::Path; fn main() { let _s = ["lorem", "ipsum"].join(" "); + //~^ redundant_clone let s = String::from("foo"); - let _s = s; + let _s = s; //~ redundant_clone let s = String::from("foo"); - let _s = s; + let _s = s; //~ redundant_clone let s = String::from("foo"); - let _s = s; + let _s = s; //~ redundant_clone let _s = Path::new("/a/b/").join("c"); + //~^ redundant_clone let _s = Path::new("/a/b/").join("c"); + //~^ redundant_clone - let _s = OsString::new(); + let _s = OsString::new(); //~ redundant_clone - let _s = OsString::new(); + let _s = OsString::new(); //~ redundant_clone // Check that lint level works #[allow(clippy::redundant_clone)] @@ -40,7 +43,7 @@ fn main() { let _s = String::new().to_string(); let tup = (String::from("foo"),); - let _t = tup.0; + let _t = tup.0; //~ redundant_clone let tup_ref = &(String::from("foo"),); let _s = tup_ref.0.clone(); // this `.clone()` cannot be removed @@ -73,6 +76,7 @@ fn main() { struct Alpha; fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) { if b { (a.clone(), a) } else { (Alpha, a) } + //~^ redundant_clone } fn cannot_double_move(a: Alpha) -> (Alpha, Alpha) { @@ -129,8 +133,8 @@ fn borrower_propagation() { let _s = s.clone(); // ok, `u` borrows `s` } - let _s = s; - let _t = t; + let _s = s; //~ redundant_clone + let _t = t; //~ redundant_clone #[derive(Clone)] struct Foo { @@ -140,7 +144,7 @@ fn borrower_propagation() { { let f = Foo { x: 123 }; let _x = Some(f.x); - let _f = f; + let _f = f; //~ redundant_clone } { @@ -152,7 +156,7 @@ fn borrower_propagation() { fn not_consumed() { let x = std::path::PathBuf::from("home"); - let y = x.join("matthias"); + let y = x.join("matthias"); //~ redundant_clone // join() creates a new owned PathBuf, does not take a &mut to x variable, thus the .clone() is // redundant. (It also does not consume the PathBuf) @@ -206,6 +210,7 @@ fn clone_then_move_cloned() { fn foo(_: &Alpha, _: F) {} let x = Alpha; // ok, data is moved while the clone is in use. + //~v redundant_clone foo(&x, move || { let _ = x; }); diff --git a/tests/ui/redundant_clone.rs b/tests/ui/redundant_clone.rs index adcbd01e819c..a32463dd1b78 100644 --- a/tests/ui/redundant_clone.rs +++ b/tests/ui/redundant_clone.rs @@ -13,23 +13,26 @@ use std::path::Path; fn main() { let _s = ["lorem", "ipsum"].join(" ").to_string(); + //~^ redundant_clone let s = String::from("foo"); - let _s = s.clone(); + let _s = s.clone(); //~ redundant_clone let s = String::from("foo"); - let _s = s.to_string(); + let _s = s.to_string(); //~ redundant_clone let s = String::from("foo"); - let _s = s.to_owned(); + let _s = s.to_owned(); //~ redundant_clone let _s = Path::new("/a/b/").join("c").to_owned(); + //~^ redundant_clone let _s = Path::new("/a/b/").join("c").to_path_buf(); + //~^ redundant_clone - let _s = OsString::new().to_owned(); + let _s = OsString::new().to_owned(); //~ redundant_clone - let _s = OsString::new().to_os_string(); + let _s = OsString::new().to_os_string(); //~ redundant_clone // Check that lint level works #[allow(clippy::redundant_clone)] @@ -40,7 +43,7 @@ fn main() { let _s = String::new().to_string(); let tup = (String::from("foo"),); - let _t = tup.0.clone(); + let _t = tup.0.clone(); //~ redundant_clone let tup_ref = &(String::from("foo"),); let _s = tup_ref.0.clone(); // this `.clone()` cannot be removed @@ -73,6 +76,7 @@ fn main() { struct Alpha; fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) { if b { (a.clone(), a.clone()) } else { (Alpha, a) } + //~^ redundant_clone } fn cannot_double_move(a: Alpha) -> (Alpha, Alpha) { @@ -129,8 +133,8 @@ fn borrower_propagation() { let _s = s.clone(); // ok, `u` borrows `s` } - let _s = s.clone(); - let _t = t.clone(); + let _s = s.clone(); //~ redundant_clone + let _t = t.clone(); //~ redundant_clone #[derive(Clone)] struct Foo { @@ -140,7 +144,7 @@ fn borrower_propagation() { { let f = Foo { x: 123 }; let _x = Some(f.x); - let _f = f.clone(); + let _f = f.clone(); //~ redundant_clone } { @@ -152,7 +156,7 @@ fn borrower_propagation() { fn not_consumed() { let x = std::path::PathBuf::from("home"); - let y = x.clone().join("matthias"); + let y = x.clone().join("matthias"); //~ redundant_clone // join() creates a new owned PathBuf, does not take a &mut to x variable, thus the .clone() is // redundant. (It also does not consume the PathBuf) @@ -206,6 +210,7 @@ fn clone_then_move_cloned() { fn foo(_: &Alpha, _: F) {} let x = Alpha; // ok, data is moved while the clone is in use. + //~v redundant_clone foo(&x.clone(), move || { let _ = x; }); diff --git a/tests/ui/redundant_clone.stderr b/tests/ui/redundant_clone.stderr index 4115fcf21228..0f8856c212ef 100644 --- a/tests/ui/redundant_clone.stderr +++ b/tests/ui/redundant_clone.stderr @@ -13,169 +13,169 @@ LL | let _s = ["lorem", "ipsum"].join(" ").to_string(); = help: to override `-D warnings` add `#[allow(clippy::redundant_clone)]` error: redundant clone - --> $DIR/redundant_clone.rs:18:15 + --> $DIR/redundant_clone.rs:19:15 | LL | let _s = s.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:18:14 + --> $DIR/redundant_clone.rs:19:14 | LL | let _s = s.clone(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:21:15 + --> $DIR/redundant_clone.rs:22:15 | LL | let _s = s.to_string(); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:21:14 + --> $DIR/redundant_clone.rs:22:14 | LL | let _s = s.to_string(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:24:15 + --> $DIR/redundant_clone.rs:25:15 | LL | let _s = s.to_owned(); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:24:14 + --> $DIR/redundant_clone.rs:25:14 | LL | let _s = s.to_owned(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:26:42 + --> $DIR/redundant_clone.rs:27:42 | LL | let _s = Path::new("/a/b/").join("c").to_owned(); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:26:14 + --> $DIR/redundant_clone.rs:27:14 | LL | let _s = Path::new("/a/b/").join("c").to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:28:42 + --> $DIR/redundant_clone.rs:30:42 | LL | let _s = Path::new("/a/b/").join("c").to_path_buf(); | ^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:28:14 + --> $DIR/redundant_clone.rs:30:14 | LL | let _s = Path::new("/a/b/").join("c").to_path_buf(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:30:29 + --> $DIR/redundant_clone.rs:33:29 | LL | let _s = OsString::new().to_owned(); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:30:14 + --> $DIR/redundant_clone.rs:33:14 | LL | let _s = OsString::new().to_owned(); | ^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:32:29 + --> $DIR/redundant_clone.rs:35:29 | LL | let _s = OsString::new().to_os_string(); | ^^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:32:14 + --> $DIR/redundant_clone.rs:35:14 | LL | let _s = OsString::new().to_os_string(); | ^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:43:19 + --> $DIR/redundant_clone.rs:46:19 | LL | let _t = tup.0.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:43:14 + --> $DIR/redundant_clone.rs:46:14 | LL | let _t = tup.0.clone(); | ^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:75:25 + --> $DIR/redundant_clone.rs:78:25 | LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) } | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:75:24 + --> $DIR/redundant_clone.rs:78:24 | LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) } | ^ error: redundant clone - --> $DIR/redundant_clone.rs:132:15 + --> $DIR/redundant_clone.rs:136:15 | LL | let _s = s.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:132:14 + --> $DIR/redundant_clone.rs:136:14 | LL | let _s = s.clone(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:133:15 + --> $DIR/redundant_clone.rs:137:15 | LL | let _t = t.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:133:14 + --> $DIR/redundant_clone.rs:137:14 | LL | let _t = t.clone(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:143:19 + --> $DIR/redundant_clone.rs:147:19 | LL | let _f = f.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:143:18 + --> $DIR/redundant_clone.rs:147:18 | LL | let _f = f.clone(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:155:14 + --> $DIR/redundant_clone.rs:159:14 | LL | let y = x.clone().join("matthias"); | ^^^^^^^^ help: remove this | note: cloned value is neither consumed nor mutated - --> $DIR/redundant_clone.rs:155:13 + --> $DIR/redundant_clone.rs:159:13 | LL | let y = x.clone().join("matthias"); | ^^^^^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:209:11 + --> $DIR/redundant_clone.rs:214:11 | LL | foo(&x.clone(), move || { | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:209:10 + --> $DIR/redundant_clone.rs:214:10 | LL | foo(&x.clone(), move || { | ^ diff --git a/tests/ui/redundant_closure_call_fixable.fixed b/tests/ui/redundant_closure_call_fixable.fixed index ce5c7f2600be..1fa5d50dcb05 100644 --- a/tests/ui/redundant_closure_call_fixable.fixed +++ b/tests/ui/redundant_closure_call_fixable.fixed @@ -13,18 +13,22 @@ async fn something_else() -> u32 { } fn main() { - let a = 42; + let a = 42; //~ redundant_closure_call + + //~v redundant_closure_call let b = async { let x = something().await; let y = something_else().await; x * y }; + //~v redundant_closure_call let c = { let x = 21; let y = 2; x * y }; let d = async { something().await }; + //~^ redundant_closure_call macro_rules! m { () => { @@ -33,15 +37,15 @@ fn main() { } macro_rules! m2 { () => { - m!() + m!() //~ redundant_closure_call }; } - m2!(); + m2!(); //~ redundant_closure_call issue9956(); } fn issue9956() { - assert_eq!(43, 42); + assert_eq!(43, 42); //~ redundant_closure_call // ... and some more interesting cases I've found while implementing the fix @@ -50,14 +54,15 @@ fn issue9956() { dbg!(a()); // immediately calling it inside of a macro - dbg!(42); + dbg!(42); //~ redundant_closure_call // immediately calling only one closure, so we can't remove the other ones - let a = (|| || 123); + let a = (|| || 123); //~ redundant_closure_call dbg!(a()()); // nested async closures let a = async { 1 }; + //~^ redundant_closure_call let h = async { a.await }; // macro expansion tests @@ -67,8 +72,9 @@ fn issue9956() { }; } let a = 1; + //~^ redundant_closure_call assert_eq!(a, 1); - let a = 123; + let a = 123; //~ redundant_closure_call assert_eq!(a, 123); // chaining calls, but not closures @@ -81,12 +87,12 @@ fn issue9956() { foo } fn foo(_: i32, _: i32) {} - bar()(42, 5); - foo(42, 5); + bar()(42, 5); //~ redundant_closure_call + foo(42, 5); //~ redundant_closure_call } async fn issue11357() { - async {}.await; + async {}.await; //~ redundant_closure_call } mod issue11707 { @@ -95,12 +101,13 @@ mod issue11707 { fn spawn_on(fut: impl Future) {} fn demo() { - spawn_on(async move {}); + spawn_on(async move {}); //~ redundant_closure_call } } fn avoid_double_parens() { std::convert::identity(13_i32 + 36_i32).leading_zeros(); + //~^ redundant_closure_call } fn fp_11274() { diff --git a/tests/ui/redundant_closure_call_fixable.rs b/tests/ui/redundant_closure_call_fixable.rs index ac09390e6eae..9b1529f24370 100644 --- a/tests/ui/redundant_closure_call_fixable.rs +++ b/tests/ui/redundant_closure_call_fixable.rs @@ -13,18 +13,22 @@ async fn something_else() -> u32 { } fn main() { - let a = (|| 42)(); + let a = (|| 42)(); //~ redundant_closure_call + + //~v redundant_closure_call let b = (async || { let x = something().await; let y = something_else().await; x * y })(); + //~v redundant_closure_call let c = (|| { let x = 21; let y = 2; x * y })(); let d = (async || something().await)(); + //~^ redundant_closure_call macro_rules! m { () => { @@ -33,15 +37,15 @@ fn main() { } macro_rules! m2 { () => { - (|| m!())() + (|| m!())() //~ redundant_closure_call }; } - m2!(); + m2!(); //~ redundant_closure_call issue9956(); } fn issue9956() { - assert_eq!((|| || 43)()(), 42); + assert_eq!((|| || 43)()(), 42); //~ redundant_closure_call // ... and some more interesting cases I've found while implementing the fix @@ -50,14 +54,15 @@ fn issue9956() { dbg!(a()); // immediately calling it inside of a macro - dbg!((|| 42)()); + dbg!((|| 42)()); //~ redundant_closure_call // immediately calling only one closure, so we can't remove the other ones - let a = (|| || || 123)(); + let a = (|| || || 123)(); //~ redundant_closure_call dbg!(a()()); // nested async closures let a = (|| || || || async || 1)()()()()(); + //~^ redundant_closure_call let h = async { a.await }; // macro expansion tests @@ -67,8 +72,9 @@ fn issue9956() { }; } let a = (|| echo!(|| echo!(|| 1)))()()(); + //~^ redundant_closure_call assert_eq!(a, 1); - let a = (|| echo!((|| 123)))()(); + let a = (|| echo!((|| 123)))()(); //~ redundant_closure_call assert_eq!(a, 123); // chaining calls, but not closures @@ -81,12 +87,12 @@ fn issue9956() { foo } fn foo(_: i32, _: i32) {} - bar()((|| || 42)()(), 5); - foo((|| || 42)()(), 5); + bar()((|| || 42)()(), 5); //~ redundant_closure_call + foo((|| || 42)()(), 5); //~ redundant_closure_call } async fn issue11357() { - (|| async {})().await; + (|| async {})().await; //~ redundant_closure_call } mod issue11707 { @@ -95,12 +101,13 @@ mod issue11707 { fn spawn_on(fut: impl Future) {} fn demo() { - spawn_on((|| async move {})()); + spawn_on((|| async move {})()); //~ redundant_closure_call } } fn avoid_double_parens() { std::convert::identity((|| 13_i32 + 36_i32)()).leading_zeros(); + //~^ redundant_closure_call } fn fp_11274() { diff --git a/tests/ui/redundant_closure_call_fixable.stderr b/tests/ui/redundant_closure_call_fixable.stderr index 028d383ad354..8c4ac387179e 100644 --- a/tests/ui/redundant_closure_call_fixable.stderr +++ b/tests/ui/redundant_closure_call_fixable.stderr @@ -8,7 +8,7 @@ LL | let a = (|| 42)(); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_call)]` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:17:13 + --> $DIR/redundant_closure_call_fixable.rs:19:13 | LL | let b = (async || { | _____________^ @@ -28,7 +28,7 @@ LL ~ }; | error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:22:13 + --> $DIR/redundant_closure_call_fixable.rs:25:13 | LL | let c = (|| { | _____________^ @@ -48,13 +48,13 @@ LL ~ }; | error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:27:13 + --> $DIR/redundant_closure_call_fixable.rs:30:13 | LL | let d = (async || something().await)(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try doing something like: `async { something().await }` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:36:13 + --> $DIR/redundant_closure_call_fixable.rs:40:13 | LL | (|| m!())() | ^^^^^^^^^^^ help: try doing something like: `m!()` @@ -65,7 +65,7 @@ LL | m2!(); = note: this error originates in the macro `m2` (in Nightly builds, run with -Z macro-backtrace for more info) error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:31:13 + --> $DIR/redundant_closure_call_fixable.rs:35:13 | LL | (|| 0)() | ^^^^^^^^ help: try doing something like: `0` @@ -76,67 +76,67 @@ LL | m2!(); = note: this error originates in the macro `m` which comes from the expansion of the macro `m2` (in Nightly builds, run with -Z macro-backtrace for more info) error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:44:16 + --> $DIR/redundant_closure_call_fixable.rs:48:16 | LL | assert_eq!((|| || 43)()(), 42); | ^^^^^^^^^^^^^^ help: try doing something like: `43` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:53:10 + --> $DIR/redundant_closure_call_fixable.rs:57:10 | LL | dbg!((|| 42)()); | ^^^^^^^^^ help: try doing something like: `42` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:56:13 + --> $DIR/redundant_closure_call_fixable.rs:60:13 | LL | let a = (|| || || 123)(); | ^^^^^^^^^^^^^^^^ help: try doing something like: `(|| || 123)` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:60:13 + --> $DIR/redundant_closure_call_fixable.rs:64:13 | LL | let a = (|| || || || async || 1)()()()()(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try doing something like: `async { 1 }` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:69:13 + --> $DIR/redundant_closure_call_fixable.rs:74:13 | LL | let a = (|| echo!(|| echo!(|| 1)))()()(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try doing something like: `1` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:71:13 + --> $DIR/redundant_closure_call_fixable.rs:77:13 | LL | let a = (|| echo!((|| 123)))()(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try doing something like: `123` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:84:11 + --> $DIR/redundant_closure_call_fixable.rs:90:11 | LL | bar()((|| || 42)()(), 5); | ^^^^^^^^^^^^^^ help: try doing something like: `42` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:85:9 + --> $DIR/redundant_closure_call_fixable.rs:91:9 | LL | foo((|| || 42)()(), 5); | ^^^^^^^^^^^^^^ help: try doing something like: `42` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:89:5 + --> $DIR/redundant_closure_call_fixable.rs:95:5 | LL | (|| async {})().await; | ^^^^^^^^^^^^^^^ help: try doing something like: `async {}` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:98:18 + --> $DIR/redundant_closure_call_fixable.rs:104:18 | LL | spawn_on((|| async move {})()); | ^^^^^^^^^^^^^^^^^^^^ help: try doing something like: `async move {}` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:103:28 + --> $DIR/redundant_closure_call_fixable.rs:109:28 | LL | std::convert::identity((|| 13_i32 + 36_i32)()).leading_zeros(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try doing something like: `13_i32 + 36_i32` diff --git a/tests/ui/redundant_field_names.fixed b/tests/ui/redundant_field_names.fixed index c578e786426f..11b2d79a6947 100644 --- a/tests/ui/redundant_field_names.fixed +++ b/tests/ui/redundant_field_names.fixed @@ -30,8 +30,8 @@ fn main() { let name: u8 = 0; let me = Person { - gender, - age, + gender, //~ redundant_field_names + age, //~ redundant_field_names name, //should be ok buzz: fizz, //should be ok @@ -52,11 +52,13 @@ fn main() { let _: Vec<_> = (start..end).collect(); // hand-written Range family structs are linted - let _ = RangeFrom { start }; - let _ = RangeTo { end }; + let _ = RangeFrom { start }; //~ redundant_field_names + let _ = RangeTo { end }; //~ redundant_field_names let _ = Range { start, end }; + //~^ redundant_field_names + //~| redundant_field_names let _ = RangeInclusive::new(start, end); - let _ = RangeToInclusive { end }; + let _ = RangeToInclusive { end }; //~ redundant_field_names external! { let v = String::new(); @@ -85,5 +87,5 @@ fn msrv_1_16() { #[clippy::msrv = "1.17"] fn msrv_1_17() { let start = 0; - let _ = RangeFrom { start }; + let _ = RangeFrom { start }; //~ redundant_field_names } diff --git a/tests/ui/redundant_field_names.rs b/tests/ui/redundant_field_names.rs index d8c2286d5ad6..244cb31a04d8 100644 --- a/tests/ui/redundant_field_names.rs +++ b/tests/ui/redundant_field_names.rs @@ -30,8 +30,8 @@ fn main() { let name: u8 = 0; let me = Person { - gender: gender, - age: age, + gender: gender, //~ redundant_field_names + age: age, //~ redundant_field_names name, //should be ok buzz: fizz, //should be ok @@ -52,11 +52,13 @@ fn main() { let _: Vec<_> = (start..end).collect(); // hand-written Range family structs are linted - let _ = RangeFrom { start: start }; - let _ = RangeTo { end: end }; + let _ = RangeFrom { start: start }; //~ redundant_field_names + let _ = RangeTo { end: end }; //~ redundant_field_names let _ = Range { start: start, end: end }; + //~^ redundant_field_names + //~| redundant_field_names let _ = RangeInclusive::new(start, end); - let _ = RangeToInclusive { end: end }; + let _ = RangeToInclusive { end: end }; //~ redundant_field_names external! { let v = String::new(); @@ -85,5 +87,5 @@ fn msrv_1_16() { #[clippy::msrv = "1.17"] fn msrv_1_17() { let start = 0; - let _ = RangeFrom { start: start }; + let _ = RangeFrom { start: start }; //~ redundant_field_names } diff --git a/tests/ui/redundant_field_names.stderr b/tests/ui/redundant_field_names.stderr index 6eb1cc753192..b09b74c0736f 100644 --- a/tests/ui/redundant_field_names.stderr +++ b/tests/ui/redundant_field_names.stderr @@ -38,13 +38,13 @@ LL | let _ = Range { start: start, end: end }; | ^^^^^^^^ help: replace it with: `end` error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:59:32 + --> $DIR/redundant_field_names.rs:61:32 | LL | let _ = RangeToInclusive { end: end }; | ^^^^^^^^ help: replace it with: `end` error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:88:25 + --> $DIR/redundant_field_names.rs:90:25 | LL | let _ = RangeFrom { start: start }; | ^^^^^^^^^^^^ help: replace it with: `start` diff --git a/tests/ui/redundant_guards.fixed b/tests/ui/redundant_guards.fixed index 0a2ae911ad43..028584da4747 100644 --- a/tests/ui/redundant_guards.fixed +++ b/tests/ui/redundant_guards.fixed @@ -30,20 +30,23 @@ fn issue11304() { fn main() { let c = C(1, 2); match c { - C(x, 1) => .., + C(x, 1) => .., //~ redundant_guards _ => todo!(), }; let x = Some(Some(1)); match x { Some(Some(1)) if true => .., + //~^ redundant_guards + + //~v redundant_guards Some(Some(1)) => { println!("a"); .. }, - Some(Some(1)) => .., - Some(Some(2)) => .., - Some(Some(2)) => .., + Some(Some(1)) => .., //~ redundant_guards + Some(Some(2)) => .., //~ redundant_guards + Some(Some(2)) => .., //~ redundant_guards // Don't lint, since x is used in the body Some(x) if let Some(1) = x => { x; @@ -69,6 +72,7 @@ fn main() { let b = B { e: Some(A(0)) }; match b { B { e: Some(A(2)) } => .., + //~^ redundant_guards _ => todo!(), }; // Do not lint, since we cannot represent this as a pattern (at least, without a conversion) @@ -106,21 +110,22 @@ fn i() { // Do not lint E::A(x) | E::B(x) | E::C(x) if x == "from an or pattern" => {}, E::A("not from an or pattern") => {}, + //~^ redundant_guards _ => {}, }; } fn h(v: Option) { match v { - Some(0) => .., + Some(0) => .., //~ redundant_guards _ => .., }; } fn negative_literal(i: i32) { match i { - -1 => {}, - 1 => {}, + -1 => {}, //~ redundant_guards + 1 => {}, //~ redundant_guards _ => {}, } } @@ -170,10 +175,11 @@ mod issue11465 { fn issue11465() { let c = Some(1); match c { - Some(1) => {}, - Some(1) => {}, - Some(2) => {}, + Some(1) => {}, //~ redundant_guards + Some(1) => {}, //~ redundant_guards + Some(2) => {}, //~ redundant_guards Some(3) => {}, + //~^ redundant_guards _ => {}, }; @@ -193,10 +199,12 @@ mod issue11465 { match struct_b { B { ref b, .. } if b == "bar" => {}, B { ref b, .. } if "bar" == b => {}, + B { c: 1, .. } => {}, //~ redundant_guards + B { c: 1, .. } => {}, //~ redundant_guards B { c: 1, .. } => {}, + //~^ redundant_guards B { c: 1, .. } => {}, - B { c: 1, .. } => {}, - B { c: 1, .. } => {}, + //~^ redundant_guards _ => {}, } } @@ -206,7 +214,7 @@ fn issue11807() { #![allow(clippy::single_match)] match Some(Some("")) { - Some(Some("")) => {}, + Some(Some("")) => {}, //~ redundant_guards _ => {}, } @@ -217,12 +225,12 @@ fn issue11807() { } match Some(Some(&[] as &[i32])) { - Some(Some([])) => {}, + Some(Some([])) => {}, //~ redundant_guards _ => {}, } match Some(Some([] as [i32; 0])) { - Some(Some([])) => {}, + Some(Some([])) => {}, //~ redundant_guards _ => {}, } @@ -234,21 +242,25 @@ fn issue11807() { match Some(Some(&[] as &[i32])) { Some(Some([..])) => {}, + //~^ redundant_guards _ => {}, } match Some(Some(&[] as &[i32])) { Some(Some([1, ..])) => {}, + //~^ redundant_guards _ => {}, } match Some(Some(&[] as &[i32])) { Some(Some([1, 2, ..])) => {}, + //~^ redundant_guards _ => {}, } match Some(Some(&[] as &[i32])) { Some(Some([.., 1, 2])) => {}, + //~^ redundant_guards _ => {}, } diff --git a/tests/ui/redundant_guards.rs b/tests/ui/redundant_guards.rs index c8656f26ef33..d57e00039f1e 100644 --- a/tests/ui/redundant_guards.rs +++ b/tests/ui/redundant_guards.rs @@ -30,20 +30,23 @@ fn issue11304() { fn main() { let c = C(1, 2); match c { - C(x, y) if let 1 = y => .., + C(x, y) if let 1 = y => .., //~ redundant_guards _ => todo!(), }; let x = Some(Some(1)); match x { Some(x) if matches!(x, Some(1) if true) => .., + //~^ redundant_guards + + //~v redundant_guards Some(x) if matches!(x, Some(1)) => { println!("a"); .. }, - Some(x) if let Some(1) = x => .., - Some(x) if x == Some(2) => .., - Some(x) if Some(2) == x => .., + Some(x) if let Some(1) = x => .., //~ redundant_guards + Some(x) if x == Some(2) => .., //~ redundant_guards + Some(x) if Some(2) == x => .., //~ redundant_guards // Don't lint, since x is used in the body Some(x) if let Some(1) = x => { x; @@ -69,6 +72,7 @@ fn main() { let b = B { e: Some(A(0)) }; match b { B { e } if matches!(e, Some(A(2))) => .., + //~^ redundant_guards _ => todo!(), }; // Do not lint, since we cannot represent this as a pattern (at least, without a conversion) @@ -106,21 +110,22 @@ fn i() { // Do not lint E::A(x) | E::B(x) | E::C(x) if x == "from an or pattern" => {}, E::A(y) if y == "not from an or pattern" => {}, + //~^ redundant_guards _ => {}, }; } fn h(v: Option) { match v { - x if matches!(x, Some(0)) => .., + x if matches!(x, Some(0)) => .., //~ redundant_guards _ => .., }; } fn negative_literal(i: i32) { match i { - i if i == -1 => {}, - i if i == 1 => {}, + i if i == -1 => {}, //~ redundant_guards + i if i == 1 => {}, //~ redundant_guards _ => {}, } } @@ -170,10 +175,11 @@ mod issue11465 { fn issue11465() { let c = Some(1); match c { - Some(ref x) if x == &1 => {}, - Some(ref x) if &1 == x => {}, - Some(ref x) if let &2 = x => {}, + Some(ref x) if x == &1 => {}, //~ redundant_guards + Some(ref x) if &1 == x => {}, //~ redundant_guards + Some(ref x) if let &2 = x => {}, //~ redundant_guards Some(ref x) if matches!(x, &3) => {}, + //~^ redundant_guards _ => {}, }; @@ -193,10 +199,12 @@ mod issue11465 { match struct_b { B { ref b, .. } if b == "bar" => {}, B { ref b, .. } if "bar" == b => {}, - B { ref c, .. } if c == &1 => {}, - B { ref c, .. } if &1 == c => {}, + B { ref c, .. } if c == &1 => {}, //~ redundant_guards + B { ref c, .. } if &1 == c => {}, //~ redundant_guards B { ref c, .. } if let &1 = c => {}, + //~^ redundant_guards B { ref c, .. } if matches!(c, &1) => {}, + //~^ redundant_guards _ => {}, } } @@ -206,7 +214,7 @@ fn issue11807() { #![allow(clippy::single_match)] match Some(Some("")) { - Some(Some(x)) if x.is_empty() => {}, + Some(Some(x)) if x.is_empty() => {}, //~ redundant_guards _ => {}, } @@ -217,12 +225,12 @@ fn issue11807() { } match Some(Some(&[] as &[i32])) { - Some(Some(x)) if x.is_empty() => {}, + Some(Some(x)) if x.is_empty() => {}, //~ redundant_guards _ => {}, } match Some(Some([] as [i32; 0])) { - Some(Some(x)) if x.is_empty() => {}, + Some(Some(x)) if x.is_empty() => {}, //~ redundant_guards _ => {}, } @@ -234,21 +242,25 @@ fn issue11807() { match Some(Some(&[] as &[i32])) { Some(Some(x)) if x.starts_with(&[]) => {}, + //~^ redundant_guards _ => {}, } match Some(Some(&[] as &[i32])) { Some(Some(x)) if x.starts_with(&[1]) => {}, + //~^ redundant_guards _ => {}, } match Some(Some(&[] as &[i32])) { Some(Some(x)) if x.starts_with(&[1, 2]) => {}, + //~^ redundant_guards _ => {}, } match Some(Some(&[] as &[i32])) { Some(Some(x)) if x.ends_with(&[1, 2]) => {}, + //~^ redundant_guards _ => {}, } diff --git a/tests/ui/redundant_guards.stderr b/tests/ui/redundant_guards.stderr index 27bd8bfabb15..c0546ae06415 100644 --- a/tests/ui/redundant_guards.stderr +++ b/tests/ui/redundant_guards.stderr @@ -24,7 +24,7 @@ LL | Some(Some(1)) if true => .., | ~~~~~~~ ~~~~~~~ error: redundant guard - --> $DIR/redundant_guards.rs:40:20 + --> $DIR/redundant_guards.rs:43:20 | LL | Some(x) if matches!(x, Some(1)) => { | ^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL + Some(Some(1)) => { | error: redundant guard - --> $DIR/redundant_guards.rs:44:20 + --> $DIR/redundant_guards.rs:47:20 | LL | Some(x) if let Some(1) = x => .., | ^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + Some(Some(1)) => .., | error: redundant guard - --> $DIR/redundant_guards.rs:45:20 + --> $DIR/redundant_guards.rs:48:20 | LL | Some(x) if x == Some(2) => .., | ^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL + Some(Some(2)) => .., | error: redundant guard - --> $DIR/redundant_guards.rs:46:20 + --> $DIR/redundant_guards.rs:49:20 | LL | Some(x) if Some(2) == x => .., | ^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL + Some(Some(2)) => .., | error: redundant guard - --> $DIR/redundant_guards.rs:71:20 + --> $DIR/redundant_guards.rs:74:20 | LL | B { e } if matches!(e, Some(A(2))) => .., | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -84,7 +84,7 @@ LL + B { e: Some(A(2)) } => .., | error: redundant guard - --> $DIR/redundant_guards.rs:108:20 + --> $DIR/redundant_guards.rs:112:20 | LL | E::A(y) if y == "not from an or pattern" => {}, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL + E::A("not from an or pattern") => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:115:14 + --> $DIR/redundant_guards.rs:120:14 | LL | x if matches!(x, Some(0)) => .., | ^^^^^^^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL + Some(0) => .., | error: redundant guard - --> $DIR/redundant_guards.rs:122:14 + --> $DIR/redundant_guards.rs:127:14 | LL | i if i == -1 => {}, | ^^^^^^^ @@ -120,7 +120,7 @@ LL + -1 => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:123:14 + --> $DIR/redundant_guards.rs:128:14 | LL | i if i == 1 => {}, | ^^^^^^ @@ -132,7 +132,7 @@ LL + 1 => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:173:28 + --> $DIR/redundant_guards.rs:178:28 | LL | Some(ref x) if x == &1 => {}, | ^^^^^^^ @@ -144,7 +144,7 @@ LL + Some(1) => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:174:28 + --> $DIR/redundant_guards.rs:179:28 | LL | Some(ref x) if &1 == x => {}, | ^^^^^^^ @@ -156,7 +156,7 @@ LL + Some(1) => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:175:28 + --> $DIR/redundant_guards.rs:180:28 | LL | Some(ref x) if let &2 = x => {}, | ^^^^^^^^^^ @@ -168,7 +168,7 @@ LL + Some(2) => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:176:28 + --> $DIR/redundant_guards.rs:181:28 | LL | Some(ref x) if matches!(x, &3) => {}, | ^^^^^^^^^^^^^^^ @@ -180,7 +180,7 @@ LL + Some(3) => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:196:32 + --> $DIR/redundant_guards.rs:202:32 | LL | B { ref c, .. } if c == &1 => {}, | ^^^^^^^ @@ -192,7 +192,7 @@ LL + B { c: 1, .. } => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:197:32 + --> $DIR/redundant_guards.rs:203:32 | LL | B { ref c, .. } if &1 == c => {}, | ^^^^^^^ @@ -204,7 +204,7 @@ LL + B { c: 1, .. } => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:198:32 + --> $DIR/redundant_guards.rs:204:32 | LL | B { ref c, .. } if let &1 = c => {}, | ^^^^^^^^^^ @@ -216,7 +216,7 @@ LL + B { c: 1, .. } => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:199:32 + --> $DIR/redundant_guards.rs:206:32 | LL | B { ref c, .. } if matches!(c, &1) => {}, | ^^^^^^^^^^^^^^^ @@ -228,7 +228,7 @@ LL + B { c: 1, .. } => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:209:26 + --> $DIR/redundant_guards.rs:217:26 | LL | Some(Some(x)) if x.is_empty() => {}, | ^^^^^^^^^^^^ @@ -240,7 +240,7 @@ LL + Some(Some("")) => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:220:26 + --> $DIR/redundant_guards.rs:228:26 | LL | Some(Some(x)) if x.is_empty() => {}, | ^^^^^^^^^^^^ @@ -252,7 +252,7 @@ LL + Some(Some([])) => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:225:26 + --> $DIR/redundant_guards.rs:233:26 | LL | Some(Some(x)) if x.is_empty() => {}, | ^^^^^^^^^^^^ @@ -264,7 +264,7 @@ LL + Some(Some([])) => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:236:26 + --> $DIR/redundant_guards.rs:244:26 | LL | Some(Some(x)) if x.starts_with(&[]) => {}, | ^^^^^^^^^^^^^^^^^^ @@ -276,7 +276,7 @@ LL + Some(Some([..])) => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:241:26 + --> $DIR/redundant_guards.rs:250:26 | LL | Some(Some(x)) if x.starts_with(&[1]) => {}, | ^^^^^^^^^^^^^^^^^^^ @@ -288,7 +288,7 @@ LL + Some(Some([1, ..])) => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:246:26 + --> $DIR/redundant_guards.rs:256:26 | LL | Some(Some(x)) if x.starts_with(&[1, 2]) => {}, | ^^^^^^^^^^^^^^^^^^^^^^ @@ -300,7 +300,7 @@ LL + Some(Some([1, 2, ..])) => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:251:26 + --> $DIR/redundant_guards.rs:262:26 | LL | Some(Some(x)) if x.ends_with(&[1, 2]) => {}, | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_locals.rs b/tests/ui/redundant_locals.rs index f6909828aa9a..b1f19826fe62 100644 --- a/tests/ui/redundant_locals.rs +++ b/tests/ui/redundant_locals.rs @@ -10,12 +10,12 @@ fn main() {} fn immutable() { let x = 1; - let x = x; + let x = x; //~ redundant_locals } fn mutable() { let mut x = 1; - let mut x = x; + let mut x = x; //~ redundant_locals } fn upgraded_mutability() { @@ -45,38 +45,38 @@ fn coercion(par: &mut i32) { } fn parameter(x: i32) { - let x = x; + let x = x; //~ redundant_locals } fn many() { let x = 1; - let x = x; - let x = x; - let x = x; - let x = x; + let x = x; //~ redundant_locals + let x = x; //~ redundant_locals + let x = x; //~ redundant_locals + let x = x; //~ redundant_locals } fn interleaved() { let a = 1; let b = 2; - let a = a; - let b = b; + let a = a; //~ redundant_locals + let b = b; //~ redundant_locals } fn block() { { let x = 1; - let x = x; + let x = x; //~ redundant_locals } } fn closure() { || { let x = 1; - let x = x; + let x = x; //~ redundant_locals }; |x: i32| { - let x = x; + let x = x; //~ redundant_locals }; } @@ -95,7 +95,7 @@ fn inconsequential_drop_order() { let x = 1; { - let x = x; + let x = x; //~ redundant_locals } } @@ -150,7 +150,7 @@ fn drop_trait() { fn without_drop() { let a = WithoutDrop(1); let b = WithoutDrop(2); - let a = a; + let a = a; //~ redundant_locals } fn drop_inner() { diff --git a/tests/ui/redundant_pattern_matching_drop_order.fixed b/tests/ui/redundant_pattern_matching_drop_order.fixed index 148eaa4b33a6..1583387720f4 100644 --- a/tests/ui/redundant_pattern_matching_drop_order.fixed +++ b/tests/ui/redundant_pattern_matching_drop_order.fixed @@ -12,50 +12,71 @@ fn main() { let m = std::sync::Mutex::new((0, 0)); // Result - if m.lock().is_ok() {} + if m.lock().is_ok() {} //~ redundant_pattern_matching if Err::<(), _>(m.lock().unwrap().0).is_err() {} + //~^ redundant_pattern_matching { if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok() {} + //~^ redundant_pattern_matching } + //~v redundant_pattern_matching if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok() { } else { } if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok() {} + //~^ redundant_pattern_matching if Err::, _>(()).is_err() {} + //~^ redundant_pattern_matching if Ok::<_, ()>(String::new()).is_ok() {} + //~^ redundant_pattern_matching if Err::<(), _>((String::new(), ())).is_err() {} + //~^ redundant_pattern_matching // Option if Some(m.lock()).is_some() {} + //~^ redundant_pattern_matching if Some(m.lock().unwrap().0).is_some() {} + //~^ redundant_pattern_matching { if None::>.is_none() {} + //~^ redundant_pattern_matching } + //~v redundant_pattern_matching if None::>.is_none() { } else { } if None::>.is_none() {} + //~^ redundant_pattern_matching if Some(String::new()).is_some() {} + //~^ redundant_pattern_matching if Some((String::new(), ())).is_some() {} + //~^ redundant_pattern_matching // Poll if Ready(m.lock()).is_ready() {} + //~^ redundant_pattern_matching if Ready(m.lock().unwrap().0).is_ready() {} + //~^ redundant_pattern_matching { if Pending::>.is_pending() {} + //~^ redundant_pattern_matching } + //~v redundant_pattern_matching if Pending::>.is_pending() { } else { } if Pending::>.is_pending() {} + //~^ redundant_pattern_matching if Ready(String::new()).is_ready() {} + //~^ redundant_pattern_matching if Ready((String::new(), ())).is_ready() {} + //~^ redundant_pattern_matching } diff --git a/tests/ui/redundant_pattern_matching_drop_order.rs b/tests/ui/redundant_pattern_matching_drop_order.rs index 5bc06f3cc529..50a747c8e1e8 100644 --- a/tests/ui/redundant_pattern_matching_drop_order.rs +++ b/tests/ui/redundant_pattern_matching_drop_order.rs @@ -12,50 +12,71 @@ fn main() { let m = std::sync::Mutex::new((0, 0)); // Result - if let Ok(_) = m.lock() {} + if let Ok(_) = m.lock() {} //~ redundant_pattern_matching if let Err(_) = Err::<(), _>(m.lock().unwrap().0) {} + //~^ redundant_pattern_matching { if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {} + //~^ redundant_pattern_matching } + //~v redundant_pattern_matching if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) { } else { } if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {} + //~^ redundant_pattern_matching if let Err(_) = Err::, _>(()) {} + //~^ redundant_pattern_matching if let Ok(_) = Ok::<_, ()>(String::new()) {} + //~^ redundant_pattern_matching if let Err(_) = Err::<(), _>((String::new(), ())) {} + //~^ redundant_pattern_matching // Option if let Some(_) = Some(m.lock()) {} + //~^ redundant_pattern_matching if let Some(_) = Some(m.lock().unwrap().0) {} + //~^ redundant_pattern_matching { if let None = None::> {} + //~^ redundant_pattern_matching } + //~v redundant_pattern_matching if let None = None::> { } else { } if let None = None::> {} + //~^ redundant_pattern_matching if let Some(_) = Some(String::new()) {} + //~^ redundant_pattern_matching if let Some(_) = Some((String::new(), ())) {} + //~^ redundant_pattern_matching // Poll if let Ready(_) = Ready(m.lock()) {} + //~^ redundant_pattern_matching if let Ready(_) = Ready(m.lock().unwrap().0) {} + //~^ redundant_pattern_matching { if let Pending = Pending::> {} + //~^ redundant_pattern_matching } + //~v redundant_pattern_matching if let Pending = Pending::> { } else { } if let Pending = Pending::> {} + //~^ redundant_pattern_matching if let Ready(_) = Ready(String::new()) {} + //~^ redundant_pattern_matching if let Ready(_) = Ready((String::new(), ())) {} + //~^ redundant_pattern_matching } diff --git a/tests/ui/redundant_pattern_matching_drop_order.stderr b/tests/ui/redundant_pattern_matching_drop_order.stderr index 28f0244b9e87..3a2645fa8c5a 100644 --- a/tests/ui/redundant_pattern_matching_drop_order.stderr +++ b/tests/ui/redundant_pattern_matching_drop_order.stderr @@ -19,7 +19,7 @@ LL | if let Err(_) = Err::<(), _>(m.lock().unwrap().0) {} = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_drop_order.rs:19:16 + --> $DIR/redundant_pattern_matching_drop_order.rs:20:16 | LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {} | -------^^^^^----------------------------------------- help: try: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()` @@ -28,7 +28,7 @@ LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {} = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_drop_order.rs:21:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:24:12 | LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) { | -------^^^^^----------------------------------------- help: try: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()` @@ -37,31 +37,31 @@ LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) { = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_drop_order.rs:24:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:27:12 | LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {} | -------^^^^^----------------------------------------- help: try: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_drop_order.rs:25:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:29:12 | LL | if let Err(_) = Err::, _>(()) {} | -------^^^^^^------------------------------------------ help: try: `if Err::, _>(()).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_drop_order.rs:27:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:32:12 | LL | if let Ok(_) = Ok::<_, ()>(String::new()) {} | -------^^^^^----------------------------- help: try: `if Ok::<_, ()>(String::new()).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_drop_order.rs:28:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:34:12 | LL | if let Err(_) = Err::<(), _>((String::new(), ())) {} | -------^^^^^^------------------------------------ help: try: `if Err::<(), _>((String::new(), ())).is_err()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_drop_order.rs:31:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:38:12 | LL | if let Some(_) = Some(m.lock()) {} | -------^^^^^^^----------------- help: try: `if Some(m.lock()).is_some()` @@ -70,7 +70,7 @@ LL | if let Some(_) = Some(m.lock()) {} = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_drop_order.rs:32:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:40:12 | LL | if let Some(_) = Some(m.lock().unwrap().0) {} | -------^^^^^^^---------------------------- help: try: `if Some(m.lock().unwrap().0).is_some()` @@ -79,7 +79,7 @@ LL | if let Some(_) = Some(m.lock().unwrap().0) {} = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_drop_order.rs:35:16 + --> $DIR/redundant_pattern_matching_drop_order.rs:44:16 | LL | if let None = None::> {} | -------^^^^------------------------------------ help: try: `if None::>.is_none()` @@ -88,7 +88,7 @@ LL | if let None = None::> {} = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_drop_order.rs:37:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:48:12 | LL | if let None = None::> { | -------^^^^------------------------------------ help: try: `if None::>.is_none()` @@ -97,25 +97,25 @@ LL | if let None = None::> { = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_drop_order.rs:41:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:52:12 | LL | if let None = None::> {} | -------^^^^------------------------------------ help: try: `if None::>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_drop_order.rs:43:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:55:12 | LL | if let Some(_) = Some(String::new()) {} | -------^^^^^^^---------------------- help: try: `if Some(String::new()).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_drop_order.rs:44:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:57:12 | LL | if let Some(_) = Some((String::new(), ())) {} | -------^^^^^^^---------------------------- help: try: `if Some((String::new(), ())).is_some()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_drop_order.rs:47:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:61:12 | LL | if let Ready(_) = Ready(m.lock()) {} | -------^^^^^^^^------------------ help: try: `if Ready(m.lock()).is_ready()` @@ -124,7 +124,7 @@ LL | if let Ready(_) = Ready(m.lock()) {} = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_drop_order.rs:48:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:63:12 | LL | if let Ready(_) = Ready(m.lock().unwrap().0) {} | -------^^^^^^^^----------------------------- help: try: `if Ready(m.lock().unwrap().0).is_ready()` @@ -133,7 +133,7 @@ LL | if let Ready(_) = Ready(m.lock().unwrap().0) {} = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_drop_order.rs:51:16 + --> $DIR/redundant_pattern_matching_drop_order.rs:67:16 | LL | if let Pending = Pending::> {} | -------^^^^^^^--------------------------------------- help: try: `if Pending::>.is_pending()` @@ -142,7 +142,7 @@ LL | if let Pending = Pending::> {} = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_drop_order.rs:53:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:71:12 | LL | if let Pending = Pending::> { | -------^^^^^^^--------------------------------------- help: try: `if Pending::>.is_pending()` @@ -151,19 +151,19 @@ LL | if let Pending = Pending::> { = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_drop_order.rs:57:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:75:12 | LL | if let Pending = Pending::> {} | -------^^^^^^^--------------------------------------- help: try: `if Pending::>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_drop_order.rs:59:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:78:12 | LL | if let Ready(_) = Ready(String::new()) {} | -------^^^^^^^^----------------------- help: try: `if Ready(String::new()).is_ready()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_drop_order.rs:60:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:80:12 | LL | if let Ready(_) = Ready((String::new(), ())) {} | -------^^^^^^^^----------------------------- help: try: `if Ready((String::new(), ())).is_ready()` diff --git a/tests/ui/redundant_pattern_matching_if_let_true.fixed b/tests/ui/redundant_pattern_matching_if_let_true.fixed index 6d9106789340..0e7e4ccacaf1 100644 --- a/tests/ui/redundant_pattern_matching_if_let_true.fixed +++ b/tests/ui/redundant_pattern_matching_if_let_true.fixed @@ -19,19 +19,21 @@ macro_rules! lettrue { fn main() { let mut k = 5; - if k > 1 {} - if !(k > 5) {} - if k > 1 {} + if k > 1 {} //~ redundant_pattern_matching + if !(k > 5) {} //~ redundant_pattern_matching + if k > 1 {} //~ redundant_pattern_matching if let (true, true) = (k > 1, k > 2) {} + //~v redundant_pattern_matching while k > 1 { k += 1; } + //~v redundant_pattern_matching while condition!() { k += 1; } - k > 5; - !(k > 5); + k > 5; //~ redundant_pattern_matching + !(k > 5); //~ redundant_pattern_matching // Whole loop is from a macro expansion, don't lint: lettrue!(if); lettrue!(while); diff --git a/tests/ui/redundant_pattern_matching_if_let_true.rs b/tests/ui/redundant_pattern_matching_if_let_true.rs index a82e673982a3..3742c6771167 100644 --- a/tests/ui/redundant_pattern_matching_if_let_true.rs +++ b/tests/ui/redundant_pattern_matching_if_let_true.rs @@ -19,19 +19,21 @@ macro_rules! lettrue { fn main() { let mut k = 5; - if let true = k > 1 {} - if let false = k > 5 {} - if let (true) = k > 1 {} + if let true = k > 1 {} //~ redundant_pattern_matching + if let false = k > 5 {} //~ redundant_pattern_matching + if let (true) = k > 1 {} //~ redundant_pattern_matching if let (true, true) = (k > 1, k > 2) {} + //~v redundant_pattern_matching while let true = k > 1 { k += 1; } + //~v redundant_pattern_matching while let true = condition!() { k += 1; } - matches!(k > 5, true); - matches!(k > 5, false); + matches!(k > 5, true); //~ redundant_pattern_matching + matches!(k > 5, false); //~ redundant_pattern_matching // Whole loop is from a macro expansion, don't lint: lettrue!(if); lettrue!(while); diff --git a/tests/ui/redundant_pattern_matching_if_let_true.stderr b/tests/ui/redundant_pattern_matching_if_let_true.stderr index 211a332d79a6..85b8c6fb0be8 100644 --- a/tests/ui/redundant_pattern_matching_if_let_true.stderr +++ b/tests/ui/redundant_pattern_matching_if_let_true.stderr @@ -20,25 +20,25 @@ LL | if let (true) = k > 1 {} | ^^^^^^^^^^^^^^^^^^ help: consider using the condition directly: `k > 1` error: using `if let` to pattern match a bool - --> $DIR/redundant_pattern_matching_if_let_true.rs:26:11 + --> $DIR/redundant_pattern_matching_if_let_true.rs:27:11 | LL | while let true = k > 1 { | ^^^^^^^^^^^^^^^^ help: consider using the condition directly: `k > 1` error: using `if let` to pattern match a bool - --> $DIR/redundant_pattern_matching_if_let_true.rs:29:11 + --> $DIR/redundant_pattern_matching_if_let_true.rs:31:11 | LL | while let true = condition!() { | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the condition directly: `condition!()` error: using `matches!` to pattern match a bool - --> $DIR/redundant_pattern_matching_if_let_true.rs:33:5 + --> $DIR/redundant_pattern_matching_if_let_true.rs:35:5 | LL | matches!(k > 5, true); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using the condition directly: `k > 5` error: using `matches!` to pattern match a bool - --> $DIR/redundant_pattern_matching_if_let_true.rs:34:5 + --> $DIR/redundant_pattern_matching_if_let_true.rs:36:5 | LL | matches!(k > 5, false); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using the condition directly: `!(k > 5)` diff --git a/tests/ui/redundant_pattern_matching_ipaddr.fixed b/tests/ui/redundant_pattern_matching_ipaddr.fixed index 429d33118a58..15fab502b28f 100644 --- a/tests/ui/redundant_pattern_matching_ipaddr.fixed +++ b/tests/ui/redundant_pattern_matching_ipaddr.fixed @@ -12,21 +12,27 @@ use std::net::{Ipv4Addr, Ipv6Addr}; fn main() { let ipaddr: IpAddr = V4(Ipv4Addr::LOCALHOST); - if ipaddr.is_ipv4() {} + if ipaddr.is_ipv4() {} //~ redundant_pattern_matching if V4(Ipv4Addr::LOCALHOST).is_ipv4() {} + //~^ redundant_pattern_matching if V6(Ipv6Addr::LOCALHOST).is_ipv6() {} + //~^ redundant_pattern_matching // Issue 6459 if V4(Ipv4Addr::LOCALHOST).is_ipv4() {} + //~^ redundant_pattern_matching // Issue 6459 if V6(Ipv6Addr::LOCALHOST).is_ipv6() {} + //~^ redundant_pattern_matching while V4(Ipv4Addr::LOCALHOST).is_ipv4() {} + //~^ redundant_pattern_matching while V6(Ipv6Addr::LOCALHOST).is_ipv6() {} + //~^ redundant_pattern_matching if V4(Ipv4Addr::LOCALHOST).is_ipv4() {} @@ -36,14 +42,19 @@ fn main() { println!("{}", ipaddr); } + //~v redundant_pattern_matching V4(Ipv4Addr::LOCALHOST).is_ipv4(); + //~v redundant_pattern_matching V4(Ipv4Addr::LOCALHOST).is_ipv6(); + //~v redundant_pattern_matching V6(Ipv6Addr::LOCALHOST).is_ipv6(); + //~v redundant_pattern_matching V6(Ipv6Addr::LOCALHOST).is_ipv4(); + //~v redundant_pattern_matching let _ = if V4(Ipv4Addr::LOCALHOST).is_ipv4() { true } else { @@ -52,8 +63,10 @@ fn main() { ipaddr_const(); + //~v redundant_pattern_matching let _ = if gen_ipaddr().is_ipv4() { 1 + //~v redundant_pattern_matching } else if gen_ipaddr().is_ipv6() { 2 } else { @@ -67,14 +80,20 @@ fn gen_ipaddr() -> IpAddr { const fn ipaddr_const() { if V4(Ipv4Addr::LOCALHOST).is_ipv4() {} + //~^ redundant_pattern_matching if V6(Ipv6Addr::LOCALHOST).is_ipv6() {} + //~^ redundant_pattern_matching while V4(Ipv4Addr::LOCALHOST).is_ipv4() {} + //~^ redundant_pattern_matching while V6(Ipv6Addr::LOCALHOST).is_ipv6() {} + //~^ redundant_pattern_matching + //~v redundant_pattern_matching V4(Ipv4Addr::LOCALHOST).is_ipv4(); + //~v redundant_pattern_matching V6(Ipv6Addr::LOCALHOST).is_ipv6(); } diff --git a/tests/ui/redundant_pattern_matching_ipaddr.rs b/tests/ui/redundant_pattern_matching_ipaddr.rs index e7136b72c20c..d97138e0c5fd 100644 --- a/tests/ui/redundant_pattern_matching_ipaddr.rs +++ b/tests/ui/redundant_pattern_matching_ipaddr.rs @@ -12,21 +12,27 @@ use std::net::{Ipv4Addr, Ipv6Addr}; fn main() { let ipaddr: IpAddr = V4(Ipv4Addr::LOCALHOST); - if let V4(_) = &ipaddr {} + if let V4(_) = &ipaddr {} //~ redundant_pattern_matching if let V4(_) = V4(Ipv4Addr::LOCALHOST) {} + //~^ redundant_pattern_matching if let V6(_) = V6(Ipv6Addr::LOCALHOST) {} + //~^ redundant_pattern_matching // Issue 6459 if matches!(V4(Ipv4Addr::LOCALHOST), V4(_)) {} + //~^ redundant_pattern_matching // Issue 6459 if matches!(V6(Ipv6Addr::LOCALHOST), V6(_)) {} + //~^ redundant_pattern_matching while let V4(_) = V4(Ipv4Addr::LOCALHOST) {} + //~^ redundant_pattern_matching while let V6(_) = V6(Ipv6Addr::LOCALHOST) {} + //~^ redundant_pattern_matching if V4(Ipv4Addr::LOCALHOST).is_ipv4() {} @@ -36,26 +42,31 @@ fn main() { println!("{}", ipaddr); } + //~v redundant_pattern_matching match V4(Ipv4Addr::LOCALHOST) { V4(_) => true, V6(_) => false, }; + //~v redundant_pattern_matching match V4(Ipv4Addr::LOCALHOST) { V4(_) => false, V6(_) => true, }; + //~v redundant_pattern_matching match V6(Ipv6Addr::LOCALHOST) { V4(_) => false, V6(_) => true, }; + //~v redundant_pattern_matching match V6(Ipv6Addr::LOCALHOST) { V4(_) => true, V6(_) => false, }; + //~v redundant_pattern_matching let _ = if let V4(_) = V4(Ipv4Addr::LOCALHOST) { true } else { @@ -64,8 +75,10 @@ fn main() { ipaddr_const(); + //~v redundant_pattern_matching let _ = if let V4(_) = gen_ipaddr() { 1 + //~v redundant_pattern_matching } else if let V6(_) = gen_ipaddr() { 2 } else { @@ -79,18 +92,24 @@ fn gen_ipaddr() -> IpAddr { const fn ipaddr_const() { if let V4(_) = V4(Ipv4Addr::LOCALHOST) {} + //~^ redundant_pattern_matching if let V6(_) = V6(Ipv6Addr::LOCALHOST) {} + //~^ redundant_pattern_matching while let V4(_) = V4(Ipv4Addr::LOCALHOST) {} + //~^ redundant_pattern_matching while let V6(_) = V6(Ipv6Addr::LOCALHOST) {} + //~^ redundant_pattern_matching + //~v redundant_pattern_matching match V4(Ipv4Addr::LOCALHOST) { V4(_) => true, V6(_) => false, }; + //~v redundant_pattern_matching match V6(Ipv6Addr::LOCALHOST) { V4(_) => false, V6(_) => true, diff --git a/tests/ui/redundant_pattern_matching_ipaddr.stderr b/tests/ui/redundant_pattern_matching_ipaddr.stderr index 54cefa5e82b1..51276081304d 100644 --- a/tests/ui/redundant_pattern_matching_ipaddr.stderr +++ b/tests/ui/redundant_pattern_matching_ipaddr.stderr @@ -14,37 +14,37 @@ LL | if let V4(_) = V4(Ipv4Addr::LOCALHOST) {} | -------^^^^^-------------------------- help: try: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:19:12 + --> $DIR/redundant_pattern_matching_ipaddr.rs:20:12 | LL | if let V6(_) = V6(Ipv6Addr::LOCALHOST) {} | -------^^^^^-------------------------- help: try: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:22:8 + --> $DIR/redundant_pattern_matching_ipaddr.rs:24:8 | LL | if matches!(V4(Ipv4Addr::LOCALHOST), V4(_)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:25:8 + --> $DIR/redundant_pattern_matching_ipaddr.rs:28:8 | LL | if matches!(V6(Ipv6Addr::LOCALHOST), V6(_)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:27:15 + --> $DIR/redundant_pattern_matching_ipaddr.rs:31:15 | LL | while let V4(_) = V4(Ipv4Addr::LOCALHOST) {} | ----------^^^^^-------------------------- help: try: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:29:15 + --> $DIR/redundant_pattern_matching_ipaddr.rs:34:15 | LL | while let V6(_) = V6(Ipv6Addr::LOCALHOST) {} | ----------^^^^^-------------------------- help: try: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:39:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:46:5 | LL | / match V4(Ipv4Addr::LOCALHOST) { LL | | V4(_) => true, @@ -53,7 +53,7 @@ LL | | }; | |_____^ help: try: `V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:44:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:52:5 | LL | / match V4(Ipv4Addr::LOCALHOST) { LL | | V4(_) => false, @@ -62,7 +62,7 @@ LL | | }; | |_____^ help: try: `V4(Ipv4Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:49:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:58:5 | LL | / match V6(Ipv6Addr::LOCALHOST) { LL | | V4(_) => false, @@ -71,7 +71,7 @@ LL | | }; | |_____^ help: try: `V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:54:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:64:5 | LL | / match V6(Ipv6Addr::LOCALHOST) { LL | | V4(_) => true, @@ -80,49 +80,49 @@ LL | | }; | |_____^ help: try: `V6(Ipv6Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:59:20 + --> $DIR/redundant_pattern_matching_ipaddr.rs:70:20 | LL | let _ = if let V4(_) = V4(Ipv4Addr::LOCALHOST) { | -------^^^^^-------------------------- help: try: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:67:20 + --> $DIR/redundant_pattern_matching_ipaddr.rs:79:20 | LL | let _ = if let V4(_) = gen_ipaddr() { | -------^^^^^--------------- help: try: `if gen_ipaddr().is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:69:19 + --> $DIR/redundant_pattern_matching_ipaddr.rs:82:19 | LL | } else if let V6(_) = gen_ipaddr() { | -------^^^^^--------------- help: try: `if gen_ipaddr().is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:81:12 + --> $DIR/redundant_pattern_matching_ipaddr.rs:94:12 | LL | if let V4(_) = V4(Ipv4Addr::LOCALHOST) {} | -------^^^^^-------------------------- help: try: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:83:12 + --> $DIR/redundant_pattern_matching_ipaddr.rs:97:12 | LL | if let V6(_) = V6(Ipv6Addr::LOCALHOST) {} | -------^^^^^-------------------------- help: try: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:85:15 + --> $DIR/redundant_pattern_matching_ipaddr.rs:100:15 | LL | while let V4(_) = V4(Ipv4Addr::LOCALHOST) {} | ----------^^^^^-------------------------- help: try: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:87:15 + --> $DIR/redundant_pattern_matching_ipaddr.rs:103:15 | LL | while let V6(_) = V6(Ipv6Addr::LOCALHOST) {} | ----------^^^^^-------------------------- help: try: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:89:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:107:5 | LL | / match V4(Ipv4Addr::LOCALHOST) { LL | | V4(_) => true, @@ -131,7 +131,7 @@ LL | | }; | |_____^ help: try: `V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:94:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:113:5 | LL | / match V6(Ipv6Addr::LOCALHOST) { LL | | V4(_) => false, diff --git a/tests/ui/redundant_pattern_matching_option.fixed b/tests/ui/redundant_pattern_matching_option.fixed index c9b76262d70b..c9eead3714f4 100644 --- a/tests/ui/redundant_pattern_matching_option.fixed +++ b/tests/ui/redundant_pattern_matching_option.fixed @@ -12,9 +12,11 @@ fn issue_11174(boolean: bool, maybe_some: Option) -> bool { maybe_some.is_none() && (!boolean) + //~^ redundant_pattern_matching } fn issue_11174_edge_cases(boolean: bool, boolean2: bool, maybe_some: Option) { + //~v redundant_pattern_matching let _ = maybe_some.is_none() && (boolean || boolean2); // guard needs parentheses let _ = match maybe_some { // can't use `matches!` here @@ -29,23 +31,25 @@ fn issue_11174_edge_cases(boolean: bool, boolean2: bool, maybe_some: Option.is_none() {} + if None::<()>.is_none() {} //~ redundant_pattern_matching - if Some(42).is_some() {} + if Some(42).is_some() {} //~ redundant_pattern_matching + //~v redundant_pattern_matching if Some(42).is_some() { foo(); } else { bar(); } - while Some(42).is_some() {} + while Some(42).is_some() {} //~ redundant_pattern_matching - while Some(42).is_none() {} + while Some(42).is_none() {} //~ redundant_pattern_matching - while None::<()>.is_none() {} + while None::<()>.is_none() {} //~ redundant_pattern_matching let mut v = vec![1, 2, 3]; + //~v redundant_pattern_matching while v.pop().is_some() { foo(); } @@ -54,28 +58,34 @@ fn main() { if Some(42).is_some() {} + //~v redundant_pattern_matching Some(42).is_some(); + //~v redundant_pattern_matching None::<()>.is_none(); + //~v redundant_pattern_matching let _ = None::<()>.is_none(); let opt = Some(false); let _ = if opt.is_some() { true } else { false }; + //~^ redundant_pattern_matching issue6067(); issue10726(); issue10803(); + //~v redundant_pattern_matching let _ = if gen_opt().is_some() { 1 + //~v redundant_pattern_matching } else if gen_opt().is_none() { 2 } else { 3 }; - if gen_opt().is_some() {} + if gen_opt().is_some() {} //~ redundant_pattern_matching } fn gen_opt() -> Option<()> { @@ -90,34 +100,40 @@ fn bar() {} // However, in Rust 1.48.0 the methods `is_some` and `is_none` of `Option` were stabilized as const, // so the following should be linted. const fn issue6067() { - if Some(42).is_some() {} + if Some(42).is_some() {} //~ redundant_pattern_matching - if None::<()>.is_none() {} + if None::<()>.is_none() {} //~ redundant_pattern_matching - while Some(42).is_some() {} + while Some(42).is_some() {} //~ redundant_pattern_matching - while None::<()>.is_none() {} + while None::<()>.is_none() {} //~ redundant_pattern_matching + //~v redundant_pattern_matching Some(42).is_some(); + //~v redundant_pattern_matching None::<()>.is_none(); } #[allow(clippy::deref_addrof, dead_code, clippy::needless_borrow)] fn issue7921() { - if (&None::<()>).is_none() {} - if (&None::<()>).is_none() {} + if (&None::<()>).is_none() {} //~ redundant_pattern_matching + if (&None::<()>).is_none() {} //~ redundant_pattern_matching } fn issue10726() { let x = Some(42); + //~v redundant_pattern_matching x.is_some(); + //~v redundant_pattern_matching x.is_none(); + //~v redundant_pattern_matching x.is_none(); + //~v redundant_pattern_matching x.is_some(); // Don't lint @@ -130,9 +146,9 @@ fn issue10726() { fn issue10803() { let x = Some(42); - let _ = x.is_some(); + let _ = x.is_some(); //~ redundant_pattern_matching - let _ = x.is_none(); + let _ = x.is_none(); //~ redundant_pattern_matching // Don't lint let _ = matches!(x, Some(16)); diff --git a/tests/ui/redundant_pattern_matching_option.rs b/tests/ui/redundant_pattern_matching_option.rs index a5f9caf659c6..955e88b26af1 100644 --- a/tests/ui/redundant_pattern_matching_option.rs +++ b/tests/ui/redundant_pattern_matching_option.rs @@ -12,9 +12,11 @@ fn issue_11174(boolean: bool, maybe_some: Option) -> bool { matches!(maybe_some, None if !boolean) + //~^ redundant_pattern_matching } fn issue_11174_edge_cases(boolean: bool, boolean2: bool, maybe_some: Option) { + //~v redundant_pattern_matching let _ = matches!(maybe_some, None if boolean || boolean2); // guard needs parentheses let _ = match maybe_some { // can't use `matches!` here @@ -29,23 +31,25 @@ fn issue_11174_edge_cases(boolean: bool, boolean2: bool, maybe_some: Option {} + if let None = None::<()> {} //~ redundant_pattern_matching - if let Some(_) = Some(42) {} + if let Some(_) = Some(42) {} //~ redundant_pattern_matching + //~v redundant_pattern_matching if let Some(_) = Some(42) { foo(); } else { bar(); } - while let Some(_) = Some(42) {} + while let Some(_) = Some(42) {} //~ redundant_pattern_matching - while let None = Some(42) {} + while let None = Some(42) {} //~ redundant_pattern_matching - while let None = None::<()> {} + while let None = None::<()> {} //~ redundant_pattern_matching let mut v = vec![1, 2, 3]; + //~v redundant_pattern_matching while let Some(_) = v.pop() { foo(); } @@ -54,16 +58,19 @@ fn main() { if Some(42).is_some() {} + //~v redundant_pattern_matching match Some(42) { Some(_) => true, None => false, }; + //~v redundant_pattern_matching match None::<()> { Some(_) => false, None => true, }; + //~v redundant_pattern_matching let _ = match None::<()> { Some(_) => false, None => true, @@ -71,20 +78,23 @@ fn main() { let opt = Some(false); let _ = if let Some(_) = opt { true } else { false }; + //~^ redundant_pattern_matching issue6067(); issue10726(); issue10803(); + //~v redundant_pattern_matching let _ = if let Some(_) = gen_opt() { 1 + //~v redundant_pattern_matching } else if let None = gen_opt() { 2 } else { 3 }; - if let Some(..) = gen_opt() {} + if let Some(..) = gen_opt() {} //~ redundant_pattern_matching } fn gen_opt() -> Option<()> { @@ -99,19 +109,21 @@ fn bar() {} // However, in Rust 1.48.0 the methods `is_some` and `is_none` of `Option` were stabilized as const, // so the following should be linted. const fn issue6067() { - if let Some(_) = Some(42) {} + if let Some(_) = Some(42) {} //~ redundant_pattern_matching - if let None = None::<()> {} + if let None = None::<()> {} //~ redundant_pattern_matching - while let Some(_) = Some(42) {} + while let Some(_) = Some(42) {} //~ redundant_pattern_matching - while let None = None::<()> {} + while let None = None::<()> {} //~ redundant_pattern_matching + //~v redundant_pattern_matching match Some(42) { Some(_) => true, None => false, }; + //~v redundant_pattern_matching match None::<()> { Some(_) => false, None => true, @@ -120,28 +132,32 @@ const fn issue6067() { #[allow(clippy::deref_addrof, dead_code, clippy::needless_borrow)] fn issue7921() { - if let None = *(&None::<()>) {} - if let None = *&None::<()> {} + if let None = *(&None::<()>) {} //~ redundant_pattern_matching + if let None = *&None::<()> {} //~ redundant_pattern_matching } fn issue10726() { let x = Some(42); + //~v redundant_pattern_matching match x { Some(_) => true, _ => false, }; + //~v redundant_pattern_matching match x { None => true, _ => false, }; + //~v redundant_pattern_matching match x { Some(_) => false, _ => true, }; + //~v redundant_pattern_matching match x { None => false, _ => true, @@ -157,9 +173,9 @@ fn issue10726() { fn issue10803() { let x = Some(42); - let _ = matches!(x, Some(_)); + let _ = matches!(x, Some(_)); //~ redundant_pattern_matching - let _ = matches!(x, None); + let _ = matches!(x, None); //~ redundant_pattern_matching // Don't lint let _ = matches!(x, Some(16)); diff --git a/tests/ui/redundant_pattern_matching_option.stderr b/tests/ui/redundant_pattern_matching_option.stderr index a75551c56f29..cdcf19b312d0 100644 --- a/tests/ui/redundant_pattern_matching_option.stderr +++ b/tests/ui/redundant_pattern_matching_option.stderr @@ -8,55 +8,55 @@ LL | matches!(maybe_some, None if !boolean) = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:18:13 + --> $DIR/redundant_pattern_matching_option.rs:20:13 | LL | let _ = matches!(maybe_some, None if boolean || boolean2); // guard needs parentheses | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `maybe_some.is_none() && (boolean || boolean2)` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:32:12 + --> $DIR/redundant_pattern_matching_option.rs:34:12 | LL | if let None = None::<()> {} | -------^^^^------------- help: try: `if None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:34:12 + --> $DIR/redundant_pattern_matching_option.rs:36:12 | LL | if let Some(_) = Some(42) {} | -------^^^^^^^----------- help: try: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:36:12 + --> $DIR/redundant_pattern_matching_option.rs:39:12 | LL | if let Some(_) = Some(42) { | -------^^^^^^^----------- help: try: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:42:15 + --> $DIR/redundant_pattern_matching_option.rs:45:15 | LL | while let Some(_) = Some(42) {} | ----------^^^^^^^----------- help: try: `while Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:44:15 + --> $DIR/redundant_pattern_matching_option.rs:47:15 | LL | while let None = Some(42) {} | ----------^^^^----------- help: try: `while Some(42).is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:46:15 + --> $DIR/redundant_pattern_matching_option.rs:49:15 | LL | while let None = None::<()> {} | ----------^^^^------------- help: try: `while None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:49:15 + --> $DIR/redundant_pattern_matching_option.rs:53:15 | LL | while let Some(_) = v.pop() { | ----------^^^^^^^---------- help: try: `while v.pop().is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:57:5 + --> $DIR/redundant_pattern_matching_option.rs:62:5 | LL | / match Some(42) { LL | | Some(_) => true, @@ -65,7 +65,7 @@ LL | | }; | |_____^ help: try: `Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:62:5 + --> $DIR/redundant_pattern_matching_option.rs:68:5 | LL | / match None::<()> { LL | | Some(_) => false, @@ -74,7 +74,7 @@ LL | | }; | |_____^ help: try: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:67:13 + --> $DIR/redundant_pattern_matching_option.rs:74:13 | LL | let _ = match None::<()> { | _____________^ @@ -84,55 +84,55 @@ LL | | }; | |_____^ help: try: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:73:20 + --> $DIR/redundant_pattern_matching_option.rs:80:20 | LL | let _ = if let Some(_) = opt { true } else { false }; | -------^^^^^^^------ help: try: `if opt.is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:79:20 + --> $DIR/redundant_pattern_matching_option.rs:88:20 | LL | let _ = if let Some(_) = gen_opt() { | -------^^^^^^^------------ help: try: `if gen_opt().is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:81:19 + --> $DIR/redundant_pattern_matching_option.rs:91:19 | LL | } else if let None = gen_opt() { | -------^^^^------------ help: try: `if gen_opt().is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:87:12 + --> $DIR/redundant_pattern_matching_option.rs:97:12 | LL | if let Some(..) = gen_opt() {} | -------^^^^^^^^------------ help: try: `if gen_opt().is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:102:12 + --> $DIR/redundant_pattern_matching_option.rs:112:12 | LL | if let Some(_) = Some(42) {} | -------^^^^^^^----------- help: try: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:104:12 + --> $DIR/redundant_pattern_matching_option.rs:114:12 | LL | if let None = None::<()> {} | -------^^^^------------- help: try: `if None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:106:15 + --> $DIR/redundant_pattern_matching_option.rs:116:15 | LL | while let Some(_) = Some(42) {} | ----------^^^^^^^----------- help: try: `while Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:108:15 + --> $DIR/redundant_pattern_matching_option.rs:118:15 | LL | while let None = None::<()> {} | ----------^^^^------------- help: try: `while None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:110:5 + --> $DIR/redundant_pattern_matching_option.rs:121:5 | LL | / match Some(42) { LL | | Some(_) => true, @@ -141,7 +141,7 @@ LL | | }; | |_____^ help: try: `Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:115:5 + --> $DIR/redundant_pattern_matching_option.rs:127:5 | LL | / match None::<()> { LL | | Some(_) => false, @@ -150,19 +150,19 @@ LL | | }; | |_____^ help: try: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:123:12 + --> $DIR/redundant_pattern_matching_option.rs:135:12 | LL | if let None = *(&None::<()>) {} | -------^^^^----------------- help: try: `if (&None::<()>).is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:124:12 + --> $DIR/redundant_pattern_matching_option.rs:136:12 | LL | if let None = *&None::<()> {} | -------^^^^--------------- help: try: `if (&None::<()>).is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:130:5 + --> $DIR/redundant_pattern_matching_option.rs:143:5 | LL | / match x { LL | | Some(_) => true, @@ -171,7 +171,7 @@ LL | | }; | |_____^ help: try: `x.is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:135:5 + --> $DIR/redundant_pattern_matching_option.rs:149:5 | LL | / match x { LL | | None => true, @@ -180,7 +180,7 @@ LL | | }; | |_____^ help: try: `x.is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:140:5 + --> $DIR/redundant_pattern_matching_option.rs:155:5 | LL | / match x { LL | | Some(_) => false, @@ -189,7 +189,7 @@ LL | | }; | |_____^ help: try: `x.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:145:5 + --> $DIR/redundant_pattern_matching_option.rs:161:5 | LL | / match x { LL | | None => false, @@ -198,13 +198,13 @@ LL | | }; | |_____^ help: try: `x.is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:160:13 + --> $DIR/redundant_pattern_matching_option.rs:176:13 | LL | let _ = matches!(x, Some(_)); | ^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:162:13 + --> $DIR/redundant_pattern_matching_option.rs:178:13 | LL | let _ = matches!(x, None); | ^^^^^^^^^^^^^^^^^ help: try: `x.is_none()` diff --git a/tests/ui/redundant_pattern_matching_poll.fixed b/tests/ui/redundant_pattern_matching_poll.fixed index 08d83f87e4c3..be54a9201ad0 100644 --- a/tests/ui/redundant_pattern_matching_poll.fixed +++ b/tests/ui/redundant_pattern_matching_poll.fixed @@ -12,10 +12,11 @@ use std::task::Poll::{self, Pending, Ready}; fn main() { - if Pending::<()>.is_pending() {} + if Pending::<()>.is_pending() {} //~ redundant_pattern_matching - if Ready(42).is_ready() {} + if Ready(42).is_ready() {} //~ redundant_pattern_matching + //~v redundant_pattern_matching if Ready(42).is_ready() { foo(); } else { @@ -24,33 +25,42 @@ fn main() { // Issue 6459 if Ready(42).is_ready() {} + //~^ redundant_pattern_matching // Issue 6459 if Pending::<()>.is_pending() {} + //~^ redundant_pattern_matching - while Ready(42).is_ready() {} + while Ready(42).is_ready() {} //~ redundant_pattern_matching - while Ready(42).is_pending() {} + while Ready(42).is_pending() {} //~ redundant_pattern_matching while Pending::<()>.is_pending() {} + //~^ redundant_pattern_matching if Pending::.is_pending() {} if Ready(42).is_ready() {} + //~v redundant_pattern_matching Ready(42).is_ready(); + //~v redundant_pattern_matching Pending::<()>.is_pending(); + //~v redundant_pattern_matching let _ = Pending::<()>.is_pending(); let poll = Ready(false); let _ = if poll.is_ready() { true } else { false }; + //~^ redundant_pattern_matching poll_const(); + //~v redundant_pattern_matching let _ = if gen_poll().is_ready() { 1 + //~v redundant_pattern_matching } else if gen_poll().is_pending() { 2 } else { @@ -67,15 +77,18 @@ fn foo() {} fn bar() {} const fn poll_const() { - if Ready(42).is_ready() {} + if Ready(42).is_ready() {} //~ redundant_pattern_matching - if Pending::<()>.is_pending() {} + if Pending::<()>.is_pending() {} //~ redundant_pattern_matching - while Ready(42).is_ready() {} + while Ready(42).is_ready() {} //~ redundant_pattern_matching while Pending::<()>.is_pending() {} + //~^ redundant_pattern_matching + //~v redundant_pattern_matching Ready(42).is_ready(); + //~v redundant_pattern_matching Pending::<()>.is_pending(); } diff --git a/tests/ui/redundant_pattern_matching_poll.rs b/tests/ui/redundant_pattern_matching_poll.rs index 7bc2b3be4d34..57a4baba6ab6 100644 --- a/tests/ui/redundant_pattern_matching_poll.rs +++ b/tests/ui/redundant_pattern_matching_poll.rs @@ -12,10 +12,11 @@ use std::task::Poll::{self, Pending, Ready}; fn main() { - if let Pending = Pending::<()> {} + if let Pending = Pending::<()> {} //~ redundant_pattern_matching - if let Ready(_) = Ready(42) {} + if let Ready(_) = Ready(42) {} //~ redundant_pattern_matching + //~v redundant_pattern_matching if let Ready(_) = Ready(42) { foo(); } else { @@ -24,30 +25,36 @@ fn main() { // Issue 6459 if matches!(Ready(42), Ready(_)) {} + //~^ redundant_pattern_matching // Issue 6459 if matches!(Pending::<()>, Pending) {} + //~^ redundant_pattern_matching - while let Ready(_) = Ready(42) {} + while let Ready(_) = Ready(42) {} //~ redundant_pattern_matching - while let Pending = Ready(42) {} + while let Pending = Ready(42) {} //~ redundant_pattern_matching while let Pending = Pending::<()> {} + //~^ redundant_pattern_matching if Pending::.is_pending() {} if Ready(42).is_ready() {} + //~v redundant_pattern_matching match Ready(42) { Ready(_) => true, Pending => false, }; + //~v redundant_pattern_matching match Pending::<()> { Ready(_) => false, Pending => true, }; + //~v redundant_pattern_matching let _ = match Pending::<()> { Ready(_) => false, Pending => true, @@ -55,11 +62,14 @@ fn main() { let poll = Ready(false); let _ = if let Ready(_) = poll { true } else { false }; + //~^ redundant_pattern_matching poll_const(); + //~v redundant_pattern_matching let _ = if let Ready(_) = gen_poll() { 1 + //~v redundant_pattern_matching } else if let Pending = gen_poll() { 2 } else { @@ -76,19 +86,22 @@ fn foo() {} fn bar() {} const fn poll_const() { - if let Ready(_) = Ready(42) {} + if let Ready(_) = Ready(42) {} //~ redundant_pattern_matching - if let Pending = Pending::<()> {} + if let Pending = Pending::<()> {} //~ redundant_pattern_matching - while let Ready(_) = Ready(42) {} + while let Ready(_) = Ready(42) {} //~ redundant_pattern_matching while let Pending = Pending::<()> {} + //~^ redundant_pattern_matching + //~v redundant_pattern_matching match Ready(42) { Ready(_) => true, Pending => false, }; + //~v redundant_pattern_matching match Pending::<()> { Ready(_) => false, Pending => true, diff --git a/tests/ui/redundant_pattern_matching_poll.stderr b/tests/ui/redundant_pattern_matching_poll.stderr index de64331b4e8c..fd2828100b85 100644 --- a/tests/ui/redundant_pattern_matching_poll.stderr +++ b/tests/ui/redundant_pattern_matching_poll.stderr @@ -14,43 +14,43 @@ LL | if let Ready(_) = Ready(42) {} | -------^^^^^^^^------------ help: try: `if Ready(42).is_ready()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:19:12 + --> $DIR/redundant_pattern_matching_poll.rs:20:12 | LL | if let Ready(_) = Ready(42) { | -------^^^^^^^^------------ help: try: `if Ready(42).is_ready()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:26:8 + --> $DIR/redundant_pattern_matching_poll.rs:27:8 | LL | if matches!(Ready(42), Ready(_)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:29:8 + --> $DIR/redundant_pattern_matching_poll.rs:31:8 | LL | if matches!(Pending::<()>, Pending) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:31:15 + --> $DIR/redundant_pattern_matching_poll.rs:34:15 | LL | while let Ready(_) = Ready(42) {} | ----------^^^^^^^^------------ help: try: `while Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:33:15 + --> $DIR/redundant_pattern_matching_poll.rs:36:15 | LL | while let Pending = Ready(42) {} | ----------^^^^^^^------------ help: try: `while Ready(42).is_pending()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:35:15 + --> $DIR/redundant_pattern_matching_poll.rs:38:15 | LL | while let Pending = Pending::<()> {} | ----------^^^^^^^---------------- help: try: `while Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:41:5 + --> $DIR/redundant_pattern_matching_poll.rs:46:5 | LL | / match Ready(42) { LL | | Ready(_) => true, @@ -59,7 +59,7 @@ LL | | }; | |_____^ help: try: `Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:46:5 + --> $DIR/redundant_pattern_matching_poll.rs:52:5 | LL | / match Pending::<()> { LL | | Ready(_) => false, @@ -68,7 +68,7 @@ LL | | }; | |_____^ help: try: `Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:51:13 + --> $DIR/redundant_pattern_matching_poll.rs:58:13 | LL | let _ = match Pending::<()> { | _____________^ @@ -78,49 +78,49 @@ LL | | }; | |_____^ help: try: `Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:57:20 + --> $DIR/redundant_pattern_matching_poll.rs:64:20 | LL | let _ = if let Ready(_) = poll { true } else { false }; | -------^^^^^^^^------- help: try: `if poll.is_ready()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:61:20 + --> $DIR/redundant_pattern_matching_poll.rs:70:20 | LL | let _ = if let Ready(_) = gen_poll() { | -------^^^^^^^^------------- help: try: `if gen_poll().is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:63:19 + --> $DIR/redundant_pattern_matching_poll.rs:73:19 | LL | } else if let Pending = gen_poll() { | -------^^^^^^^------------- help: try: `if gen_poll().is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:79:12 + --> $DIR/redundant_pattern_matching_poll.rs:89:12 | LL | if let Ready(_) = Ready(42) {} | -------^^^^^^^^------------ help: try: `if Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:81:12 + --> $DIR/redundant_pattern_matching_poll.rs:91:12 | LL | if let Pending = Pending::<()> {} | -------^^^^^^^---------------- help: try: `if Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:83:15 + --> $DIR/redundant_pattern_matching_poll.rs:93:15 | LL | while let Ready(_) = Ready(42) {} | ----------^^^^^^^^------------ help: try: `while Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:85:15 + --> $DIR/redundant_pattern_matching_poll.rs:95:15 | LL | while let Pending = Pending::<()> {} | ----------^^^^^^^---------------- help: try: `while Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:87:5 + --> $DIR/redundant_pattern_matching_poll.rs:99:5 | LL | / match Ready(42) { LL | | Ready(_) => true, @@ -129,7 +129,7 @@ LL | | }; | |_____^ help: try: `Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:92:5 + --> $DIR/redundant_pattern_matching_poll.rs:105:5 | LL | / match Pending::<()> { LL | | Ready(_) => false, diff --git a/tests/ui/redundant_pattern_matching_result.fixed b/tests/ui/redundant_pattern_matching_result.fixed index 9571aaee7424..22120e1a4ba8 100644 --- a/tests/ui/redundant_pattern_matching_result.fixed +++ b/tests/ui/redundant_pattern_matching_result.fixed @@ -12,15 +12,19 @@ fn main() { let result: Result = Err(5); - if result.is_ok() {} + if result.is_ok() {} //~ redundant_pattern_matching if Ok::(42).is_ok() {} + //~^ redundant_pattern_matching if Err::(42).is_err() {} + //~^ redundant_pattern_matching while Ok::(10).is_ok() {} + //~^ redundant_pattern_matching while Ok::(10).is_err() {} + //~^ redundant_pattern_matching if Ok::(42).is_ok() {} @@ -30,15 +34,20 @@ fn main() { println!("{}", x); } + //~v redundant_pattern_matching Ok::(42).is_ok(); + //~v redundant_pattern_matching Ok::(42).is_err(); + //~v redundant_pattern_matching Err::(42).is_err(); + //~v redundant_pattern_matching Err::(42).is_ok(); let _ = if Ok::(4).is_ok() { true } else { false }; + //~^ redundant_pattern_matching issue5504(); issue6067(); @@ -46,8 +55,10 @@ fn main() { issue10726(); issue10803(); + //~v redundant_pattern_matching let _ = if gen_res().is_ok() { 1 + //~v redundant_pattern_matching } else if gen_res().is_err() { 2 } else { @@ -72,14 +83,16 @@ fn issue5504() { fn try_result_opt() -> Result { while r#try!(result_opt()).is_some() {} + //~^ redundant_pattern_matching if r#try!(result_opt()).is_some() {} + //~^ redundant_pattern_matching Ok(42) } try_result_opt(); - if m!().is_some() {} - while m!().is_some() {} + if m!().is_some() {} //~ redundant_pattern_matching + while m!().is_some() {} //~ redundant_pattern_matching } fn issue6065() { @@ -98,15 +111,21 @@ fn issue6065() { // so the following should be linted. const fn issue6067() { if Ok::(42).is_ok() {} + //~^ redundant_pattern_matching if Err::(42).is_err() {} + //~^ redundant_pattern_matching while Ok::(10).is_ok() {} + //~^ redundant_pattern_matching while Ok::(10).is_err() {} + //~^ redundant_pattern_matching + //~v redundant_pattern_matching Ok::(42).is_ok(); + //~v redundant_pattern_matching Err::(42).is_err(); } @@ -114,12 +133,16 @@ fn issue10726() { // This is optional, but it makes the examples easier let x: Result = Ok(42); + //~v redundant_pattern_matching x.is_ok(); + //~v redundant_pattern_matching x.is_err(); + //~v redundant_pattern_matching x.is_err(); + //~v redundant_pattern_matching x.is_ok(); // Don't lint @@ -138,9 +161,9 @@ fn issue10726() { fn issue10803() { let x: Result = Ok(42); - let _ = x.is_ok(); + let _ = x.is_ok(); //~ redundant_pattern_matching - let _ = x.is_err(); + let _ = x.is_err(); //~ redundant_pattern_matching // Don't lint let _ = matches!(x, Ok(16)); diff --git a/tests/ui/redundant_pattern_matching_result.rs b/tests/ui/redundant_pattern_matching_result.rs index 4fc65aa70b54..7eaa7c26c81f 100644 --- a/tests/ui/redundant_pattern_matching_result.rs +++ b/tests/ui/redundant_pattern_matching_result.rs @@ -12,15 +12,19 @@ fn main() { let result: Result = Err(5); - if let Ok(_) = &result {} + if let Ok(_) = &result {} //~ redundant_pattern_matching if let Ok(_) = Ok::(42) {} + //~^ redundant_pattern_matching if let Err(_) = Err::(42) {} + //~^ redundant_pattern_matching while let Ok(_) = Ok::(10) {} + //~^ redundant_pattern_matching while let Err(_) = Ok::(10) {} + //~^ redundant_pattern_matching if Ok::(42).is_ok() {} @@ -30,27 +34,32 @@ fn main() { println!("{}", x); } + //~v redundant_pattern_matching match Ok::(42) { Ok(_) => true, Err(_) => false, }; + //~v redundant_pattern_matching match Ok::(42) { Ok(_) => false, Err(_) => true, }; + //~v redundant_pattern_matching match Err::(42) { Ok(_) => false, Err(_) => true, }; + //~v redundant_pattern_matching match Err::(42) { Ok(_) => true, Err(_) => false, }; let _ = if let Ok(_) = Ok::(4) { true } else { false }; + //~^ redundant_pattern_matching issue5504(); issue6067(); @@ -58,8 +67,10 @@ fn main() { issue10726(); issue10803(); + //~v redundant_pattern_matching let _ = if let Ok(_) = gen_res() { 1 + //~v redundant_pattern_matching } else if let Err(_) = gen_res() { 2 } else { @@ -84,14 +95,16 @@ fn issue5504() { fn try_result_opt() -> Result { while let Some(_) = r#try!(result_opt()) {} + //~^ redundant_pattern_matching if let Some(_) = r#try!(result_opt()) {} + //~^ redundant_pattern_matching Ok(42) } try_result_opt(); - if let Some(_) = m!() {} - while let Some(_) = m!() {} + if let Some(_) = m!() {} //~ redundant_pattern_matching + while let Some(_) = m!() {} //~ redundant_pattern_matching } fn issue6065() { @@ -110,18 +123,24 @@ fn issue6065() { // so the following should be linted. const fn issue6067() { if let Ok(_) = Ok::(42) {} + //~^ redundant_pattern_matching if let Err(_) = Err::(42) {} + //~^ redundant_pattern_matching while let Ok(_) = Ok::(10) {} + //~^ redundant_pattern_matching while let Err(_) = Ok::(10) {} + //~^ redundant_pattern_matching + //~v redundant_pattern_matching match Ok::(42) { Ok(_) => true, Err(_) => false, }; + //~v redundant_pattern_matching match Err::(42) { Ok(_) => false, Err(_) => true, @@ -132,21 +151,25 @@ fn issue10726() { // This is optional, but it makes the examples easier let x: Result = Ok(42); + //~v redundant_pattern_matching match x { Ok(_) => true, _ => false, }; + //~v redundant_pattern_matching match x { Ok(_) => false, _ => true, }; + //~v redundant_pattern_matching match x { Err(_) => true, _ => false, }; + //~v redundant_pattern_matching match x { Err(_) => false, _ => true, @@ -168,9 +191,9 @@ fn issue10726() { fn issue10803() { let x: Result = Ok(42); - let _ = matches!(x, Ok(_)); + let _ = matches!(x, Ok(_)); //~ redundant_pattern_matching - let _ = matches!(x, Err(_)); + let _ = matches!(x, Err(_)); //~ redundant_pattern_matching // Don't lint let _ = matches!(x, Ok(16)); diff --git a/tests/ui/redundant_pattern_matching_result.stderr b/tests/ui/redundant_pattern_matching_result.stderr index 19e7f82298ea..ea51fada1983 100644 --- a/tests/ui/redundant_pattern_matching_result.stderr +++ b/tests/ui/redundant_pattern_matching_result.stderr @@ -14,25 +14,25 @@ LL | if let Ok(_) = Ok::(42) {} | -------^^^^^--------------------- help: try: `if Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:19:12 + --> $DIR/redundant_pattern_matching_result.rs:20:12 | LL | if let Err(_) = Err::(42) {} | -------^^^^^^---------------------- help: try: `if Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:21:15 + --> $DIR/redundant_pattern_matching_result.rs:23:15 | LL | while let Ok(_) = Ok::(10) {} | ----------^^^^^--------------------- help: try: `while Ok::(10).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:23:15 + --> $DIR/redundant_pattern_matching_result.rs:26:15 | LL | while let Err(_) = Ok::(10) {} | ----------^^^^^^--------------------- help: try: `while Ok::(10).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:33:5 + --> $DIR/redundant_pattern_matching_result.rs:38:5 | LL | / match Ok::(42) { LL | | Ok(_) => true, @@ -41,7 +41,7 @@ LL | | }; | |_____^ help: try: `Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:38:5 + --> $DIR/redundant_pattern_matching_result.rs:44:5 | LL | / match Ok::(42) { LL | | Ok(_) => false, @@ -50,7 +50,7 @@ LL | | }; | |_____^ help: try: `Ok::(42).is_err()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:43:5 + --> $DIR/redundant_pattern_matching_result.rs:50:5 | LL | / match Err::(42) { LL | | Ok(_) => false, @@ -59,7 +59,7 @@ LL | | }; | |_____^ help: try: `Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:48:5 + --> $DIR/redundant_pattern_matching_result.rs:56:5 | LL | / match Err::(42) { LL | | Ok(_) => true, @@ -68,73 +68,73 @@ LL | | }; | |_____^ help: try: `Err::(42).is_ok()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:53:20 + --> $DIR/redundant_pattern_matching_result.rs:61:20 | LL | let _ = if let Ok(_) = Ok::(4) { true } else { false }; | -------^^^^^--------------------- help: try: `if Ok::(4).is_ok()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:61:20 + --> $DIR/redundant_pattern_matching_result.rs:71:20 | LL | let _ = if let Ok(_) = gen_res() { | -------^^^^^------------ help: try: `if gen_res().is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:63:19 + --> $DIR/redundant_pattern_matching_result.rs:74:19 | LL | } else if let Err(_) = gen_res() { | -------^^^^^^------------ help: try: `if gen_res().is_err()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_result.rs:86:19 + --> $DIR/redundant_pattern_matching_result.rs:97:19 | LL | while let Some(_) = r#try!(result_opt()) {} | ----------^^^^^^^----------------------- help: try: `while r#try!(result_opt()).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_result.rs:87:16 + --> $DIR/redundant_pattern_matching_result.rs:99:16 | LL | if let Some(_) = r#try!(result_opt()) {} | -------^^^^^^^----------------------- help: try: `if r#try!(result_opt()).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_result.rs:93:12 + --> $DIR/redundant_pattern_matching_result.rs:106:12 | LL | if let Some(_) = m!() {} | -------^^^^^^^------- help: try: `if m!().is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_result.rs:94:15 + --> $DIR/redundant_pattern_matching_result.rs:107:15 | LL | while let Some(_) = m!() {} | ----------^^^^^^^------- help: try: `while m!().is_some()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:112:12 + --> $DIR/redundant_pattern_matching_result.rs:125:12 | LL | if let Ok(_) = Ok::(42) {} | -------^^^^^--------------------- help: try: `if Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:114:12 + --> $DIR/redundant_pattern_matching_result.rs:128:12 | LL | if let Err(_) = Err::(42) {} | -------^^^^^^---------------------- help: try: `if Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:116:15 + --> $DIR/redundant_pattern_matching_result.rs:131:15 | LL | while let Ok(_) = Ok::(10) {} | ----------^^^^^--------------------- help: try: `while Ok::(10).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:118:15 + --> $DIR/redundant_pattern_matching_result.rs:134:15 | LL | while let Err(_) = Ok::(10) {} | ----------^^^^^^--------------------- help: try: `while Ok::(10).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:120:5 + --> $DIR/redundant_pattern_matching_result.rs:138:5 | LL | / match Ok::(42) { LL | | Ok(_) => true, @@ -143,7 +143,7 @@ LL | | }; | |_____^ help: try: `Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:125:5 + --> $DIR/redundant_pattern_matching_result.rs:144:5 | LL | / match Err::(42) { LL | | Ok(_) => false, @@ -152,7 +152,7 @@ LL | | }; | |_____^ help: try: `Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:135:5 + --> $DIR/redundant_pattern_matching_result.rs:155:5 | LL | / match x { LL | | Ok(_) => true, @@ -161,7 +161,7 @@ LL | | }; | |_____^ help: try: `x.is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:140:5 + --> $DIR/redundant_pattern_matching_result.rs:161:5 | LL | / match x { LL | | Ok(_) => false, @@ -170,7 +170,7 @@ LL | | }; | |_____^ help: try: `x.is_err()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:145:5 + --> $DIR/redundant_pattern_matching_result.rs:167:5 | LL | / match x { LL | | Err(_) => true, @@ -179,7 +179,7 @@ LL | | }; | |_____^ help: try: `x.is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:150:5 + --> $DIR/redundant_pattern_matching_result.rs:173:5 | LL | / match x { LL | | Err(_) => false, @@ -188,13 +188,13 @@ LL | | }; | |_____^ help: try: `x.is_ok()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:171:13 + --> $DIR/redundant_pattern_matching_result.rs:194:13 | LL | let _ = matches!(x, Ok(_)); | ^^^^^^^^^^^^^^^^^^ help: try: `x.is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:173:13 + --> $DIR/redundant_pattern_matching_result.rs:196:13 | LL | let _ = matches!(x, Err(_)); | ^^^^^^^^^^^^^^^^^^^ help: try: `x.is_err()` diff --git a/tests/ui/redundant_pub_crate.fixed b/tests/ui/redundant_pub_crate.fixed index e1d845721a9c..e9e0b5e11d76 100644 --- a/tests/ui/redundant_pub_crate.fixed +++ b/tests/ui/redundant_pub_crate.fixed @@ -3,24 +3,29 @@ mod m1 { fn f() {} + //~v redundant_pub_crate pub fn g() {} // private due to m1 pub fn h() {} mod m1_1 { fn f() {} + //~v redundant_pub_crate pub fn g() {} // private due to m1_1 and m1 pub fn h() {} } + //~v redundant_pub_crate pub mod m1_2 { //:^ private due to m1 fn f() {} + //~v redundant_pub_crate pub fn g() {} // private due to m1_2 and m1 pub fn h() {} } pub mod m1_3 { fn f() {} + //~v redundant_pub_crate pub fn g() {} // private due to m1 pub fn h() {} } @@ -28,24 +33,29 @@ mod m1 { pub(crate) mod m2 { fn f() {} + //~v redundant_pub_crate pub fn g() {} // already crate visible due to m2 pub fn h() {} mod m2_1 { fn f() {} + //~v redundant_pub_crate pub fn g() {} // private due to m2_1 pub fn h() {} } + //~v redundant_pub_crate pub mod m2_2 { //:^ already crate visible due to m2 fn f() {} + //~v redundant_pub_crate pub fn g() {} // already crate visible due to m2_2 and m2 pub fn h() {} } pub mod m2_3 { fn f() {} + //~v redundant_pub_crate pub fn g() {} // already crate visible due to m2 pub fn h() {} } @@ -58,6 +68,7 @@ pub mod m3 { mod m3_1 { fn f() {} + //~v redundant_pub_crate pub fn g() {} // private due to m3_1 pub fn h() {} } @@ -65,6 +76,7 @@ pub mod m3 { pub(crate) mod m3_2 { //:^ ok fn f() {} + //~v redundant_pub_crate pub fn g() {} // already crate visible due to m3_2 pub fn h() {} } @@ -78,18 +90,22 @@ pub mod m3 { mod m4 { fn f() {} + //~v redundant_pub_crate pub fn g() {} // private: not re-exported by `pub use m4::*` pub fn h() {} mod m4_1 { fn f() {} + //~v redundant_pub_crate pub fn g() {} // private due to m4_1 pub fn h() {} } + //~v redundant_pub_crate pub mod m4_2 { //:^ private: not re-exported by `pub use m4::*` fn f() {} + //~v redundant_pub_crate pub fn g() {} // private due to m4_2 pub fn h() {} } diff --git a/tests/ui/redundant_pub_crate.rs b/tests/ui/redundant_pub_crate.rs index 4d7f44892d0c..3292186250e3 100644 --- a/tests/ui/redundant_pub_crate.rs +++ b/tests/ui/redundant_pub_crate.rs @@ -3,24 +3,29 @@ mod m1 { fn f() {} + //~v redundant_pub_crate pub(crate) fn g() {} // private due to m1 pub fn h() {} mod m1_1 { fn f() {} + //~v redundant_pub_crate pub(crate) fn g() {} // private due to m1_1 and m1 pub fn h() {} } + //~v redundant_pub_crate pub(crate) mod m1_2 { //:^ private due to m1 fn f() {} + //~v redundant_pub_crate pub(crate) fn g() {} // private due to m1_2 and m1 pub fn h() {} } pub mod m1_3 { fn f() {} + //~v redundant_pub_crate pub(crate) fn g() {} // private due to m1 pub fn h() {} } @@ -28,24 +33,29 @@ mod m1 { pub(crate) mod m2 { fn f() {} + //~v redundant_pub_crate pub(crate) fn g() {} // already crate visible due to m2 pub fn h() {} mod m2_1 { fn f() {} + //~v redundant_pub_crate pub(crate) fn g() {} // private due to m2_1 pub fn h() {} } + //~v redundant_pub_crate pub(crate) mod m2_2 { //:^ already crate visible due to m2 fn f() {} + //~v redundant_pub_crate pub(crate) fn g() {} // already crate visible due to m2_2 and m2 pub fn h() {} } pub mod m2_3 { fn f() {} + //~v redundant_pub_crate pub(crate) fn g() {} // already crate visible due to m2 pub fn h() {} } @@ -58,6 +68,7 @@ pub mod m3 { mod m3_1 { fn f() {} + //~v redundant_pub_crate pub(crate) fn g() {} // private due to m3_1 pub fn h() {} } @@ -65,6 +76,7 @@ pub mod m3 { pub(crate) mod m3_2 { //:^ ok fn f() {} + //~v redundant_pub_crate pub(crate) fn g() {} // already crate visible due to m3_2 pub fn h() {} } @@ -78,18 +90,22 @@ pub mod m3 { mod m4 { fn f() {} + //~v redundant_pub_crate pub(crate) fn g() {} // private: not re-exported by `pub use m4::*` pub fn h() {} mod m4_1 { fn f() {} + //~v redundant_pub_crate pub(crate) fn g() {} // private due to m4_1 pub fn h() {} } + //~v redundant_pub_crate pub(crate) mod m4_2 { //:^ private: not re-exported by `pub use m4::*` fn f() {} + //~v redundant_pub_crate pub(crate) fn g() {} // private due to m4_2 pub fn h() {} } diff --git a/tests/ui/redundant_pub_crate.stderr b/tests/ui/redundant_pub_crate.stderr index 5d7744aa8649..a579b2ad388e 100644 --- a/tests/ui/redundant_pub_crate.stderr +++ b/tests/ui/redundant_pub_crate.stderr @@ -1,5 +1,5 @@ error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:6:5 + --> $DIR/redundant_pub_crate.rs:7:5 | LL | pub(crate) fn g() {} // private due to m1 | ----------^^^^^ @@ -10,7 +10,7 @@ LL | pub(crate) fn g() {} // private due to m1 = help: to override `-D warnings` add `#[allow(clippy::redundant_pub_crate)]` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:11:9 + --> $DIR/redundant_pub_crate.rs:13:9 | LL | pub(crate) fn g() {} // private due to m1_1 and m1 | ----------^^^^^ @@ -18,7 +18,7 @@ LL | pub(crate) fn g() {} // private due to m1_1 and m1 | help: consider using: `pub` error: pub(crate) module inside private module - --> $DIR/redundant_pub_crate.rs:15:5 + --> $DIR/redundant_pub_crate.rs:18:5 | LL | pub(crate) mod m1_2 { | ----------^^^^^^^^^ @@ -26,7 +26,7 @@ LL | pub(crate) mod m1_2 { | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:18:9 + --> $DIR/redundant_pub_crate.rs:22:9 | LL | pub(crate) fn g() {} // private due to m1_2 and m1 | ----------^^^^^ @@ -34,7 +34,7 @@ LL | pub(crate) fn g() {} // private due to m1_2 and m1 | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:24:9 + --> $DIR/redundant_pub_crate.rs:29:9 | LL | pub(crate) fn g() {} // private due to m1 | ----------^^^^^ @@ -42,7 +42,7 @@ LL | pub(crate) fn g() {} // private due to m1 | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:31:5 + --> $DIR/redundant_pub_crate.rs:37:5 | LL | pub(crate) fn g() {} // already crate visible due to m2 | ----------^^^^^ @@ -50,7 +50,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m2 | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:36:9 + --> $DIR/redundant_pub_crate.rs:43:9 | LL | pub(crate) fn g() {} // private due to m2_1 | ----------^^^^^ @@ -58,7 +58,7 @@ LL | pub(crate) fn g() {} // private due to m2_1 | help: consider using: `pub` error: pub(crate) module inside private module - --> $DIR/redundant_pub_crate.rs:40:5 + --> $DIR/redundant_pub_crate.rs:48:5 | LL | pub(crate) mod m2_2 { | ----------^^^^^^^^^ @@ -66,7 +66,7 @@ LL | pub(crate) mod m2_2 { | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:43:9 + --> $DIR/redundant_pub_crate.rs:52:9 | LL | pub(crate) fn g() {} // already crate visible due to m2_2 and m2 | ----------^^^^^ @@ -74,7 +74,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m2_2 and m2 | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:49:9 + --> $DIR/redundant_pub_crate.rs:59:9 | LL | pub(crate) fn g() {} // already crate visible due to m2 | ----------^^^^^ @@ -82,7 +82,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m2 | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:61:9 + --> $DIR/redundant_pub_crate.rs:72:9 | LL | pub(crate) fn g() {} // private due to m3_1 | ----------^^^^^ @@ -90,7 +90,7 @@ LL | pub(crate) fn g() {} // private due to m3_1 | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:68:9 + --> $DIR/redundant_pub_crate.rs:80:9 | LL | pub(crate) fn g() {} // already crate visible due to m3_2 | ----------^^^^^ @@ -98,7 +98,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m3_2 | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:81:5 + --> $DIR/redundant_pub_crate.rs:94:5 | LL | pub(crate) fn g() {} // private: not re-exported by `pub use m4::*` | ----------^^^^^ @@ -106,7 +106,7 @@ LL | pub(crate) fn g() {} // private: not re-exported by `pub use m4::*` | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:86:9 + --> $DIR/redundant_pub_crate.rs:100:9 | LL | pub(crate) fn g() {} // private due to m4_1 | ----------^^^^^ @@ -114,7 +114,7 @@ LL | pub(crate) fn g() {} // private due to m4_1 | help: consider using: `pub` error: pub(crate) module inside private module - --> $DIR/redundant_pub_crate.rs:90:5 + --> $DIR/redundant_pub_crate.rs:105:5 | LL | pub(crate) mod m4_2 { | ----------^^^^^^^^^ @@ -122,7 +122,7 @@ LL | pub(crate) mod m4_2 { | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:93:9 + --> $DIR/redundant_pub_crate.rs:109:9 | LL | pub(crate) fn g() {} // private due to m4_2 | ----------^^^^^ diff --git a/tests/ui/redundant_slicing.fixed b/tests/ui/redundant_slicing.fixed index a4c035ba8407..0a58918ab2c0 100644 --- a/tests/ui/redundant_slicing.fixed +++ b/tests/ui/redundant_slicing.fixed @@ -5,10 +5,13 @@ use std::io::Read; fn main() { let slice: &[u32] = &[0]; + //~v redundant_slicing let _ = slice; // Redundant slice let v = vec![0]; let _ = &v[..]; // Ok, results in `&[_]` + + //~v redundant_slicing let _ = (&*v); // Outer borrow is redundant static S: &[u8] = &[0, 1, 2]; @@ -26,7 +29,7 @@ fn main() { $e }; } - let _ = slice; + let _ = slice; //~ redundant_slicing macro_rules! m2 { ($e:expr) => { diff --git a/tests/ui/redundant_slicing.rs b/tests/ui/redundant_slicing.rs index 67fe702acf54..752fdc4eab50 100644 --- a/tests/ui/redundant_slicing.rs +++ b/tests/ui/redundant_slicing.rs @@ -5,10 +5,13 @@ use std::io::Read; fn main() { let slice: &[u32] = &[0]; + //~v redundant_slicing let _ = &slice[..]; // Redundant slice let v = vec![0]; let _ = &v[..]; // Ok, results in `&[_]` + + //~v redundant_slicing let _ = &(&*v)[..]; // Outer borrow is redundant static S: &[u8] = &[0, 1, 2]; @@ -26,7 +29,7 @@ fn main() { $e }; } - let _ = &m!(slice)[..]; + let _ = &m!(slice)[..]; //~ redundant_slicing macro_rules! m2 { ($e:expr) => { diff --git a/tests/ui/redundant_slicing.stderr b/tests/ui/redundant_slicing.stderr index 05287c882f7e..b6a9e8a1a7f3 100644 --- a/tests/ui/redundant_slicing.stderr +++ b/tests/ui/redundant_slicing.stderr @@ -1,5 +1,5 @@ error: redundant slicing of the whole range - --> $DIR/redundant_slicing.rs:8:13 + --> $DIR/redundant_slicing.rs:9:13 | LL | let _ = &slice[..]; // Redundant slice | ^^^^^^^^^^ help: use the original value instead: `slice` @@ -8,13 +8,13 @@ LL | let _ = &slice[..]; // Redundant slice = help: to override `-D warnings` add `#[allow(clippy::redundant_slicing)]` error: redundant slicing of the whole range - --> $DIR/redundant_slicing.rs:12:13 + --> $DIR/redundant_slicing.rs:15:13 | LL | let _ = &(&*v)[..]; // Outer borrow is redundant | ^^^^^^^^^^ help: use the original value instead: `(&*v)` error: redundant slicing of the whole range - --> $DIR/redundant_slicing.rs:29:13 + --> $DIR/redundant_slicing.rs:32:13 | LL | let _ = &m!(slice)[..]; | ^^^^^^^^^^^^^^ help: use the original value instead: `slice` diff --git a/tests/ui/redundant_static_lifetimes.fixed b/tests/ui/redundant_static_lifetimes.fixed index 9787bb635e70..d5a0fb463506 100644 --- a/tests/ui/redundant_static_lifetimes.fixed +++ b/tests/ui/redundant_static_lifetimes.fixed @@ -3,41 +3,57 @@ #[derive(Debug)] struct Foo; +//~v redundant_static_lifetimes const VAR_ONE: &str = "Test constant #1"; // ERROR: Consider removing 'static. const VAR_TWO: &str = "Test constant #2"; // This line should not raise a warning. +//~v redundant_static_lifetimes const VAR_THREE: &[&str] = &["one", "two"]; // ERROR: Consider removing 'static +//~| redundant_static_lifetimes +//~v redundant_static_lifetimes const VAR_FOUR: (&str, (&str, &str), &str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static -const VAR_SIX: &u8 = &5; +const VAR_SIX: &u8 = &5; //~ redundant_static_lifetimes const VAR_HEIGHT: &Foo = &Foo {}; +//~^ redundant_static_lifetimes +//~v redundant_static_lifetimes const VAR_SLICE: &[u8] = b"Test constant #1"; // ERROR: Consider removing 'static. +//~v redundant_static_lifetimes const VAR_TUPLE: &(u8, u8) = &(1, 2); // ERROR: Consider removing 'static. +//~v redundant_static_lifetimes const VAR_ARRAY: &[u8; 1] = b"T"; // ERROR: Consider removing 'static. +//~v redundant_static_lifetimes static STATIC_VAR_ONE: &str = "Test static #1"; // ERROR: Consider removing 'static. static STATIC_VAR_TWO: &str = "Test static #2"; // This line should not raise a warning. +//~v redundant_static_lifetimes static STATIC_VAR_THREE: &[&str] = &["one", "two"]; // ERROR: Consider removing 'static static STATIC_VAR_SIX: &u8 = &5; +//~^ redundant_static_lifetimes static STATIC_VAR_HEIGHT: &Foo = &Foo {}; +//~^ redundant_static_lifetimes +//~v redundant_static_lifetimes static STATIC_VAR_SLICE: &[u8] = b"Test static #3"; // ERROR: Consider removing 'static. +//~v redundant_static_lifetimes static STATIC_VAR_TUPLE: &(u8, u8) = &(1, 2); // ERROR: Consider removing 'static. +//~v redundant_static_lifetimes static STATIC_VAR_ARRAY: &[u8; 1] = b"T"; // ERROR: Consider removing 'static. static mut STATIC_MUT_SLICE: &mut [u32] = &mut [0]; +//~^ redundant_static_lifetimes fn main() { let false_positive: &'static str = "test"; @@ -66,5 +82,5 @@ fn msrv_1_16() { #[clippy::msrv = "1.17"] fn msrv_1_17() { - static V: &u8 = &17; + static V: &u8 = &17; //~ redundant_static_lifetimes } diff --git a/tests/ui/redundant_static_lifetimes.rs b/tests/ui/redundant_static_lifetimes.rs index b5a4827fa948..35bc985dd31d 100644 --- a/tests/ui/redundant_static_lifetimes.rs +++ b/tests/ui/redundant_static_lifetimes.rs @@ -3,41 +3,57 @@ #[derive(Debug)] struct Foo; +//~v redundant_static_lifetimes const VAR_ONE: &'static str = "Test constant #1"; // ERROR: Consider removing 'static. const VAR_TWO: &str = "Test constant #2"; // This line should not raise a warning. +//~v redundant_static_lifetimes const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR: Consider removing 'static +//~| redundant_static_lifetimes +//~v redundant_static_lifetimes const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static -const VAR_SIX: &'static u8 = &5; +const VAR_SIX: &'static u8 = &5; //~ redundant_static_lifetimes const VAR_HEIGHT: &'static Foo = &Foo {}; +//~^ redundant_static_lifetimes +//~v redundant_static_lifetimes const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR: Consider removing 'static. +//~v redundant_static_lifetimes const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR: Consider removing 'static. +//~v redundant_static_lifetimes const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR: Consider removing 'static. +//~v redundant_static_lifetimes static STATIC_VAR_ONE: &'static str = "Test static #1"; // ERROR: Consider removing 'static. static STATIC_VAR_TWO: &str = "Test static #2"; // This line should not raise a warning. +//~v redundant_static_lifetimes static STATIC_VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR: Consider removing 'static static STATIC_VAR_SIX: &'static u8 = &5; +//~^ redundant_static_lifetimes static STATIC_VAR_HEIGHT: &'static Foo = &Foo {}; +//~^ redundant_static_lifetimes +//~v redundant_static_lifetimes static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR: Consider removing 'static. +//~v redundant_static_lifetimes static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR: Consider removing 'static. +//~v redundant_static_lifetimes static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR: Consider removing 'static. static mut STATIC_MUT_SLICE: &'static mut [u32] = &mut [0]; +//~^ redundant_static_lifetimes fn main() { let false_positive: &'static str = "test"; @@ -66,5 +82,5 @@ fn msrv_1_16() { #[clippy::msrv = "1.17"] fn msrv_1_17() { - static V: &'static u8 = &17; + static V: &'static u8 = &17; //~ redundant_static_lifetimes } diff --git a/tests/ui/redundant_static_lifetimes.stderr b/tests/ui/redundant_static_lifetimes.stderr index 26f50345351f..94e6a4e4b7aa 100644 --- a/tests/ui/redundant_static_lifetimes.stderr +++ b/tests/ui/redundant_static_lifetimes.stderr @@ -1,5 +1,5 @@ error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:6:17 + --> $DIR/redundant_static_lifetimes.rs:7:17 | LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR: Consider removing 'static. | -^^^^^^^---- help: consider removing `'static`: `&str` @@ -8,103 +8,103 @@ LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR: Consider removi = help: to override `-D warnings` add `#[allow(clippy::redundant_static_lifetimes)]` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:10:21 + --> $DIR/redundant_static_lifetimes.rs:12:21 | LL | const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:12:32 + --> $DIR/redundant_static_lifetimes.rs:16:32 | LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:12:47 + --> $DIR/redundant_static_lifetimes.rs:16:47 | LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:14:17 + --> $DIR/redundant_static_lifetimes.rs:18:17 | LL | const VAR_SIX: &'static u8 = &5; | -^^^^^^^--- help: consider removing `'static`: `&u8` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:16:20 + --> $DIR/redundant_static_lifetimes.rs:20:20 | LL | const VAR_HEIGHT: &'static Foo = &Foo {}; | -^^^^^^^---- help: consider removing `'static`: `&Foo` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:18:19 + --> $DIR/redundant_static_lifetimes.rs:24:19 | LL | const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR: Consider removing 'static. | -^^^^^^^----- help: consider removing `'static`: `&[u8]` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:20:19 + --> $DIR/redundant_static_lifetimes.rs:27:19 | LL | const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR: Consider removing 'static. | -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:22:19 + --> $DIR/redundant_static_lifetimes.rs:30:19 | LL | const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR: Consider removing 'static. | -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:24:25 + --> $DIR/redundant_static_lifetimes.rs:33:25 | LL | static STATIC_VAR_ONE: &'static str = "Test static #1"; // ERROR: Consider removing 'static. | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:28:29 + --> $DIR/redundant_static_lifetimes.rs:38:29 | LL | static STATIC_VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:30:25 + --> $DIR/redundant_static_lifetimes.rs:40:25 | LL | static STATIC_VAR_SIX: &'static u8 = &5; | -^^^^^^^--- help: consider removing `'static`: `&u8` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:32:28 + --> $DIR/redundant_static_lifetimes.rs:43:28 | LL | static STATIC_VAR_HEIGHT: &'static Foo = &Foo {}; | -^^^^^^^---- help: consider removing `'static`: `&Foo` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:34:27 + --> $DIR/redundant_static_lifetimes.rs:47:27 | LL | static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR: Consider removing 'static. | -^^^^^^^----- help: consider removing `'static`: `&[u8]` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:36:27 + --> $DIR/redundant_static_lifetimes.rs:50:27 | LL | static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR: Consider removing 'static. | -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:38:27 + --> $DIR/redundant_static_lifetimes.rs:53:27 | LL | static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR: Consider removing 'static. | -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:40:31 + --> $DIR/redundant_static_lifetimes.rs:55:31 | LL | static mut STATIC_MUT_SLICE: &'static mut [u32] = &mut [0]; | -^^^^^^^---------- help: consider removing `'static`: `&mut [u32]` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:69:16 + --> $DIR/redundant_static_lifetimes.rs:85:16 | LL | static V: &'static u8 = &17; | -^^^^^^^--- help: consider removing `'static`: `&u8` diff --git a/tests/ui/ref_as_ptr.fixed b/tests/ui/ref_as_ptr.fixed index 7a946393f259..442fd0a89ada 100644 --- a/tests/ui/ref_as_ptr.fixed +++ b/tests/ui/ref_as_ptr.fixed @@ -2,54 +2,58 @@ #![allow(clippy::unnecessary_mut_passed)] fn main() { - let _ = std::ptr::from_ref(&1u8); - let _ = std::ptr::from_ref::(&2u32); - let _ = std::ptr::from_ref::(&3.0f64); + let _ = std::ptr::from_ref(&1u8); //~ ref_as_ptr + let _ = std::ptr::from_ref::(&2u32); //~ ref_as_ptr + let _ = std::ptr::from_ref::(&3.0f64); //~ ref_as_ptr - let _ = std::ptr::from_ref(&4) as *const f32; - let _ = std::ptr::from_ref::(&5.0f32) as *const u32; + let _ = std::ptr::from_ref(&4) as *const f32; //~ ref_as_ptr + let _ = std::ptr::from_ref::(&5.0f32) as *const u32; //~ ref_as_ptr - let _ = std::ptr::from_ref(&mut 6u8); - let _ = std::ptr::from_ref::(&mut 7u32); - let _ = std::ptr::from_ref::(&mut 8.0f64); + let _ = std::ptr::from_ref(&mut 6u8); //~ ref_as_ptr + let _ = std::ptr::from_ref::(&mut 7u32); //~ ref_as_ptr + let _ = std::ptr::from_ref::(&mut 8.0f64); //~ ref_as_ptr - let _ = std::ptr::from_ref(&mut 9) as *const f32; - let _ = std::ptr::from_ref::(&mut 10.0f32) as *const u32; + let _ = std::ptr::from_ref(&mut 9) as *const f32; //~ ref_as_ptr + let _ = std::ptr::from_ref::(&mut 10.0f32) as *const u32; //~ ref_as_ptr - let _ = std::ptr::from_mut(&mut 11u8); - let _ = std::ptr::from_mut::(&mut 12u32); - let _ = std::ptr::from_mut::(&mut 13.0f64); + let _ = std::ptr::from_mut(&mut 11u8); //~ ref_as_ptr + let _ = std::ptr::from_mut::(&mut 12u32); //~ ref_as_ptr + let _ = std::ptr::from_mut::(&mut 13.0f64); //~ ref_as_ptr - let _ = std::ptr::from_mut(&mut 14) as *const f32; - let _ = std::ptr::from_mut::(&mut 15.0f32) as *const u32; + let _ = std::ptr::from_mut(&mut 14) as *const f32; //~ ref_as_ptr + let _ = std::ptr::from_mut::(&mut 15.0f32) as *const u32; //~ ref_as_ptr - let _ = std::ptr::from_ref(&1u8); - let _ = std::ptr::from_ref::(&2u32); - let _ = std::ptr::from_ref::(&3.0f64); + let _ = std::ptr::from_ref(&1u8); //~ ref_as_ptr + let _ = std::ptr::from_ref::(&2u32); //~ ref_as_ptr + let _ = std::ptr::from_ref::(&3.0f64); //~ ref_as_ptr - let _ = std::ptr::from_ref(&4) as *const f32; - let _ = std::ptr::from_ref::(&5.0f32) as *const u32; + let _ = std::ptr::from_ref(&4) as *const f32; //~ ref_as_ptr + let _ = std::ptr::from_ref::(&5.0f32) as *const u32; //~ ref_as_ptr let val = 1; - let _ = std::ptr::from_ref(&val); - let _ = std::ptr::from_ref::(&val); + let _ = std::ptr::from_ref(&val); //~ ref_as_ptr + let _ = std::ptr::from_ref::(&val); //~ ref_as_ptr - let _ = std::ptr::from_ref(&val) as *const f32; - let _ = std::ptr::from_ref::(&val) as *const f64; + let _ = std::ptr::from_ref(&val) as *const f32; //~ ref_as_ptr + let _ = std::ptr::from_ref::(&val) as *const f64; //~ ref_as_ptr let mut val: u8 = 2; - let _ = std::ptr::from_mut::(&mut val); - let _ = std::ptr::from_mut(&mut val); + let _ = std::ptr::from_mut::(&mut val); //~ ref_as_ptr + let _ = std::ptr::from_mut(&mut val); //~ ref_as_ptr - let _ = std::ptr::from_ref::(&mut val); - let _ = std::ptr::from_ref(&mut val); + let _ = std::ptr::from_ref::(&mut val); //~ ref_as_ptr + let _ = std::ptr::from_ref(&mut val); //~ ref_as_ptr - let _ = std::ptr::from_ref::(&mut val) as *const f64; + let _ = std::ptr::from_ref::(&mut val) as *const f64; //~ ref_as_ptr let _: *const Option = std::ptr::from_ref(&mut val) as *const _; + //~^ ref_as_ptr let _ = std::ptr::from_ref::<[usize; 7]>(&std::array::from_fn(|i| i * i)); + //~^ ref_as_ptr let _ = std::ptr::from_ref::<[usize; 8]>(&mut std::array::from_fn(|i| i * i)); + //~^ ref_as_ptr let _ = std::ptr::from_mut::<[usize; 9]>(&mut std::array::from_fn(|i| i * i)); + //~^ ref_as_ptr } #[clippy::msrv = "1.75"] @@ -67,29 +71,29 @@ fn _msrv_1_76() { let val = &42_i32; let mut_val = &mut 42_i32; - let _ = std::ptr::from_ref::(val); - let _ = std::ptr::from_mut::(mut_val); + let _ = std::ptr::from_ref::(val); //~ ref_as_ptr + let _ = std::ptr::from_mut::(mut_val); //~ ref_as_ptr } fn foo(val: &[u8]) { - let _ = std::ptr::from_ref(val); - let _ = std::ptr::from_ref::<[u8]>(val); + let _ = std::ptr::from_ref(val); //~ ref_as_ptr + let _ = std::ptr::from_ref::<[u8]>(val); //~ ref_as_ptr } fn bar(val: &mut str) { - let _ = std::ptr::from_mut(val); - let _ = std::ptr::from_mut::(val); + let _ = std::ptr::from_mut(val); //~ ref_as_ptr + let _ = std::ptr::from_mut::(val); //~ ref_as_ptr } struct X<'a>(&'a i32); impl<'a> X<'a> { fn foo(&self) -> *const i64 { - std::ptr::from_ref(self.0) as *const _ + std::ptr::from_ref(self.0) as *const _ //~ ref_as_ptr } fn bar(&mut self) -> *const i64 { - std::ptr::from_ref(self.0) as *const _ + std::ptr::from_ref(self.0) as *const _ //~ ref_as_ptr } } @@ -97,14 +101,14 @@ struct Y<'a>(&'a mut i32); impl<'a> Y<'a> { fn foo(&self) -> *const i64 { - std::ptr::from_ref(self.0) as *const _ + std::ptr::from_ref(self.0) as *const _ //~ ref_as_ptr } fn bar(&mut self) -> *const i64 { - std::ptr::from_ref(self.0) as *const _ + std::ptr::from_ref(self.0) as *const _ //~ ref_as_ptr } fn baz(&mut self) -> *const i64 { - std::ptr::from_mut(self.0) as *mut _ + std::ptr::from_mut(self.0) as *mut _ //~ ref_as_ptr } } diff --git a/tests/ui/ref_as_ptr.rs b/tests/ui/ref_as_ptr.rs index 6f745505b469..df2c147601db 100644 --- a/tests/ui/ref_as_ptr.rs +++ b/tests/ui/ref_as_ptr.rs @@ -2,54 +2,58 @@ #![allow(clippy::unnecessary_mut_passed)] fn main() { - let _ = &1u8 as *const _; - let _ = &2u32 as *const u32; - let _ = &3.0f64 as *const f64; + let _ = &1u8 as *const _; //~ ref_as_ptr + let _ = &2u32 as *const u32; //~ ref_as_ptr + let _ = &3.0f64 as *const f64; //~ ref_as_ptr - let _ = &4 as *const _ as *const f32; - let _ = &5.0f32 as *const f32 as *const u32; + let _ = &4 as *const _ as *const f32; //~ ref_as_ptr + let _ = &5.0f32 as *const f32 as *const u32; //~ ref_as_ptr - let _ = &mut 6u8 as *const _; - let _ = &mut 7u32 as *const u32; - let _ = &mut 8.0f64 as *const f64; + let _ = &mut 6u8 as *const _; //~ ref_as_ptr + let _ = &mut 7u32 as *const u32; //~ ref_as_ptr + let _ = &mut 8.0f64 as *const f64; //~ ref_as_ptr - let _ = &mut 9 as *const _ as *const f32; - let _ = &mut 10.0f32 as *const f32 as *const u32; + let _ = &mut 9 as *const _ as *const f32; //~ ref_as_ptr + let _ = &mut 10.0f32 as *const f32 as *const u32; //~ ref_as_ptr - let _ = &mut 11u8 as *mut _; - let _ = &mut 12u32 as *mut u32; - let _ = &mut 13.0f64 as *mut f64; + let _ = &mut 11u8 as *mut _; //~ ref_as_ptr + let _ = &mut 12u32 as *mut u32; //~ ref_as_ptr + let _ = &mut 13.0f64 as *mut f64; //~ ref_as_ptr - let _ = &mut 14 as *mut _ as *const f32; - let _ = &mut 15.0f32 as *mut f32 as *const u32; + let _ = &mut 14 as *mut _ as *const f32; //~ ref_as_ptr + let _ = &mut 15.0f32 as *mut f32 as *const u32; //~ ref_as_ptr - let _ = &1u8 as *const _; - let _ = &2u32 as *const u32; - let _ = &3.0f64 as *const f64; + let _ = &1u8 as *const _; //~ ref_as_ptr + let _ = &2u32 as *const u32; //~ ref_as_ptr + let _ = &3.0f64 as *const f64; //~ ref_as_ptr - let _ = &4 as *const _ as *const f32; - let _ = &5.0f32 as *const f32 as *const u32; + let _ = &4 as *const _ as *const f32; //~ ref_as_ptr + let _ = &5.0f32 as *const f32 as *const u32; //~ ref_as_ptr let val = 1; - let _ = &val as *const _; - let _ = &val as *const i32; + let _ = &val as *const _; //~ ref_as_ptr + let _ = &val as *const i32; //~ ref_as_ptr - let _ = &val as *const _ as *const f32; - let _ = &val as *const i32 as *const f64; + let _ = &val as *const _ as *const f32; //~ ref_as_ptr + let _ = &val as *const i32 as *const f64; //~ ref_as_ptr let mut val: u8 = 2; - let _ = &mut val as *mut u8; - let _ = &mut val as *mut _; + let _ = &mut val as *mut u8; //~ ref_as_ptr + let _ = &mut val as *mut _; //~ ref_as_ptr - let _ = &mut val as *const u8; - let _ = &mut val as *const _; + let _ = &mut val as *const u8; //~ ref_as_ptr + let _ = &mut val as *const _; //~ ref_as_ptr - let _ = &mut val as *const u8 as *const f64; + let _ = &mut val as *const u8 as *const f64; //~ ref_as_ptr let _: *const Option = &mut val as *const _ as *const _; + //~^ ref_as_ptr let _ = &std::array::from_fn(|i| i * i) as *const [usize; 7]; + //~^ ref_as_ptr let _ = &mut std::array::from_fn(|i| i * i) as *const [usize; 8]; + //~^ ref_as_ptr let _ = &mut std::array::from_fn(|i| i * i) as *mut [usize; 9]; + //~^ ref_as_ptr } #[clippy::msrv = "1.75"] @@ -67,29 +71,29 @@ fn _msrv_1_76() { let val = &42_i32; let mut_val = &mut 42_i32; - let _ = val as *const i32; - let _ = mut_val as *mut i32; + let _ = val as *const i32; //~ ref_as_ptr + let _ = mut_val as *mut i32; //~ ref_as_ptr } fn foo(val: &[u8]) { - let _ = val as *const _; - let _ = val as *const [u8]; + let _ = val as *const _; //~ ref_as_ptr + let _ = val as *const [u8]; //~ ref_as_ptr } fn bar(val: &mut str) { - let _ = val as *mut _; - let _ = val as *mut str; + let _ = val as *mut _; //~ ref_as_ptr + let _ = val as *mut str; //~ ref_as_ptr } struct X<'a>(&'a i32); impl<'a> X<'a> { fn foo(&self) -> *const i64 { - self.0 as *const _ as *const _ + self.0 as *const _ as *const _ //~ ref_as_ptr } fn bar(&mut self) -> *const i64 { - self.0 as *const _ as *const _ + self.0 as *const _ as *const _ //~ ref_as_ptr } } @@ -97,14 +101,14 @@ struct Y<'a>(&'a mut i32); impl<'a> Y<'a> { fn foo(&self) -> *const i64 { - self.0 as *const _ as *const _ + self.0 as *const _ as *const _ //~ ref_as_ptr } fn bar(&mut self) -> *const i64 { - self.0 as *const _ as *const _ + self.0 as *const _ as *const _ //~ ref_as_ptr } fn baz(&mut self) -> *const i64 { - self.0 as *mut _ as *mut _ + self.0 as *mut _ as *mut _ //~ ref_as_ptr } } diff --git a/tests/ui/ref_as_ptr.stderr b/tests/ui/ref_as_ptr.stderr index 371d42df528b..24430787f6c7 100644 --- a/tests/ui/ref_as_ptr.stderr +++ b/tests/ui/ref_as_ptr.stderr @@ -182,85 +182,85 @@ LL | let _: *const Option = &mut val as *const _ as *const _; | ^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut val)` error: reference as raw pointer - --> $DIR/ref_as_ptr.rs:50:13 + --> $DIR/ref_as_ptr.rs:51:13 | LL | let _ = &std::array::from_fn(|i| i * i) as *const [usize; 7]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<[usize; 7]>(&std::array::from_fn(|i| i * i))` error: reference as raw pointer - --> $DIR/ref_as_ptr.rs:51:13 + --> $DIR/ref_as_ptr.rs:53:13 | LL | let _ = &mut std::array::from_fn(|i| i * i) as *const [usize; 8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<[usize; 8]>(&mut std::array::from_fn(|i| i * i))` error: reference as raw pointer - --> $DIR/ref_as_ptr.rs:52:13 + --> $DIR/ref_as_ptr.rs:55:13 | LL | let _ = &mut std::array::from_fn(|i| i * i) as *mut [usize; 9]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::<[usize; 9]>(&mut std::array::from_fn(|i| i * i))` error: reference as raw pointer - --> $DIR/ref_as_ptr.rs:70:13 + --> $DIR/ref_as_ptr.rs:74:13 | LL | let _ = val as *const i32; | ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(val)` error: reference as raw pointer - --> $DIR/ref_as_ptr.rs:71:13 + --> $DIR/ref_as_ptr.rs:75:13 | LL | let _ = mut_val as *mut i32; | ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(mut_val)` error: reference as raw pointer - --> $DIR/ref_as_ptr.rs:75:13 + --> $DIR/ref_as_ptr.rs:79:13 | LL | let _ = val as *const _; | ^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(val)` error: reference as raw pointer - --> $DIR/ref_as_ptr.rs:76:13 + --> $DIR/ref_as_ptr.rs:80:13 | LL | let _ = val as *const [u8]; | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<[u8]>(val)` error: reference as raw pointer - --> $DIR/ref_as_ptr.rs:80:13 + --> $DIR/ref_as_ptr.rs:84:13 | LL | let _ = val as *mut _; | ^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(val)` error: reference as raw pointer - --> $DIR/ref_as_ptr.rs:81:13 + --> $DIR/ref_as_ptr.rs:85:13 | LL | let _ = val as *mut str; | ^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(val)` error: reference as raw pointer - --> $DIR/ref_as_ptr.rs:88:9 + --> $DIR/ref_as_ptr.rs:92:9 | LL | self.0 as *const _ as *const _ | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)` error: reference as raw pointer - --> $DIR/ref_as_ptr.rs:92:9 + --> $DIR/ref_as_ptr.rs:96:9 | LL | self.0 as *const _ as *const _ | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)` error: reference as raw pointer - --> $DIR/ref_as_ptr.rs:100:9 + --> $DIR/ref_as_ptr.rs:104:9 | LL | self.0 as *const _ as *const _ | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)` error: reference as raw pointer - --> $DIR/ref_as_ptr.rs:104:9 + --> $DIR/ref_as_ptr.rs:108:9 | LL | self.0 as *const _ as *const _ | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)` error: reference as raw pointer - --> $DIR/ref_as_ptr.rs:108:9 + --> $DIR/ref_as_ptr.rs:112:9 | LL | self.0 as *mut _ as *mut _ | ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(self.0)` diff --git a/tests/ui/regex.rs b/tests/ui/regex.rs index 4fb6c08bb449..6ac06d681958 100644 --- a/tests/ui/regex.rs +++ b/tests/ui/regex.rs @@ -26,12 +26,14 @@ fn syntax_error() { let some_unicode = Regex::new("[é-è]"); //~^ ERROR: regex syntax error: invalid character class range, the start must be <= th - let some_regex = Regex::new(OPENING_PAREN); + let some_regex = Regex::new(OPENING_PAREN); //~ invalid_regex let binary_pipe_in_wrong_position = BRegex::new("|"); //~^ ERROR: trivial regex let some_binary_regex = BRegex::new(OPENING_PAREN); + //~^ invalid_regex let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN); + //~^ invalid_regex let closing_paren = ")"; let not_linted = Regex::new(closing_paren); @@ -44,7 +46,9 @@ fn syntax_error() { ]); let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); + //~^ invalid_regex let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); + //~^ invalid_regex // These following three cases are considering valid since regex-1.8.0 let raw_string_error = Regex::new(r"[...\/...]"); @@ -52,6 +56,7 @@ fn syntax_error() { let _ = Regex::new(r"(?hi)").unwrap(); let escaped_string_span = Regex::new("\\b\\c"); + //~^ invalid_regex let aux_span = Regex::new("(?ixi)"); //~^ ERROR: regex syntax error: duplicate flag diff --git a/tests/ui/regex.stderr b/tests/ui/regex.stderr index 6d98d691d6f0..7f076e1a9390 100644 --- a/tests/ui/regex.stderr +++ b/tests/ui/regex.stderr @@ -61,7 +61,7 @@ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:34:56 + --> $DIR/regex.rs:35:56 | LL | let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN); | ^^^^^^^^^^^^^ @@ -70,7 +70,7 @@ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:46:37 + --> $DIR/regex.rs:48:37 | LL | let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); | ^^^^^^^^^^^^^ @@ -79,7 +79,7 @@ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:47:39 + --> $DIR/regex.rs:50:39 | LL | let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); | ^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ error: regex parse error: \b\c ^^ error: unrecognized escape sequence - --> $DIR/regex.rs:54:42 + --> $DIR/regex.rs:58:42 | LL | let escaped_string_span = Regex::new("\\b\\c"); | ^^^^^^^^ @@ -96,19 +96,19 @@ LL | let escaped_string_span = Regex::new("\\b\\c"); = help: consider using a raw string literal: `r".."` error: regex syntax error: duplicate flag - --> $DIR/regex.rs:56:34 + --> $DIR/regex.rs:61:34 | LL | let aux_span = Regex::new("(?ixi)"); | ^ ^ error: regex syntax error: pattern can match invalid UTF-8 - --> $DIR/regex.rs:62:53 + --> $DIR/regex.rs:67:53 | LL | let invalid_utf8_should_lint = Regex::new("(?-u)."); | ^ error: trivial regex - --> $DIR/regex.rs:67:33 + --> $DIR/regex.rs:72:33 | LL | let trivial_eq = Regex::new("^foobar$"); | ^^^^^^^^^^ @@ -116,7 +116,7 @@ LL | let trivial_eq = Regex::new("^foobar$"); = help: consider using `==` on `str`s error: trivial regex - --> $DIR/regex.rs:70:48 + --> $DIR/regex.rs:75:48 | LL | let trivial_eq_builder = RegexBuilder::new("^foobar$"); | ^^^^^^^^^^ @@ -124,7 +124,7 @@ LL | let trivial_eq_builder = RegexBuilder::new("^foobar$"); = help: consider using `==` on `str`s error: trivial regex - --> $DIR/regex.rs:73:42 + --> $DIR/regex.rs:78:42 | LL | let trivial_starts_with = Regex::new("^foobar"); | ^^^^^^^^^ @@ -132,7 +132,7 @@ LL | let trivial_starts_with = Regex::new("^foobar"); = help: consider using `str::starts_with` error: trivial regex - --> $DIR/regex.rs:76:40 + --> $DIR/regex.rs:81:40 | LL | let trivial_ends_with = Regex::new("foobar$"); | ^^^^^^^^^ @@ -140,7 +140,7 @@ LL | let trivial_ends_with = Regex::new("foobar$"); = help: consider using `str::ends_with` error: trivial regex - --> $DIR/regex.rs:79:39 + --> $DIR/regex.rs:84:39 | LL | let trivial_contains = Regex::new("foobar"); | ^^^^^^^^ @@ -148,7 +148,7 @@ LL | let trivial_contains = Regex::new("foobar"); = help: consider using `str::contains` error: trivial regex - --> $DIR/regex.rs:82:39 + --> $DIR/regex.rs:87:39 | LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX); | ^^^^^^^^^^^^^^^^ @@ -156,7 +156,7 @@ LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX); = help: consider using `str::contains` error: trivial regex - --> $DIR/regex.rs:85:40 + --> $DIR/regex.rs:90:40 | LL | let trivial_backslash = Regex::new("a\\.b"); | ^^^^^^^ @@ -164,7 +164,7 @@ LL | let trivial_backslash = Regex::new("a\\.b"); = help: consider using `str::contains` error: trivial regex - --> $DIR/regex.rs:89:36 + --> $DIR/regex.rs:94:36 | LL | let trivial_empty = Regex::new(""); | ^^ @@ -172,7 +172,7 @@ LL | let trivial_empty = Regex::new(""); = help: the regex is unlikely to be useful as it is error: trivial regex - --> $DIR/regex.rs:92:36 + --> $DIR/regex.rs:97:36 | LL | let trivial_empty = Regex::new("^"); | ^^^ @@ -180,7 +180,7 @@ LL | let trivial_empty = Regex::new("^"); = help: the regex is unlikely to be useful as it is error: trivial regex - --> $DIR/regex.rs:95:36 + --> $DIR/regex.rs:100:36 | LL | let trivial_empty = Regex::new("^$"); | ^^^^ @@ -188,7 +188,7 @@ LL | let trivial_empty = Regex::new("^$"); = help: consider using `str::is_empty` error: trivial regex - --> $DIR/regex.rs:98:44 + --> $DIR/regex.rs:103:44 | LL | let binary_trivial_empty = BRegex::new("^$"); | ^^^^ diff --git a/tests/ui/repeat_once.fixed b/tests/ui/repeat_once.fixed index 72e97350a0c8..5e8d6b26e219 100644 --- a/tests/ui/repeat_once.fixed +++ b/tests/ui/repeat_once.fixed @@ -6,10 +6,10 @@ fn main() { let string = "String".to_string(); let slice = [1; 5]; - let a = [1; 5].to_vec(); - let b = slice.to_vec(); - let c = "hello".to_string(); - let d = "hi".to_string(); - let e = s.to_string(); - let f = string.clone(); + let a = [1; 5].to_vec(); //~ repeat_once + let b = slice.to_vec(); //~ repeat_once + let c = "hello".to_string(); //~ repeat_once + let d = "hi".to_string(); //~ repeat_once + let e = s.to_string(); //~ repeat_once + let f = string.clone(); //~ repeat_once } diff --git a/tests/ui/repeat_once.rs b/tests/ui/repeat_once.rs index 7557c4d0bd41..c0192863d104 100644 --- a/tests/ui/repeat_once.rs +++ b/tests/ui/repeat_once.rs @@ -6,10 +6,10 @@ fn main() { let string = "String".to_string(); let slice = [1; 5]; - let a = [1; 5].repeat(1); - let b = slice.repeat(1); - let c = "hello".repeat(N); - let d = "hi".repeat(1); - let e = s.repeat(1); - let f = string.repeat(1); + let a = [1; 5].repeat(1); //~ repeat_once + let b = slice.repeat(1); //~ repeat_once + let c = "hello".repeat(N); //~ repeat_once + let d = "hi".repeat(1); //~ repeat_once + let e = s.repeat(1); //~ repeat_once + let f = string.repeat(1); //~ repeat_once } diff --git a/tests/ui/reserve_after_initialization.fixed b/tests/ui/reserve_after_initialization.fixed index 0675277849ad..406e3bbc00a3 100644 --- a/tests/ui/reserve_after_initialization.fixed +++ b/tests/ui/reserve_after_initialization.fixed @@ -7,12 +7,14 @@ use proc_macros::{external, with_span}; // Should lint fn standard() { + //~v reserve_after_initialization let mut v1: Vec = Vec::with_capacity(10); } // Should lint fn capacity_as_expr() { let capacity = 10; + //~v reserve_after_initialization let mut v2: Vec = Vec::with_capacity(capacity); } @@ -30,6 +32,7 @@ fn called_with_capacity() { // Should lint fn assign_expression() { let mut v5: Vec = Vec::new(); + //~v reserve_after_initialization v5 = Vec::with_capacity(10); } diff --git a/tests/ui/reserve_after_initialization.rs b/tests/ui/reserve_after_initialization.rs index b57a8e162c53..48f5972d6279 100644 --- a/tests/ui/reserve_after_initialization.rs +++ b/tests/ui/reserve_after_initialization.rs @@ -7,6 +7,7 @@ use proc_macros::{external, with_span}; // Should lint fn standard() { + //~v reserve_after_initialization let mut v1: Vec = vec![]; v1.reserve(10); } @@ -14,6 +15,7 @@ fn standard() { // Should lint fn capacity_as_expr() { let capacity = 10; + //~v reserve_after_initialization let mut v2: Vec = vec![]; v2.reserve(capacity); } @@ -32,6 +34,7 @@ fn called_with_capacity() { // Should lint fn assign_expression() { let mut v5: Vec = Vec::new(); + //~v reserve_after_initialization v5 = Vec::new(); v5.reserve(10); } diff --git a/tests/ui/reserve_after_initialization.stderr b/tests/ui/reserve_after_initialization.stderr index a91033890766..220ce420cef3 100644 --- a/tests/ui/reserve_after_initialization.stderr +++ b/tests/ui/reserve_after_initialization.stderr @@ -1,5 +1,5 @@ error: call to `reserve` immediately after creation - --> $DIR/reserve_after_initialization.rs:10:5 + --> $DIR/reserve_after_initialization.rs:11:5 | LL | / let mut v1: Vec = vec![]; LL | | v1.reserve(10); @@ -9,14 +9,14 @@ LL | | v1.reserve(10); = help: to override `-D warnings` add `#[allow(clippy::reserve_after_initialization)]` error: call to `reserve` immediately after creation - --> $DIR/reserve_after_initialization.rs:17:5 + --> $DIR/reserve_after_initialization.rs:19:5 | LL | / let mut v2: Vec = vec![]; LL | | v2.reserve(capacity); | |_________________________^ help: consider using `Vec::with_capacity(/* Space hint */)`: `let mut v2: Vec = Vec::with_capacity(capacity);` error: call to `reserve` immediately after creation - --> $DIR/reserve_after_initialization.rs:35:5 + --> $DIR/reserve_after_initialization.rs:38:5 | LL | / v5 = Vec::new(); LL | | v5.reserve(10); diff --git a/tests/ui/result_map_unit_fn_fixable.fixed b/tests/ui/result_map_unit_fn_fixable.fixed index 3890f916b606..263389beb18d 100644 --- a/tests/ui/result_map_unit_fn_fixable.fixed +++ b/tests/ui/result_map_unit_fn_fixable.fixed @@ -31,51 +31,66 @@ fn result_map_unit_fn() { x.field.map(plus_one); let _: Result<(), usize> = x.field.map(do_nothing); - if let Ok(x_field) = x.field { do_nothing(x_field) } + if let Ok(x_field) = x.field { do_nothing(x_field) } //~ result_map_unit_fn - if let Ok(x_field) = x.field { do_nothing(x_field) } + if let Ok(x_field) = x.field { do_nothing(x_field) } //~ result_map_unit_fn - if let Ok(x_field) = x.field { diverge(x_field) } + if let Ok(x_field) = x.field { diverge(x_field) } //~ result_map_unit_fn let captured = 10; if let Ok(value) = x.field { do_nothing(value + captured) }; let _: Result<(), usize> = x.field.map(|value| do_nothing(value + captured)); if let Ok(value) = x.field { x.do_result_nothing(value + captured) } + //~^ result_map_unit_fn if let Ok(value) = x.field { x.do_result_plus_one(value + captured); } + //~^ result_map_unit_fn if let Ok(value) = x.field { do_nothing(value + captured) } + //~^ result_map_unit_fn if let Ok(value) = x.field { do_nothing(value + captured) } + //~^ result_map_unit_fn if let Ok(value) = x.field { do_nothing(value + captured); } + //~^ result_map_unit_fn if let Ok(value) = x.field { do_nothing(value + captured); } + //~^ result_map_unit_fn if let Ok(value) = x.field { diverge(value + captured) } + //~^ result_map_unit_fn if let Ok(value) = x.field { diverge(value + captured) } + //~^ result_map_unit_fn if let Ok(value) = x.field { diverge(value + captured); } + //~^ result_map_unit_fn if let Ok(value) = x.field { diverge(value + captured); } + //~^ result_map_unit_fn x.field.map(|value| plus_one(value + captured)); x.field.map(|value| { plus_one(value + captured) }); if let Ok(value) = x.field { let y = plus_one(value + captured); } + //~^ result_map_unit_fn if let Ok(value) = x.field { plus_one(value + captured); } + //~^ result_map_unit_fn if let Ok(value) = x.field { plus_one(value + captured); } + //~^ result_map_unit_fn if let Ok(ref value) = x.field { do_nothing(value + captured) } + //~^ result_map_unit_fn if let Ok(value) = x.field { println!("{:?}", value) } + //~^ result_map_unit_fn } fn main() {} diff --git a/tests/ui/result_map_unit_fn_fixable.rs b/tests/ui/result_map_unit_fn_fixable.rs index c3f5aca7bfbe..a74b8d6aa207 100644 --- a/tests/ui/result_map_unit_fn_fixable.rs +++ b/tests/ui/result_map_unit_fn_fixable.rs @@ -31,51 +31,66 @@ fn result_map_unit_fn() { x.field.map(plus_one); let _: Result<(), usize> = x.field.map(do_nothing); - x.field.map(do_nothing); + x.field.map(do_nothing); //~ result_map_unit_fn - x.field.map(do_nothing); + x.field.map(do_nothing); //~ result_map_unit_fn - x.field.map(diverge); + x.field.map(diverge); //~ result_map_unit_fn let captured = 10; if let Ok(value) = x.field { do_nothing(value + captured) }; let _: Result<(), usize> = x.field.map(|value| do_nothing(value + captured)); x.field.map(|value| x.do_result_nothing(value + captured)); + //~^ result_map_unit_fn x.field.map(|value| { x.do_result_plus_one(value + captured); }); + //~^ result_map_unit_fn x.field.map(|value| do_nothing(value + captured)); + //~^ result_map_unit_fn x.field.map(|value| { do_nothing(value + captured) }); + //~^ result_map_unit_fn x.field.map(|value| { do_nothing(value + captured); }); + //~^ result_map_unit_fn x.field.map(|value| { { do_nothing(value + captured); } }); + //~^ result_map_unit_fn x.field.map(|value| diverge(value + captured)); + //~^ result_map_unit_fn x.field.map(|value| { diverge(value + captured) }); + //~^ result_map_unit_fn x.field.map(|value| { diverge(value + captured); }); + //~^ result_map_unit_fn x.field.map(|value| { { diverge(value + captured); } }); + //~^ result_map_unit_fn x.field.map(|value| plus_one(value + captured)); x.field.map(|value| { plus_one(value + captured) }); x.field.map(|value| { let y = plus_one(value + captured); }); + //~^ result_map_unit_fn x.field.map(|value| { plus_one(value + captured); }); + //~^ result_map_unit_fn x.field.map(|value| { { plus_one(value + captured); } }); + //~^ result_map_unit_fn x.field.map(|ref value| { do_nothing(value + captured) }); + //~^ result_map_unit_fn x.field.map(|value| println!("{:?}", value)); + //~^ result_map_unit_fn } fn main() {} diff --git a/tests/ui/result_map_unit_fn_fixable.stderr b/tests/ui/result_map_unit_fn_fixable.stderr index 42ee273c2bd2..4264818b2c57 100644 --- a/tests/ui/result_map_unit_fn_fixable.stderr +++ b/tests/ui/result_map_unit_fn_fixable.stderr @@ -34,7 +34,7 @@ LL | x.field.map(|value| x.do_result_nothing(value + captured)); | help: try: `if let Ok(value) = x.field { x.do_result_nothing(value + captured) }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:46:5 + --> $DIR/result_map_unit_fn_fixable.rs:47:5 | LL | x.field.map(|value| { x.do_result_plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -42,7 +42,7 @@ LL | x.field.map(|value| { x.do_result_plus_one(value + captured); }); | help: try: `if let Ok(value) = x.field { x.do_result_plus_one(value + captured); }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:49:5 + --> $DIR/result_map_unit_fn_fixable.rs:51:5 | LL | x.field.map(|value| do_nothing(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -50,7 +50,7 @@ LL | x.field.map(|value| do_nothing(value + captured)); | help: try: `if let Ok(value) = x.field { do_nothing(value + captured) }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:51:5 + --> $DIR/result_map_unit_fn_fixable.rs:54:5 | LL | x.field.map(|value| { do_nothing(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -58,7 +58,7 @@ LL | x.field.map(|value| { do_nothing(value + captured) }); | help: try: `if let Ok(value) = x.field { do_nothing(value + captured) }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:53:5 + --> $DIR/result_map_unit_fn_fixable.rs:57:5 | LL | x.field.map(|value| { do_nothing(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -66,7 +66,7 @@ LL | x.field.map(|value| { do_nothing(value + captured); }); | help: try: `if let Ok(value) = x.field { do_nothing(value + captured); }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:55:5 + --> $DIR/result_map_unit_fn_fixable.rs:60:5 | LL | x.field.map(|value| { { do_nothing(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -74,7 +74,7 @@ LL | x.field.map(|value| { { do_nothing(value + captured); } }); | help: try: `if let Ok(value) = x.field { do_nothing(value + captured); }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:58:5 + --> $DIR/result_map_unit_fn_fixable.rs:64:5 | LL | x.field.map(|value| diverge(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -82,7 +82,7 @@ LL | x.field.map(|value| diverge(value + captured)); | help: try: `if let Ok(value) = x.field { diverge(value + captured) }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:60:5 + --> $DIR/result_map_unit_fn_fixable.rs:67:5 | LL | x.field.map(|value| { diverge(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -90,7 +90,7 @@ LL | x.field.map(|value| { diverge(value + captured) }); | help: try: `if let Ok(value) = x.field { diverge(value + captured) }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:62:5 + --> $DIR/result_map_unit_fn_fixable.rs:70:5 | LL | x.field.map(|value| { diverge(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -98,7 +98,7 @@ LL | x.field.map(|value| { diverge(value + captured); }); | help: try: `if let Ok(value) = x.field { diverge(value + captured); }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:64:5 + --> $DIR/result_map_unit_fn_fixable.rs:73:5 | LL | x.field.map(|value| { { diverge(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -106,7 +106,7 @@ LL | x.field.map(|value| { { diverge(value + captured); } }); | help: try: `if let Ok(value) = x.field { diverge(value + captured); }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:69:5 + --> $DIR/result_map_unit_fn_fixable.rs:79:5 | LL | x.field.map(|value| { let y = plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -114,7 +114,7 @@ LL | x.field.map(|value| { let y = plus_one(value + captured); }); | help: try: `if let Ok(value) = x.field { let y = plus_one(value + captured); }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:71:5 + --> $DIR/result_map_unit_fn_fixable.rs:82:5 | LL | x.field.map(|value| { plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -122,7 +122,7 @@ LL | x.field.map(|value| { plus_one(value + captured); }); | help: try: `if let Ok(value) = x.field { plus_one(value + captured); }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:73:5 + --> $DIR/result_map_unit_fn_fixable.rs:85:5 | LL | x.field.map(|value| { { plus_one(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -130,7 +130,7 @@ LL | x.field.map(|value| { { plus_one(value + captured); } }); | help: try: `if let Ok(value) = x.field { plus_one(value + captured); }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:76:5 + --> $DIR/result_map_unit_fn_fixable.rs:89:5 | LL | x.field.map(|ref value| { do_nothing(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -138,7 +138,7 @@ LL | x.field.map(|ref value| { do_nothing(value + captured) }); | help: try: `if let Ok(ref value) = x.field { do_nothing(value + captured) }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:78:5 + --> $DIR/result_map_unit_fn_fixable.rs:92:5 | LL | x.field.map(|value| println!("{:?}", value)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- diff --git a/tests/ui/reversed_empty_ranges_fixable.fixed b/tests/ui/reversed_empty_ranges_fixable.fixed index c8bf1b35085d..5efe5bf34468 100644 --- a/tests/ui/reversed_empty_ranges_fixable.fixed +++ b/tests/ui/reversed_empty_ranges_fixable.fixed @@ -7,10 +7,12 @@ fn main() { // These should be linted: (21..=42).rev().for_each(|x| println!("{}", x)); + //~^ reversed_empty_ranges let _ = (21..ANSWER).rev().filter(|x| x % 2 == 0).take(10).collect::>(); + //~^ reversed_empty_ranges - for _ in (-42..=-21).rev() {} - for _ in (21u32..42u32).rev() {} + for _ in (-42..=-21).rev() {} //~ reversed_empty_ranges + for _ in (21u32..42u32).rev() {} //~ reversed_empty_ranges // These should be ignored as they are not empty ranges: diff --git a/tests/ui/reversed_empty_ranges_fixable.rs b/tests/ui/reversed_empty_ranges_fixable.rs index 6733c096420b..ed63967fb817 100644 --- a/tests/ui/reversed_empty_ranges_fixable.rs +++ b/tests/ui/reversed_empty_ranges_fixable.rs @@ -7,10 +7,12 @@ fn main() { // These should be linted: (42..=21).for_each(|x| println!("{}", x)); + //~^ reversed_empty_ranges let _ = (ANSWER..21).filter(|x| x % 2 == 0).take(10).collect::>(); + //~^ reversed_empty_ranges - for _ in -21..=-42 {} - for _ in 42u32..21u32 {} + for _ in -21..=-42 {} //~ reversed_empty_ranges + for _ in 42u32..21u32 {} //~ reversed_empty_ranges // These should be ignored as they are not empty ranges: diff --git a/tests/ui/reversed_empty_ranges_fixable.stderr b/tests/ui/reversed_empty_ranges_fixable.stderr index 92fbac8e30c9..0d2d096d7704 100644 --- a/tests/ui/reversed_empty_ranges_fixable.stderr +++ b/tests/ui/reversed_empty_ranges_fixable.stderr @@ -12,7 +12,7 @@ LL | (21..=42).rev().for_each(|x| println!("{}", x)); | ~~~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_fixable.rs:10:13 + --> $DIR/reversed_empty_ranges_fixable.rs:11:13 | LL | let _ = (ANSWER..21).filter(|x| x % 2 == 0).take(10).collect::>(); | ^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _ = (21..ANSWER).rev().filter(|x| x % 2 == 0).take(10).collect:: $DIR/reversed_empty_ranges_fixable.rs:12:14 + --> $DIR/reversed_empty_ranges_fixable.rs:14:14 | LL | for _ in -21..=-42 {} | ^^^^^^^^^ @@ -34,7 +34,7 @@ LL | for _ in (-42..=-21).rev() {} | ~~~~~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_fixable.rs:13:14 + --> $DIR/reversed_empty_ranges_fixable.rs:15:14 | LL | for _ in 42u32..21u32 {} | ^^^^^^^^^^^^ diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.fixed b/tests/ui/reversed_empty_ranges_loops_fixable.fixed index df5f2c441f41..d3c834e2364a 100644 --- a/tests/ui/reversed_empty_ranges_loops_fixable.fixed +++ b/tests/ui/reversed_empty_ranges_loops_fixable.fixed @@ -4,14 +4,17 @@ fn main() { const MAX_LEN: usize = 42; + //~v reversed_empty_ranges for i in (0..10).rev() { println!("{}", i); } + //~v reversed_empty_ranges for i in (0..=10).rev() { println!("{}", i); } + //~v reversed_empty_ranges for i in (0..MAX_LEN).rev() { println!("{}", i); } @@ -31,15 +34,18 @@ fn main() { println!("{}", i); } + //~v reversed_empty_ranges for i in (0..10).rev().map(|x| x * 2) { println!("{}", i); } // testing that the empty range lint folds constants + //~v reversed_empty_ranges for i in (5 + 4..10).rev() { println!("{}", i); } + //~v reversed_empty_ranges for i in ((3 - 1)..(5 + 2)).rev() { println!("{}", i); } diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.rs b/tests/ui/reversed_empty_ranges_loops_fixable.rs index 92481be6cfc9..513977b69e53 100644 --- a/tests/ui/reversed_empty_ranges_loops_fixable.rs +++ b/tests/ui/reversed_empty_ranges_loops_fixable.rs @@ -4,14 +4,17 @@ fn main() { const MAX_LEN: usize = 42; + //~v reversed_empty_ranges for i in 10..0 { println!("{}", i); } + //~v reversed_empty_ranges for i in 10..=0 { println!("{}", i); } + //~v reversed_empty_ranges for i in MAX_LEN..0 { println!("{}", i); } @@ -31,15 +34,18 @@ fn main() { println!("{}", i); } + //~v reversed_empty_ranges for i in (10..0).map(|x| x * 2) { println!("{}", i); } // testing that the empty range lint folds constants + //~v reversed_empty_ranges for i in 10..5 + 4 { println!("{}", i); } + //~v reversed_empty_ranges for i in (5 + 2)..(3 - 1) { println!("{}", i); } diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.stderr b/tests/ui/reversed_empty_ranges_loops_fixable.stderr index 843d6a36d9be..8f73a08b71e5 100644 --- a/tests/ui/reversed_empty_ranges_loops_fixable.stderr +++ b/tests/ui/reversed_empty_ranges_loops_fixable.stderr @@ -1,5 +1,5 @@ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:7:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:8:14 | LL | for i in 10..0 { | ^^^^^ @@ -12,7 +12,7 @@ LL | for i in (0..10).rev() { | ~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:11:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:13:14 | LL | for i in 10..=0 { | ^^^^^^ @@ -23,7 +23,7 @@ LL | for i in (0..=10).rev() { | ~~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:15:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:18:14 | LL | for i in MAX_LEN..0 { | ^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | for i in (0..MAX_LEN).rev() { | ~~~~~~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:34:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:38:14 | LL | for i in (10..0).map(|x| x * 2) { | ^^^^^^^ @@ -45,7 +45,7 @@ LL | for i in (0..10).rev().map(|x| x * 2) { | ~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:39:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:44:14 | LL | for i in 10..5 + 4 { | ^^^^^^^^^ @@ -56,7 +56,7 @@ LL | for i in (5 + 4..10).rev() { | ~~~~~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:43:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:49:14 | LL | for i in (5 + 2)..(3 - 1) { | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/search_is_some.rs b/tests/ui/search_is_some.rs index e8a0920b645d..3eb419c65781 100644 --- a/tests/ui/search_is_some.rs +++ b/tests/ui/search_is_some.rs @@ -12,18 +12,21 @@ fn main() { // Check `find().is_some()`, multi-line case. + //~v search_is_some let _ = v.iter().find(|&x| { *x < 0 } ).is_some(); // Check `position().is_some()`, multi-line case. + //~v search_is_some let _ = v.iter().position(|&x| { x < 0 } ).is_some(); // Check `rposition().is_some()`, multi-line case. + //~v search_is_some let _ = v.iter().rposition(|&x| { x < 0 } @@ -39,7 +42,7 @@ fn main() { let _ = "hello world".find(|c: char| c == 'o' || c == 'l').is_some(); let some_closure = |x: &u32| *x == 0; - let _ = (0..1).find(some_closure).is_some(); + let _ = (0..1).find(some_closure).is_some(); //~ search_is_some } #[rustfmt::skip] @@ -49,18 +52,21 @@ fn is_none() { // Check `find().is_none()`, multi-line case. + //~v search_is_some let _ = v.iter().find(|&x| { *x < 0 } ).is_none(); // Check `position().is_none()`, multi-line case. + //~v search_is_some let _ = v.iter().position(|&x| { x < 0 } ).is_none(); // Check `rposition().is_none()`, multi-line case. + //~v search_is_some let _ = v.iter().rposition(|&x| { x < 0 } @@ -76,5 +82,5 @@ fn is_none() { let _ = "hello world".find(|c: char| c == 'o' || c == 'l').is_none(); let some_closure = |x: &u32| *x == 0; - let _ = (0..1).find(some_closure).is_none(); + let _ = (0..1).find(some_closure).is_none(); //~ search_is_some } diff --git a/tests/ui/search_is_some.stderr b/tests/ui/search_is_some.stderr index 9dec8c9caf27..4ba6de5b304f 100644 --- a/tests/ui/search_is_some.stderr +++ b/tests/ui/search_is_some.stderr @@ -1,5 +1,5 @@ error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some.rs:15:13 + --> $DIR/search_is_some.rs:16:13 | LL | let _ = v.iter().find(|&x| { | _____________^ @@ -13,7 +13,7 @@ LL | | ).is_some(); = help: to override `-D warnings` add `#[allow(clippy::search_is_some)]` error: called `is_some()` after searching an `Iterator` with `position` - --> $DIR/search_is_some.rs:21:13 + --> $DIR/search_is_some.rs:23:13 | LL | let _ = v.iter().position(|&x| { | _____________^ @@ -25,7 +25,7 @@ LL | | ).is_some(); = help: this is more succinctly expressed by calling `any()` error: called `is_some()` after searching an `Iterator` with `rposition` - --> $DIR/search_is_some.rs:27:13 + --> $DIR/search_is_some.rs:30:13 | LL | let _ = v.iter().rposition(|&x| { | _____________^ @@ -37,13 +37,13 @@ LL | | ).is_some(); = help: this is more succinctly expressed by calling `any()` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some.rs:42:20 + --> $DIR/search_is_some.rs:45:20 | LL | let _ = (0..1).find(some_closure).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(some_closure)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some.rs:52:13 + --> $DIR/search_is_some.rs:56:13 | LL | let _ = v.iter().find(|&x| { | _____________^ @@ -55,7 +55,7 @@ LL | | ).is_none(); = help: this is more succinctly expressed by calling `any()` with negation error: called `is_none()` after searching an `Iterator` with `position` - --> $DIR/search_is_some.rs:58:13 + --> $DIR/search_is_some.rs:63:13 | LL | let _ = v.iter().position(|&x| { | _____________^ @@ -67,7 +67,7 @@ LL | | ).is_none(); = help: this is more succinctly expressed by calling `any()` with negation error: called `is_none()` after searching an `Iterator` with `rposition` - --> $DIR/search_is_some.rs:64:13 + --> $DIR/search_is_some.rs:70:13 | LL | let _ = v.iter().rposition(|&x| { | _____________^ @@ -79,7 +79,7 @@ LL | | ).is_none(); = help: this is more succinctly expressed by calling `any()` with negation error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some.rs:79:13 + --> $DIR/search_is_some.rs:85:13 | LL | let _ = (0..1).find(some_closure).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(0..1).any(some_closure)` diff --git a/tests/ui/search_is_some_fixable_none.fixed b/tests/ui/search_is_some_fixable_none.fixed index 51636392f2bc..2f7872bf2356 100644 --- a/tests/ui/search_is_some_fixable_none.fixed +++ b/tests/ui/search_is_some_fixable_none.fixed @@ -6,37 +6,50 @@ fn main() { let y = &&42; // Check `find().is_none()`, single-line case. - let _ = !v.iter().any(|x| *x < 0); + let _ = !v.iter().any(|x| *x < 0); //~ search_is_some + + //~v search_is_some let _ = !(0..1).any(|x| **y == x); // one dereference less - let _ = !(0..1).any(|x| x == 0); + let _ = !(0..1).any(|x| x == 0); //~ search_is_some let _ = !v.iter().any(|x| *x == 0); + //~^ search_is_some let _ = !(4..5).any(|x| x == 1 || x == 3 || x == 5); + //~^ search_is_some let _ = !(1..3).any(|x| [1, 2, 3].contains(&x)); + //~^ search_is_some let _ = !(1..3).any(|x| x == 0 || [1, 2, 3].contains(&x)); + //~^ search_is_some let _ = !(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0); + //~^ search_is_some + + //~v search_is_some let _ = !(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0 || [4, 5, 6].contains(&x) || x == -1); // Check `position().is_none()`, single-line case. let _ = !v.iter().any(|&x| x < 0); + //~^ search_is_some // Check `rposition().is_none()`, single-line case. let _ = !v.iter().any(|&x| x < 0); + //~^ search_is_some let s1 = String::from("hello world"); let s2 = String::from("world"); // caller of `find()` is a `&`static str` let _ = !"hello world".contains("world"); - let _ = !"hello world".contains(&s2); + //~^ search_is_some + let _ = !"hello world".contains(&s2); //~ search_is_some let _ = !"hello world".contains(&s2[2..]); + //~^ search_is_some // caller of `find()` is a `String` - let _ = !s1.contains("world"); - let _ = !s1.contains(&s2); - let _ = !s1.contains(&s2[2..]); + let _ = !s1.contains("world"); //~ search_is_some + let _ = !s1.contains(&s2); //~ search_is_some + let _ = !s1.contains(&s2[2..]); //~ search_is_some // caller of `find()` is slice of `String` - let _ = !s1[2..].contains("world"); - let _ = !s1[2..].contains(&s2); - let _ = !s1[2..].contains(&s2[2..]); + let _ = !s1[2..].contains("world"); //~ search_is_some + let _ = !s1[2..].contains(&s2); //~ search_is_some + let _ = !s1[2..].contains(&s2[2..]); //~ search_is_some } #[allow(clippy::clone_on_copy, clippy::map_clone)] @@ -53,6 +66,7 @@ mod issue7392 { .hand .iter() .filter(|c| !filter_hand.iter().any(|cc| c == &cc)) + //~^ search_is_some .map(|c| c.clone()) .collect::>(); } @@ -69,6 +83,7 @@ mod issue7392 { .hand .iter() .filter(|(c, _)| !filter_hand.iter().any(|cc| c == cc)) + //~^ search_is_some .map(|c| c.clone()) .collect::>(); } @@ -80,8 +95,10 @@ mod issue7392 { } let vfoo = vec![Foo { foo: 1, bar: 2 }]; let _ = !vfoo.iter().any(|v| v.foo == 1 && v.bar == 2); + //~^ search_is_some let vfoo = vec![(42, Foo { foo: 1, bar: 2 })]; + //~v search_is_some let _ = !vfoo .iter().any(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2); } @@ -89,12 +106,14 @@ mod issue7392 { fn index_projection() { let vfoo = vec![[0, 1, 2, 3]]; let _ = !vfoo.iter().any(|a| a[0] == 42); + //~^ search_is_some } #[allow(clippy::match_like_matches_macro)] fn slice_projection() { let vfoo = vec![[0, 1, 2, 3, 0, 1, 2, 3]]; let _ = !vfoo.iter().any(|sub| sub[1..4].len() == 3); + //~^ search_is_some } fn please(x: &u32) -> bool { @@ -113,16 +132,22 @@ mod issue7392 { let x = 19; let ppx: &u32 = &x; let _ = ![ppx].iter().any(|ppp_x: &&u32| please(ppp_x)); + //~^ search_is_some let _ = ![String::from("Hey hey")].iter().any(|s| s.len() == 2); + //~^ search_is_some let v = vec![3, 2, 1, 0]; let _ = !v.iter().any(|x| deref_enough(*x)); + //~^ search_is_some let _ = !v.iter().any(|x: &u32| deref_enough(*x)); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = !v.iter().any(|x| arg_no_deref(&x)); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = !v.iter().any(|x: &u32| arg_no_deref(&x)); + //~^ search_is_some } fn field_index_projection() { @@ -142,6 +167,7 @@ mod issue7392 { bar: vec![vec![0, 1, 2, 3]], }, }]; + //~v search_is_some let _ = !vfoo .iter().any(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2); } @@ -157,11 +183,13 @@ mod issue7392 { inner: vec![Foo { bar: 0 }], }]; let _ = !vfoo.iter().any(|v| v.inner[0].bar == 2); + //~^ search_is_some } fn double_deref_index_projection() { let vfoo = vec![&&[0, 1, 2, 3]]; let _ = !vfoo.iter().any(|x| (**x)[0] == 9); + //~^ search_is_some } fn method_call_by_ref() { @@ -175,11 +203,14 @@ mod issue7392 { } let vfoo = vec![Foo { bar: 1 }]; let _ = !vfoo.iter().any(|v| v.by_ref(&v.bar)); + //~^ search_is_some } fn ref_bindings() { let _ = ![&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y); + //~^ search_is_some let _ = ![&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y); + //~^ search_is_some } fn test_string_1(s: &str) -> bool { @@ -199,7 +230,9 @@ mod issue7392 { let lst = &[String::from("Hello"), String::from("world")]; let v: Vec<&[String]> = vec![lst]; let _ = !v.iter().any(|s| s[0].is_empty()); + //~^ search_is_some let _ = !v.iter().any(|s| test_string_1(&s[0])); + //~^ search_is_some // Field projections struct FieldProjection<'a> { @@ -209,7 +242,10 @@ mod issue7392 { let instance = FieldProjection { field: &field }; let v = vec![instance]; let _ = !v.iter().any(|fp| fp.field.is_power_of_two()); + //~^ search_is_some let _ = !v.iter().any(|fp| test_u32_1(fp.field)); + //~^ search_is_some let _ = !v.iter().any(|fp| test_u32_2(*fp.field)); + //~^ search_is_some } } diff --git a/tests/ui/search_is_some_fixable_none.rs b/tests/ui/search_is_some_fixable_none.rs index c7d773e18a32..6a5857d90975 100644 --- a/tests/ui/search_is_some_fixable_none.rs +++ b/tests/ui/search_is_some_fixable_none.rs @@ -6,39 +6,52 @@ fn main() { let y = &&42; // Check `find().is_none()`, single-line case. - let _ = v.iter().find(|&x| *x < 0).is_none(); + let _ = v.iter().find(|&x| *x < 0).is_none(); //~ search_is_some + + //~v search_is_some let _ = (0..1).find(|x| **y == *x).is_none(); // one dereference less - let _ = (0..1).find(|x| *x == 0).is_none(); + let _ = (0..1).find(|x| *x == 0).is_none(); //~ search_is_some let _ = v.iter().find(|x| **x == 0).is_none(); + //~^ search_is_some let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_none(); + //~^ search_is_some let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_none(); + //~^ search_is_some let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_none(); + //~^ search_is_some let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_none(); + //~^ search_is_some + + //~v search_is_some let _ = (1..3) .find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1) .is_none(); // Check `position().is_none()`, single-line case. let _ = v.iter().position(|&x| x < 0).is_none(); + //~^ search_is_some // Check `rposition().is_none()`, single-line case. let _ = v.iter().rposition(|&x| x < 0).is_none(); + //~^ search_is_some let s1 = String::from("hello world"); let s2 = String::from("world"); // caller of `find()` is a `&`static str` let _ = "hello world".find("world").is_none(); - let _ = "hello world".find(&s2).is_none(); + //~^ search_is_some + let _ = "hello world".find(&s2).is_none(); //~ search_is_some let _ = "hello world".find(&s2[2..]).is_none(); + //~^ search_is_some // caller of `find()` is a `String` - let _ = s1.find("world").is_none(); - let _ = s1.find(&s2).is_none(); - let _ = s1.find(&s2[2..]).is_none(); + let _ = s1.find("world").is_none(); //~ search_is_some + let _ = s1.find(&s2).is_none(); //~ search_is_some + let _ = s1.find(&s2[2..]).is_none(); //~ search_is_some // caller of `find()` is slice of `String` - let _ = s1[2..].find("world").is_none(); - let _ = s1[2..].find(&s2).is_none(); - let _ = s1[2..].find(&s2[2..]).is_none(); + let _ = s1[2..].find("world").is_none(); //~ search_is_some + let _ = s1[2..].find(&s2).is_none(); //~ search_is_some + let _ = s1[2..].find(&s2[2..]).is_none(); //~ search_is_some } #[allow(clippy::clone_on_copy, clippy::map_clone)] @@ -55,6 +68,7 @@ mod issue7392 { .hand .iter() .filter(|c| filter_hand.iter().find(|cc| c == cc).is_none()) + //~^ search_is_some .map(|c| c.clone()) .collect::>(); } @@ -71,6 +85,7 @@ mod issue7392 { .hand .iter() .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_none()) + //~^ search_is_some .map(|c| c.clone()) .collect::>(); } @@ -82,8 +97,10 @@ mod issue7392 { } let vfoo = vec![Foo { foo: 1, bar: 2 }]; let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_none(); + //~^ search_is_some let vfoo = vec![(42, Foo { foo: 1, bar: 2 })]; + //~v search_is_some let _ = vfoo .iter() .find(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2) @@ -93,12 +110,14 @@ mod issue7392 { fn index_projection() { let vfoo = vec![[0, 1, 2, 3]]; let _ = vfoo.iter().find(|a| a[0] == 42).is_none(); + //~^ search_is_some } #[allow(clippy::match_like_matches_macro)] fn slice_projection() { let vfoo = vec![[0, 1, 2, 3, 0, 1, 2, 3]]; let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_none(); + //~^ search_is_some } fn please(x: &u32) -> bool { @@ -117,16 +136,22 @@ mod issue7392 { let x = 19; let ppx: &u32 = &x; let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_none(); + //~^ search_is_some let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_none(); + //~^ search_is_some let v = vec![3, 2, 1, 0]; let _ = v.iter().find(|x| deref_enough(**x)).is_none(); + //~^ search_is_some let _ = v.iter().find(|x: &&u32| deref_enough(**x)).is_none(); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().find(|x| arg_no_deref(x)).is_none(); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().find(|x: &&u32| arg_no_deref(x)).is_none(); + //~^ search_is_some } fn field_index_projection() { @@ -146,6 +171,7 @@ mod issue7392 { bar: vec![vec![0, 1, 2, 3]], }, }]; + //~v search_is_some let _ = vfoo .iter() .find(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2) @@ -163,11 +189,13 @@ mod issue7392 { inner: vec![Foo { bar: 0 }], }]; let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_none(); + //~^ search_is_some } fn double_deref_index_projection() { let vfoo = vec![&&[0, 1, 2, 3]]; let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_none(); + //~^ search_is_some } fn method_call_by_ref() { @@ -181,11 +209,14 @@ mod issue7392 { } let vfoo = vec![Foo { bar: 1 }]; let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_none(); + //~^ search_is_some } fn ref_bindings() { let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|(&x, y)| x == *y).is_none(); + //~^ search_is_some let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_none(); + //~^ search_is_some } fn test_string_1(s: &str) -> bool { @@ -205,7 +236,9 @@ mod issue7392 { let lst = &[String::from("Hello"), String::from("world")]; let v: Vec<&[String]> = vec![lst]; let _ = v.iter().find(|s| s[0].is_empty()).is_none(); + //~^ search_is_some let _ = v.iter().find(|s| test_string_1(&s[0])).is_none(); + //~^ search_is_some // Field projections struct FieldProjection<'a> { @@ -215,7 +248,10 @@ mod issue7392 { let instance = FieldProjection { field: &field }; let v = vec![instance]; let _ = v.iter().find(|fp| fp.field.is_power_of_two()).is_none(); + //~^ search_is_some let _ = v.iter().find(|fp| test_u32_1(fp.field)).is_none(); + //~^ search_is_some let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_none(); + //~^ search_is_some } } diff --git a/tests/ui/search_is_some_fixable_none.stderr b/tests/ui/search_is_some_fixable_none.stderr index 107f59a97d2f..d81d213a26a0 100644 --- a/tests/ui/search_is_some_fixable_none.stderr +++ b/tests/ui/search_is_some_fixable_none.stderr @@ -8,49 +8,49 @@ LL | let _ = v.iter().find(|&x| *x < 0).is_none(); = help: to override `-D warnings` add `#[allow(clippy::search_is_some)]` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:10:13 + --> $DIR/search_is_some_fixable_none.rs:12:13 | LL | let _ = (0..1).find(|x| **y == *x).is_none(); // one dereference less | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(0..1).any(|x| **y == x)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:11:13 + --> $DIR/search_is_some_fixable_none.rs:13:13 | LL | let _ = (0..1).find(|x| *x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(0..1).any(|x| x == 0)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:12:13 + --> $DIR/search_is_some_fixable_none.rs:14:13 | LL | let _ = v.iter().find(|x| **x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| *x == 0)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:13:13 + --> $DIR/search_is_some_fixable_none.rs:16:13 | LL | let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(4..5).any(|x| x == 1 || x == 3 || x == 5)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:14:13 + --> $DIR/search_is_some_fixable_none.rs:18:13 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(1..3).any(|x| [1, 2, 3].contains(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:15:13 + --> $DIR/search_is_some_fixable_none.rs:20:13 | LL | let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(1..3).any(|x| x == 0 || [1, 2, 3].contains(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:16:13 + --> $DIR/search_is_some_fixable_none.rs:22:13 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:17:13 + --> $DIR/search_is_some_fixable_none.rs:26:13 | LL | let _ = (1..3) | _____________^ @@ -59,91 +59,91 @@ LL | | .is_none(); | |__________________^ help: consider using: `!(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0 || [4, 5, 6].contains(&x) || x == -1)` error: called `is_none()` after searching an `Iterator` with `position` - --> $DIR/search_is_some_fixable_none.rs:22:13 + --> $DIR/search_is_some_fixable_none.rs:31:13 | LL | let _ = v.iter().position(|&x| x < 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|&x| x < 0)` error: called `is_none()` after searching an `Iterator` with `rposition` - --> $DIR/search_is_some_fixable_none.rs:25:13 + --> $DIR/search_is_some_fixable_none.rs:35:13 | LL | let _ = v.iter().rposition(|&x| x < 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|&x| x < 0)` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:31:13 + --> $DIR/search_is_some_fixable_none.rs:42:13 | LL | let _ = "hello world".find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!"hello world".contains("world")` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:32:13 + --> $DIR/search_is_some_fixable_none.rs:44:13 | LL | let _ = "hello world".find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!"hello world".contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:33:13 + --> $DIR/search_is_some_fixable_none.rs:45:13 | LL | let _ = "hello world".find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!"hello world".contains(&s2[2..])` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:35:13 + --> $DIR/search_is_some_fixable_none.rs:48:13 | LL | let _ = s1.find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1.contains("world")` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:36:13 + --> $DIR/search_is_some_fixable_none.rs:49:13 | LL | let _ = s1.find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1.contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:37:13 + --> $DIR/search_is_some_fixable_none.rs:50:13 | LL | let _ = s1.find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1.contains(&s2[2..])` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:39:13 + --> $DIR/search_is_some_fixable_none.rs:52:13 | LL | let _ = s1[2..].find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1[2..].contains("world")` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:40:13 + --> $DIR/search_is_some_fixable_none.rs:53:13 | LL | let _ = s1[2..].find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1[2..].contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:41:13 + --> $DIR/search_is_some_fixable_none.rs:54:13 | LL | let _ = s1[2..].find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1[2..].contains(&s2[2..])` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:57:25 + --> $DIR/search_is_some_fixable_none.rs:70:25 | LL | .filter(|c| filter_hand.iter().find(|cc| c == cc).is_none()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!filter_hand.iter().any(|cc| c == &cc)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:73:30 + --> $DIR/search_is_some_fixable_none.rs:87:30 | LL | .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_none()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!filter_hand.iter().any(|cc| c == cc)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:84:17 + --> $DIR/search_is_some_fixable_none.rs:99:17 | LL | let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|v| v.foo == 1 && v.bar == 2)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:87:17 + --> $DIR/search_is_some_fixable_none.rs:104:17 | LL | let _ = vfoo | _________________^ @@ -159,55 +159,55 @@ LL ~ .iter().any(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2); | error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:95:17 + --> $DIR/search_is_some_fixable_none.rs:112:17 | LL | let _ = vfoo.iter().find(|a| a[0] == 42).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|a| a[0] == 42)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:101:17 + --> $DIR/search_is_some_fixable_none.rs:119:17 | LL | let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|sub| sub[1..4].len() == 3)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:119:17 + --> $DIR/search_is_some_fixable_none.rs:138:17 | LL | let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `![ppx].iter().any(|ppp_x: &&u32| please(ppp_x))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:120:17 + --> $DIR/search_is_some_fixable_none.rs:140:17 | LL | let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `![String::from("Hey hey")].iter().any(|s| s.len() == 2)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:123:17 + --> $DIR/search_is_some_fixable_none.rs:144:17 | LL | let _ = v.iter().find(|x| deref_enough(**x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| deref_enough(*x))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:124:17 + --> $DIR/search_is_some_fixable_none.rs:146:17 | LL | let _ = v.iter().find(|x: &&u32| deref_enough(**x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x: &u32| deref_enough(*x))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:127:17 + --> $DIR/search_is_some_fixable_none.rs:150:17 | LL | let _ = v.iter().find(|x| arg_no_deref(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| arg_no_deref(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:129:17 + --> $DIR/search_is_some_fixable_none.rs:153:17 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x: &u32| arg_no_deref(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:149:17 + --> $DIR/search_is_some_fixable_none.rs:175:17 | LL | let _ = vfoo | _________________^ @@ -223,61 +223,61 @@ LL ~ .iter().any(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] | error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:165:17 + --> $DIR/search_is_some_fixable_none.rs:191:17 | LL | let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|v| v.inner[0].bar == 2)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:170:17 + --> $DIR/search_is_some_fixable_none.rs:197:17 | LL | let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|x| (**x)[0] == 9)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:183:17 + --> $DIR/search_is_some_fixable_none.rs:211:17 | LL | let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|v| v.by_ref(&v.bar))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:187:17 + --> $DIR/search_is_some_fixable_none.rs:216:17 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|(&x, y)| x == *y).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `![&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:188:17 + --> $DIR/search_is_some_fixable_none.rs:218:17 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `![&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:207:17 + --> $DIR/search_is_some_fixable_none.rs:238:17 | LL | let _ = v.iter().find(|s| s[0].is_empty()).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|s| s[0].is_empty())` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:208:17 + --> $DIR/search_is_some_fixable_none.rs:240:17 | LL | let _ = v.iter().find(|s| test_string_1(&s[0])).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|s| test_string_1(&s[0]))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:217:17 + --> $DIR/search_is_some_fixable_none.rs:250:17 | LL | let _ = v.iter().find(|fp| fp.field.is_power_of_two()).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|fp| fp.field.is_power_of_two())` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:218:17 + --> $DIR/search_is_some_fixable_none.rs:252:17 | LL | let _ = v.iter().find(|fp| test_u32_1(fp.field)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|fp| test_u32_1(fp.field))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:219:17 + --> $DIR/search_is_some_fixable_none.rs:254:17 | LL | let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|fp| test_u32_2(*fp.field))` diff --git a/tests/ui/search_is_some_fixable_some.fixed b/tests/ui/search_is_some_fixable_some.fixed index ae3cbc3c4da2..d814474dda10 100644 --- a/tests/ui/search_is_some_fixable_some.fixed +++ b/tests/ui/search_is_some_fixable_some.fixed @@ -6,37 +6,49 @@ fn main() { let y = &&42; // Check `find().is_some()`, single-line case. - let _ = v.iter().any(|x| *x < 0); + let _ = v.iter().any(|x| *x < 0); //~ search_is_some + + //~v search_is_some let _ = (0..1).any(|x| **y == x); // one dereference less - let _ = (0..1).any(|x| x == 0); + let _ = (0..1).any(|x| x == 0); //~ search_is_some let _ = v.iter().any(|x| *x == 0); + //~^ search_is_some let _ = (4..5).any(|x| x == 1 || x == 3 || x == 5); + //~^ search_is_some let _ = (1..3).any(|x| [1, 2, 3].contains(&x)); + //~^ search_is_some let _ = (1..3).any(|x| x == 0 || [1, 2, 3].contains(&x)); + //~^ search_is_some let _ = (1..3).any(|x| [1, 2, 3].contains(&x) || x == 0); + //~^ search_is_some let _ = (1..3) + //~v search_is_some .any(|x| [1, 2, 3].contains(&x) || x == 0 || [4, 5, 6].contains(&x) || x == -1); // Check `position().is_some()`, single-line case. let _ = v.iter().any(|&x| x < 0); + //~^ search_is_some // Check `rposition().is_some()`, single-line case. let _ = v.iter().any(|&x| x < 0); + //~^ search_is_some let s1 = String::from("hello world"); let s2 = String::from("world"); // caller of `find()` is a `&`static str` let _ = "hello world".contains("world"); - let _ = "hello world".contains(&s2); + //~^ search_is_some + let _ = "hello world".contains(&s2); //~ search_is_some let _ = "hello world".contains(&s2[2..]); + //~^ search_is_some // caller of `find()` is a `String` - let _ = s1.contains("world"); - let _ = s1.contains(&s2); - let _ = s1.contains(&s2[2..]); + let _ = s1.contains("world"); //~ search_is_some + let _ = s1.contains(&s2); //~ search_is_some + let _ = s1.contains(&s2[2..]); //~ search_is_some // caller of `find()` is slice of `String` - let _ = s1[2..].contains("world"); - let _ = s1[2..].contains(&s2); - let _ = s1[2..].contains(&s2[2..]); + let _ = s1[2..].contains("world"); //~ search_is_some + let _ = s1[2..].contains(&s2); //~ search_is_some + let _ = s1[2..].contains(&s2[2..]); //~ search_is_some } #[allow(clippy::clone_on_copy, clippy::map_clone)] @@ -53,6 +65,7 @@ mod issue7392 { .hand .iter() .filter(|c| filter_hand.iter().any(|cc| c == &cc)) + //~^ search_is_some .map(|c| c.clone()) .collect::>(); } @@ -69,6 +82,7 @@ mod issue7392 { .hand .iter() .filter(|(c, _)| filter_hand.iter().any(|cc| c == cc)) + //~^ search_is_some .map(|c| c.clone()) .collect::>(); } @@ -80,22 +94,26 @@ mod issue7392 { } let vfoo = vec![Foo { foo: 1, bar: 2 }]; let _ = vfoo.iter().any(|v| v.foo == 1 && v.bar == 2); + //~^ search_is_some let vfoo = vec![(42, Foo { foo: 1, bar: 2 })]; let _ = vfoo .iter() + //~v search_is_some .any(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2); } fn index_projection() { let vfoo = vec![[0, 1, 2, 3]]; let _ = vfoo.iter().any(|a| a[0] == 42); + //~^ search_is_some } #[allow(clippy::match_like_matches_macro)] fn slice_projection() { let vfoo = vec![[0, 1, 2, 3, 0, 1, 2, 3]]; let _ = vfoo.iter().any(|sub| sub[1..4].len() == 3); + //~^ search_is_some } fn please(x: &u32) -> bool { @@ -114,16 +132,22 @@ mod issue7392 { let x = 19; let ppx: &u32 = &x; let _ = [ppx].iter().any(|ppp_x: &&u32| please(ppp_x)); + //~^ search_is_some let _ = [String::from("Hey hey")].iter().any(|s| s.len() == 2); + //~^ search_is_some let v = vec![3, 2, 1, 0]; let _ = v.iter().any(|x| deref_enough(*x)); + //~^ search_is_some let _ = v.iter().any(|x: &u32| deref_enough(*x)); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().any(|x| arg_no_deref(&x)); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().any(|x: &u32| arg_no_deref(&x)); + //~^ search_is_some } fn field_index_projection() { @@ -145,6 +169,7 @@ mod issue7392 { }]; let _ = vfoo .iter() + //~v search_is_some .any(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2); } @@ -159,11 +184,13 @@ mod issue7392 { inner: vec![Foo { bar: 0 }], }]; let _ = vfoo.iter().any(|v| v.inner[0].bar == 2); + //~^ search_is_some } fn double_deref_index_projection() { let vfoo = vec![&&[0, 1, 2, 3]]; let _ = vfoo.iter().any(|x| (**x)[0] == 9); + //~^ search_is_some } fn method_call_by_ref() { @@ -177,11 +204,14 @@ mod issue7392 { } let vfoo = vec![Foo { bar: 1 }]; let _ = vfoo.iter().any(|v| v.by_ref(&v.bar)); + //~^ search_is_some } fn ref_bindings() { let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y); + //~^ search_is_some let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y); + //~^ search_is_some } fn test_string_1(s: &str) -> bool { @@ -201,7 +231,9 @@ mod issue7392 { let lst = &[String::from("Hello"), String::from("world")]; let v: Vec<&[String]> = vec![lst]; let _ = v.iter().any(|s| s[0].is_empty()); + //~^ search_is_some let _ = v.iter().any(|s| test_string_1(&s[0])); + //~^ search_is_some // Field projections struct FieldProjection<'a> { @@ -211,8 +243,11 @@ mod issue7392 { let instance = FieldProjection { field: &field }; let v = vec![instance]; let _ = v.iter().any(|fp| fp.field.is_power_of_two()); + //~^ search_is_some let _ = v.iter().any(|fp| test_u32_1(fp.field)); + //~^ search_is_some let _ = v.iter().any(|fp| test_u32_2(*fp.field)); + //~^ search_is_some } } @@ -228,6 +263,7 @@ mod issue9120 { fn wrapper bool>(v: Vec, func: T) -> bool { #[allow(clippy::redundant_closure)] v.iter().any(|x: &u32| func(&x)) + //~^ search_is_some } fn do_tests() { @@ -237,11 +273,14 @@ mod issue9120 { #[allow(clippy::redundant_closure)] let _ = v.iter().any(|x: &u32| arg_no_deref_impl(&x)); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().any(|x: &u32| arg_no_deref_dyn(&x)); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().any(|x: &u32| (*arg_no_deref_dyn)(&x)); + //~^ search_is_some } } diff --git a/tests/ui/search_is_some_fixable_some.rs b/tests/ui/search_is_some_fixable_some.rs index 19a44803fd54..5a96409f4ce7 100644 --- a/tests/ui/search_is_some_fixable_some.rs +++ b/tests/ui/search_is_some_fixable_some.rs @@ -6,38 +6,50 @@ fn main() { let y = &&42; // Check `find().is_some()`, single-line case. - let _ = v.iter().find(|&x| *x < 0).is_some(); + let _ = v.iter().find(|&x| *x < 0).is_some(); //~ search_is_some + + //~v search_is_some let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less - let _ = (0..1).find(|x| *x == 0).is_some(); + let _ = (0..1).find(|x| *x == 0).is_some(); //~ search_is_some let _ = v.iter().find(|x| **x == 0).is_some(); + //~^ search_is_some let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_some(); + //~^ search_is_some let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_some(); + //~^ search_is_some let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_some(); + //~^ search_is_some let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_some(); + //~^ search_is_some let _ = (1..3) + //~v search_is_some .find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1) .is_some(); // Check `position().is_some()`, single-line case. let _ = v.iter().position(|&x| x < 0).is_some(); + //~^ search_is_some // Check `rposition().is_some()`, single-line case. let _ = v.iter().rposition(|&x| x < 0).is_some(); + //~^ search_is_some let s1 = String::from("hello world"); let s2 = String::from("world"); // caller of `find()` is a `&`static str` let _ = "hello world".find("world").is_some(); - let _ = "hello world".find(&s2).is_some(); + //~^ search_is_some + let _ = "hello world".find(&s2).is_some(); //~ search_is_some let _ = "hello world".find(&s2[2..]).is_some(); + //~^ search_is_some // caller of `find()` is a `String` - let _ = s1.find("world").is_some(); - let _ = s1.find(&s2).is_some(); - let _ = s1.find(&s2[2..]).is_some(); + let _ = s1.find("world").is_some(); //~ search_is_some + let _ = s1.find(&s2).is_some(); //~ search_is_some + let _ = s1.find(&s2[2..]).is_some(); //~ search_is_some // caller of `find()` is slice of `String` - let _ = s1[2..].find("world").is_some(); - let _ = s1[2..].find(&s2).is_some(); - let _ = s1[2..].find(&s2[2..]).is_some(); + let _ = s1[2..].find("world").is_some(); //~ search_is_some + let _ = s1[2..].find(&s2).is_some(); //~ search_is_some + let _ = s1[2..].find(&s2[2..]).is_some(); //~ search_is_some } #[allow(clippy::clone_on_copy, clippy::map_clone)] @@ -54,6 +66,7 @@ mod issue7392 { .hand .iter() .filter(|c| filter_hand.iter().find(|cc| c == cc).is_some()) + //~^ search_is_some .map(|c| c.clone()) .collect::>(); } @@ -70,6 +83,7 @@ mod issue7392 { .hand .iter() .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_some()) + //~^ search_is_some .map(|c| c.clone()) .collect::>(); } @@ -81,10 +95,12 @@ mod issue7392 { } let vfoo = vec![Foo { foo: 1, bar: 2 }]; let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_some(); + //~^ search_is_some let vfoo = vec![(42, Foo { foo: 1, bar: 2 })]; let _ = vfoo .iter() + //~v search_is_some .find(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2) .is_some(); } @@ -92,12 +108,14 @@ mod issue7392 { fn index_projection() { let vfoo = vec![[0, 1, 2, 3]]; let _ = vfoo.iter().find(|a| a[0] == 42).is_some(); + //~^ search_is_some } #[allow(clippy::match_like_matches_macro)] fn slice_projection() { let vfoo = vec![[0, 1, 2, 3, 0, 1, 2, 3]]; let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_some(); + //~^ search_is_some } fn please(x: &u32) -> bool { @@ -116,16 +134,22 @@ mod issue7392 { let x = 19; let ppx: &u32 = &x; let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_some(); + //~^ search_is_some let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_some(); + //~^ search_is_some let v = vec![3, 2, 1, 0]; let _ = v.iter().find(|x| deref_enough(**x)).is_some(); + //~^ search_is_some let _ = v.iter().find(|x: &&u32| deref_enough(**x)).is_some(); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().find(|x| arg_no_deref(x)).is_some(); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().find(|x: &&u32| arg_no_deref(x)).is_some(); + //~^ search_is_some } fn field_index_projection() { @@ -147,6 +171,7 @@ mod issue7392 { }]; let _ = vfoo .iter() + //~v search_is_some .find(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2) .is_some(); } @@ -162,11 +187,13 @@ mod issue7392 { inner: vec![Foo { bar: 0 }], }]; let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_some(); + //~^ search_is_some } fn double_deref_index_projection() { let vfoo = vec![&&[0, 1, 2, 3]]; let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_some(); + //~^ search_is_some } fn method_call_by_ref() { @@ -180,11 +207,14 @@ mod issue7392 { } let vfoo = vec![Foo { bar: 1 }]; let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_some(); + //~^ search_is_some } fn ref_bindings() { let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|(&x, y)| x == *y).is_some(); + //~^ search_is_some let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_some(); + //~^ search_is_some } fn test_string_1(s: &str) -> bool { @@ -204,7 +234,9 @@ mod issue7392 { let lst = &[String::from("Hello"), String::from("world")]; let v: Vec<&[String]> = vec![lst]; let _ = v.iter().find(|s| s[0].is_empty()).is_some(); + //~^ search_is_some let _ = v.iter().find(|s| test_string_1(&s[0])).is_some(); + //~^ search_is_some // Field projections struct FieldProjection<'a> { @@ -214,8 +246,11 @@ mod issue7392 { let instance = FieldProjection { field: &field }; let v = vec![instance]; let _ = v.iter().find(|fp| fp.field.is_power_of_two()).is_some(); + //~^ search_is_some let _ = v.iter().find(|fp| test_u32_1(fp.field)).is_some(); + //~^ search_is_some let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_some(); + //~^ search_is_some } } @@ -231,6 +266,7 @@ mod issue9120 { fn wrapper bool>(v: Vec, func: T) -> bool { #[allow(clippy::redundant_closure)] v.iter().find(|x: &&u32| func(x)).is_some() + //~^ search_is_some } fn do_tests() { @@ -240,11 +276,14 @@ mod issue9120 { #[allow(clippy::redundant_closure)] let _ = v.iter().find(|x: &&u32| arg_no_deref_impl(x)).is_some(); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().find(|x: &&u32| arg_no_deref_dyn(x)).is_some(); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().find(|x: &&u32| (*arg_no_deref_dyn)(x)).is_some(); + //~^ search_is_some } } diff --git a/tests/ui/search_is_some_fixable_some.stderr b/tests/ui/search_is_some_fixable_some.stderr index e706ce646923..fdf9f686814c 100644 --- a/tests/ui/search_is_some_fixable_some.stderr +++ b/tests/ui/search_is_some_fixable_some.stderr @@ -8,49 +8,49 @@ LL | let _ = v.iter().find(|&x| *x < 0).is_some(); = help: to override `-D warnings` add `#[allow(clippy::search_is_some)]` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:10:20 + --> $DIR/search_is_some_fixable_some.rs:12:20 | LL | let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| **y == x)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:11:20 + --> $DIR/search_is_some_fixable_some.rs:13:20 | LL | let _ = (0..1).find(|x| *x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| x == 0)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:12:22 + --> $DIR/search_is_some_fixable_some.rs:14:22 | LL | let _ = v.iter().find(|x| **x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| *x == 0)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:13:20 + --> $DIR/search_is_some_fixable_some.rs:16:20 | LL | let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| x == 1 || x == 3 || x == 5)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:14:20 + --> $DIR/search_is_some_fixable_some.rs:18:20 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| [1, 2, 3].contains(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:15:20 + --> $DIR/search_is_some_fixable_some.rs:20:20 | LL | let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| x == 0 || [1, 2, 3].contains(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:16:20 + --> $DIR/search_is_some_fixable_some.rs:22:20 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| [1, 2, 3].contains(&x) || x == 0)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:18:10 + --> $DIR/search_is_some_fixable_some.rs:26:10 | LL | .find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1) | __________^ @@ -58,91 +58,91 @@ LL | | .is_some(); | |__________________^ help: consider using: `any(|x| [1, 2, 3].contains(&x) || x == 0 || [4, 5, 6].contains(&x) || x == -1)` error: called `is_some()` after searching an `Iterator` with `position` - --> $DIR/search_is_some_fixable_some.rs:22:22 + --> $DIR/search_is_some_fixable_some.rs:30:22 | LL | let _ = v.iter().position(|&x| x < 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|&x| x < 0)` error: called `is_some()` after searching an `Iterator` with `rposition` - --> $DIR/search_is_some_fixable_some.rs:25:22 + --> $DIR/search_is_some_fixable_some.rs:34:22 | LL | let _ = v.iter().rposition(|&x| x < 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|&x| x < 0)` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:30:27 + --> $DIR/search_is_some_fixable_some.rs:40:27 | LL | let _ = "hello world".find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains("world")` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:31:27 + --> $DIR/search_is_some_fixable_some.rs:42:27 | LL | let _ = "hello world".find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:32:27 + --> $DIR/search_is_some_fixable_some.rs:43:27 | LL | let _ = "hello world".find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2[2..])` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:34:16 + --> $DIR/search_is_some_fixable_some.rs:46:16 | LL | let _ = s1.find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains("world")` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:35:16 + --> $DIR/search_is_some_fixable_some.rs:47:16 | LL | let _ = s1.find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:36:16 + --> $DIR/search_is_some_fixable_some.rs:48:16 | LL | let _ = s1.find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2[2..])` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:38:21 + --> $DIR/search_is_some_fixable_some.rs:50:21 | LL | let _ = s1[2..].find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains("world")` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:39:21 + --> $DIR/search_is_some_fixable_some.rs:51:21 | LL | let _ = s1[2..].find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:40:21 + --> $DIR/search_is_some_fixable_some.rs:52:21 | LL | let _ = s1[2..].find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2[2..])` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:56:44 + --> $DIR/search_is_some_fixable_some.rs:68:44 | LL | .filter(|c| filter_hand.iter().find(|cc| c == cc).is_some()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|cc| c == &cc)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:72:49 + --> $DIR/search_is_some_fixable_some.rs:85:49 | LL | .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_some()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|cc| c == cc)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:83:29 + --> $DIR/search_is_some_fixable_some.rs:97:29 | LL | let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|v| v.foo == 1 && v.bar == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:88:14 + --> $DIR/search_is_some_fixable_some.rs:104:14 | LL | .find(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2) | ______________^ @@ -150,55 +150,55 @@ LL | | .is_some(); | |______________________^ help: consider using: `any(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:94:29 + --> $DIR/search_is_some_fixable_some.rs:110:29 | LL | let _ = vfoo.iter().find(|a| a[0] == 42).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|a| a[0] == 42)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:100:29 + --> $DIR/search_is_some_fixable_some.rs:117:29 | LL | let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|sub| sub[1..4].len() == 3)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:118:30 + --> $DIR/search_is_some_fixable_some.rs:136:30 | LL | let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|ppp_x: &&u32| please(ppp_x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:119:50 + --> $DIR/search_is_some_fixable_some.rs:138:50 | LL | let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|s| s.len() == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:122:26 + --> $DIR/search_is_some_fixable_some.rs:142:26 | LL | let _ = v.iter().find(|x| deref_enough(**x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| deref_enough(*x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:123:26 + --> $DIR/search_is_some_fixable_some.rs:144:26 | LL | let _ = v.iter().find(|x: &&u32| deref_enough(**x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| deref_enough(*x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:126:26 + --> $DIR/search_is_some_fixable_some.rs:148:26 | LL | let _ = v.iter().find(|x| arg_no_deref(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| arg_no_deref(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:128:26 + --> $DIR/search_is_some_fixable_some.rs:151:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| arg_no_deref(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:150:14 + --> $DIR/search_is_some_fixable_some.rs:175:14 | LL | .find(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2) | ______________^ @@ -206,85 +206,85 @@ LL | | .is_some(); | |______________________^ help: consider using: `any(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:164:29 + --> $DIR/search_is_some_fixable_some.rs:189:29 | LL | let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|v| v.inner[0].bar == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:169:29 + --> $DIR/search_is_some_fixable_some.rs:195:29 | LL | let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| (**x)[0] == 9)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:182:29 + --> $DIR/search_is_some_fixable_some.rs:209:29 | LL | let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|v| v.by_ref(&v.bar))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:186:55 + --> $DIR/search_is_some_fixable_some.rs:214:55 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|(&x, y)| x == *y).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|(&x, y)| x == *y)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:187:55 + --> $DIR/search_is_some_fixable_some.rs:216:55 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|(&x, y)| x == *y)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:206:26 + --> $DIR/search_is_some_fixable_some.rs:236:26 | LL | let _ = v.iter().find(|s| s[0].is_empty()).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|s| s[0].is_empty())` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:207:26 + --> $DIR/search_is_some_fixable_some.rs:238:26 | LL | let _ = v.iter().find(|s| test_string_1(&s[0])).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|s| test_string_1(&s[0]))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:216:26 + --> $DIR/search_is_some_fixable_some.rs:248:26 | LL | let _ = v.iter().find(|fp| fp.field.is_power_of_two()).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|fp| fp.field.is_power_of_two())` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:217:26 + --> $DIR/search_is_some_fixable_some.rs:250:26 | LL | let _ = v.iter().find(|fp| test_u32_1(fp.field)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|fp| test_u32_1(fp.field))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:218:26 + --> $DIR/search_is_some_fixable_some.rs:252:26 | LL | let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|fp| test_u32_2(*fp.field))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:233:18 + --> $DIR/search_is_some_fixable_some.rs:268:18 | LL | v.iter().find(|x: &&u32| func(x)).is_some() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| func(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:242:26 + --> $DIR/search_is_some_fixable_some.rs:278:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref_impl(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| arg_no_deref_impl(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:245:26 + --> $DIR/search_is_some_fixable_some.rs:282:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref_dyn(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| arg_no_deref_dyn(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:248:26 + --> $DIR/search_is_some_fixable_some.rs:286:26 | LL | let _ = v.iter().find(|x: &&u32| (*arg_no_deref_dyn)(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| (*arg_no_deref_dyn)(&x))` diff --git a/tests/ui/seek_from_current.fixed b/tests/ui/seek_from_current.fixed index 543f0c681393..fd2e99c3563b 100644 --- a/tests/ui/seek_from_current.fixed +++ b/tests/ui/seek_from_current.fixed @@ -16,7 +16,7 @@ fn _msrv_1_50() -> io::Result<()> { fn _msrv_1_51() -> io::Result<()> { let mut f = File::create("foo.txt")?; f.write_all(b"Hi!")?; - f.stream_position()?; + f.stream_position()?; //~ seek_from_current f.seek(SeekFrom::Current(1))?; Ok(()) } diff --git a/tests/ui/seek_from_current.rs b/tests/ui/seek_from_current.rs index 4ed877f8ec21..67d9fb27eb62 100644 --- a/tests/ui/seek_from_current.rs +++ b/tests/ui/seek_from_current.rs @@ -16,7 +16,7 @@ fn _msrv_1_50() -> io::Result<()> { fn _msrv_1_51() -> io::Result<()> { let mut f = File::create("foo.txt")?; f.write_all(b"Hi!")?; - f.seek(SeekFrom::Current(0))?; + f.seek(SeekFrom::Current(0))?; //~ seek_from_current f.seek(SeekFrom::Current(1))?; Ok(()) } diff --git a/tests/ui/seek_to_start_instead_of_rewind.fixed b/tests/ui/seek_to_start_instead_of_rewind.fixed index 8859a68320f0..448215292ac2 100644 --- a/tests/ui/seek_to_start_instead_of_rewind.fixed +++ b/tests/ui/seek_to_start_instead_of_rewind.fixed @@ -49,12 +49,12 @@ fn seek_to_start_false_trait_bound(t: &mut T) { // This should trigger clippy warning fn seek_to_start(t: &mut T) { - t.rewind(); + t.rewind(); //~ seek_to_start_instead_of_rewind } // This should trigger clippy warning fn owned_seek_to_start(mut t: T) { - t.rewind(); + t.rewind(); //~ seek_to_start_instead_of_rewind } // This should NOT trigger clippy warning because @@ -133,7 +133,7 @@ fn msrv_1_55() { let hello = "Hello!\n"; write!(f, "{hello}").unwrap(); - f.rewind(); + f.rewind(); //~ seek_to_start_instead_of_rewind let mut buf = String::new(); f.read_to_string(&mut buf).unwrap(); diff --git a/tests/ui/seek_to_start_instead_of_rewind.rs b/tests/ui/seek_to_start_instead_of_rewind.rs index 7b72efb34ff8..4ad791d71bc3 100644 --- a/tests/ui/seek_to_start_instead_of_rewind.rs +++ b/tests/ui/seek_to_start_instead_of_rewind.rs @@ -49,12 +49,12 @@ fn seek_to_start_false_trait_bound(t: &mut T) { // This should trigger clippy warning fn seek_to_start(t: &mut T) { - t.seek(SeekFrom::Start(0)); + t.seek(SeekFrom::Start(0)); //~ seek_to_start_instead_of_rewind } // This should trigger clippy warning fn owned_seek_to_start(mut t: T) { - t.seek(SeekFrom::Start(0)); + t.seek(SeekFrom::Start(0)); //~ seek_to_start_instead_of_rewind } // This should NOT trigger clippy warning because @@ -133,7 +133,7 @@ fn msrv_1_55() { let hello = "Hello!\n"; write!(f, "{hello}").unwrap(); - f.seek(SeekFrom::Start(0)); + f.seek(SeekFrom::Start(0)); //~ seek_to_start_instead_of_rewind let mut buf = String::new(); f.read_to_string(&mut buf).unwrap(); diff --git a/tests/ui/semicolon_if_nothing_returned.fixed b/tests/ui/semicolon_if_nothing_returned.fixed index cdfa5d9cc780..b5247912b90f 100644 --- a/tests/ui/semicolon_if_nothing_returned.fixed +++ b/tests/ui/semicolon_if_nothing_returned.fixed @@ -10,22 +10,22 @@ fn get_unit() {} // the functions below trigger the lint fn main() { - println!("Hello"); + println!("Hello"); //~ semicolon_if_nothing_returned } fn hello() { - get_unit(); + get_unit(); //~ semicolon_if_nothing_returned } fn basic101(x: i32) { let y: i32; - y = x + 1; + y = x + 1; //~ semicolon_if_nothing_returned } #[rustfmt::skip] fn closure_error() { let _d = || { - hello(); + hello(); //~ semicolon_if_nothing_returned }; } @@ -37,6 +37,7 @@ fn unsafe_checks_error() { let mut s = MaybeUninit::::uninit(); let _d = || unsafe { ptr::drop_in_place(s.as_mut_ptr()); + //~^ semicolon_if_nothing_returned }; } diff --git a/tests/ui/semicolon_if_nothing_returned.rs b/tests/ui/semicolon_if_nothing_returned.rs index 315b7e4f3839..67caa507f85e 100644 --- a/tests/ui/semicolon_if_nothing_returned.rs +++ b/tests/ui/semicolon_if_nothing_returned.rs @@ -10,22 +10,22 @@ fn get_unit() {} // the functions below trigger the lint fn main() { - println!("Hello") + println!("Hello") //~ semicolon_if_nothing_returned } fn hello() { - get_unit() + get_unit() //~ semicolon_if_nothing_returned } fn basic101(x: i32) { let y: i32; - y = x + 1 + y = x + 1 //~ semicolon_if_nothing_returned } #[rustfmt::skip] fn closure_error() { let _d = || { - hello() + hello() //~ semicolon_if_nothing_returned }; } @@ -37,6 +37,7 @@ fn unsafe_checks_error() { let mut s = MaybeUninit::::uninit(); let _d = || unsafe { ptr::drop_in_place(s.as_mut_ptr()) + //~^ semicolon_if_nothing_returned }; } diff --git a/tests/ui/semicolon_inside_block.fixed b/tests/ui/semicolon_inside_block.fixed index 21681e71589e..bb8e3ba29efc 100644 --- a/tests/ui/semicolon_inside_block.fixed +++ b/tests/ui/semicolon_inside_block.fixed @@ -35,8 +35,8 @@ fn main() { unit_fn_block() } - { unit_fn_block(); } - unsafe { unit_fn_block(); } + { unit_fn_block(); } //~ semicolon_inside_block + unsafe { unit_fn_block(); } //~ semicolon_inside_block { unit_fn_block(); } unsafe { unit_fn_block(); } @@ -44,6 +44,7 @@ fn main() { { unit_fn_block(); }; unsafe { unit_fn_block(); }; + //~v semicolon_inside_block { unit_fn_block(); unit_fn_block(); @@ -57,7 +58,7 @@ fn main() { unit_fn_block(); }; - { m!(()); } + { m!(()); } //~ semicolon_inside_block { m!(()); } { m!(()); }; m!(0); diff --git a/tests/ui/semicolon_inside_block.rs b/tests/ui/semicolon_inside_block.rs index 3a81661cd16f..0dc53a80aa9e 100644 --- a/tests/ui/semicolon_inside_block.rs +++ b/tests/ui/semicolon_inside_block.rs @@ -35,8 +35,8 @@ fn main() { unit_fn_block() } - { unit_fn_block() }; - unsafe { unit_fn_block() }; + { unit_fn_block() }; //~ semicolon_inside_block + unsafe { unit_fn_block() }; //~ semicolon_inside_block { unit_fn_block(); } unsafe { unit_fn_block(); } @@ -44,6 +44,7 @@ fn main() { { unit_fn_block(); }; unsafe { unit_fn_block(); }; + //~v semicolon_inside_block { unit_fn_block(); unit_fn_block() @@ -57,7 +58,7 @@ fn main() { unit_fn_block(); }; - { m!(()) }; + { m!(()) }; //~ semicolon_inside_block { m!(()); } { m!(()); }; m!(0); diff --git a/tests/ui/semicolon_inside_block.stderr b/tests/ui/semicolon_inside_block.stderr index 1bfc1f24c436..dee010199409 100644 --- a/tests/ui/semicolon_inside_block.stderr +++ b/tests/ui/semicolon_inside_block.stderr @@ -25,7 +25,7 @@ LL + unsafe { unit_fn_block(); } | error: consider moving the `;` inside the block for consistent formatting - --> $DIR/semicolon_inside_block.rs:47:5 + --> $DIR/semicolon_inside_block.rs:48:5 | LL | / { LL | | unit_fn_block(); @@ -40,7 +40,7 @@ LL ~ } | error: consider moving the `;` inside the block for consistent formatting - --> $DIR/semicolon_inside_block.rs:60:5 + --> $DIR/semicolon_inside_block.rs:61:5 | LL | { m!(()) }; | ^^^^^^^^^^^ diff --git a/tests/ui/semicolon_outside_block.fixed b/tests/ui/semicolon_outside_block.fixed index 148e112e0bcb..7b2afbbf075d 100644 --- a/tests/ui/semicolon_outside_block.fixed +++ b/tests/ui/semicolon_outside_block.fixed @@ -38,8 +38,8 @@ fn main() { { unit_fn_block() }; unsafe { unit_fn_block() }; - { unit_fn_block() }; - unsafe { unit_fn_block() }; + { unit_fn_block() }; //~ semicolon_outside_block + unsafe { unit_fn_block() }; //~ semicolon_outside_block { unit_fn_block(); }; unsafe { unit_fn_block(); }; @@ -48,6 +48,7 @@ fn main() { unit_fn_block(); unit_fn_block() }; + //~v semicolon_outside_block { unit_fn_block(); unit_fn_block() @@ -58,7 +59,7 @@ fn main() { }; { m!(()) }; - { m!(()) }; + { m!(()) }; //~ semicolon_outside_block { m!(()); }; m!(0); m!(1); diff --git a/tests/ui/semicolon_outside_block.rs b/tests/ui/semicolon_outside_block.rs index c767201469ab..65180f5509e4 100644 --- a/tests/ui/semicolon_outside_block.rs +++ b/tests/ui/semicolon_outside_block.rs @@ -38,8 +38,8 @@ fn main() { { unit_fn_block() }; unsafe { unit_fn_block() }; - { unit_fn_block(); } - unsafe { unit_fn_block(); } + { unit_fn_block(); } //~ semicolon_outside_block + unsafe { unit_fn_block(); } //~ semicolon_outside_block { unit_fn_block(); }; unsafe { unit_fn_block(); }; @@ -48,6 +48,7 @@ fn main() { unit_fn_block(); unit_fn_block() }; + //~v semicolon_outside_block { unit_fn_block(); unit_fn_block(); @@ -58,7 +59,7 @@ fn main() { }; { m!(()) }; - { m!(()); } + { m!(()); } //~ semicolon_outside_block { m!(()); }; m!(0); m!(1); diff --git a/tests/ui/semicolon_outside_block.stderr b/tests/ui/semicolon_outside_block.stderr index 427271fca64d..a42ba3e7f046 100644 --- a/tests/ui/semicolon_outside_block.stderr +++ b/tests/ui/semicolon_outside_block.stderr @@ -25,7 +25,7 @@ LL + unsafe { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> $DIR/semicolon_outside_block.rs:51:5 + --> $DIR/semicolon_outside_block.rs:52:5 | LL | / { LL | | unit_fn_block(); @@ -40,7 +40,7 @@ LL ~ }; | error: consider moving the `;` outside the block for consistent formatting - --> $DIR/semicolon_outside_block.rs:61:5 + --> $DIR/semicolon_outside_block.rs:62:5 | LL | { m!(()); } | ^^^^^^^^^^^ diff --git a/tests/ui/shadow.rs b/tests/ui/shadow.rs index 258dba9dd831..784a4c66870a 100644 --- a/tests/ui/shadow.rs +++ b/tests/ui/shadow.rs @@ -21,22 +21,23 @@ macro_rules! reuse { fn shadow_same() { let x = 1; - let x = x; - let mut x = &x; - let x = &mut x; - let x = *x; + let x = x; //~ shadow_same + let mut x = &x; //~ shadow_same + let x = &mut x; //~ shadow_same + let x = *x; //~ shadow_same } fn shadow_reuse() -> Option<()> { let x = ([[0]], ()); - let x = x.0; - let x = x[0]; - let [x] = x; - let x = Some(x); - let x = foo(x); - let x = || x; - let x = Some(1).map(|_| x)?; + let x = x.0; //~ shadow_reuse + let x = x[0]; //~ shadow_reuse + let [x] = x; //~ shadow_reuse + let x = Some(x); //~ shadow_reuse + let x = foo(x); //~ shadow_reuse + let x = || x; //~ shadow_reuse + let x = Some(1).map(|_| x)?; //~ shadow_reuse let y = 1; + //~v shadow_reuse let y = match y { 1 => 2, _ => 3, @@ -52,28 +53,31 @@ fn shadow_reuse_macro() { fn shadow_unrelated() { let x = 1; - let x = 2; + let x = 2; //~ shadow_unrelated } fn syntax() { fn f(x: u32) { - let x = 1; + let x = 1; //~ shadow_unrelated } let x = 1; match Some(1) { Some(1) => {}, + //~v shadow_unrelated Some(x) => { - let x = 1; + let x = 1; //~ shadow_unrelated }, _ => {}, } - if let Some(x) = Some(1) {} - while let Some(x) = Some(1) {} + if let Some(x) = Some(1) {} //~ shadow_unrelated + while let Some(x) = Some(1) {} //~ shadow_unrelated + + //~v shadow_unrelated let _ = |[x]: [u32; 1]| { - let x = 1; + let x = 1; //~ shadow_unrelated }; let y = Some(1); - if let Some(y) = y {} + if let Some(y) = y {} //~ shadow_reuse } fn negative() { @@ -109,13 +113,14 @@ fn question_mark() -> Option<()> { pub async fn foo1(_a: i32) {} pub async fn foo2(_a: i32, _b: i64) { - let _b = _a; + let _b = _a; //~ shadow_unrelated } fn ice_8748() { let _ = [0; { let x = 1; if let Some(x) = Some(1) { x } else { 1 } + //~^ shadow_unrelated }]; } diff --git a/tests/ui/shadow.stderr b/tests/ui/shadow.stderr index 26ace287b1f4..65d2155f6452 100644 --- a/tests/ui/shadow.stderr +++ b/tests/ui/shadow.stderr @@ -135,7 +135,7 @@ LL | let x = || x; | ^ error: `y` is shadowed - --> $DIR/shadow.rs:40:9 + --> $DIR/shadow.rs:41:9 | LL | let y = match y { | ^ @@ -147,13 +147,13 @@ LL | let y = 1; | ^ error: `x` shadows a previous, unrelated binding - --> $DIR/shadow.rs:55:9 + --> $DIR/shadow.rs:56:9 | LL | let x = 2; | ^ | note: previous binding is here - --> $DIR/shadow.rs:54:9 + --> $DIR/shadow.rs:55:9 | LL | let x = 1; | ^ @@ -161,121 +161,121 @@ LL | let x = 1; = help: to override `-D warnings` add `#[allow(clippy::shadow_unrelated)]` error: `x` shadows a previous, unrelated binding - --> $DIR/shadow.rs:60:13 + --> $DIR/shadow.rs:61:13 | LL | let x = 1; | ^ | note: previous binding is here - --> $DIR/shadow.rs:59:10 + --> $DIR/shadow.rs:60:10 | LL | fn f(x: u32) { | ^ error: `x` shadows a previous, unrelated binding - --> $DIR/shadow.rs:65:14 + --> $DIR/shadow.rs:67:14 | LL | Some(x) => { | ^ | note: previous binding is here - --> $DIR/shadow.rs:62:9 + --> $DIR/shadow.rs:63:9 | LL | let x = 1; | ^ error: `x` shadows a previous, unrelated binding - --> $DIR/shadow.rs:66:17 + --> $DIR/shadow.rs:68:17 | LL | let x = 1; | ^ | note: previous binding is here - --> $DIR/shadow.rs:65:14 + --> $DIR/shadow.rs:67:14 | LL | Some(x) => { | ^ error: `x` shadows a previous, unrelated binding - --> $DIR/shadow.rs:70:17 + --> $DIR/shadow.rs:72:17 | LL | if let Some(x) = Some(1) {} | ^ | note: previous binding is here - --> $DIR/shadow.rs:62:9 + --> $DIR/shadow.rs:63:9 | LL | let x = 1; | ^ error: `x` shadows a previous, unrelated binding - --> $DIR/shadow.rs:71:20 + --> $DIR/shadow.rs:73:20 | LL | while let Some(x) = Some(1) {} | ^ | note: previous binding is here - --> $DIR/shadow.rs:62:9 + --> $DIR/shadow.rs:63:9 | LL | let x = 1; | ^ error: `x` shadows a previous, unrelated binding - --> $DIR/shadow.rs:72:15 + --> $DIR/shadow.rs:76:15 | LL | let _ = |[x]: [u32; 1]| { | ^ | note: previous binding is here - --> $DIR/shadow.rs:62:9 + --> $DIR/shadow.rs:63:9 | LL | let x = 1; | ^ error: `x` shadows a previous, unrelated binding - --> $DIR/shadow.rs:73:13 + --> $DIR/shadow.rs:77:13 | LL | let x = 1; | ^ | note: previous binding is here - --> $DIR/shadow.rs:72:15 + --> $DIR/shadow.rs:76:15 | LL | let _ = |[x]: [u32; 1]| { | ^ error: `y` is shadowed - --> $DIR/shadow.rs:76:17 + --> $DIR/shadow.rs:80:17 | LL | if let Some(y) = y {} | ^ | note: previous binding is here - --> $DIR/shadow.rs:75:9 + --> $DIR/shadow.rs:79:9 | LL | let y = Some(1); | ^ error: `_b` shadows a previous, unrelated binding - --> $DIR/shadow.rs:112:9 + --> $DIR/shadow.rs:116:9 | LL | let _b = _a; | ^^ | note: previous binding is here - --> $DIR/shadow.rs:111:28 + --> $DIR/shadow.rs:115:28 | LL | pub async fn foo2(_a: i32, _b: i64) { | ^^ error: `x` shadows a previous, unrelated binding - --> $DIR/shadow.rs:118:21 + --> $DIR/shadow.rs:122:21 | LL | if let Some(x) = Some(1) { x } else { 1 } | ^ | note: previous binding is here - --> $DIR/shadow.rs:117:13 + --> $DIR/shadow.rs:121:13 | LL | let x = 1; | ^ diff --git a/tests/ui/short_circuit_statement.fixed b/tests/ui/short_circuit_statement.fixed index a9930ef4dbb6..c3cbc3c5bdc7 100644 --- a/tests/ui/short_circuit_statement.fixed +++ b/tests/ui/short_circuit_statement.fixed @@ -2,9 +2,9 @@ #![allow(clippy::nonminimal_bool)] fn main() { - if f() { g(); } - if !f() { g(); } - if 1 != 2 { g(); } + if f() { g(); } //~ short_circuit_statement + if !f() { g(); } //~ short_circuit_statement + if 1 != 2 { g(); } //~ short_circuit_statement } fn f() -> bool { diff --git a/tests/ui/short_circuit_statement.rs b/tests/ui/short_circuit_statement.rs index 71f7c7f2abf7..72b48b1492ea 100644 --- a/tests/ui/short_circuit_statement.rs +++ b/tests/ui/short_circuit_statement.rs @@ -2,9 +2,9 @@ #![allow(clippy::nonminimal_bool)] fn main() { - f() && g(); - f() || g(); - 1 == 2 || g(); + f() && g(); //~ short_circuit_statement + f() || g(); //~ short_circuit_statement + 1 == 2 || g(); //~ short_circuit_statement } fn f() -> bool { diff --git a/tests/ui/should_panic_without_expect.rs b/tests/ui/should_panic_without_expect.rs index b554fdaf2249..ff788c5e35fd 100644 --- a/tests/ui/should_panic_without_expect.rs +++ b/tests/ui/should_panic_without_expect.rs @@ -2,7 +2,7 @@ #![deny(clippy::should_panic_without_expect)] #[test] -#[should_panic] +#[should_panic] //~ should_panic_without_expect fn no_message() {} #[test] diff --git a/tests/ui/significant_drop_tightening.fixed b/tests/ui/significant_drop_tightening.fixed index ed05f6e0c8d3..3d416056226c 100644 --- a/tests/ui/significant_drop_tightening.fixed +++ b/tests/ui/significant_drop_tightening.fixed @@ -8,6 +8,7 @@ pub fn complex_return_triggers_the_lint() -> i32 { } let mutex = Mutex::new(1); let lock = mutex.lock().unwrap(); + //~^ significant_drop_tightening let _ = *lock; let _ = *lock; drop(lock); @@ -103,6 +104,7 @@ pub fn unnecessary_contention_with_multiple_owned_results() { { let mutex = Mutex::new(1i32); let lock = mutex.lock().unwrap(); + //~^ significant_drop_tightening let rslt0 = lock.abs(); let rslt1 = lock.is_positive(); drop(lock); @@ -126,6 +128,7 @@ pub fn unnecessary_contention_with_single_owned_results() { let mutex = Mutex::new(1i32); let rslt0 = mutex.lock().unwrap().abs(); + //~^ significant_drop_tightening do_heavy_computation_that_takes_time(rslt0); } @@ -133,6 +136,7 @@ pub fn unnecessary_contention_with_single_owned_results() { let mutex = Mutex::new(vec![1i32]); mutex.lock().unwrap().clear(); + //~^ significant_drop_tightening do_heavy_computation_that_takes_time(()); } diff --git a/tests/ui/significant_drop_tightening.rs b/tests/ui/significant_drop_tightening.rs index e5f17278f0f6..d9c4ad543593 100644 --- a/tests/ui/significant_drop_tightening.rs +++ b/tests/ui/significant_drop_tightening.rs @@ -8,6 +8,7 @@ pub fn complex_return_triggers_the_lint() -> i32 { } let mutex = Mutex::new(1); let lock = mutex.lock().unwrap(); + //~^ significant_drop_tightening let _ = *lock; let _ = *lock; foo() @@ -102,6 +103,7 @@ pub fn unnecessary_contention_with_multiple_owned_results() { { let mutex = Mutex::new(1i32); let lock = mutex.lock().unwrap(); + //~^ significant_drop_tightening let rslt0 = lock.abs(); let rslt1 = lock.is_positive(); do_heavy_computation_that_takes_time((rslt0, rslt1)); @@ -123,12 +125,14 @@ pub fn unnecessary_contention_with_single_owned_results() { { let mutex = Mutex::new(1i32); let lock = mutex.lock().unwrap(); + //~^ significant_drop_tightening let rslt0 = lock.abs(); do_heavy_computation_that_takes_time(rslt0); } { let mutex = Mutex::new(vec![1i32]); let mut lock = mutex.lock().unwrap(); + //~^ significant_drop_tightening lock.clear(); do_heavy_computation_that_takes_time(()); } diff --git a/tests/ui/significant_drop_tightening.stderr b/tests/ui/significant_drop_tightening.stderr index 6572d9969317..2e97fbe604cc 100644 --- a/tests/ui/significant_drop_tightening.stderr +++ b/tests/ui/significant_drop_tightening.stderr @@ -24,14 +24,14 @@ LL + drop(lock); | error: temporary with significant `Drop` can be early dropped - --> $DIR/significant_drop_tightening.rs:104:13 + --> $DIR/significant_drop_tightening.rs:105:13 | LL | / { LL | | let mutex = Mutex::new(1i32); LL | | let lock = mutex.lock().unwrap(); | | ^^^^ -LL | | let rslt0 = lock.abs(); -LL | | let rslt1 = lock.is_positive(); +LL | | +... | LL | | do_heavy_computation_that_takes_time((rslt0, rslt1)); LL | | } | |_____- temporary `lock` is currently being dropped at the end of its contained scope @@ -44,12 +44,13 @@ LL + drop(lock); | error: temporary with significant `Drop` can be early dropped - --> $DIR/significant_drop_tightening.rs:125:13 + --> $DIR/significant_drop_tightening.rs:127:13 | LL | / { LL | | let mutex = Mutex::new(1i32); LL | | let lock = mutex.lock().unwrap(); | | ^^^^ +LL | | LL | | let rslt0 = lock.abs(); LL | | do_heavy_computation_that_takes_time(rslt0); LL | | } @@ -68,12 +69,13 @@ LL + | error: temporary with significant `Drop` can be early dropped - --> $DIR/significant_drop_tightening.rs:131:17 + --> $DIR/significant_drop_tightening.rs:134:17 | LL | / { LL | | let mutex = Mutex::new(vec![1i32]); LL | | let mut lock = mutex.lock().unwrap(); | | ^^^^ +LL | | LL | | lock.clear(); LL | | do_heavy_computation_that_takes_time(()); LL | | } diff --git a/tests/ui/single_call_fn.rs b/tests/ui/single_call_fn.rs index c20214feccce..82721e5411ce 100644 --- a/tests/ui/single_call_fn.rs +++ b/tests/ui/single_call_fn.rs @@ -10,8 +10,8 @@ extern crate proc_macros; // Do not lint since it's public pub fn f() {} -fn i() {} -fn j() {} +fn i() {} //~ single_call_fn +fn j() {} //~ single_call_fn fn h() { // Linted @@ -31,6 +31,7 @@ fn g() { f(); } +//~v single_call_fn fn c() { println!("really"); println!("long"); @@ -41,7 +42,7 @@ fn d() { c(); } -fn a() {} +fn a() {} //~ single_call_fn fn b() { a(); diff --git a/tests/ui/single_call_fn.stderr b/tests/ui/single_call_fn.stderr index d5cd707754c2..df76b907142d 100644 --- a/tests/ui/single_call_fn.stderr +++ b/tests/ui/single_call_fn.stderr @@ -1,5 +1,5 @@ error: this function is only used once - --> $DIR/single_call_fn.rs:34:1 + --> $DIR/single_call_fn.rs:35:1 | LL | / fn c() { LL | | println!("really"); @@ -9,7 +9,7 @@ LL | | } | |_^ | help: used here - --> $DIR/single_call_fn.rs:41:5 + --> $DIR/single_call_fn.rs:42:5 | LL | c(); | ^ @@ -29,13 +29,13 @@ LL | let a = i; | ^ error: this function is only used once - --> $DIR/single_call_fn.rs:44:1 + --> $DIR/single_call_fn.rs:45:1 | LL | fn a() {} | ^^^^^^^^^ | help: used here - --> $DIR/single_call_fn.rs:47:5 + --> $DIR/single_call_fn.rs:48:5 | LL | a(); | ^ diff --git a/tests/ui/single_char_add_str.fixed b/tests/ui/single_char_add_str.fixed index eafd17f53874..f27b9333d2f4 100644 --- a/tests/ui/single_char_add_str.fixed +++ b/tests/ui/single_char_add_str.fixed @@ -11,35 +11,35 @@ fn main() { // `push_str` tests let mut string = String::new(); - string.push('R'); - string.push('\''); + string.push('R'); //~ single_char_add_str + string.push('\''); //~ single_char_add_str string.push('u'); string.push_str("st"); string.push_str(""); - string.push('\x52'); - string.push('\u{0052}'); - string.push('a'); + string.push('\x52'); //~ single_char_add_str + string.push('\u{0052}'); //~ single_char_add_str + string.push('a'); //~ single_char_add_str - get_string!().push('ö'); + get_string!().push('ö'); //~ single_char_add_str // `insert_str` tests let mut string = String::new(); - string.insert(0, 'R'); - string.insert(1, '\''); + string.insert(0, 'R'); //~ single_char_add_str + string.insert(1, '\''); //~ single_char_add_str string.insert(0, 'u'); string.insert_str(2, "st"); string.insert_str(0, ""); - string.insert(0, '\x52'); - string.insert(0, '\u{0052}'); + string.insert(0, '\x52'); //~ single_char_add_str + string.insert(0, '\u{0052}'); //~ single_char_add_str let x: usize = 2; - string.insert(x, 'a'); + string.insert(x, 'a'); //~ single_char_add_str const Y: usize = 1; - string.insert(Y, 'a'); - string.insert(Y, '"'); - string.insert(Y, '\''); + string.insert(Y, 'a'); //~ single_char_add_str + string.insert(Y, '"'); //~ single_char_add_str + string.insert(Y, '\''); //~ single_char_add_str - get_string!().insert(1, '?'); + get_string!().insert(1, '?'); //~ single_char_add_str } diff --git a/tests/ui/single_char_add_str.rs b/tests/ui/single_char_add_str.rs index 5326c7cf24c6..1e8a0caf856c 100644 --- a/tests/ui/single_char_add_str.rs +++ b/tests/ui/single_char_add_str.rs @@ -11,35 +11,35 @@ fn main() { // `push_str` tests let mut string = String::new(); - string.push_str("R"); - string.push_str("'"); + string.push_str("R"); //~ single_char_add_str + string.push_str("'"); //~ single_char_add_str string.push('u'); string.push_str("st"); string.push_str(""); - string.push_str("\x52"); - string.push_str("\u{0052}"); - string.push_str(r##"a"##); + string.push_str("\x52"); //~ single_char_add_str + string.push_str("\u{0052}"); //~ single_char_add_str + string.push_str(r##"a"##); //~ single_char_add_str - get_string!().push_str("ö"); + get_string!().push_str("ö"); //~ single_char_add_str // `insert_str` tests let mut string = String::new(); - string.insert_str(0, "R"); - string.insert_str(1, "'"); + string.insert_str(0, "R"); //~ single_char_add_str + string.insert_str(1, "'"); //~ single_char_add_str string.insert(0, 'u'); string.insert_str(2, "st"); string.insert_str(0, ""); - string.insert_str(0, "\x52"); - string.insert_str(0, "\u{0052}"); + string.insert_str(0, "\x52"); //~ single_char_add_str + string.insert_str(0, "\u{0052}"); //~ single_char_add_str let x: usize = 2; - string.insert_str(x, r##"a"##); + string.insert_str(x, r##"a"##); //~ single_char_add_str const Y: usize = 1; - string.insert_str(Y, r##"a"##); - string.insert_str(Y, r##"""##); - string.insert_str(Y, r##"'"##); + string.insert_str(Y, r##"a"##); //~ single_char_add_str + string.insert_str(Y, r##"""##); //~ single_char_add_str + string.insert_str(Y, r##"'"##); //~ single_char_add_str - get_string!().insert_str(1, "?"); + get_string!().insert_str(1, "?"); //~ single_char_add_str } diff --git a/tests/ui/single_char_pattern.fixed b/tests/ui/single_char_pattern.fixed index 9573fdbcfde3..3a0d020f4d04 100644 --- a/tests/ui/single_char_pattern.fixed +++ b/tests/ui/single_char_pattern.fixed @@ -4,51 +4,54 @@ use std::collections::HashSet; fn main() { let x = "foo"; - x.split('x'); + x.split('x'); //~ single_char_pattern x.split("xx"); x.split('x'); let y = "x"; x.split(y); - x.split('ß'); - x.split('ℝ'); - x.split('💣'); + x.split('ß'); //~ single_char_pattern + x.split('ℝ'); //~ single_char_pattern + x.split('💣'); //~ single_char_pattern // Can't use this lint for unicode code points which don't fit in a char x.split("❤️"); - x.split_inclusive('x'); - x.contains('x'); - x.starts_with('x'); - x.ends_with('x'); - x.find('x'); - x.rfind('x'); - x.rsplit('x'); - x.split_terminator('x'); - x.rsplit_terminator('x'); - x.splitn(2, 'x'); - x.rsplitn(2, 'x'); - x.split_once('x'); - x.rsplit_once('x'); - x.matches('x'); - x.rmatches('x'); - x.match_indices('x'); - x.rmatch_indices('x'); - x.trim_start_matches('x'); - x.trim_end_matches('x'); - x.strip_prefix('x'); - x.strip_suffix('x'); - x.replace('x', "y"); - x.replacen('x', "y", 3); + x.split_inclusive('x'); //~ single_char_pattern + x.contains('x'); //~ single_char_pattern + x.starts_with('x'); //~ single_char_pattern + x.ends_with('x'); //~ single_char_pattern + x.find('x'); //~ single_char_pattern + x.rfind('x'); //~ single_char_pattern + x.rsplit('x'); //~ single_char_pattern + x.split_terminator('x'); //~ single_char_pattern + x.rsplit_terminator('x'); //~ single_char_pattern + x.splitn(2, 'x'); //~ single_char_pattern + x.rsplitn(2, 'x'); //~ single_char_pattern + x.split_once('x'); //~ single_char_pattern + x.rsplit_once('x'); //~ single_char_pattern + x.matches('x'); //~ single_char_pattern + x.rmatches('x'); //~ single_char_pattern + x.match_indices('x'); //~ single_char_pattern + x.rmatch_indices('x'); //~ single_char_pattern + x.trim_start_matches('x'); //~ single_char_pattern + x.trim_end_matches('x'); //~ single_char_pattern + x.strip_prefix('x'); //~ single_char_pattern + x.strip_suffix('x'); //~ single_char_pattern + x.replace('x', "y"); //~ single_char_pattern + x.replacen('x', "y", 3); //~ single_char_pattern // Make sure we escape characters correctly. - x.split('\n'); - x.split('\''); - x.split('\''); + x.split('\n'); //~ single_char_pattern + x.split('\''); //~ single_char_pattern + x.split('\''); //~ single_char_pattern // Issue #11973: Don't escape `"` in `'"'` - x.split('"'); + x.split('"'); //~ single_char_pattern let h = HashSet::::new(); h.contains("X"); // should not warn + //~v single_char_pattern x.replace(';', ",").split(','); // issue #2978 + + //~v single_char_pattern x.starts_with('\x03'); // issue #2996 // Issue #3204 @@ -56,12 +59,12 @@ fn main() { x.find(S); // Raw string - x.split('a'); - x.split('a'); - x.split('a'); - x.split('\''); - x.split('#'); + x.split('a'); //~ single_char_pattern + x.split('a'); //~ single_char_pattern + x.split('a'); //~ single_char_pattern + x.split('\''); //~ single_char_pattern + x.split('#'); //~ single_char_pattern // Must escape backslash in raw strings when converting to char #8060 - x.split('\\'); - x.split('\\'); + x.split('\\'); //~ single_char_pattern + x.split('\\'); //~ single_char_pattern } diff --git a/tests/ui/single_char_pattern.rs b/tests/ui/single_char_pattern.rs index 8a04480dbc64..a7e1aab05317 100644 --- a/tests/ui/single_char_pattern.rs +++ b/tests/ui/single_char_pattern.rs @@ -4,51 +4,54 @@ use std::collections::HashSet; fn main() { let x = "foo"; - x.split("x"); + x.split("x"); //~ single_char_pattern x.split("xx"); x.split('x'); let y = "x"; x.split(y); - x.split("ß"); - x.split("ℝ"); - x.split("💣"); + x.split("ß"); //~ single_char_pattern + x.split("ℝ"); //~ single_char_pattern + x.split("💣"); //~ single_char_pattern // Can't use this lint for unicode code points which don't fit in a char x.split("❤️"); - x.split_inclusive("x"); - x.contains("x"); - x.starts_with("x"); - x.ends_with("x"); - x.find("x"); - x.rfind("x"); - x.rsplit("x"); - x.split_terminator("x"); - x.rsplit_terminator("x"); - x.splitn(2, "x"); - x.rsplitn(2, "x"); - x.split_once("x"); - x.rsplit_once("x"); - x.matches("x"); - x.rmatches("x"); - x.match_indices("x"); - x.rmatch_indices("x"); - x.trim_start_matches("x"); - x.trim_end_matches("x"); - x.strip_prefix("x"); - x.strip_suffix("x"); - x.replace("x", "y"); - x.replacen("x", "y", 3); + x.split_inclusive("x"); //~ single_char_pattern + x.contains("x"); //~ single_char_pattern + x.starts_with("x"); //~ single_char_pattern + x.ends_with("x"); //~ single_char_pattern + x.find("x"); //~ single_char_pattern + x.rfind("x"); //~ single_char_pattern + x.rsplit("x"); //~ single_char_pattern + x.split_terminator("x"); //~ single_char_pattern + x.rsplit_terminator("x"); //~ single_char_pattern + x.splitn(2, "x"); //~ single_char_pattern + x.rsplitn(2, "x"); //~ single_char_pattern + x.split_once("x"); //~ single_char_pattern + x.rsplit_once("x"); //~ single_char_pattern + x.matches("x"); //~ single_char_pattern + x.rmatches("x"); //~ single_char_pattern + x.match_indices("x"); //~ single_char_pattern + x.rmatch_indices("x"); //~ single_char_pattern + x.trim_start_matches("x"); //~ single_char_pattern + x.trim_end_matches("x"); //~ single_char_pattern + x.strip_prefix("x"); //~ single_char_pattern + x.strip_suffix("x"); //~ single_char_pattern + x.replace("x", "y"); //~ single_char_pattern + x.replacen("x", "y", 3); //~ single_char_pattern // Make sure we escape characters correctly. - x.split("\n"); - x.split("'"); - x.split("\'"); + x.split("\n"); //~ single_char_pattern + x.split("'"); //~ single_char_pattern + x.split("\'"); //~ single_char_pattern // Issue #11973: Don't escape `"` in `'"'` - x.split("\""); + x.split("\""); //~ single_char_pattern let h = HashSet::::new(); h.contains("X"); // should not warn + //~v single_char_pattern x.replace(';', ",").split(","); // issue #2978 + + //~v single_char_pattern x.starts_with("\x03"); // issue #2996 // Issue #3204 @@ -56,12 +59,12 @@ fn main() { x.find(S); // Raw string - x.split(r"a"); - x.split(r#"a"#); - x.split(r###"a"###); - x.split(r###"'"###); - x.split(r###"#"###); + x.split(r"a"); //~ single_char_pattern + x.split(r#"a"#); //~ single_char_pattern + x.split(r###"a"###); //~ single_char_pattern + x.split(r###"'"###); //~ single_char_pattern + x.split(r###"#"###); //~ single_char_pattern // Must escape backslash in raw strings when converting to char #8060 - x.split(r#"\"#); - x.split(r"\"); + x.split(r#"\"#); //~ single_char_pattern + x.split(r"\"); //~ single_char_pattern } diff --git a/tests/ui/single_char_pattern.stderr b/tests/ui/single_char_pattern.stderr index 664d6b5a1e9b..b29dc3c8d38e 100644 --- a/tests/ui/single_char_pattern.stderr +++ b/tests/ui/single_char_pattern.stderr @@ -188,55 +188,55 @@ LL | x.split("\""); | ^^^^ help: consider using a `char`: `'"'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:51:31 + --> $DIR/single_char_pattern.rs:52:31 | LL | x.replace(';', ",").split(","); // issue #2978 | ^^^ help: consider using a `char`: `','` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:52:19 + --> $DIR/single_char_pattern.rs:55:19 | LL | x.starts_with("\x03"); // issue #2996 | ^^^^^^ help: consider using a `char`: `'\x03'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:59:13 + --> $DIR/single_char_pattern.rs:62:13 | LL | x.split(r"a"); | ^^^^ help: consider using a `char`: `'a'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:60:13 + --> $DIR/single_char_pattern.rs:63:13 | LL | x.split(r#"a"#); | ^^^^^^ help: consider using a `char`: `'a'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:61:13 + --> $DIR/single_char_pattern.rs:64:13 | LL | x.split(r###"a"###); | ^^^^^^^^^^ help: consider using a `char`: `'a'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:62:13 + --> $DIR/single_char_pattern.rs:65:13 | LL | x.split(r###"'"###); | ^^^^^^^^^^ help: consider using a `char`: `'\''` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:63:13 + --> $DIR/single_char_pattern.rs:66:13 | LL | x.split(r###"#"###); | ^^^^^^^^^^ help: consider using a `char`: `'#'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:65:13 + --> $DIR/single_char_pattern.rs:68:13 | LL | x.split(r#"\"#); | ^^^^^^ help: consider using a `char`: `'\\'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:66:13 + --> $DIR/single_char_pattern.rs:69:13 | LL | x.split(r"\"); | ^^^^ help: consider using a `char`: `'\\'` diff --git a/tests/ui/single_component_path_imports.fixed b/tests/ui/single_component_path_imports.fixed index fdff336c281b..df54a1f7f423 100644 --- a/tests/ui/single_component_path_imports.fixed +++ b/tests/ui/single_component_path_imports.fixed @@ -3,7 +3,7 @@ use core; - + //~ single_component_path_imports use serde as edres; @@ -29,7 +29,7 @@ fn main() { } mod hello_mod { - + //~ single_component_path_imports #[allow(dead_code)] fn hello_mod() {} } diff --git a/tests/ui/single_component_path_imports.rs b/tests/ui/single_component_path_imports.rs index 2d72f122adf2..8c4adb1b628d 100644 --- a/tests/ui/single_component_path_imports.rs +++ b/tests/ui/single_component_path_imports.rs @@ -3,7 +3,7 @@ use core; -use regex; +use regex; //~ single_component_path_imports use serde as edres; @@ -29,7 +29,7 @@ fn main() { } mod hello_mod { - use regex; + use regex; //~ single_component_path_imports #[allow(dead_code)] fn hello_mod() {} } diff --git a/tests/ui/single_element_loop.fixed b/tests/ui/single_element_loop.fixed index 4e59c7631986..193986871840 100644 --- a/tests/ui/single_element_loop.fixed +++ b/tests/ui/single_element_loop.fixed @@ -5,28 +5,34 @@ #[warn(clippy::single_element_loop)] fn main() { let item1 = 2; + //~v single_element_loop { let item = &item1; dbg!(item); } + //~v single_element_loop { let item = &item1; dbg!(item); } + //~v single_element_loop for item in 0..5 { dbg!(item); } + //~v single_element_loop for item in 0..5 { dbg!(item); } + //~v single_element_loop for item in 0..5 { dbg!(item); } + //~v single_element_loop for item in 0..5 { dbg!(item); } @@ -46,6 +52,7 @@ fn main() { } // should lint (issue #10018) + //~v single_element_loop { let _ = 42; let _f = |n: u32| { diff --git a/tests/ui/single_element_loop.rs b/tests/ui/single_element_loop.rs index a55ece6b0650..16a87228ef47 100644 --- a/tests/ui/single_element_loop.rs +++ b/tests/ui/single_element_loop.rs @@ -5,26 +5,32 @@ #[warn(clippy::single_element_loop)] fn main() { let item1 = 2; + //~v single_element_loop for item in &[item1] { dbg!(item); } + //~v single_element_loop for item in [item1].iter() { dbg!(item); } + //~v single_element_loop for item in &[0..5] { dbg!(item); } + //~v single_element_loop for item in [0..5].iter_mut() { dbg!(item); } + //~v single_element_loop for item in [0..5] { dbg!(item); } + //~v single_element_loop for item in [0..5].into_iter() { dbg!(item); } @@ -44,6 +50,7 @@ fn main() { } // should lint (issue #10018) + //~v single_element_loop for _ in [42] { let _f = |n: u32| { for i in 0..n { diff --git a/tests/ui/single_element_loop.stderr b/tests/ui/single_element_loop.stderr index 952d704143a5..56e2717ffe02 100644 --- a/tests/ui/single_element_loop.stderr +++ b/tests/ui/single_element_loop.stderr @@ -1,5 +1,5 @@ error: for loop over a single element - --> $DIR/single_element_loop.rs:8:5 + --> $DIR/single_element_loop.rs:9:5 | LL | / for item in &[item1] { LL | | dbg!(item); @@ -17,7 +17,7 @@ LL + } | error: for loop over a single element - --> $DIR/single_element_loop.rs:12:5 + --> $DIR/single_element_loop.rs:14:5 | LL | / for item in [item1].iter() { LL | | dbg!(item); @@ -33,31 +33,31 @@ LL + } | error: this loops only once with `item` being `0..5` - --> $DIR/single_element_loop.rs:16:17 + --> $DIR/single_element_loop.rs:19:17 | LL | for item in &[0..5] { | ^^^^^^^ help: did you mean to iterate over the range instead?: `0..5` error: this loops only once with `item` being `0..5` - --> $DIR/single_element_loop.rs:20:17 + --> $DIR/single_element_loop.rs:24:17 | LL | for item in [0..5].iter_mut() { | ^^^^^^^^^^^^^^^^^ help: did you mean to iterate over the range instead?: `0..5` error: this loops only once with `item` being `0..5` - --> $DIR/single_element_loop.rs:24:17 + --> $DIR/single_element_loop.rs:29:17 | LL | for item in [0..5] { | ^^^^^^ help: did you mean to iterate over the range instead?: `0..5` error: this loops only once with `item` being `0..5` - --> $DIR/single_element_loop.rs:28:17 + --> $DIR/single_element_loop.rs:34:17 | LL | for item in [0..5].into_iter() { | ^^^^^^^^^^^^^^^^^^ help: did you mean to iterate over the range instead?: `0..5` error: for loop over a single element - --> $DIR/single_element_loop.rs:47:5 + --> $DIR/single_element_loop.rs:54:5 | LL | / for _ in [42] { LL | | let _f = |n: u32| { diff --git a/tests/ui/single_match.fixed b/tests/ui/single_match.fixed index 0a49be2dc4f3..4cd89166c7d8 100644 --- a/tests/ui/single_match.fixed +++ b/tests/ui/single_match.fixed @@ -11,14 +11,17 @@ fn dummy() {} fn single_match() { let x = Some(1u8); + //~v single_match if let Some(y) = x { println!("{:?}", y); }; let x = Some(1u8); + //~v single_match if let Some(y) = x { println!("{:?}", y) } let z = (1u8, 1u8); + //~v single_match if let (2..=3, 7..=9) = z { dummy() }; // Not linted (pattern guards used) @@ -45,12 +48,15 @@ fn single_match_know_enum() { let x = Some(1u8); let y: Result<_, i8> = Ok(1i8); + //~v single_match if let Some(y) = x { dummy() }; + //~v single_match if let Ok(y) = y { dummy() }; let c = Cow::Borrowed(""); + //~v single_match if let Cow::Borrowed(..) = c { dummy() }; let z = Foo::Bar; @@ -69,6 +75,7 @@ fn single_match_know_enum() { // issue #173 fn if_suggestion() { let x = "test"; + //~v single_match if x == "test" { println!() } #[derive(PartialEq, Eq)] @@ -79,14 +86,18 @@ fn if_suggestion() { } let x = Foo::A; + //~v single_match if x == Foo::A { println!() } const FOO_C: Foo = Foo::C(0); + //~v single_match if x == FOO_C { println!() } + //~v single_match if x == Foo::A { println!() } let x = &x; + //~v single_match if x == &Foo::A { println!() } enum Bar { @@ -101,11 +112,13 @@ fn if_suggestion() { impl Eq for Bar {} let x = Bar::A; + //~v single_match if let Bar::A = x { println!() } // issue #7038 struct X; let x = Some(X); + //~v single_match if let None = x { println!() }; } @@ -125,12 +138,15 @@ fn ranges() { } // lint + //~v single_match if let (Some(_), _) = x {} // lint + //~v single_match if let (Some(E::V), _) = x { todo!() } // lint + //~v single_match if let (.., Some(E::V), _) = (Some(42), Some(E::V), Some(42)) {} // Don't lint, see above. @@ -200,11 +216,13 @@ fn main() { } fn issue_10808(bar: Option) { + //~v single_match if let Some(v) = bar { unsafe { let r = &v as *const i32; println!("{}", *r); } } + //~v single_match if let Some(v) = bar { unsafe { let r = &v as *const i32; diff --git a/tests/ui/single_match.rs b/tests/ui/single_match.rs index 4e35d265acbf..1ec15b5303ef 100644 --- a/tests/ui/single_match.rs +++ b/tests/ui/single_match.rs @@ -11,6 +11,7 @@ fn dummy() {} fn single_match() { let x = Some(1u8); + //~v single_match match x { Some(y) => { println!("{:?}", y); @@ -19,6 +20,7 @@ fn single_match() { }; let x = Some(1u8); + //~v single_match match x { // Note the missing block braces. // We suggest `if let Some(y) = x { .. }` because the macro @@ -28,6 +30,7 @@ fn single_match() { } let z = (1u8, 1u8); + //~v single_match match z { (2..=3, 7..=9) => dummy(), _ => {}, @@ -57,11 +60,13 @@ fn single_match_know_enum() { let x = Some(1u8); let y: Result<_, i8> = Ok(1i8); + //~v single_match match x { Some(y) => dummy(), None => (), }; + //~v single_match match y { Ok(y) => dummy(), Err(..) => (), @@ -69,6 +74,7 @@ fn single_match_know_enum() { let c = Cow::Borrowed(""); + //~v single_match match c { Cow::Borrowed(..) => dummy(), Cow::Owned(..) => (), @@ -90,6 +96,7 @@ fn single_match_know_enum() { // issue #173 fn if_suggestion() { let x = "test"; + //~v single_match match x { "test" => println!(), _ => (), @@ -103,23 +110,27 @@ fn if_suggestion() { } let x = Foo::A; + //~v single_match match x { Foo::A => println!(), _ => (), } const FOO_C: Foo = Foo::C(0); + //~v single_match match x { FOO_C => println!(), _ => (), } + //~v single_match match &&x { Foo::A => println!(), _ => (), } let x = &x; + //~v single_match match &x { Foo::A => println!(), _ => (), @@ -137,6 +148,7 @@ fn if_suggestion() { impl Eq for Bar {} let x = Bar::A; + //~v single_match match x { Bar::A => println!(), _ => (), @@ -145,6 +157,7 @@ fn if_suggestion() { // issue #7038 struct X; let x = Some(X); + //~v single_match match x { None => println!(), _ => (), @@ -167,18 +180,21 @@ fn ranges() { } // lint + //~v single_match match x { (Some(_), _) => {}, (None, _) => {}, } // lint + //~v single_match match x { (Some(E::V), _) => todo!(), (_, _) => {}, } // lint + //~v single_match match (Some(42), Some(E::V), Some(42)) { (.., Some(E::V), _) => {}, (..) => {}, @@ -251,6 +267,7 @@ fn main() { } fn issue_10808(bar: Option) { + //~v single_match match bar { Some(v) => unsafe { let r = &v as *const i32; @@ -259,6 +276,7 @@ fn issue_10808(bar: Option) { _ => {}, } + //~v single_match match bar { #[rustfmt::skip] Some(v) => { diff --git a/tests/ui/single_match.stderr b/tests/ui/single_match.stderr index d4b865995213..ba987be1fa9b 100644 --- a/tests/ui/single_match.stderr +++ b/tests/ui/single_match.stderr @@ -1,5 +1,5 @@ error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:14:5 + --> $DIR/single_match.rs:15:5 | LL | / match x { LL | | Some(y) => { @@ -19,7 +19,7 @@ LL ~ }; | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:22:5 + --> $DIR/single_match.rs:24:5 | LL | / match x { LL | | // Note the missing block braces. @@ -31,7 +31,7 @@ LL | | } | |_____^ help: try: `if let Some(y) = x { println!("{:?}", y) }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:31:5 + --> $DIR/single_match.rs:34:5 | LL | / match z { LL | | (2..=3, 7..=9) => dummy(), @@ -40,7 +40,7 @@ LL | | }; | |_____^ help: try: `if let (2..=3, 7..=9) = z { dummy() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:60:5 + --> $DIR/single_match.rs:64:5 | LL | / match x { LL | | Some(y) => dummy(), @@ -49,7 +49,7 @@ LL | | }; | |_____^ help: try: `if let Some(y) = x { dummy() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:65:5 + --> $DIR/single_match.rs:70:5 | LL | / match y { LL | | Ok(y) => dummy(), @@ -58,7 +58,7 @@ LL | | }; | |_____^ help: try: `if let Ok(y) = y { dummy() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:72:5 + --> $DIR/single_match.rs:78:5 | LL | / match c { LL | | Cow::Borrowed(..) => dummy(), @@ -67,7 +67,7 @@ LL | | }; | |_____^ help: try: `if let Cow::Borrowed(..) = c { dummy() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> $DIR/single_match.rs:93:5 + --> $DIR/single_match.rs:100:5 | LL | / match x { LL | | "test" => println!(), @@ -76,7 +76,7 @@ LL | | } | |_____^ help: try: `if x == "test" { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> $DIR/single_match.rs:106:5 + --> $DIR/single_match.rs:114:5 | LL | / match x { LL | | Foo::A => println!(), @@ -85,7 +85,7 @@ LL | | } | |_____^ help: try: `if x == Foo::A { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> $DIR/single_match.rs:112:5 + --> $DIR/single_match.rs:121:5 | LL | / match x { LL | | FOO_C => println!(), @@ -94,7 +94,7 @@ LL | | } | |_____^ help: try: `if x == FOO_C { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> $DIR/single_match.rs:117:5 + --> $DIR/single_match.rs:127:5 | LL | / match &&x { LL | | Foo::A => println!(), @@ -103,7 +103,7 @@ LL | | } | |_____^ help: try: `if x == Foo::A { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> $DIR/single_match.rs:123:5 + --> $DIR/single_match.rs:134:5 | LL | / match &x { LL | | Foo::A => println!(), @@ -112,7 +112,7 @@ LL | | } | |_____^ help: try: `if x == &Foo::A { println!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:140:5 + --> $DIR/single_match.rs:152:5 | LL | / match x { LL | | Bar::A => println!(), @@ -121,7 +121,7 @@ LL | | } | |_____^ help: try: `if let Bar::A = x { println!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:148:5 + --> $DIR/single_match.rs:161:5 | LL | / match x { LL | | None => println!(), @@ -130,7 +130,7 @@ LL | | }; | |_____^ help: try: `if let None = x { println!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:170:5 + --> $DIR/single_match.rs:184:5 | LL | / match x { LL | | (Some(_), _) => {}, @@ -139,7 +139,7 @@ LL | | } | |_____^ help: try: `if let (Some(_), _) = x {}` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:176:5 + --> $DIR/single_match.rs:191:5 | LL | / match x { LL | | (Some(E::V), _) => todo!(), @@ -148,7 +148,7 @@ LL | | } | |_____^ help: try: `if let (Some(E::V), _) = x { todo!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:182:5 + --> $DIR/single_match.rs:198:5 | LL | / match (Some(42), Some(E::V), Some(42)) { LL | | (.., Some(E::V), _) => {}, @@ -157,7 +157,7 @@ LL | | } | |_____^ help: try: `if let (.., Some(E::V), _) = (Some(42), Some(E::V), Some(42)) {}` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:254:5 + --> $DIR/single_match.rs:271:5 | LL | / match bar { LL | | Some(v) => unsafe { @@ -177,7 +177,7 @@ LL + } } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:262:5 + --> $DIR/single_match.rs:280:5 | LL | / match bar { LL | | #[rustfmt::skip] diff --git a/tests/ui/single_match_else.fixed b/tests/ui/single_match_else.fixed index f3b1de3b44f9..0d6374e17dc1 100644 --- a/tests/ui/single_match_else.fixed +++ b/tests/ui/single_match_else.fixed @@ -13,6 +13,7 @@ enum ExprNode { static NODE: ExprNode = ExprNode::Unicorns; fn unwrap_addr() -> Option<&'static ExprNode> { + //~v single_match_else let _ = if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else { let x = 5; None @@ -75,12 +76,14 @@ fn main() { // // lint here + //~v single_match_else if let Some(a) = Some(1) { println!("${:?}", a) } else { println!("else block"); return } // lint here + //~v single_match_else if let Some(a) = Some(1) { println!("${:?}", a) } else { println!("else block"); return; @@ -88,12 +91,14 @@ fn main() { // lint here use std::convert::Infallible; + //~v single_match_else if let Ok(a) = Result::::Ok(1) { println!("${:?}", a) } else { println!("else block"); return; } use std::borrow::Cow; + //~v single_match_else if let Cow::Owned(a) = Cow::from("moo") { println!("${:?}", a) } else { println!("else block"); return; @@ -101,6 +106,7 @@ fn main() { } fn issue_10808(bar: Option) { + //~v single_match_else if let Some(v) = bar { unsafe { let r = &v as *const i32; println!("{}", *r); @@ -109,6 +115,7 @@ fn issue_10808(bar: Option) { println!("None2"); } + //~v single_match_else if let Some(v) = bar { println!("Some"); println!("{v}"); @@ -118,6 +125,7 @@ fn issue_10808(bar: Option) { println!("{}", *r); } } + //~v single_match_else if let Some(v) = bar { unsafe { let r = &v as *const i32; println!("{}", *r); @@ -127,6 +135,7 @@ fn issue_10808(bar: Option) { println!("{}", *r); } } + //~v single_match_else if let Some(v) = bar { unsafe { let r = &v as *const i32; diff --git a/tests/ui/single_match_else.rs b/tests/ui/single_match_else.rs index ddee2e42ec2a..cf5f272f032a 100644 --- a/tests/ui/single_match_else.rs +++ b/tests/ui/single_match_else.rs @@ -13,6 +13,7 @@ enum ExprNode { static NODE: ExprNode = ExprNode::Unicorns; fn unwrap_addr() -> Option<&'static ExprNode> { + //~v single_match_else let _ = match ExprNode::Butterflies { ExprNode::ExprAddrOf => Some(&NODE), _ => { @@ -78,6 +79,7 @@ fn main() { // // lint here + //~v single_match_else match Some(1) { Some(a) => println!("${:?}", a), None => { @@ -87,6 +89,7 @@ fn main() { } // lint here + //~v single_match_else match Some(1) { Some(a) => println!("${:?}", a), None => { @@ -97,6 +100,7 @@ fn main() { // lint here use std::convert::Infallible; + //~v single_match_else match Result::::Ok(1) { Ok(a) => println!("${:?}", a), Err(_) => { @@ -106,6 +110,7 @@ fn main() { } use std::borrow::Cow; + //~v single_match_else match Cow::from("moo") { Cow::Owned(a) => println!("${:?}", a), Cow::Borrowed(_) => { @@ -116,6 +121,7 @@ fn main() { } fn issue_10808(bar: Option) { + //~v single_match_else match bar { Some(v) => unsafe { let r = &v as *const i32; @@ -127,6 +133,7 @@ fn issue_10808(bar: Option) { }, } + //~v single_match_else match bar { Some(v) => { println!("Some"); @@ -139,6 +146,7 @@ fn issue_10808(bar: Option) { }, } + //~v single_match_else match bar { Some(v) => unsafe { let r = &v as *const i32; @@ -151,6 +159,7 @@ fn issue_10808(bar: Option) { }, } + //~v single_match_else match bar { #[rustfmt::skip] Some(v) => { diff --git a/tests/ui/single_match_else.stderr b/tests/ui/single_match_else.stderr index 3b4b1332c403..ce855d570e62 100644 --- a/tests/ui/single_match_else.stderr +++ b/tests/ui/single_match_else.stderr @@ -1,5 +1,5 @@ error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:16:13 + --> $DIR/single_match_else.rs:17:13 | LL | let _ = match ExprNode::Butterflies { | _____________^ @@ -22,7 +22,7 @@ LL ~ }; | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:81:5 + --> $DIR/single_match_else.rs:83:5 | LL | / match Some(1) { LL | | Some(a) => println!("${:?}", a), @@ -42,7 +42,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:90:5 + --> $DIR/single_match_else.rs:93:5 | LL | / match Some(1) { LL | | Some(a) => println!("${:?}", a), @@ -62,7 +62,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:100:5 + --> $DIR/single_match_else.rs:104:5 | LL | / match Result::::Ok(1) { LL | | Ok(a) => println!("${:?}", a), @@ -82,7 +82,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:109:5 + --> $DIR/single_match_else.rs:114:5 | LL | / match Cow::from("moo") { LL | | Cow::Owned(a) => println!("${:?}", a), @@ -102,7 +102,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:119:5 + --> $DIR/single_match_else.rs:125:5 | LL | / match bar { LL | | Some(v) => unsafe { @@ -125,7 +125,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:130:5 + --> $DIR/single_match_else.rs:137:5 | LL | / match bar { LL | | Some(v) => { @@ -149,7 +149,7 @@ LL + } } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:142:5 + --> $DIR/single_match_else.rs:150:5 | LL | / match bar { LL | | Some(v) => unsafe { @@ -173,7 +173,7 @@ LL + } } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:154:5 + --> $DIR/single_match_else.rs:163:5 | LL | / match bar { LL | | #[rustfmt::skip] diff --git a/tests/ui/single_range_in_vec_init.rs b/tests/ui/single_range_in_vec_init.rs index 7887cfc61750..01ac087645e3 100644 --- a/tests/ui/single_range_in_vec_init.rs +++ b/tests/ui/single_range_in_vec_init.rs @@ -23,17 +23,17 @@ fn awa_vec(start: T, end: T) { fn main() { // Lint - [0..200]; - vec![0..200]; - [0u8..200]; - [0usize..200]; - [0..200usize]; - vec![0u8..200]; - vec![0usize..200]; - vec![0..200usize]; + [0..200]; //~ single_range_in_vec_init + vec![0..200]; //~ single_range_in_vec_init + [0u8..200]; //~ single_range_in_vec_init + [0usize..200]; //~ single_range_in_vec_init + [0..200usize]; //~ single_range_in_vec_init + vec![0u8..200]; //~ single_range_in_vec_init + vec![0usize..200]; //~ single_range_in_vec_init + vec![0..200usize]; //~ single_range_in_vec_init // Only suggest collect - [0..200isize]; - vec![0..200isize]; + [0..200isize]; //~ single_range_in_vec_init + vec![0..200isize]; //~ single_range_in_vec_init // Do not lint [0..200, 0..100]; vec![0..200, 0..100]; diff --git a/tests/ui/skip_while_next.rs b/tests/ui/skip_while_next.rs index 8e4cd82cec30..dbf159599a10 100644 --- a/tests/ui/skip_while_next.rs +++ b/tests/ui/skip_while_next.rs @@ -12,8 +12,10 @@ fn skip_while_next() { // Single-line case. let _ = v.iter().skip_while(|&x| *x < 0).next(); + //~^ skip_while_next // Multi-line case. + //~v skip_while_next let _ = v.iter().skip_while(|&x| { *x < 0 } diff --git a/tests/ui/skip_while_next.stderr b/tests/ui/skip_while_next.stderr index 3c33af3a1608..833e8ba4f547 100644 --- a/tests/ui/skip_while_next.stderr +++ b/tests/ui/skip_while_next.stderr @@ -9,7 +9,7 @@ LL | let _ = v.iter().skip_while(|&x| *x < 0).next(); = help: to override `-D warnings` add `#[allow(clippy::skip_while_next)]` error: called `skip_while(

).next()` on an `Iterator` - --> $DIR/skip_while_next.rs:17:13 + --> $DIR/skip_while_next.rs:19:13 | LL | let _ = v.iter().skip_while(|&x| { | _____________^ diff --git a/tests/ui/stable_sort_primitive.fixed b/tests/ui/stable_sort_primitive.fixed index 97f3a92238d2..9455b3570bc6 100644 --- a/tests/ui/stable_sort_primitive.fixed +++ b/tests/ui/stable_sort_primitive.fixed @@ -4,19 +4,19 @@ fn main() { // positive examples let mut vec = vec![1, 3, 2]; - vec.sort_unstable(); + vec.sort_unstable(); //~ stable_sort_primitive let mut vec = vec![false, false, true]; - vec.sort_unstable(); + vec.sort_unstable(); //~ stable_sort_primitive let mut vec = vec!['a', 'A', 'c']; - vec.sort_unstable(); + vec.sort_unstable(); //~ stable_sort_primitive let mut vec = vec!["ab", "cd", "ab", "bc"]; - vec.sort_unstable(); + vec.sort_unstable(); //~ stable_sort_primitive let mut vec = vec![(2, 1), (1, 2), (2, 5)]; - vec.sort_unstable(); + vec.sort_unstable(); //~ stable_sort_primitive let mut vec = vec![[2, 1], [1, 2], [2, 5]]; - vec.sort_unstable(); + vec.sort_unstable(); //~ stable_sort_primitive let mut arr = [1, 3, 2]; - arr.sort_unstable(); + arr.sort_unstable(); //~ stable_sort_primitive // Negative examples: behavior changes if made unstable let mut vec = vec![1, 3, 2]; vec.sort_by_key(|i| i / 2); diff --git a/tests/ui/stable_sort_primitive.rs b/tests/ui/stable_sort_primitive.rs index 26e3d8e74f71..4eae4ef0f382 100644 --- a/tests/ui/stable_sort_primitive.rs +++ b/tests/ui/stable_sort_primitive.rs @@ -4,19 +4,19 @@ fn main() { // positive examples let mut vec = vec![1, 3, 2]; - vec.sort(); + vec.sort(); //~ stable_sort_primitive let mut vec = vec![false, false, true]; - vec.sort(); + vec.sort(); //~ stable_sort_primitive let mut vec = vec!['a', 'A', 'c']; - vec.sort(); + vec.sort(); //~ stable_sort_primitive let mut vec = vec!["ab", "cd", "ab", "bc"]; - vec.sort(); + vec.sort(); //~ stable_sort_primitive let mut vec = vec![(2, 1), (1, 2), (2, 5)]; - vec.sort(); + vec.sort(); //~ stable_sort_primitive let mut vec = vec![[2, 1], [1, 2], [2, 5]]; - vec.sort(); + vec.sort(); //~ stable_sort_primitive let mut arr = [1, 3, 2]; - arr.sort(); + arr.sort(); //~ stable_sort_primitive // Negative examples: behavior changes if made unstable let mut vec = vec![1, 3, 2]; vec.sort_by_key(|i| i / 2); diff --git a/tests/ui/starts_ends_with.fixed b/tests/ui/starts_ends_with.fixed index 4a66ca7ec91a..856f53349027 100644 --- a/tests/ui/starts_ends_with.fixed +++ b/tests/ui/starts_ends_with.fixed @@ -4,36 +4,42 @@ fn main() {} #[allow(clippy::unnecessary_operation)] fn starts_with() { - "".starts_with(' '); - !"".starts_with(' '); + "".starts_with(' '); //~ chars_next_cmp + !"".starts_with(' '); //~ chars_next_cmp // Ensure that suggestion is escaped correctly - "".starts_with('\n'); - !"".starts_with('\n'); + "".starts_with('\n'); //~ chars_next_cmp + !"".starts_with('\n'); //~ chars_next_cmp } fn chars_cmp_with_unwrap() { let s = String::from("foo"); + //~v chars_next_cmp if s.starts_with('f') { // s.starts_with('f') // Nothing here } + //~v chars_last_cmp if s.ends_with('o') { // s.ends_with('o') // Nothing here } + //~v chars_last_cmp if s.ends_with('o') { // s.ends_with('o') // Nothing here } + //~v chars_next_cmp if !s.starts_with('f') { // !s.starts_with('f') // Nothing here } + //~v chars_last_cmp if !s.ends_with('o') { // !s.ends_with('o') // Nothing here } + //~v chars_last_cmp if !s.ends_with('\n') { // !s.ends_with('o') // Nothing here @@ -42,12 +48,12 @@ fn chars_cmp_with_unwrap() { #[allow(clippy::unnecessary_operation)] fn ends_with() { - "".ends_with(' '); - !"".ends_with(' '); - "".ends_with(' '); - !"".ends_with(' '); + "".ends_with(' '); //~ chars_last_cmp + !"".ends_with(' '); //~ chars_last_cmp + "".ends_with(' '); //~ chars_last_cmp + !"".ends_with(' '); //~ chars_last_cmp // Ensure that suggestion is escaped correctly - "".ends_with('\n'); - !"".ends_with('\n'); + "".ends_with('\n'); //~ chars_last_cmp + !"".ends_with('\n'); //~ chars_last_cmp } diff --git a/tests/ui/starts_ends_with.rs b/tests/ui/starts_ends_with.rs index 16a68e02d66d..ec374c6ea392 100644 --- a/tests/ui/starts_ends_with.rs +++ b/tests/ui/starts_ends_with.rs @@ -4,36 +4,42 @@ fn main() {} #[allow(clippy::unnecessary_operation)] fn starts_with() { - "".chars().next() == Some(' '); - Some(' ') != "".chars().next(); + "".chars().next() == Some(' '); //~ chars_next_cmp + Some(' ') != "".chars().next(); //~ chars_next_cmp // Ensure that suggestion is escaped correctly - "".chars().next() == Some('\n'); - Some('\n') != "".chars().next(); + "".chars().next() == Some('\n'); //~ chars_next_cmp + Some('\n') != "".chars().next(); //~ chars_next_cmp } fn chars_cmp_with_unwrap() { let s = String::from("foo"); + //~v chars_next_cmp if s.chars().next().unwrap() == 'f' { // s.starts_with('f') // Nothing here } + //~v chars_last_cmp if s.chars().next_back().unwrap() == 'o' { // s.ends_with('o') // Nothing here } + //~v chars_last_cmp if s.chars().last().unwrap() == 'o' { // s.ends_with('o') // Nothing here } + //~v chars_next_cmp if s.chars().next().unwrap() != 'f' { // !s.starts_with('f') // Nothing here } + //~v chars_last_cmp if s.chars().next_back().unwrap() != 'o' { // !s.ends_with('o') // Nothing here } + //~v chars_last_cmp if s.chars().last().unwrap() != '\n' { // !s.ends_with('o') // Nothing here @@ -42,12 +48,12 @@ fn chars_cmp_with_unwrap() { #[allow(clippy::unnecessary_operation)] fn ends_with() { - "".chars().last() == Some(' '); - Some(' ') != "".chars().last(); - "".chars().next_back() == Some(' '); - Some(' ') != "".chars().next_back(); + "".chars().last() == Some(' '); //~ chars_last_cmp + Some(' ') != "".chars().last(); //~ chars_last_cmp + "".chars().next_back() == Some(' '); //~ chars_last_cmp + Some(' ') != "".chars().next_back(); //~ chars_last_cmp // Ensure that suggestion is escaped correctly - "".chars().last() == Some('\n'); - Some('\n') != "".chars().last(); + "".chars().last() == Some('\n'); //~ chars_last_cmp + Some('\n') != "".chars().last(); //~ chars_last_cmp } diff --git a/tests/ui/starts_ends_with.stderr b/tests/ui/starts_ends_with.stderr index c4c547949a36..4f4e50f3265d 100644 --- a/tests/ui/starts_ends_with.stderr +++ b/tests/ui/starts_ends_with.stderr @@ -26,13 +26,13 @@ LL | Some('\n') != "".chars().next(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".starts_with('\n')` error: you should use the `starts_with` method - --> $DIR/starts_ends_with.rs:17:8 + --> $DIR/starts_ends_with.rs:18:8 | LL | if s.chars().next().unwrap() == 'f' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.starts_with('f')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:21:8 + --> $DIR/starts_ends_with.rs:23:8 | LL | if s.chars().next_back().unwrap() == 'o' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')` @@ -41,61 +41,61 @@ LL | if s.chars().next_back().unwrap() == 'o' { = help: to override `-D warnings` add `#[allow(clippy::chars_last_cmp)]` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:25:8 + --> $DIR/starts_ends_with.rs:28:8 | LL | if s.chars().last().unwrap() == 'o' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')` error: you should use the `starts_with` method - --> $DIR/starts_ends_with.rs:29:8 + --> $DIR/starts_ends_with.rs:33:8 | LL | if s.chars().next().unwrap() != 'f' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.starts_with('f')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:33:8 + --> $DIR/starts_ends_with.rs:38:8 | LL | if s.chars().next_back().unwrap() != 'o' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('o')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:37:8 + --> $DIR/starts_ends_with.rs:43:8 | LL | if s.chars().last().unwrap() != '\n' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('\n')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:45:5 + --> $DIR/starts_ends_with.rs:51:5 | LL | "".chars().last() == Some(' '); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with(' ')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:46:5 + --> $DIR/starts_ends_with.rs:52:5 | LL | Some(' ') != "".chars().last(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:47:5 + --> $DIR/starts_ends_with.rs:53:5 | LL | "".chars().next_back() == Some(' '); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with(' ')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:48:5 + --> $DIR/starts_ends_with.rs:54:5 | LL | Some(' ') != "".chars().next_back(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:51:5 + --> $DIR/starts_ends_with.rs:57:5 | LL | "".chars().last() == Some('\n'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with('\n')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:52:5 + --> $DIR/starts_ends_with.rs:58:5 | LL | Some('\n') != "".chars().last(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with('\n')` diff --git a/tests/ui/str_split.fixed b/tests/ui/str_split.fixed index 4f33241da7a2..7e8af65ff2ca 100644 --- a/tests/ui/str_split.fixed +++ b/tests/ui/str_split.fixed @@ -56,26 +56,27 @@ fn main() { // CASES THAT SHOULD EMIT A LINT // Splitting a `str` variable at "\n" or "\r\n" after trimming should warn - let _ = s1.lines(); + let _ = s1.lines(); //~ str_split_at_newline #[allow(clippy::single_char_pattern)] - let _ = s1.lines(); - let _ = s1.lines(); + let _ = s1.lines(); //~ str_split_at_newline + let _ = s1.lines(); //~ str_split_at_newline // Splitting a `String` variable at "\n" or "\r\n" after trimming should warn - let _ = s2.lines(); + let _ = s2.lines(); //~ str_split_at_newline #[allow(clippy::single_char_pattern)] - let _ = s2.lines(); - let _ = s2.lines(); + let _ = s2.lines(); //~ str_split_at_newline + let _ = s2.lines(); //~ str_split_at_newline // Splitting a variable that derefs into `str` at "\n" or "\r\n" after trimming should warn. let s3 = DerefsIntoStr { s: s1 }; - let _ = s3.lines(); + let _ = s3.lines(); //~ str_split_at_newline #[allow(clippy::single_char_pattern)] - let _ = s3.lines(); - let _ = s3.lines(); + let _ = s3.lines(); //~ str_split_at_newline + let _ = s3.lines(); //~ str_split_at_newline // If the `&str` is generated by a macro then the macro should not be expanded in the suggested fix. let _ = make_str!(s1).lines(); + //~^ str_split_at_newline // CASES THAT SHOULD NOT EMIT A LINT diff --git a/tests/ui/str_split.rs b/tests/ui/str_split.rs index f24caa61c305..15e3d0aa864b 100644 --- a/tests/ui/str_split.rs +++ b/tests/ui/str_split.rs @@ -56,26 +56,27 @@ fn main() { // CASES THAT SHOULD EMIT A LINT // Splitting a `str` variable at "\n" or "\r\n" after trimming should warn - let _ = s1.trim().split('\n'); + let _ = s1.trim().split('\n'); //~ str_split_at_newline #[allow(clippy::single_char_pattern)] - let _ = s1.trim().split("\n"); - let _ = s1.trim().split("\r\n"); + let _ = s1.trim().split("\n"); //~ str_split_at_newline + let _ = s1.trim().split("\r\n"); //~ str_split_at_newline // Splitting a `String` variable at "\n" or "\r\n" after trimming should warn - let _ = s2.trim().split('\n'); + let _ = s2.trim().split('\n'); //~ str_split_at_newline #[allow(clippy::single_char_pattern)] - let _ = s2.trim().split("\n"); - let _ = s2.trim().split("\r\n"); + let _ = s2.trim().split("\n"); //~ str_split_at_newline + let _ = s2.trim().split("\r\n"); //~ str_split_at_newline // Splitting a variable that derefs into `str` at "\n" or "\r\n" after trimming should warn. let s3 = DerefsIntoStr { s: s1 }; - let _ = s3.trim().split('\n'); + let _ = s3.trim().split('\n'); //~ str_split_at_newline #[allow(clippy::single_char_pattern)] - let _ = s3.trim().split("\n"); - let _ = s3.trim().split("\r\n"); + let _ = s3.trim().split("\n"); //~ str_split_at_newline + let _ = s3.trim().split("\r\n"); //~ str_split_at_newline // If the `&str` is generated by a macro then the macro should not be expanded in the suggested fix. let _ = make_str!(s1).trim().split('\n'); + //~^ str_split_at_newline // CASES THAT SHOULD NOT EMIT A LINT diff --git a/tests/ui/string_add.rs b/tests/ui/string_add.rs index c535f2ebbfcb..be74305c3e0c 100644 --- a/tests/ui/string_add.rs +++ b/tests/ui/string_add.rs @@ -11,15 +11,17 @@ fn main() { for _ in 1..3 { x = x + "."; + //~^ assign_op_pattern + //~| string_add } let y = String::new(); - let z = y + "..."; + let z = y + "..."; //~ string_add assert_eq!(&x, &z); let mut x = 1; - x = x + 1; + x = x + 1; //~ assign_op_pattern assert_eq!(2, x); external!({ diff --git a/tests/ui/string_add.stderr b/tests/ui/string_add.stderr index 892753b9034e..f5b13f6bf77c 100644 --- a/tests/ui/string_add.stderr +++ b/tests/ui/string_add.stderr @@ -17,13 +17,13 @@ LL | x = x + "."; = help: to override `-D warnings` add `#[allow(clippy::string_add)]` error: you added something to a string. Consider using `String::push_str()` instead - --> $DIR/string_add.rs:17:13 + --> $DIR/string_add.rs:19:13 | LL | let z = y + "..."; | ^^^^^^^^^ error: manual implementation of an assign operation - --> $DIR/string_add.rs:22:5 + --> $DIR/string_add.rs:24:5 | LL | x = x + 1; | ^^^^^^^^^ help: replace it with: `x += 1` diff --git a/tests/ui/string_add_assign.fixed b/tests/ui/string_add_assign.fixed index 31d84831d09a..df8529c187d2 100644 --- a/tests/ui/string_add_assign.fixed +++ b/tests/ui/string_add_assign.fixed @@ -6,6 +6,8 @@ fn main() { for _ in 1..3 { x += "."; + //~^ string_add_assign + //~| assign_op_pattern } let y = String::new(); @@ -14,6 +16,6 @@ fn main() { assert_eq!(&x, &z); let mut x = 1; - x += 1; + x += 1; //~ assign_op_pattern assert_eq!(2, x); } diff --git a/tests/ui/string_add_assign.rs b/tests/ui/string_add_assign.rs index cdea91573cc7..4b6a84aa6c6c 100644 --- a/tests/ui/string_add_assign.rs +++ b/tests/ui/string_add_assign.rs @@ -6,6 +6,8 @@ fn main() { for _ in 1..3 { x = x + "."; + //~^ string_add_assign + //~| assign_op_pattern } let y = String::new(); @@ -14,6 +16,6 @@ fn main() { assert_eq!(&x, &z); let mut x = 1; - x = x + 1; + x = x + 1; //~ assign_op_pattern assert_eq!(2, x); } diff --git a/tests/ui/string_add_assign.stderr b/tests/ui/string_add_assign.stderr index 7d37c98a8f93..bf237eeee27a 100644 --- a/tests/ui/string_add_assign.stderr +++ b/tests/ui/string_add_assign.stderr @@ -17,7 +17,7 @@ LL | x = x + "."; = help: to override `-D warnings` add `#[allow(clippy::assign_op_pattern)]` error: manual implementation of an assign operation - --> $DIR/string_add_assign.rs:17:5 + --> $DIR/string_add_assign.rs:19:5 | LL | x = x + 1; | ^^^^^^^^^ help: replace it with: `x += 1` diff --git a/tests/ui/string_extend.fixed b/tests/ui/string_extend.fixed index 142cb6a34980..98631f2892f2 100644 --- a/tests/ui/string_extend.fixed +++ b/tests/ui/string_extend.fixed @@ -13,13 +13,13 @@ fn main() { let mut s = String::new(); s.push_str(abc); - s.push_str(abc); + s.push_str(abc); //~ string_extend_chars s.push_str("abc"); - s.push_str("abc"); + s.push_str("abc"); //~ string_extend_chars s.push_str(&def); - s.push_str(&def); + s.push_str(&def); //~ string_extend_chars s.extend(abc.chars().skip(1)); s.extend("abc".chars().skip(1)); @@ -29,5 +29,5 @@ fn main() { s.extend(f.chars()); // issue #9735 - s.push_str(&abc[0..2]); + s.push_str(&abc[0..2]); //~ string_extend_chars } diff --git a/tests/ui/string_extend.rs b/tests/ui/string_extend.rs index 41c0d29fae9c..ece323180907 100644 --- a/tests/ui/string_extend.rs +++ b/tests/ui/string_extend.rs @@ -13,13 +13,13 @@ fn main() { let mut s = String::new(); s.push_str(abc); - s.extend(abc.chars()); + s.extend(abc.chars()); //~ string_extend_chars s.push_str("abc"); - s.extend("abc".chars()); + s.extend("abc".chars()); //~ string_extend_chars s.push_str(&def); - s.extend(def.chars()); + s.extend(def.chars()); //~ string_extend_chars s.extend(abc.chars().skip(1)); s.extend("abc".chars().skip(1)); @@ -29,5 +29,5 @@ fn main() { s.extend(f.chars()); // issue #9735 - s.extend(abc[0..2].chars()); + s.extend(abc[0..2].chars()); //~ string_extend_chars } diff --git a/tests/ui/string_from_utf8_as_bytes.fixed b/tests/ui/string_from_utf8_as_bytes.fixed index 6aa5a95c6f40..193217114d88 100644 --- a/tests/ui/string_from_utf8_as_bytes.fixed +++ b/tests/ui/string_from_utf8_as_bytes.fixed @@ -2,4 +2,5 @@ fn main() { let _ = Some(&"Hello World!"[6..11]); + //~^ string_from_utf8_as_bytes } diff --git a/tests/ui/string_from_utf8_as_bytes.rs b/tests/ui/string_from_utf8_as_bytes.rs index c8717f7950bd..49beb19ee40f 100644 --- a/tests/ui/string_from_utf8_as_bytes.rs +++ b/tests/ui/string_from_utf8_as_bytes.rs @@ -2,4 +2,5 @@ fn main() { let _ = std::str::from_utf8(&"Hello World!".as_bytes()[6..11]); + //~^ string_from_utf8_as_bytes } diff --git a/tests/ui/string_lit_as_bytes.fixed b/tests/ui/string_lit_as_bytes.fixed index 225d4e90c4e2..d3f0ac9ff1aa 100644 --- a/tests/ui/string_lit_as_bytes.fixed +++ b/tests/ui/string_lit_as_bytes.fixed @@ -8,17 +8,20 @@ extern crate macro_rules; macro_rules! b { ($b:literal) => { - const B: &[u8] = b"warning"; + const B: &[u8] = b"warning"; //~ string_lit_as_bytes }; } fn str_lit_as_bytes() { - let bs = b"hello there"; + let bs = b"hello there"; //~ string_lit_as_bytes let bs = br###"raw string with 3# plus " ""###; + //~^ string_lit_as_bytes let bs = b"lit to string".to_vec(); + //~^ string_lit_as_bytes let bs = b"lit to owned".to_vec(); + //~^ string_lit_as_bytes b!("warning"); @@ -36,8 +39,10 @@ fn str_lit_as_bytes() { let current_version = env!("CARGO_PKG_VERSION").as_bytes(); let includestr = include_bytes!("string_lit_as_bytes.rs"); + //~^ string_lit_as_bytes let _ = b"string with newline\t\n"; + //~^ string_lit_as_bytes let _ = match "x".as_bytes() { b"xx" => 0, diff --git a/tests/ui/string_lit_as_bytes.rs b/tests/ui/string_lit_as_bytes.rs index 3d116214ca42..a3d58d18b8bf 100644 --- a/tests/ui/string_lit_as_bytes.rs +++ b/tests/ui/string_lit_as_bytes.rs @@ -8,17 +8,20 @@ extern crate macro_rules; macro_rules! b { ($b:literal) => { - const B: &[u8] = $b.as_bytes(); + const B: &[u8] = $b.as_bytes(); //~ string_lit_as_bytes }; } fn str_lit_as_bytes() { - let bs = "hello there".as_bytes(); + let bs = "hello there".as_bytes(); //~ string_lit_as_bytes let bs = r###"raw string with 3# plus " ""###.as_bytes(); + //~^ string_lit_as_bytes let bs = "lit to string".to_string().into_bytes(); + //~^ string_lit_as_bytes let bs = "lit to owned".to_owned().into_bytes(); + //~^ string_lit_as_bytes b!("warning"); @@ -36,8 +39,10 @@ fn str_lit_as_bytes() { let current_version = env!("CARGO_PKG_VERSION").as_bytes(); let includestr = include_str!("string_lit_as_bytes.rs").as_bytes(); + //~^ string_lit_as_bytes let _ = "string with newline\t\n".as_bytes(); + //~^ string_lit_as_bytes let _ = match "x".as_bytes() { b"xx" => 0, diff --git a/tests/ui/string_lit_as_bytes.stderr b/tests/ui/string_lit_as_bytes.stderr index 1c12cb8e56d2..642d0a0c23a0 100644 --- a/tests/ui/string_lit_as_bytes.stderr +++ b/tests/ui/string_lit_as_bytes.stderr @@ -14,13 +14,13 @@ LL | let bs = r###"raw string with 3# plus " ""###.as_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `br###"raw string with 3# plus " ""###` error: calling `into_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:20:14 + --> $DIR/string_lit_as_bytes.rs:21:14 | LL | let bs = "lit to string".to_string().into_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"lit to string".to_vec()` error: calling `into_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:21:14 + --> $DIR/string_lit_as_bytes.rs:23:14 | LL | let bs = "lit to owned".to_owned().into_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"lit to owned".to_vec()` @@ -37,13 +37,13 @@ LL | b!("warning"); = note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info) error: calling `as_bytes()` on `include_str!(..)` - --> $DIR/string_lit_as_bytes.rs:38:22 + --> $DIR/string_lit_as_bytes.rs:41:22 | LL | let includestr = include_str!("string_lit_as_bytes.rs").as_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `include_bytes!(..)` instead: `include_bytes!("string_lit_as_bytes.rs")` error: calling `as_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:40:13 + --> $DIR/string_lit_as_bytes.rs:44:13 | LL | let _ = "string with newline\t\n".as_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"string with newline\t\n"` diff --git a/tests/ui/string_lit_chars_any.fixed b/tests/ui/string_lit_chars_any.fixed index 03e20c16ee63..cf05a2c2e835 100644 --- a/tests/ui/string_lit_chars_any.fixed +++ b/tests/ui/string_lit_chars_any.fixed @@ -16,11 +16,16 @@ impl NotStringLit { fn main() { let c = 'c'; matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + //~^ string_lit_chars_any matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + //~^ string_lit_chars_any matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + //~^ string_lit_chars_any matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + //~^ string_lit_chars_any #[rustfmt::skip] matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + //~^ string_lit_chars_any // Do not lint NotStringLit.chars().any(|x| x == c); "\\.+*?()|[]{}^$#&-~".chars().any(|x| { diff --git a/tests/ui/string_lit_chars_any.rs b/tests/ui/string_lit_chars_any.rs index 12e6ffb6a9c4..22cfb784ed7d 100644 --- a/tests/ui/string_lit_chars_any.rs +++ b/tests/ui/string_lit_chars_any.rs @@ -16,11 +16,16 @@ impl NotStringLit { fn main() { let c = 'c'; "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == c); + //~^ string_lit_chars_any r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| x == c); + //~^ string_lit_chars_any "\\.+*?()|[]{}^$#&-~".chars().any(|x| c == x); + //~^ string_lit_chars_any r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| c == x); + //~^ string_lit_chars_any #[rustfmt::skip] "\\.+*?()|[]{}^$#&-~".chars().any(|x| { x == c }); + //~^ string_lit_chars_any // Do not lint NotStringLit.chars().any(|x| x == c); "\\.+*?()|[]{}^$#&-~".chars().any(|x| { diff --git a/tests/ui/string_lit_chars_any.stderr b/tests/ui/string_lit_chars_any.stderr index 09c4f02eb062..35f1e4ad6cd8 100644 --- a/tests/ui/string_lit_chars_any.stderr +++ b/tests/ui/string_lit_chars_any.stderr @@ -12,7 +12,7 @@ LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: usage of `.chars().any(...)` to check if a char matches any from a string literal - --> $DIR/string_lit_chars_any.rs:19:5 + --> $DIR/string_lit_chars_any.rs:20:5 | LL | r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| x == c); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: usage of `.chars().any(...)` to check if a char matches any from a string literal - --> $DIR/string_lit_chars_any.rs:20:5 + --> $DIR/string_lit_chars_any.rs:22:5 | LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| c == x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: usage of `.chars().any(...)` to check if a char matches any from a string literal - --> $DIR/string_lit_chars_any.rs:21:5 + --> $DIR/string_lit_chars_any.rs:24:5 | LL | r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| c == x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: usage of `.chars().any(...)` to check if a char matches any from a string literal - --> $DIR/string_lit_chars_any.rs:23:5 + --> $DIR/string_lit_chars_any.rs:27:5 | LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| { x == c }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/strlen_on_c_strings.fixed b/tests/ui/strlen_on_c_strings.fixed index 1e7d04ffb9df..31ed1cf03a2d 100644 --- a/tests/ui/strlen_on_c_strings.fixed +++ b/tests/ui/strlen_on_c_strings.fixed @@ -11,22 +11,29 @@ fn main() { // CString let cstring = CString::new("foo").expect("CString::new failed"); let _ = cstring.as_bytes().len(); + //~^ strlen_on_c_strings // CStr let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed"); let _ = cstr.to_bytes().len(); + //~^ strlen_on_c_strings let _ = cstr.to_bytes().len(); + //~^ strlen_on_c_strings let pcstr: *const &CStr = &cstr; let _ = unsafe { (*pcstr).to_bytes().len() }; + //~^ strlen_on_c_strings unsafe fn unsafe_identity(x: T) -> T { x } let _ = unsafe { unsafe_identity(cstr).to_bytes().len() }; + //~^ strlen_on_c_strings let _ = unsafe { unsafe_identity(cstr) }.to_bytes().len(); + //~^ strlen_on_c_strings let f: unsafe fn(_) -> _ = unsafe_identity; let _ = unsafe { f(cstr).to_bytes().len() }; + //~^ strlen_on_c_strings } diff --git a/tests/ui/strlen_on_c_strings.rs b/tests/ui/strlen_on_c_strings.rs index c3ad03591d4e..0f3798c9fd8a 100644 --- a/tests/ui/strlen_on_c_strings.rs +++ b/tests/ui/strlen_on_c_strings.rs @@ -11,22 +11,29 @@ fn main() { // CString let cstring = CString::new("foo").expect("CString::new failed"); let _ = unsafe { libc::strlen(cstring.as_ptr()) }; + //~^ strlen_on_c_strings // CStr let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed"); let _ = unsafe { libc::strlen(cstr.as_ptr()) }; + //~^ strlen_on_c_strings let _ = unsafe { strlen(cstr.as_ptr()) }; + //~^ strlen_on_c_strings let pcstr: *const &CStr = &cstr; let _ = unsafe { strlen((*pcstr).as_ptr()) }; + //~^ strlen_on_c_strings unsafe fn unsafe_identity(x: T) -> T { x } let _ = unsafe { strlen(unsafe_identity(cstr).as_ptr()) }; + //~^ strlen_on_c_strings let _ = unsafe { strlen(unsafe { unsafe_identity(cstr) }.as_ptr()) }; + //~^ strlen_on_c_strings let f: unsafe fn(_) -> _ = unsafe_identity; let _ = unsafe { strlen(f(cstr).as_ptr()) }; + //~^ strlen_on_c_strings } diff --git a/tests/ui/strlen_on_c_strings.stderr b/tests/ui/strlen_on_c_strings.stderr index 6d8ad3981c04..7949c6250a54 100644 --- a/tests/ui/strlen_on_c_strings.stderr +++ b/tests/ui/strlen_on_c_strings.stderr @@ -8,37 +8,37 @@ LL | let _ = unsafe { libc::strlen(cstring.as_ptr()) }; = help: to override `-D warnings` add `#[allow(clippy::strlen_on_c_strings)]` error: using `libc::strlen` on a `CString` or `CStr` value - --> $DIR/strlen_on_c_strings.rs:17:13 + --> $DIR/strlen_on_c_strings.rs:18:13 | LL | let _ = unsafe { libc::strlen(cstr.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cstr.to_bytes().len()` error: using `libc::strlen` on a `CString` or `CStr` value - --> $DIR/strlen_on_c_strings.rs:19:13 + --> $DIR/strlen_on_c_strings.rs:21:13 | LL | let _ = unsafe { strlen(cstr.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cstr.to_bytes().len()` error: using `libc::strlen` on a `CString` or `CStr` value - --> $DIR/strlen_on_c_strings.rs:22:22 + --> $DIR/strlen_on_c_strings.rs:25:22 | LL | let _ = unsafe { strlen((*pcstr).as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(*pcstr).to_bytes().len()` error: using `libc::strlen` on a `CString` or `CStr` value - --> $DIR/strlen_on_c_strings.rs:27:22 + --> $DIR/strlen_on_c_strings.rs:31:22 | LL | let _ = unsafe { strlen(unsafe_identity(cstr).as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unsafe_identity(cstr).to_bytes().len()` error: using `libc::strlen` on a `CString` or `CStr` value - --> $DIR/strlen_on_c_strings.rs:28:13 + --> $DIR/strlen_on_c_strings.rs:33:13 | LL | let _ = unsafe { strlen(unsafe { unsafe_identity(cstr) }.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unsafe { unsafe_identity(cstr) }.to_bytes().len()` error: using `libc::strlen` on a `CString` or `CStr` value - --> $DIR/strlen_on_c_strings.rs:31:22 + --> $DIR/strlen_on_c_strings.rs:37:22 | LL | let _ = unsafe { strlen(f(cstr).as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `f(cstr).to_bytes().len()` diff --git a/tests/ui/struct_fields.rs b/tests/ui/struct_fields.rs index 30f3caa783dc..cd5b38116f89 100644 --- a/tests/ui/struct_fields.rs +++ b/tests/ui/struct_fields.rs @@ -223,6 +223,7 @@ pub struct RegexT { mod macro_tests { macro_rules! mk_struct { () => { + //~v struct_field_names struct MacroStruct { some_a: i32, some_b: i32, @@ -235,7 +236,7 @@ mod macro_tests { macro_rules! mk_struct2 { () => { struct Macrobaz { - macrobaz_a: i32, + macrobaz_a: i32, //~ struct_field_names some_b: i32, some_c: i32, } @@ -246,7 +247,7 @@ mod macro_tests { macro_rules! mk_struct_with_names { ($struct_name:ident, $field:ident) => { struct $struct_name { - $field: i32, + $field: i32, //~ struct_field_names other_something: i32, other_field: i32, } @@ -285,6 +286,7 @@ mod macro_tests { macro_rules! mk_struct_full_def { ($struct_name:ident, $field1:ident, $field2:ident, $field3:ident) => { + //~v struct_field_names struct $struct_name { $field1: i32, $field2: i32, @@ -334,8 +336,8 @@ struct Config { struct Use { use_foo: bool, //~^ ERROR: field name starts with the struct's name - use_bar: bool, - use_baz: bool, + use_bar: bool, //~ struct_field_names + use_baz: bool, //~ struct_field_names } fn main() {} diff --git a/tests/ui/struct_fields.stderr b/tests/ui/struct_fields.stderr index d2bdbd17d5cc..26a9777154b3 100644 --- a/tests/ui/struct_fields.stderr +++ b/tests/ui/struct_fields.stderr @@ -208,7 +208,7 @@ LL | proxy: i32, | ^^^^^^^^^^ error: all fields have the same prefix: `some` - --> $DIR/struct_fields.rs:226:13 + --> $DIR/struct_fields.rs:227:13 | LL | / struct MacroStruct { LL | | some_a: i32, @@ -235,7 +235,7 @@ LL | mk_struct2!(); = note: this error originates in the macro `mk_struct2` (in Nightly builds, run with -Z macro-backtrace for more info) error: field name starts with the struct's name - --> $DIR/struct_fields.rs:251:17 + --> $DIR/struct_fields.rs:250:17 | LL | $field: i32, | ^^^^^^^^^^^ @@ -246,7 +246,7 @@ LL | mk_struct_with_names!(Foo, foo); = note: this error originates in the macro `mk_struct_with_names` (in Nightly builds, run with -Z macro-backtrace for more info) error: all fields have the same prefix: `some` - --> $DIR/struct_fields.rs:291:13 + --> $DIR/struct_fields.rs:290:13 | LL | / struct $struct_name { LL | | $field1: i32, @@ -262,19 +262,19 @@ LL | mk_struct_full_def!(PrefixData, some_data, some_meta, some_other); = note: this error originates in the macro `mk_struct_full_def` (in Nightly builds, run with -Z macro-backtrace for more info) error: field name starts with the struct's name - --> $DIR/struct_fields.rs:339:5 + --> $DIR/struct_fields.rs:337:5 | LL | use_foo: bool, | ^^^^^^^^^^^^^ error: field name starts with the struct's name - --> $DIR/struct_fields.rs:341:5 + --> $DIR/struct_fields.rs:339:5 | LL | use_bar: bool, | ^^^^^^^^^^^^^ error: field name starts with the struct's name - --> $DIR/struct_fields.rs:342:5 + --> $DIR/struct_fields.rs:340:5 | LL | use_baz: bool, | ^^^^^^^^^^^^^ diff --git a/tests/ui/suspicious_doc_comments.fixed b/tests/ui/suspicious_doc_comments.fixed index 614fc03571e5..2b2c7e718c68 100644 --- a/tests/ui/suspicious_doc_comments.fixed +++ b/tests/ui/suspicious_doc_comments.fixed @@ -2,10 +2,12 @@ #![warn(clippy::suspicious_doc_comments)] //! Real module documentation. +//~v suspicious_doc_comments //! Fake module documentation. fn baz() {} pub mod singleline_outer_doc { + //~v suspicious_doc_comments //! This module contains useful functions. pub fn bar() {} @@ -18,6 +20,7 @@ pub mod singleline_inner_doc { } pub mod multiline_outer_doc { + //~v suspicious_doc_comments /*! This module contains useful functions. */ @@ -32,6 +35,7 @@ pub mod multiline_inner_doc { } pub mod multiline_outer_doc2 { + //~v suspicious_doc_comments //! This module //! contains //! useful functions. @@ -40,6 +44,7 @@ pub mod multiline_outer_doc2 { } pub mod multiline_outer_doc3 { + //~v suspicious_doc_comments //! a //! b @@ -48,12 +53,14 @@ pub mod multiline_outer_doc3 { } pub mod multiline_outer_doc4 { + //~v suspicious_doc_comments //! a /// b pub fn bar() {} } pub mod multiline_outer_doc_gap { + //~v suspicious_doc_comments //! a //! b @@ -66,6 +73,7 @@ pub mod multiline_outer_doc_commented { } pub mod outer_doc_macro { + //~v suspicious_doc_comments //! Very cool macro macro_rules! x { () => {}; @@ -73,6 +81,7 @@ pub mod outer_doc_macro { } pub mod useless_outer_doc { + //~v suspicious_doc_comments //! Huh. use std::mem; } diff --git a/tests/ui/suspicious_doc_comments.rs b/tests/ui/suspicious_doc_comments.rs index 7dcba0fefc98..7c56d8ac22b7 100644 --- a/tests/ui/suspicious_doc_comments.rs +++ b/tests/ui/suspicious_doc_comments.rs @@ -2,10 +2,12 @@ #![warn(clippy::suspicious_doc_comments)] //! Real module documentation. +//~v suspicious_doc_comments ///! Fake module documentation. fn baz() {} pub mod singleline_outer_doc { + //~v suspicious_doc_comments ///! This module contains useful functions. pub fn bar() {} @@ -18,6 +20,7 @@ pub mod singleline_inner_doc { } pub mod multiline_outer_doc { + //~v suspicious_doc_comments /**! This module contains useful functions. */ @@ -32,6 +35,7 @@ pub mod multiline_inner_doc { } pub mod multiline_outer_doc2 { + //~v suspicious_doc_comments ///! This module ///! contains ///! useful functions. @@ -40,6 +44,7 @@ pub mod multiline_outer_doc2 { } pub mod multiline_outer_doc3 { + //~v suspicious_doc_comments ///! a ///! b @@ -48,12 +53,14 @@ pub mod multiline_outer_doc3 { } pub mod multiline_outer_doc4 { + //~v suspicious_doc_comments ///! a /// b pub fn bar() {} } pub mod multiline_outer_doc_gap { + //~v suspicious_doc_comments ///! a ///! b @@ -66,6 +73,7 @@ pub mod multiline_outer_doc_commented { } pub mod outer_doc_macro { + //~v suspicious_doc_comments ///! Very cool macro macro_rules! x { () => {}; @@ -73,6 +81,7 @@ pub mod outer_doc_macro { } pub mod useless_outer_doc { + //~v suspicious_doc_comments ///! Huh. use std::mem; } diff --git a/tests/ui/suspicious_doc_comments.stderr b/tests/ui/suspicious_doc_comments.stderr index 1b238f501e13..5ef894e597a5 100644 --- a/tests/ui/suspicious_doc_comments.stderr +++ b/tests/ui/suspicious_doc_comments.stderr @@ -1,5 +1,5 @@ error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:5:1 + --> $DIR/suspicious_doc_comments.rs:6:1 | LL | ///! Fake module documentation. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL | //! Fake module documentation. | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:9:5 + --> $DIR/suspicious_doc_comments.rs:11:5 | LL | ///! This module contains useful functions. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | //! This module contains useful functions. | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:21:5 + --> $DIR/suspicious_doc_comments.rs:24:5 | LL | / /**! This module contains useful functions. LL | | */ @@ -36,7 +36,7 @@ LL + */ | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:35:5 + --> $DIR/suspicious_doc_comments.rs:39:5 | LL | / ///! This module LL | | ///! contains @@ -51,7 +51,7 @@ LL ~ //! useful functions. | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:43:5 + --> $DIR/suspicious_doc_comments.rs:48:5 | LL | / ///! a LL | | ///! b @@ -64,7 +64,7 @@ LL ~ //! b | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:51:5 + --> $DIR/suspicious_doc_comments.rs:57:5 | LL | ///! a | ^^^^^^ @@ -75,7 +75,7 @@ LL | //! a | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:57:5 + --> $DIR/suspicious_doc_comments.rs:64:5 | LL | / ///! a LL | | @@ -90,7 +90,7 @@ LL ~ //! b | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:69:5 + --> $DIR/suspicious_doc_comments.rs:77:5 | LL | ///! Very cool macro | ^^^^^^^^^^^^^^^^^^^^ @@ -101,7 +101,7 @@ LL | //! Very cool macro | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:76:5 + --> $DIR/suspicious_doc_comments.rs:85:5 | LL | ///! Huh. | ^^^^^^^^^ diff --git a/tests/ui/suspicious_else_formatting.rs b/tests/ui/suspicious_else_formatting.rs index c0856427eaef..a7b8f27c232e 100644 --- a/tests/ui/suspicious_else_formatting.rs +++ b/tests/ui/suspicious_else_formatting.rs @@ -19,10 +19,12 @@ fn foo() -> bool { fn main() { // weird `else` formatting: if foo() { + //~v suspicious_else_formatting } { } if foo() { + //~v suspicious_else_formatting } if foo() { } @@ -30,6 +32,7 @@ fn main() { let _ = 0; if foo() { + //~v suspicious_else_formatting } if foo() { } else { @@ -38,6 +41,7 @@ fn main() { let _ = { // if in the middle of a block if foo() { + //~v suspicious_else_formatting } if foo() { } else { @@ -47,6 +51,7 @@ fn main() { }; if foo() { + //~v suspicious_else_formatting } else { } @@ -59,11 +64,13 @@ fn main() { } if foo() { + //~v suspicious_else_formatting } else if foo() { // the span of the above error should continue here } if foo() { + //~v suspicious_else_formatting } else if foo() { // the span of the above error should continue here @@ -91,6 +98,7 @@ fn main() { // Almost Allman style braces. Lint these. if foo() { + //~v suspicious_else_formatting } else @@ -99,6 +107,7 @@ fn main() { } if foo() { + //~v suspicious_else_formatting } else diff --git a/tests/ui/suspicious_else_formatting.stderr b/tests/ui/suspicious_else_formatting.stderr index 95047cb95ee1..5e8b13023198 100644 --- a/tests/ui/suspicious_else_formatting.stderr +++ b/tests/ui/suspicious_else_formatting.stderr @@ -1,5 +1,5 @@ error: this looks like an `else {..}` but the `else` is missing - --> $DIR/suspicious_else_formatting.rs:22:6 + --> $DIR/suspicious_else_formatting.rs:23:6 | LL | } { | ^ @@ -9,7 +9,7 @@ LL | } { = help: to override `-D warnings` add `#[allow(clippy::suspicious_else_formatting)]` error: this looks like an `else if` but the `else` is missing - --> $DIR/suspicious_else_formatting.rs:26:6 + --> $DIR/suspicious_else_formatting.rs:28:6 | LL | } if foo() { | ^ @@ -17,7 +17,7 @@ LL | } if foo() { = note: to remove this lint, add the missing `else` or add a new line before the second `if` error: this looks like an `else if` but the `else` is missing - --> $DIR/suspicious_else_formatting.rs:33:10 + --> $DIR/suspicious_else_formatting.rs:36:10 | LL | } if foo() { | ^ @@ -25,7 +25,7 @@ LL | } if foo() { = note: to remove this lint, add the missing `else` or add a new line before the second `if` error: this looks like an `else if` but the `else` is missing - --> $DIR/suspicious_else_formatting.rs:41:10 + --> $DIR/suspicious_else_formatting.rs:45:10 | LL | } if foo() { | ^ @@ -33,7 +33,7 @@ LL | } if foo() { = note: to remove this lint, add the missing `else` or add a new line before the second `if` error: this is an `else {..}` but the formatting might hide it - --> $DIR/suspicious_else_formatting.rs:50:6 + --> $DIR/suspicious_else_formatting.rs:55:6 | LL | } else | ______^ @@ -43,7 +43,7 @@ LL | | { = note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}` error: this is an `else if` but the formatting might hide it - --> $DIR/suspicious_else_formatting.rs:62:6 + --> $DIR/suspicious_else_formatting.rs:68:6 | LL | } else | ______^ @@ -53,7 +53,7 @@ LL | | if foo() { // the span of the above error should continue here = note: to remove this lint, remove the `else` or remove the new line between `else` and `if` error: this is an `else if` but the formatting might hide it - --> $DIR/suspicious_else_formatting.rs:67:6 + --> $DIR/suspicious_else_formatting.rs:74:6 | LL | } | ______^ @@ -64,7 +64,7 @@ LL | | if foo() { // the span of the above error should continue here = note: to remove this lint, remove the `else` or remove the new line between `else` and `if` error: this is an `else {..}` but the formatting might hide it - --> $DIR/suspicious_else_formatting.rs:94:6 + --> $DIR/suspicious_else_formatting.rs:102:6 | LL | } | ______^ @@ -76,7 +76,7 @@ LL | | { = note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}` error: this is an `else {..}` but the formatting might hide it - --> $DIR/suspicious_else_formatting.rs:102:6 + --> $DIR/suspicious_else_formatting.rs:111:6 | LL | } | ______^ diff --git a/tests/ui/suspicious_operation_groupings.fixed b/tests/ui/suspicious_operation_groupings.fixed index 9d9732307c85..ed4b36fdd352 100644 --- a/tests/ui/suspicious_operation_groupings.fixed +++ b/tests/ui/suspicious_operation_groupings.fixed @@ -13,6 +13,7 @@ impl PartialEq for Vec3 { fn eq(&self, other: &Self) -> bool { // This should trigger the lint because `self.x` is compared to `other.y` self.x == other.x && self.y == other.y && self.z == other.z + //~^ suspicious_operation_groupings } } @@ -25,7 +26,7 @@ struct S { fn buggy_ab_cmp(s1: &S, s2: &S) -> bool { // There's no `s1.b` - s1.a < s2.a && s1.b < s2.b + s1.a < s2.a && s1.b < s2.b //~ suspicious_operation_groupings } struct SaOnly { @@ -74,31 +75,38 @@ fn permissable(s1: &S, s2: &S) -> bool { fn non_boolean_operators(s1: &S, s2: &S) -> i32 { // There's no `s2.c` s1.a * s2.a + s1.b * s2.b + s1.c * s2.c + s1.d * s2.d + //~^ suspicious_operation_groupings } fn odd_number_of_pairs(s1: &S, s2: &S) -> i32 { // There's no `s2.b` s1.a * s2.a + s1.b * s2.b + s1.c * s2.c + //~^ suspicious_operation_groupings + //~| suspicious_operation_groupings } fn not_caught_by_eq_op_middle_change_left(s1: &S, s2: &S) -> i32 { // There's no `s1.b` s1.a * s2.a + s1.b * s2.b + s1.c * s2.c + //~^ suspicious_operation_groupings } fn not_caught_by_eq_op_middle_change_right(s1: &S, s2: &S) -> i32 { // There's no `s2.b` s1.a * s2.a + s1.b * s2.b + s1.c * s2.c + //~^ suspicious_operation_groupings } fn not_caught_by_eq_op_start(s1: &S, s2: &S) -> i32 { // There's no `s2.a` s1.a * s2.a + s1.b * s2.b + s1.c * s2.c + //~^ suspicious_operation_groupings } fn not_caught_by_eq_op_end(s1: &S, s2: &S) -> i32 { // There's no `s2.c` s1.a * s2.a + s1.b * s2.b + s1.c * s2.c + //~^ suspicious_operation_groupings } fn the_cross_product_should_not_lint(s1: &S, s2: &S) -> (i32, i32, i32) { @@ -111,57 +119,68 @@ fn the_cross_product_should_not_lint(s1: &S, s2: &S) -> (i32, i32, i32) { fn outer_parens_simple(s1: &S, s2: &S) -> i32 { // There's no `s2.b` - (s1.a * s2.a + s1.b * s2.b) + (s1.a * s2.a + s1.b * s2.b) //~ suspicious_operation_groupings } fn outer_parens(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (s1.a * s2.a + s1.b * s2.b + s1.c * s2.c + s1.d * s2.d) + //~^ suspicious_operation_groupings } fn inner_parens(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.c) + (s1.d * s2.d) + //~^ suspicious_operation_groupings } fn outer_and_some_inner_parens(s1: &S, s2: &S) -> i32 { // There's no `s2.c` ((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.c) + (s1.d * s2.d)) + //~^ suspicious_operation_groupings } fn all_parens_balanced_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.c) + (s1.d * s2.d))) + //~^ suspicious_operation_groupings + //~| suspicious_operation_groupings } fn all_parens_left_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.c)) + (s1.d * s2.d)) + //~^ suspicious_operation_groupings } fn all_parens_right_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` ((s1.a * s2.a) + ((s1.b * s2.b) + (s1.c * s2.c) + (s1.d * s2.d))) + //~^ suspicious_operation_groupings } fn inside_other_binop_expression(s1: &S, s2: &S) -> i32 { // There's no `s1.b` (s1.a * s2.a + s1.b * s2.b) / 2 + //~^ suspicious_operation_groupings } fn inside_function_call(s1: &S, s2: &S) -> i32 { // There's no `s1.b` i32::swap_bytes(s1.a * s2.a + s1.b * s2.b) + //~^ suspicious_operation_groupings } fn inside_larger_boolean_expression(s1: &S, s2: &S) -> bool { // There's no `s1.c` s1.a > 0 && s1.b > 0 && s1.c == s2.c && s1.d == s2.d + //~^ suspicious_operation_groupings } fn inside_larger_boolean_expression_with_unsorted_ops(s1: &S, s2: &S) -> bool { // There's no `s1.c` s1.a > 0 && s1.c == s2.c && s1.b > 0 && s1.d == s2.d + //~^ suspicious_operation_groupings } struct Nested { @@ -171,6 +190,7 @@ struct Nested { fn changed_middle_ident(n1: &Nested, n2: &Nested) -> bool { // There's no `n2.inner.2.0` (n1.inner.0).0 == (n2.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0 + //~^ suspicious_operation_groupings } // `eq_op` should catch this one. @@ -185,11 +205,13 @@ fn inside_fn_with_similar_expression(s1: &S, s2: &S, strict: bool) -> bool { } else { // There's no `s1.b` in this subexpression s1.a <= s2.a && s1.b <= s2.b + //~^ suspicious_operation_groupings } } fn inside_an_if_statement(s1: &mut S, s2: &S) { // There's no `s1.b` + //~v suspicious_operation_groupings if s1.a < s2.a && s1.b < s2.b { s1.c = s2.c; } @@ -198,11 +220,13 @@ fn inside_an_if_statement(s1: &mut S, s2: &S) { fn maximum_unary_minus_right_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` -(-(-s1.a * -s2.a) + (-(-s1.b * -s2.b) + -(-s1.c * -s2.c) + -(-s1.d * -s2.d))) + //~^ suspicious_operation_groupings } fn unary_minus_and_an_if_expression(s1: &S, s2: &S) -> i32 { // There's no `s1.b` -(if -s1.a < -s2.a && -s1.b < -s2.b { s1.c } else { s2.a }) + //~^ suspicious_operation_groupings } fn main() {} diff --git a/tests/ui/suspicious_operation_groupings.rs b/tests/ui/suspicious_operation_groupings.rs index 201b8e657f4b..f26bf1562a3c 100644 --- a/tests/ui/suspicious_operation_groupings.rs +++ b/tests/ui/suspicious_operation_groupings.rs @@ -13,6 +13,7 @@ impl PartialEq for Vec3 { fn eq(&self, other: &Self) -> bool { // This should trigger the lint because `self.x` is compared to `other.y` self.x == other.y && self.y == other.y && self.z == other.z + //~^ suspicious_operation_groupings } } @@ -25,7 +26,7 @@ struct S { fn buggy_ab_cmp(s1: &S, s2: &S) -> bool { // There's no `s1.b` - s1.a < s2.a && s1.a < s2.b + s1.a < s2.a && s1.a < s2.b //~ suspicious_operation_groupings } struct SaOnly { @@ -74,31 +75,38 @@ fn permissable(s1: &S, s2: &S) -> bool { fn non_boolean_operators(s1: &S, s2: &S) -> i32 { // There's no `s2.c` s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d + //~^ suspicious_operation_groupings } fn odd_number_of_pairs(s1: &S, s2: &S) -> i32 { // There's no `s2.b` s1.a * s2.a + s1.b * s2.c + s1.c * s2.c + //~^ suspicious_operation_groupings + //~| suspicious_operation_groupings } fn not_caught_by_eq_op_middle_change_left(s1: &S, s2: &S) -> i32 { // There's no `s1.b` s1.a * s2.a + s2.b * s2.b + s1.c * s2.c + //~^ suspicious_operation_groupings } fn not_caught_by_eq_op_middle_change_right(s1: &S, s2: &S) -> i32 { // There's no `s2.b` s1.a * s2.a + s1.b * s1.b + s1.c * s2.c + //~^ suspicious_operation_groupings } fn not_caught_by_eq_op_start(s1: &S, s2: &S) -> i32 { // There's no `s2.a` s1.a * s1.a + s1.b * s2.b + s1.c * s2.c + //~^ suspicious_operation_groupings } fn not_caught_by_eq_op_end(s1: &S, s2: &S) -> i32 { // There's no `s2.c` s1.a * s2.a + s1.b * s2.b + s1.c * s1.c + //~^ suspicious_operation_groupings } fn the_cross_product_should_not_lint(s1: &S, s2: &S) -> (i32, i32, i32) { @@ -111,57 +119,68 @@ fn the_cross_product_should_not_lint(s1: &S, s2: &S) -> (i32, i32, i32) { fn outer_parens_simple(s1: &S, s2: &S) -> i32 { // There's no `s2.b` - (s1.a * s2.a + s1.b * s1.b) + (s1.a * s2.a + s1.b * s1.b) //~ suspicious_operation_groupings } fn outer_parens(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d) + //~^ suspicious_operation_groupings } fn inner_parens(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d) + //~^ suspicious_operation_groupings } fn outer_and_some_inner_parens(s1: &S, s2: &S) -> i32 { // There's no `s2.c` ((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d)) + //~^ suspicious_operation_groupings } fn all_parens_balanced_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.b) + (s1.d * s2.d))) + //~^ suspicious_operation_groupings + //~| suspicious_operation_groupings } fn all_parens_left_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b)) + (s1.d * s2.d)) + //~^ suspicious_operation_groupings } fn all_parens_right_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` ((s1.a * s2.a) + ((s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d))) + //~^ suspicious_operation_groupings } fn inside_other_binop_expression(s1: &S, s2: &S) -> i32 { // There's no `s1.b` (s1.a * s2.a + s2.b * s2.b) / 2 + //~^ suspicious_operation_groupings } fn inside_function_call(s1: &S, s2: &S) -> i32 { // There's no `s1.b` i32::swap_bytes(s1.a * s2.a + s2.b * s2.b) + //~^ suspicious_operation_groupings } fn inside_larger_boolean_expression(s1: &S, s2: &S) -> bool { // There's no `s1.c` s1.a > 0 && s1.b > 0 && s1.d == s2.c && s1.d == s2.d + //~^ suspicious_operation_groupings } fn inside_larger_boolean_expression_with_unsorted_ops(s1: &S, s2: &S) -> bool { // There's no `s1.c` s1.a > 0 && s1.d == s2.c && s1.b > 0 && s1.d == s2.d + //~^ suspicious_operation_groupings } struct Nested { @@ -171,6 +190,7 @@ struct Nested { fn changed_middle_ident(n1: &Nested, n2: &Nested) -> bool { // There's no `n2.inner.2.0` (n1.inner.0).0 == (n2.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.1).0 + //~^ suspicious_operation_groupings } // `eq_op` should catch this one. @@ -185,11 +205,13 @@ fn inside_fn_with_similar_expression(s1: &S, s2: &S, strict: bool) -> bool { } else { // There's no `s1.b` in this subexpression s1.a <= s2.a && s1.a <= s2.b + //~^ suspicious_operation_groupings } } fn inside_an_if_statement(s1: &mut S, s2: &S) { // There's no `s1.b` + //~v suspicious_operation_groupings if s1.a < s2.a && s1.a < s2.b { s1.c = s2.c; } @@ -198,11 +220,13 @@ fn inside_an_if_statement(s1: &mut S, s2: &S) { fn maximum_unary_minus_right_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` -(-(-s1.a * -s2.a) + (-(-s1.b * -s2.b) + -(-s1.c * -s2.b) + -(-s1.d * -s2.d))) + //~^ suspicious_operation_groupings } fn unary_minus_and_an_if_expression(s1: &S, s2: &S) -> i32 { // There's no `s1.b` -(if -s1.a < -s2.a && -s1.a < -s2.b { s1.c } else { s2.a }) + //~^ suspicious_operation_groupings } fn main() {} diff --git a/tests/ui/suspicious_operation_groupings.stderr b/tests/ui/suspicious_operation_groupings.stderr index 0784da06e5f5..8ab953f6c5bb 100644 --- a/tests/ui/suspicious_operation_groupings.stderr +++ b/tests/ui/suspicious_operation_groupings.stderr @@ -8,151 +8,151 @@ LL | self.x == other.y && self.y == other.y && self.z == other.z = help: to override `-D warnings` add `#[allow(clippy::suspicious_operation_groupings)]` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:28:20 + --> $DIR/suspicious_operation_groupings.rs:29:20 | LL | s1.a < s2.a && s1.a < s2.b | ^^^^^^^^^^^ help: did you mean: `s1.b < s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:76:33 + --> $DIR/suspicious_operation_groupings.rs:77:33 | LL | s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:81:19 + --> $DIR/suspicious_operation_groupings.rs:83:19 | LL | s1.a * s2.a + s1.b * s2.c + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:81:19 + --> $DIR/suspicious_operation_groupings.rs:83:19 | LL | s1.a * s2.a + s1.b * s2.c + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:86:19 + --> $DIR/suspicious_operation_groupings.rs:90:19 | LL | s1.a * s2.a + s2.b * s2.b + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:91:19 + --> $DIR/suspicious_operation_groupings.rs:96:19 | LL | s1.a * s2.a + s1.b * s1.b + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:96:5 + --> $DIR/suspicious_operation_groupings.rs:102:5 | LL | s1.a * s1.a + s1.b * s2.b + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.a * s2.a` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:101:33 + --> $DIR/suspicious_operation_groupings.rs:108:33 | LL | s1.a * s2.a + s1.b * s2.b + s1.c * s1.c | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:114:20 + --> $DIR/suspicious_operation_groupings.rs:122:20 | LL | (s1.a * s2.a + s1.b * s1.b) | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:119:34 + --> $DIR/suspicious_operation_groupings.rs:127:34 | LL | (s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:124:38 + --> $DIR/suspicious_operation_groupings.rs:133:38 | LL | (s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:129:39 + --> $DIR/suspicious_operation_groupings.rs:139:39 | LL | ((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d)) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:134:42 + --> $DIR/suspicious_operation_groupings.rs:145:42 | LL | (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.b) + (s1.d * s2.d))) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:134:42 + --> $DIR/suspicious_operation_groupings.rs:145:42 | LL | (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.b) + (s1.d * s2.d))) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:139:40 + --> $DIR/suspicious_operation_groupings.rs:152:40 | LL | (((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b)) + (s1.d * s2.d)) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:144:40 + --> $DIR/suspicious_operation_groupings.rs:158:40 | LL | ((s1.a * s2.a) + ((s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d))) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:149:20 + --> $DIR/suspicious_operation_groupings.rs:164:20 | LL | (s1.a * s2.a + s2.b * s2.b) / 2 | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:154:35 + --> $DIR/suspicious_operation_groupings.rs:170:35 | LL | i32::swap_bytes(s1.a * s2.a + s2.b * s2.b) | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:159:29 + --> $DIR/suspicious_operation_groupings.rs:176:29 | LL | s1.a > 0 && s1.b > 0 && s1.d == s2.c && s1.d == s2.d | ^^^^^^^^^^^^ help: did you mean: `s1.c == s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:164:17 + --> $DIR/suspicious_operation_groupings.rs:182:17 | LL | s1.a > 0 && s1.d == s2.c && s1.b > 0 && s1.d == s2.d | ^^^^^^^^^^^^ help: did you mean: `s1.c == s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:173:77 + --> $DIR/suspicious_operation_groupings.rs:192:77 | LL | (n1.inner.0).0 == (n2.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.1).0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `(n1.inner.2).0 == (n2.inner.2).0` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:187:25 + --> $DIR/suspicious_operation_groupings.rs:207:25 | LL | s1.a <= s2.a && s1.a <= s2.b | ^^^^^^^^^^^^ help: did you mean: `s1.b <= s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:193:23 + --> $DIR/suspicious_operation_groupings.rs:215:23 | LL | if s1.a < s2.a && s1.a < s2.b { | ^^^^^^^^^^^ help: did you mean: `s1.b < s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:200:48 + --> $DIR/suspicious_operation_groupings.rs:222:48 | LL | -(-(-s1.a * -s2.a) + (-(-s1.b * -s2.b) + -(-s1.c * -s2.b) + -(-s1.d * -s2.d))) | ^^^^^^^^^^^^^ help: did you mean: `-s1.c * -s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:205:27 + --> $DIR/suspicious_operation_groupings.rs:228:27 | LL | -(if -s1.a < -s2.a && -s1.a < -s2.b { s1.c } else { s2.a }) | ^^^^^^^^^^^^^ help: did you mean: `-s1.b < -s2.b` diff --git a/tests/ui/suspicious_xor_used_as_pow.rs b/tests/ui/suspicious_xor_used_as_pow.rs index a5319e1b2308..2194f7d4e0bb 100644 --- a/tests/ui/suspicious_xor_used_as_pow.rs +++ b/tests/ui/suspicious_xor_used_as_pow.rs @@ -10,6 +10,7 @@ macro_rules! macro_test { macro_rules! macro_test_inside { () => { + //~v suspicious_xor_used_as_pow 1 ^ 2 // should warn even if inside macro }; } diff --git a/tests/ui/suspicious_xor_used_as_pow.stderr b/tests/ui/suspicious_xor_used_as_pow.stderr index 29e9fa771019..27ecce27db8e 100644 --- a/tests/ui/suspicious_xor_used_as_pow.stderr +++ b/tests/ui/suspicious_xor_used_as_pow.stderr @@ -1,5 +1,5 @@ error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:19:13 + --> $DIR/suspicious_xor_used_as_pow.rs:20:13 | LL | let _ = 2 ^ 5; | ^^^^^ help: did you mean to write: `2.pow(5)` @@ -8,37 +8,37 @@ LL | let _ = 2 ^ 5; = help: to override `-D warnings` add `#[allow(clippy::suspicious_xor_used_as_pow)]` error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:22:13 + --> $DIR/suspicious_xor_used_as_pow.rs:23:13 | LL | let _ = 2i32 ^ 9i32; | ^^^^^^^^^^^ help: did you mean to write: `2i32.pow(9i32)` error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:24:13 + --> $DIR/suspicious_xor_used_as_pow.rs:25:13 | LL | let _ = 2i32 ^ 2i32; | ^^^^^^^^^^^ help: did you mean to write: `2i32.pow(2i32)` error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:26:13 + --> $DIR/suspicious_xor_used_as_pow.rs:27:13 | LL | let _ = 50i32 ^ 3i32; | ^^^^^^^^^^^^ help: did you mean to write: `50i32.pow(3i32)` error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:28:13 + --> $DIR/suspicious_xor_used_as_pow.rs:29:13 | LL | let _ = 5i32 ^ 8i32; | ^^^^^^^^^^^ help: did you mean to write: `5i32.pow(8i32)` error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:30:13 + --> $DIR/suspicious_xor_used_as_pow.rs:31:13 | LL | let _ = 2i32 ^ 32i32; | ^^^^^^^^^^^^ help: did you mean to write: `2i32.pow(32i32)` error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:13:9 + --> $DIR/suspicious_xor_used_as_pow.rs:14:9 | LL | 1 ^ 2 // should warn even if inside macro | ^^^^^ help: did you mean to write: `1.pow(2)` diff --git a/tests/ui/swap.fixed b/tests/ui/swap.fixed index 888665a17ad1..182f6044b867 100644 --- a/tests/ui/swap.fixed +++ b/tests/ui/swap.fixed @@ -25,6 +25,7 @@ struct Bar { fn field() { let mut bar = Bar { a: 1, b: 2 }; + //~v manual_swap std::mem::swap(&mut bar.a, &mut bar.b); let mut baz = vec![bar.clone(), bar.clone()]; @@ -35,6 +36,7 @@ fn field() { fn array() { let mut foo = [1, 2]; + //~v manual_swap foo.swap(0, 1); foo.swap(0, 1); @@ -42,6 +44,7 @@ fn array() { fn slice() { let foo = &mut [1, 2]; + //~v manual_swap foo.swap(0, 1); foo.swap(0, 1); @@ -59,6 +62,7 @@ fn unswappable_slice() { fn vec() { let mut foo = vec![1, 2]; + //~v manual_swap foo.swap(0, 1); foo.swap(0, 1); @@ -68,18 +72,21 @@ fn xor_swap_locals() { // This is an xor-based swap of local variables. let mut a = 0; let mut b = 1; + //~v manual_swap std::mem::swap(&mut a, &mut b); } fn xor_field_swap() { // This is an xor-based swap of fields in a struct. let mut bar = Bar { a: 0, b: 1 }; + //~v manual_swap std::mem::swap(&mut bar.a, &mut bar.b); } fn xor_slice_swap() { // This is an xor-based swap of a slice let foo = &mut [1, 2]; + //~v manual_swap foo.swap(0, 1); } @@ -107,6 +114,7 @@ fn xor_unswappable_slice() { fn distinct_slice() { let foo = &mut [vec![1, 2], vec![3, 4]]; let bar = &mut [vec![1, 2], vec![3, 4]]; + //~v manual_swap std::mem::swap(&mut foo[0][1], &mut bar[1][0]); } @@ -116,23 +124,30 @@ fn main() { let mut a = 42; let mut b = 1337; + //~v almost_swapped std::mem::swap(&mut a, &mut b); + //~v manual_swap ; std::mem::swap(&mut a, &mut b); let mut c = Foo(42); + //~v almost_swapped std::mem::swap(&mut c.0, &mut a); + //~v manual_swap ; std::mem::swap(&mut c.0, &mut a); + //~v almost_swapped std::mem::swap(&mut a, &mut b); let mut c = 1; let mut d = 2; + //~v almost_swapped std::mem::swap(&mut d, &mut c); let mut b = 1; + //~v almost_swapped std::mem::swap(&mut a, &mut b); let b = 1; @@ -145,6 +160,7 @@ fn main() { let mut b = 1; let mut a = 2; + //~v manual_swap std::mem::swap(&mut b, &mut a); } @@ -178,6 +194,7 @@ fn issue_8154() { let mut s = S1 { x: 0, y: 0 }; let mut s = &mut s; let s = S3(&mut s); + //~v manual_swap std::mem::swap(&mut s.0.x, &mut s.0.y); } diff --git a/tests/ui/swap.rs b/tests/ui/swap.rs index c9ad77629290..ef20ad19a5dd 100644 --- a/tests/ui/swap.rs +++ b/tests/ui/swap.rs @@ -25,6 +25,7 @@ struct Bar { fn field() { let mut bar = Bar { a: 1, b: 2 }; + //~v manual_swap let temp = bar.a; bar.a = bar.b; bar.b = temp; @@ -37,6 +38,7 @@ fn field() { fn array() { let mut foo = [1, 2]; + //~v manual_swap let temp = foo[0]; foo[0] = foo[1]; foo[1] = temp; @@ -46,6 +48,7 @@ fn array() { fn slice() { let foo = &mut [1, 2]; + //~v manual_swap let temp = foo[0]; foo[0] = foo[1]; foo[1] = temp; @@ -65,6 +68,7 @@ fn unswappable_slice() { fn vec() { let mut foo = vec![1, 2]; + //~v manual_swap let temp = foo[0]; foo[0] = foo[1]; foo[1] = temp; @@ -76,6 +80,7 @@ fn xor_swap_locals() { // This is an xor-based swap of local variables. let mut a = 0; let mut b = 1; + //~v manual_swap a ^= b; b ^= a; a ^= b; @@ -84,6 +89,7 @@ fn xor_swap_locals() { fn xor_field_swap() { // This is an xor-based swap of fields in a struct. let mut bar = Bar { a: 0, b: 1 }; + //~v manual_swap bar.a ^= bar.b; bar.b ^= bar.a; bar.a ^= bar.b; @@ -92,6 +98,7 @@ fn xor_field_swap() { fn xor_slice_swap() { // This is an xor-based swap of a slice let foo = &mut [1, 2]; + //~v manual_swap foo[0] ^= foo[1]; foo[1] ^= foo[0]; foo[0] ^= foo[1]; @@ -121,6 +128,7 @@ fn xor_unswappable_slice() { fn distinct_slice() { let foo = &mut [vec![1, 2], vec![3, 4]]; let bar = &mut [vec![1, 2], vec![3, 4]]; + //~v manual_swap let temp = foo[0][1]; foo[0][1] = bar[1][0]; bar[1][0] = temp; @@ -132,31 +140,38 @@ fn main() { let mut a = 42; let mut b = 1337; + //~v almost_swapped a = b; b = a; + //~v manual_swap ; let t = a; a = b; b = t; let mut c = Foo(42); + //~v almost_swapped c.0 = a; a = c.0; + //~v manual_swap ; let t = c.0; c.0 = a; a = t; + //~v almost_swapped let a = b; let b = a; let mut c = 1; let mut d = 2; + //~v almost_swapped d = c; c = d; let mut b = 1; + //~v almost_swapped let a = b; b = a; @@ -170,6 +185,7 @@ fn main() { let mut b = 1; let mut a = 2; + //~v manual_swap let t = b; b = a; a = t; @@ -205,6 +221,7 @@ fn issue_8154() { let mut s = S1 { x: 0, y: 0 }; let mut s = &mut s; let s = S3(&mut s); + //~v manual_swap let t = s.0.x; s.0.x = s.0.y; s.0.y = t; diff --git a/tests/ui/swap.stderr b/tests/ui/swap.stderr index e69ad02b08fe..00e921d385d1 100644 --- a/tests/ui/swap.stderr +++ b/tests/ui/swap.stderr @@ -1,5 +1,5 @@ error: this looks like you are swapping `bar.a` and `bar.b` manually - --> $DIR/swap.rs:28:5 + --> $DIR/swap.rs:29:5 | LL | / let temp = bar.a; LL | | bar.a = bar.b; @@ -11,7 +11,7 @@ LL | | bar.b = temp; = help: to override `-D warnings` add `#[allow(clippy::manual_swap)]` error: this looks like you are swapping elements of `foo` manually - --> $DIR/swap.rs:40:5 + --> $DIR/swap.rs:42:5 | LL | / let temp = foo[0]; LL | | foo[0] = foo[1]; @@ -19,7 +19,7 @@ LL | | foo[1] = temp; | |__________________^ help: try: `foo.swap(0, 1);` error: this looks like you are swapping elements of `foo` manually - --> $DIR/swap.rs:49:5 + --> $DIR/swap.rs:52:5 | LL | / let temp = foo[0]; LL | | foo[0] = foo[1]; @@ -27,7 +27,7 @@ LL | | foo[1] = temp; | |__________________^ help: try: `foo.swap(0, 1);` error: this looks like you are swapping elements of `foo` manually - --> $DIR/swap.rs:68:5 + --> $DIR/swap.rs:72:5 | LL | / let temp = foo[0]; LL | | foo[0] = foo[1]; @@ -35,7 +35,7 @@ LL | | foo[1] = temp; | |__________________^ help: try: `foo.swap(0, 1);` error: this looks like you are swapping `a` and `b` manually - --> $DIR/swap.rs:79:5 + --> $DIR/swap.rs:84:5 | LL | / a ^= b; LL | | b ^= a; @@ -43,7 +43,7 @@ LL | | a ^= b; | |___________^ help: try: `std::mem::swap(&mut a, &mut b);` error: this looks like you are swapping `bar.a` and `bar.b` manually - --> $DIR/swap.rs:87:5 + --> $DIR/swap.rs:93:5 | LL | / bar.a ^= bar.b; LL | | bar.b ^= bar.a; @@ -51,7 +51,7 @@ LL | | bar.a ^= bar.b; | |___________________^ help: try: `std::mem::swap(&mut bar.a, &mut bar.b);` error: this looks like you are swapping elements of `foo` manually - --> $DIR/swap.rs:95:5 + --> $DIR/swap.rs:102:5 | LL | / foo[0] ^= foo[1]; LL | | foo[1] ^= foo[0]; @@ -59,7 +59,7 @@ LL | | foo[0] ^= foo[1]; | |_____________________^ help: try: `foo.swap(0, 1);` error: this looks like you are swapping `foo[0][1]` and `bar[1][0]` manually - --> $DIR/swap.rs:124:5 + --> $DIR/swap.rs:132:5 | LL | / let temp = foo[0][1]; LL | | foo[0][1] = bar[1][0]; @@ -69,7 +69,7 @@ LL | | bar[1][0] = temp; = note: or maybe you should use `std::mem::replace`? error: this looks like you are swapping `a` and `b` manually - --> $DIR/swap.rs:138:7 + --> $DIR/swap.rs:148:7 | LL | ; let t = a; | _______^ @@ -80,7 +80,7 @@ LL | | b = t; = note: or maybe you should use `std::mem::replace`? error: this looks like you are swapping `c.0` and `a` manually - --> $DIR/swap.rs:147:7 + --> $DIR/swap.rs:159:7 | LL | ; let t = c.0; | _______^ @@ -91,7 +91,7 @@ LL | | a = t; = note: or maybe you should use `std::mem::replace`? error: this looks like you are swapping `b` and `a` manually - --> $DIR/swap.rs:173:5 + --> $DIR/swap.rs:189:5 | LL | / let t = b; LL | | b = a; @@ -101,7 +101,7 @@ LL | | a = t; = note: or maybe you should use `std::mem::replace`? error: this looks like you are trying to swap `a` and `b` - --> $DIR/swap.rs:135:5 + --> $DIR/swap.rs:144:5 | LL | / a = b; LL | | b = a; @@ -112,7 +112,7 @@ LL | | b = a; = help: to override `-D warnings` add `#[allow(clippy::almost_swapped)]` error: this looks like you are trying to swap `c.0` and `a` - --> $DIR/swap.rs:144:5 + --> $DIR/swap.rs:155:5 | LL | / c.0 = a; LL | | a = c.0; @@ -121,7 +121,7 @@ LL | | a = c.0; = note: or maybe you should use `std::mem::replace`? error: this looks like you are trying to swap `a` and `b` - --> $DIR/swap.rs:151:5 + --> $DIR/swap.rs:164:5 | LL | / let a = b; LL | | let b = a; @@ -130,7 +130,7 @@ LL | | let b = a; = note: or maybe you should use `std::mem::replace`? error: this looks like you are trying to swap `d` and `c` - --> $DIR/swap.rs:156:5 + --> $DIR/swap.rs:170:5 | LL | / d = c; LL | | c = d; @@ -139,7 +139,7 @@ LL | | c = d; = note: or maybe you should use `std::mem::replace`? error: this looks like you are trying to swap `a` and `b` - --> $DIR/swap.rs:160:5 + --> $DIR/swap.rs:175:5 | LL | / let a = b; LL | | b = a; @@ -148,7 +148,7 @@ LL | | b = a; = note: or maybe you should use `std::mem::replace`? error: this looks like you are swapping `s.0.x` and `s.0.y` manually - --> $DIR/swap.rs:208:5 + --> $DIR/swap.rs:225:5 | LL | / let t = s.0.x; LL | | s.0.x = s.0.y; diff --git a/tests/ui/swap_ptr_to_ref.fixed b/tests/ui/swap_ptr_to_ref.fixed index 599bb0e80443..9fc66b1c7f2b 100644 --- a/tests/ui/swap_ptr_to_ref.fixed +++ b/tests/ui/swap_ptr_to_ref.fixed @@ -8,10 +8,11 @@ fn main() { let z: *mut _ = &mut x; unsafe { - core::ptr::swap(y, z); - core::ptr::swap(y, &mut x); - core::ptr::swap(&mut x, y); + core::ptr::swap(y, z); //~ swap_ptr_to_ref + core::ptr::swap(y, &mut x); //~ swap_ptr_to_ref + core::ptr::swap(&mut x, y); //~ swap_ptr_to_ref core::ptr::swap(addr_of_mut!(x), addr_of_mut!(x)); + //~^ swap_ptr_to_ref } let y = &mut x; diff --git a/tests/ui/swap_ptr_to_ref.rs b/tests/ui/swap_ptr_to_ref.rs index 3a8a8daefddc..283b35824b8e 100644 --- a/tests/ui/swap_ptr_to_ref.rs +++ b/tests/ui/swap_ptr_to_ref.rs @@ -8,10 +8,11 @@ fn main() { let z: *mut _ = &mut x; unsafe { - core::mem::swap(&mut *y, &mut *z); - core::mem::swap(&mut *y, &mut x); - core::mem::swap(&mut x, &mut *y); + core::mem::swap(&mut *y, &mut *z); //~ swap_ptr_to_ref + core::mem::swap(&mut *y, &mut x); //~ swap_ptr_to_ref + core::mem::swap(&mut x, &mut *y); //~ swap_ptr_to_ref core::mem::swap(&mut *addr_of_mut!(x), &mut *addr_of_mut!(x)); + //~^ swap_ptr_to_ref } let y = &mut x; diff --git a/tests/ui/tabs_in_doc_comments.fixed b/tests/ui/tabs_in_doc_comments.fixed index 26cc5c27e88c..91a762497b7e 100644 --- a/tests/ui/tabs_in_doc_comments.fixed +++ b/tests/ui/tabs_in_doc_comments.fixed @@ -3,15 +3,23 @@ /// /// Struct to hold two strings: +//~| tabs_in_doc_comments +//~v tabs_in_doc_comments /// - first one +//~| tabs_in_doc_comments +//~v tabs_in_doc_comments /// - second one pub struct DoubleString { /// + //~v tabs_in_doc_comments /// - First String: + //~v tabs_in_doc_comments /// - needs to be inside here first_string: String, /// + //~v tabs_in_doc_comments /// - Second String: + //~v tabs_in_doc_comments /// - needs to be inside here second_string: String, } diff --git a/tests/ui/tabs_in_doc_comments.rs b/tests/ui/tabs_in_doc_comments.rs index 14b06966ecc1..338b62ed2ed7 100644 --- a/tests/ui/tabs_in_doc_comments.rs +++ b/tests/ui/tabs_in_doc_comments.rs @@ -3,15 +3,23 @@ /// /// Struct to hold two strings: +//~| tabs_in_doc_comments +//~v tabs_in_doc_comments /// - first one +//~| tabs_in_doc_comments +//~v tabs_in_doc_comments /// - second one pub struct DoubleString { /// + //~v tabs_in_doc_comments /// - First String: + //~v tabs_in_doc_comments /// - needs to be inside here first_string: String, /// + //~v tabs_in_doc_comments /// - Second String: + //~v tabs_in_doc_comments /// - needs to be inside here second_string: String, } diff --git a/tests/ui/tabs_in_doc_comments.stderr b/tests/ui/tabs_in_doc_comments.stderr index 69ce214ae565..213f8bb5a5e0 100644 --- a/tests/ui/tabs_in_doc_comments.stderr +++ b/tests/ui/tabs_in_doc_comments.stderr @@ -1,5 +1,5 @@ error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:10:9 + --> $DIR/tabs_in_doc_comments.rs:15:9 | LL | /// - First String: | ^^^^ help: consider using four spaces per tab @@ -8,43 +8,43 @@ LL | /// - First String: = help: to override `-D warnings` add `#[allow(clippy::tabs_in_doc_comments)]` error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:11:9 + --> $DIR/tabs_in_doc_comments.rs:17:9 | LL | /// - needs to be inside here | ^^^^^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:14:9 + --> $DIR/tabs_in_doc_comments.rs:21:9 | LL | /// - Second String: | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:15:9 + --> $DIR/tabs_in_doc_comments.rs:23:9 | LL | /// - needs to be inside here | ^^^^^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:6:5 + --> $DIR/tabs_in_doc_comments.rs:8:5 | LL | /// - first one | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:6:13 + --> $DIR/tabs_in_doc_comments.rs:8:13 | LL | /// - first one | ^^^^^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:7:5 + --> $DIR/tabs_in_doc_comments.rs:11:5 | LL | /// - second one | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:7:14 + --> $DIR/tabs_in_doc_comments.rs:11:14 | LL | /// - second one | ^^^^ help: consider using four spaces per tab diff --git a/tests/ui/test_attr_in_doctest.rs b/tests/ui/test_attr_in_doctest.rs index 4c904f7a09ac..e99245638634 100644 --- a/tests/ui/test_attr_in_doctest.rs +++ b/tests/ui/test_attr_in_doctest.rs @@ -3,6 +3,7 @@ /// # Examples /// /// ``` +//~v test_attr_in_doctest /// #[test] /// fn should_be_linted() { /// assert_eq!(1, 1); @@ -13,12 +14,14 @@ /// and show that we really parse the attr: /// /// ``` +//~v test_attr_in_doctest /// #[test] /// fn should_also_be_linted() { /// #[cfg(test)] /// assert!(true); /// } /// +//~v test_attr_in_doctest /// #[test] /// fn should_be_linted_too() { /// assert_eq!("#[test]", " diff --git a/tests/ui/test_attr_in_doctest.stderr b/tests/ui/test_attr_in_doctest.stderr index 605259f3bfb4..a7d663f7990c 100644 --- a/tests/ui/test_attr_in_doctest.stderr +++ b/tests/ui/test_attr_in_doctest.stderr @@ -1,5 +1,5 @@ error: unit tests in doctest are not executed - --> $DIR/test_attr_in_doctest.rs:6:5 + --> $DIR/test_attr_in_doctest.rs:7:5 | LL | /// #[test] | _____^ @@ -10,7 +10,7 @@ LL | | /// fn should_be_linted() { = help: to override `-D warnings` add `#[allow(clippy::test_attr_in_doctest)]` error: unit tests in doctest are not executed - --> $DIR/test_attr_in_doctest.rs:16:5 + --> $DIR/test_attr_in_doctest.rs:18:5 | LL | /// #[test] | _____^ @@ -18,7 +18,7 @@ LL | | /// fn should_also_be_linted() { | |____________________________^ error: unit tests in doctest are not executed - --> $DIR/test_attr_in_doctest.rs:22:5 + --> $DIR/test_attr_in_doctest.rs:25:5 | LL | /// #[test] | _____^ diff --git a/tests/ui/to_digit_is_some.fixed b/tests/ui/to_digit_is_some.fixed index 2ef4c05289fd..1f311ee2df4d 100644 --- a/tests/ui/to_digit_is_some.fixed +++ b/tests/ui/to_digit_is_some.fixed @@ -4,6 +4,6 @@ fn main() { let c = 'x'; let d = &c; - let _ = d.is_digit(8); - let _ = char::is_digit(c, 8); + let _ = d.is_digit(8); //~ to_digit_is_some + let _ = char::is_digit(c, 8); //~ to_digit_is_some } diff --git a/tests/ui/to_digit_is_some.rs b/tests/ui/to_digit_is_some.rs index 54d9545809c5..f4e286178de3 100644 --- a/tests/ui/to_digit_is_some.rs +++ b/tests/ui/to_digit_is_some.rs @@ -4,6 +4,6 @@ fn main() { let c = 'x'; let d = &c; - let _ = d.to_digit(8).is_some(); - let _ = char::to_digit(c, 8).is_some(); + let _ = d.to_digit(8).is_some(); //~ to_digit_is_some + let _ = char::to_digit(c, 8).is_some(); //~ to_digit_is_some } diff --git a/tests/ui/to_string_in_format_args_incremental.fixed b/tests/ui/to_string_in_format_args_incremental.fixed index 1f7895796366..fd63cfd8a43d 100644 --- a/tests/ui/to_string_in_format_args_incremental.fixed +++ b/tests/ui/to_string_in_format_args_incremental.fixed @@ -4,5 +4,5 @@ fn main() { let s = "Hello, world!"; - println!("{}", s); + println!("{}", s); //~ to_string_in_format_args } diff --git a/tests/ui/to_string_in_format_args_incremental.rs b/tests/ui/to_string_in_format_args_incremental.rs index 514febe8c92d..b66bd2fe267c 100644 --- a/tests/ui/to_string_in_format_args_incremental.rs +++ b/tests/ui/to_string_in_format_args_incremental.rs @@ -4,5 +4,5 @@ fn main() { let s = "Hello, world!"; - println!("{}", s.to_string()); + println!("{}", s.to_string()); //~ to_string_in_format_args } diff --git a/tests/ui/to_string_trait_impl.rs b/tests/ui/to_string_trait_impl.rs index 4c1202d42034..0e725d535c28 100644 --- a/tests/ui/to_string_trait_impl.rs +++ b/tests/ui/to_string_trait_impl.rs @@ -8,6 +8,7 @@ struct Point { y: usize, } +//~v to_string_trait_impl impl ToString for Point { fn to_string(&self) -> String { format!("({}, {})", self.x, self.y) @@ -53,6 +54,7 @@ mod issue12263 { } } // no specialization if the generics differ, so lint + //~v to_string_trait_impl impl ToString for S { fn to_string(&self) -> String { todo!() diff --git a/tests/ui/to_string_trait_impl.stderr b/tests/ui/to_string_trait_impl.stderr index 0051ea25ae00..5b63dd6edcf1 100644 --- a/tests/ui/to_string_trait_impl.stderr +++ b/tests/ui/to_string_trait_impl.stderr @@ -1,5 +1,5 @@ error: direct implementation of `ToString` - --> $DIR/to_string_trait_impl.rs:11:1 + --> $DIR/to_string_trait_impl.rs:12:1 | LL | / impl ToString for Point { LL | | fn to_string(&self) -> String { @@ -13,7 +13,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::to_string_trait_impl)]` error: direct implementation of `ToString` - --> $DIR/to_string_trait_impl.rs:56:5 + --> $DIR/to_string_trait_impl.rs:58:5 | LL | / impl ToString for S { LL | | fn to_string(&self) -> String { diff --git a/tests/ui/toplevel_ref_arg.fixed b/tests/ui/toplevel_ref_arg.fixed index ff5cd7abbb69..a094fdac0c46 100644 --- a/tests/ui/toplevel_ref_arg.fixed +++ b/tests/ui/toplevel_ref_arg.fixed @@ -11,18 +11,18 @@ fn main() { let y = |ref x| println!("{:?}", x); y(1u8); - let _x = &1; + let _x = &1; //~ toplevel_ref_arg - let _y: &(&_, u8) = &(&1, 2); + let _y: &(&_, u8) = &(&1, 2); //~ toplevel_ref_arg - let _z = &(1 + 2); + let _z = &(1 + 2); //~ toplevel_ref_arg - let _z = &mut (1 + 2); + let _z = &mut (1 + 2); //~ toplevel_ref_arg let (ref x, _) = (1, 2); // ok, not top level println!("The answer is {}.", x); - let _x = &vec![1, 2, 3]; + let _x = &vec![1, 2, 3]; //~ toplevel_ref_arg // Make sure that allowing the lint works #[allow(clippy::toplevel_ref_arg)] @@ -32,7 +32,7 @@ fn main() { for ref _x in 0..10 {} // lint in macro - inline!(let _y = &42;); + inline!(let _y = &42;); //~ toplevel_ref_arg // do not lint in external macro external!(let ref _y = 42;); diff --git a/tests/ui/toplevel_ref_arg.rs b/tests/ui/toplevel_ref_arg.rs index ab79b8959605..5a9ffc3779dd 100644 --- a/tests/ui/toplevel_ref_arg.rs +++ b/tests/ui/toplevel_ref_arg.rs @@ -11,18 +11,18 @@ fn main() { let y = |ref x| println!("{:?}", x); y(1u8); - let ref _x = 1; + let ref _x = 1; //~ toplevel_ref_arg - let ref _y: (&_, u8) = (&1, 2); + let ref _y: (&_, u8) = (&1, 2); //~ toplevel_ref_arg - let ref _z = 1 + 2; + let ref _z = 1 + 2; //~ toplevel_ref_arg - let ref mut _z = 1 + 2; + let ref mut _z = 1 + 2; //~ toplevel_ref_arg let (ref x, _) = (1, 2); // ok, not top level println!("The answer is {}.", x); - let ref _x = vec![1, 2, 3]; + let ref _x = vec![1, 2, 3]; //~ toplevel_ref_arg // Make sure that allowing the lint works #[allow(clippy::toplevel_ref_arg)] @@ -32,7 +32,7 @@ fn main() { for ref _x in 0..10 {} // lint in macro - inline!(let ref _y = 42;); + inline!(let ref _y = 42;); //~ toplevel_ref_arg // do not lint in external macro external!(let ref _y = 42;); diff --git a/tests/ui/toplevel_ref_arg_non_rustfix.rs b/tests/ui/toplevel_ref_arg_non_rustfix.rs index 8aaf47b1bd0c..842fb237f59c 100644 --- a/tests/ui/toplevel_ref_arg_non_rustfix.rs +++ b/tests/ui/toplevel_ref_arg_non_rustfix.rs @@ -6,6 +6,7 @@ extern crate proc_macros; use proc_macros::{external, inline_macros}; +//~v toplevel_ref_arg fn the_answer(ref mut x: u8) { *x = 42; } @@ -17,7 +18,7 @@ fn main() { // lint in macro inline! { - fn fun_example(ref _x: usize) {} + fn fun_example(ref _x: usize) {} //~ toplevel_ref_arg } // do not lint in external macro diff --git a/tests/ui/toplevel_ref_arg_non_rustfix.stderr b/tests/ui/toplevel_ref_arg_non_rustfix.stderr index 45123dd5ec0b..ebb5c8ea4565 100644 --- a/tests/ui/toplevel_ref_arg_non_rustfix.stderr +++ b/tests/ui/toplevel_ref_arg_non_rustfix.stderr @@ -1,5 +1,5 @@ error: `ref` directly on a function argument is ignored. Consider using a reference type instead - --> $DIR/toplevel_ref_arg_non_rustfix.rs:9:15 + --> $DIR/toplevel_ref_arg_non_rustfix.rs:10:15 | LL | fn the_answer(ref mut x: u8) { | ^^^^^^^^^ @@ -8,7 +8,7 @@ LL | fn the_answer(ref mut x: u8) { = help: to override `-D warnings` add `#[allow(clippy::toplevel_ref_arg)]` error: `ref` directly on a function argument is ignored. Consider using a reference type instead - --> $DIR/toplevel_ref_arg_non_rustfix.rs:20:24 + --> $DIR/toplevel_ref_arg_non_rustfix.rs:21:24 | LL | fn fun_example(ref _x: usize) {} | ^^^^^^ diff --git a/tests/ui/trait_duplication_in_bounds.fixed b/tests/ui/trait_duplication_in_bounds.fixed index 7e2663d734f6..2aae28a03f3c 100644 --- a/tests/ui/trait_duplication_in_bounds.fixed +++ b/tests/ui/trait_duplication_in_bounds.fixed @@ -3,13 +3,14 @@ use std::any::Any; +//~v trait_duplication_in_bounds fn bad_foo(arg0: T, argo1: U) { unimplemented!(); } fn bad_bar(arg0: T, arg1: U) where - T: Clone + Copy, + T: Clone + Copy, //~ trait_duplication_in_bounds U: Clone + Copy, { unimplemented!(); @@ -37,6 +38,7 @@ trait GoodSelfWhereClause { Self: Clone + Copy; } +//~v trait_duplication_in_bounds trait BadSelfTraitBound: Clone { fn f(); } @@ -44,7 +46,7 @@ trait BadSelfTraitBound: Clone { trait BadSelfWhereClause { fn f() where - Self: Clone; + Self: Clone; //~ trait_duplication_in_bounds } trait GoodTraitBound { @@ -58,6 +60,7 @@ trait GoodWhereClause { U: Clone + Copy; } +//~v trait_duplication_in_bounds trait BadTraitBound { fn f(); } @@ -66,6 +69,7 @@ trait BadWhereClause { fn f() where T: Clone + Copy, + //~^ trait_duplication_in_bounds U: Clone + Copy; } @@ -98,6 +102,7 @@ fn good_generic + GenericTrait>(arg0: T) { unimplemented!(); } +//~v trait_duplication_in_bounds fn bad_generic + GenericTrait>(arg0: T) { unimplemented!(); } @@ -106,6 +111,7 @@ mod foo { pub trait Clone {} } +//~v trait_duplication_in_bounds fn qualified_path(arg0: T) { unimplemented!(); } @@ -114,6 +120,7 @@ fn good_trait_object(arg0: &(dyn Any + Send)) { unimplemented!(); } +//~v trait_duplication_in_bounds fn bad_trait_object(arg0: &(dyn Any + Send)) { unimplemented!(); } diff --git a/tests/ui/trait_duplication_in_bounds.rs b/tests/ui/trait_duplication_in_bounds.rs index fede1671a436..ee0a7f2bc711 100644 --- a/tests/ui/trait_duplication_in_bounds.rs +++ b/tests/ui/trait_duplication_in_bounds.rs @@ -3,13 +3,14 @@ use std::any::Any; +//~v trait_duplication_in_bounds fn bad_foo(arg0: T, argo1: U) { unimplemented!(); } fn bad_bar(arg0: T, arg1: U) where - T: Clone + Clone + Clone + Copy, + T: Clone + Clone + Clone + Copy, //~ trait_duplication_in_bounds U: Clone + Copy, { unimplemented!(); @@ -37,6 +38,7 @@ trait GoodSelfWhereClause { Self: Clone + Copy; } +//~v trait_duplication_in_bounds trait BadSelfTraitBound: Clone + Clone + Clone { fn f(); } @@ -44,7 +46,7 @@ trait BadSelfTraitBound: Clone + Clone + Clone { trait BadSelfWhereClause { fn f() where - Self: Clone + Clone + Clone; + Self: Clone + Clone + Clone; //~ trait_duplication_in_bounds } trait GoodTraitBound { @@ -58,6 +60,7 @@ trait GoodWhereClause { U: Clone + Copy; } +//~v trait_duplication_in_bounds trait BadTraitBound { fn f(); } @@ -66,6 +69,7 @@ trait BadWhereClause { fn f() where T: Clone + Clone + Clone + Copy, + //~^ trait_duplication_in_bounds U: Clone + Copy; } @@ -98,6 +102,7 @@ fn good_generic + GenericTrait>(arg0: T) { unimplemented!(); } +//~v trait_duplication_in_bounds fn bad_generic + GenericTrait + GenericTrait>(arg0: T) { unimplemented!(); } @@ -106,6 +111,7 @@ mod foo { pub trait Clone {} } +//~v trait_duplication_in_bounds fn qualified_path(arg0: T) { unimplemented!(); } @@ -114,6 +120,7 @@ fn good_trait_object(arg0: &(dyn Any + Send)) { unimplemented!(); } +//~v trait_duplication_in_bounds fn bad_trait_object(arg0: &(dyn Any + Send + Send)) { unimplemented!(); } diff --git a/tests/ui/trait_duplication_in_bounds.stderr b/tests/ui/trait_duplication_in_bounds.stderr index 61a45538b65c..b117c3976475 100644 --- a/tests/ui/trait_duplication_in_bounds.stderr +++ b/tests/ui/trait_duplication_in_bounds.stderr @@ -1,5 +1,5 @@ error: these bounds contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:6:15 + --> $DIR/trait_duplication_in_bounds.rs:7:15 | LL | fn bad_foo(arg0: T, argo1: U) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` @@ -11,49 +11,49 @@ LL | #![deny(clippy::trait_duplication_in_bounds)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: these where clauses contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:12:8 + --> $DIR/trait_duplication_in_bounds.rs:13:8 | LL | T: Clone + Clone + Clone + Copy, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these bounds contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:40:26 + --> $DIR/trait_duplication_in_bounds.rs:42:26 | LL | trait BadSelfTraitBound: Clone + Clone + Clone { | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone` error: these where clauses contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:47:15 + --> $DIR/trait_duplication_in_bounds.rs:49:15 | LL | Self: Clone + Clone + Clone; | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone` error: these bounds contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:61:24 + --> $DIR/trait_duplication_in_bounds.rs:64:24 | LL | trait BadTraitBound { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these where clauses contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:68:12 + --> $DIR/trait_duplication_in_bounds.rs:71:12 | LL | T: Clone + Clone + Clone + Copy, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these bounds contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:101:19 + --> $DIR/trait_duplication_in_bounds.rs:106:19 | LL | fn bad_generic + GenericTrait + GenericTrait>(arg0: T) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `GenericTrait + GenericTrait` error: these bounds contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:109:22 + --> $DIR/trait_duplication_in_bounds.rs:115:22 | LL | fn qualified_path(arg0: T) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::clone::Clone + foo::Clone` error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds.rs:117:33 + --> $DIR/trait_duplication_in_bounds.rs:124:33 | LL | fn bad_trait_object(arg0: &(dyn Any + Send + Send)) { | ^^^^^^^^^^^^^^^^^ help: try: `Any + Send` diff --git a/tests/ui/transmute_ptr_to_ref.fixed b/tests/ui/transmute_ptr_to_ref.fixed index acec14ccb6b8..8751badb8824 100644 --- a/tests/ui/transmute_ptr_to_ref.fixed +++ b/tests/ui/transmute_ptr_to_ref.fixed @@ -2,25 +2,27 @@ #![allow(clippy::match_single_binding, clippy::unnecessary_cast)] unsafe fn _ptr_to_ref(p: *const T, m: *mut T, o: *const U, om: *mut U) { - let _: &T = &*p; + let _: &T = &*p; //~ transmute_ptr_to_ref let _: &T = &*p; - let _: &mut T = &mut *m; + let _: &mut T = &mut *m; //~ transmute_ptr_to_ref let _: &mut T = &mut *m; - let _: &T = &*m; + let _: &T = &*m; //~ transmute_ptr_to_ref let _: &T = &*m; let _: &mut T = &mut *(p as *mut T); + //~^ transmute_ptr_to_ref let _ = &mut *(p as *mut T); - let _: &T = &*(o as *const T); + let _: &T = &*(o as *const T); //~ transmute_ptr_to_ref let _: &T = &*(o as *const T); let _: &mut T = &mut *(om as *mut T); + //~^ transmute_ptr_to_ref let _: &mut T = &mut *(om as *mut T); - let _: &T = &*(om as *const T); + let _: &T = &*(om as *const T); //~ transmute_ptr_to_ref let _: &T = &*(om as *const T); } @@ -31,20 +33,25 @@ fn _issue1231() { let raw = 42 as *const i32; let _: &Foo = unsafe { &*raw.cast::>() }; + //~^ transmute_ptr_to_ref let _: &Foo<&u8> = unsafe { &*raw.cast::>() }; + //~^ transmute_ptr_to_ref type Bar<'a> = &'a u8; let raw = 42 as *const i32; unsafe { &*(raw as *const u8) }; + //~^ transmute_ptr_to_ref } unsafe fn _issue8924<'a, 'b, 'c>(x: *const &'a u32, y: *const &'b u32) -> &'c &'b u32 { match 0 { - 0 => &*x.cast::<&u32>(), - 1 => &*y.cast::<&u32>(), + 0 => &*x.cast::<&u32>(), //~ transmute_ptr_to_ref + 1 => &*y.cast::<&u32>(), //~ transmute_ptr_to_ref 2 => &*x.cast::<&'b u32>(), + //~^ transmute_ptr_to_ref _ => &*y.cast::<&'b u32>(), + //~^ transmute_ptr_to_ref } } @@ -52,11 +59,13 @@ unsafe fn _issue8924<'a, 'b, 'c>(x: *const &'a u32, y: *const &'b u32) -> &'c &' unsafe fn _meets_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 { let a = 0u32; let a = &a as *const u32; - let _: &u32 = &*a; + let _: &u32 = &*a; //~ transmute_ptr_to_ref let _: &u32 = &*a.cast::(); + //~^ transmute_ptr_to_ref match 0 { - 0 => &*x.cast::<&u32>(), + 0 => &*x.cast::<&u32>(), //~ transmute_ptr_to_ref _ => &*x.cast::<&'b u32>(), + //~^ transmute_ptr_to_ref } } @@ -64,11 +73,13 @@ unsafe fn _meets_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 { unsafe fn _under_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 { let a = 0u32; let a = &a as *const u32; - let _: &u32 = &*a; + let _: &u32 = &*a; //~ transmute_ptr_to_ref let _: &u32 = &*(a as *const u32); + //~^ transmute_ptr_to_ref match 0 { - 0 => &*(x as *const () as *const &u32), + 0 => &*(x as *const () as *const &u32), //~ transmute_ptr_to_ref _ => &*(x as *const () as *const &'b u32), + //~^ transmute_ptr_to_ref } } diff --git a/tests/ui/transmute_ptr_to_ref.rs b/tests/ui/transmute_ptr_to_ref.rs index 3376401e284b..13e09f534f1c 100644 --- a/tests/ui/transmute_ptr_to_ref.rs +++ b/tests/ui/transmute_ptr_to_ref.rs @@ -2,25 +2,27 @@ #![allow(clippy::match_single_binding, clippy::unnecessary_cast)] unsafe fn _ptr_to_ref(p: *const T, m: *mut T, o: *const U, om: *mut U) { - let _: &T = std::mem::transmute(p); + let _: &T = std::mem::transmute(p); //~ transmute_ptr_to_ref let _: &T = &*p; - let _: &mut T = std::mem::transmute(m); + let _: &mut T = std::mem::transmute(m); //~ transmute_ptr_to_ref let _: &mut T = &mut *m; - let _: &T = std::mem::transmute(m); + let _: &T = std::mem::transmute(m); //~ transmute_ptr_to_ref let _: &T = &*m; let _: &mut T = std::mem::transmute(p as *mut T); + //~^ transmute_ptr_to_ref let _ = &mut *(p as *mut T); - let _: &T = std::mem::transmute(o); + let _: &T = std::mem::transmute(o); //~ transmute_ptr_to_ref let _: &T = &*(o as *const T); let _: &mut T = std::mem::transmute(om); + //~^ transmute_ptr_to_ref let _: &mut T = &mut *(om as *mut T); - let _: &T = std::mem::transmute(om); + let _: &T = std::mem::transmute(om); //~ transmute_ptr_to_ref let _: &T = &*(om as *const T); } @@ -31,20 +33,25 @@ fn _issue1231() { let raw = 42 as *const i32; let _: &Foo = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) }; + //~^ transmute_ptr_to_ref let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) }; + //~^ transmute_ptr_to_ref type Bar<'a> = &'a u8; let raw = 42 as *const i32; unsafe { std::mem::transmute::<_, Bar>(raw) }; + //~^ transmute_ptr_to_ref } unsafe fn _issue8924<'a, 'b, 'c>(x: *const &'a u32, y: *const &'b u32) -> &'c &'b u32 { match 0 { - 0 => std::mem::transmute(x), - 1 => std::mem::transmute(y), + 0 => std::mem::transmute(x), //~ transmute_ptr_to_ref + 1 => std::mem::transmute(y), //~ transmute_ptr_to_ref 2 => std::mem::transmute::<_, &&'b u32>(x), + //~^ transmute_ptr_to_ref _ => std::mem::transmute::<_, &&'b u32>(y), + //~^ transmute_ptr_to_ref } } @@ -52,11 +59,13 @@ unsafe fn _issue8924<'a, 'b, 'c>(x: *const &'a u32, y: *const &'b u32) -> &'c &' unsafe fn _meets_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 { let a = 0u32; let a = &a as *const u32; - let _: &u32 = std::mem::transmute(a); + let _: &u32 = std::mem::transmute(a); //~ transmute_ptr_to_ref let _: &u32 = std::mem::transmute::<_, &u32>(a); + //~^ transmute_ptr_to_ref match 0 { - 0 => std::mem::transmute(x), + 0 => std::mem::transmute(x), //~ transmute_ptr_to_ref _ => std::mem::transmute::<_, &&'b u32>(x), + //~^ transmute_ptr_to_ref } } @@ -64,11 +73,13 @@ unsafe fn _meets_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 { unsafe fn _under_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 { let a = 0u32; let a = &a as *const u32; - let _: &u32 = std::mem::transmute(a); + let _: &u32 = std::mem::transmute(a); //~ transmute_ptr_to_ref let _: &u32 = std::mem::transmute::<_, &u32>(a); + //~^ transmute_ptr_to_ref match 0 { - 0 => std::mem::transmute(x), + 0 => std::mem::transmute(x), //~ transmute_ptr_to_ref _ => std::mem::transmute::<_, &&'b u32>(x), + //~^ transmute_ptr_to_ref } } diff --git a/tests/ui/transmute_ptr_to_ref.stderr b/tests/ui/transmute_ptr_to_ref.stderr index 9d1b22a795b3..cafd78a301fa 100644 --- a/tests/ui/transmute_ptr_to_ref.stderr +++ b/tests/ui/transmute_ptr_to_ref.stderr @@ -26,109 +26,109 @@ LL | let _: &mut T = std::mem::transmute(p as *mut T); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(p as *mut T)` error: transmute from a pointer type (`*const U`) to a reference type (`&T`) - --> $DIR/transmute_ptr_to_ref.rs:17:17 + --> $DIR/transmute_ptr_to_ref.rs:18:17 | LL | let _: &T = std::mem::transmute(o); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(o as *const T)` error: transmute from a pointer type (`*mut U`) to a reference type (`&mut T`) - --> $DIR/transmute_ptr_to_ref.rs:20:21 + --> $DIR/transmute_ptr_to_ref.rs:21:21 | LL | let _: &mut T = std::mem::transmute(om); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(om as *mut T)` error: transmute from a pointer type (`*mut U`) to a reference type (`&T`) - --> $DIR/transmute_ptr_to_ref.rs:23:17 + --> $DIR/transmute_ptr_to_ref.rs:25:17 | LL | let _: &T = std::mem::transmute(om); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(om as *const T)` error: transmute from a pointer type (`*const i32`) to a reference type (`&_issue1231::Foo<'_, u8>`) - --> $DIR/transmute_ptr_to_ref.rs:33:32 + --> $DIR/transmute_ptr_to_ref.rs:35:32 | LL | let _: &Foo = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*raw.cast::>()` error: transmute from a pointer type (`*const i32`) to a reference type (`&_issue1231::Foo<'_, &u8>`) - --> $DIR/transmute_ptr_to_ref.rs:35:33 + --> $DIR/transmute_ptr_to_ref.rs:38:33 | LL | let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*raw.cast::>()` error: transmute from a pointer type (`*const i32`) to a reference type (`&u8`) - --> $DIR/transmute_ptr_to_ref.rs:39:14 + --> $DIR/transmute_ptr_to_ref.rs:43:14 | LL | unsafe { std::mem::transmute::<_, Bar>(raw) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const u8)` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:44:14 + --> $DIR/transmute_ptr_to_ref.rs:49:14 | LL | 0 => std::mem::transmute(x), | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&u32>()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:45:14 + --> $DIR/transmute_ptr_to_ref.rs:50:14 | LL | 1 => std::mem::transmute(y), | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*y.cast::<&u32>()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:46:14 + --> $DIR/transmute_ptr_to_ref.rs:51:14 | LL | 2 => std::mem::transmute::<_, &&'b u32>(x), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&'b u32>()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:47:14 + --> $DIR/transmute_ptr_to_ref.rs:53:14 | LL | _ => std::mem::transmute::<_, &&'b u32>(y), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*y.cast::<&'b u32>()` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> $DIR/transmute_ptr_to_ref.rs:55:19 + --> $DIR/transmute_ptr_to_ref.rs:62:19 | LL | let _: &u32 = std::mem::transmute(a); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> $DIR/transmute_ptr_to_ref.rs:56:19 + --> $DIR/transmute_ptr_to_ref.rs:63:19 | LL | let _: &u32 = std::mem::transmute::<_, &u32>(a); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a.cast::()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:58:14 + --> $DIR/transmute_ptr_to_ref.rs:66:14 | LL | 0 => std::mem::transmute(x), | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&u32>()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:59:14 + --> $DIR/transmute_ptr_to_ref.rs:67:14 | LL | _ => std::mem::transmute::<_, &&'b u32>(x), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&'b u32>()` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> $DIR/transmute_ptr_to_ref.rs:67:19 + --> $DIR/transmute_ptr_to_ref.rs:76:19 | LL | let _: &u32 = std::mem::transmute(a); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> $DIR/transmute_ptr_to_ref.rs:68:19 + --> $DIR/transmute_ptr_to_ref.rs:77:19 | LL | let _: &u32 = std::mem::transmute::<_, &u32>(a); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(a as *const u32)` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:70:14 + --> $DIR/transmute_ptr_to_ref.rs:80:14 | LL | 0 => std::mem::transmute(x), | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(x as *const () as *const &u32)` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:71:14 + --> $DIR/transmute_ptr_to_ref.rs:81:14 | LL | _ => std::mem::transmute::<_, &&'b u32>(x), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(x as *const () as *const &'b u32)` diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.fixed b/tests/ui/transmutes_expressible_as_ptr_casts.fixed index 08b8e786611d..657a4fa162e0 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.fixed +++ b/tests/ui/transmutes_expressible_as_ptr_casts.fixed @@ -15,28 +15,33 @@ fn main() { // e is an integer and U is *U_0, while U_0: Sized; addr-ptr-cast let _ptr_i32_transmute = unsafe { usize::MAX as *const i32 }; + //~^ useless_transmute let ptr_i32 = usize::MAX as *const i32; // e has type *T, U is *U_0, and either U_0: Sized ... let _ptr_i8_transmute = unsafe { ptr_i32 as *const i8 }; + //~^ transmute_ptr_to_ptr let _ptr_i8 = ptr_i32 as *const i8; let slice_ptr = &[0, 1, 2, 3] as *const [i32]; // ... or pointer_kind(T) = pointer_kind(U_0); ptr-ptr-cast let _ptr_to_unsized_transmute = unsafe { slice_ptr as *const [u32] }; + //~^ transmute_ptr_to_ptr let _ptr_to_unsized = slice_ptr as *const [u32]; // TODO: We could try testing vtable casts here too, but maybe // we should wait until std::raw::TraitObject is stabilized? // e has type *T and U is a numeric type, while T: Sized; ptr-addr-cast let _usize_from_int_ptr_transmute = unsafe { ptr_i32 as usize }; + //~^ transmutes_expressible_as_ptr_casts let _usize_from_int_ptr = ptr_i32 as usize; let array_ref: &[i32; 4] = &[1, 2, 3, 4]; // e has type &[T; n] and U is *const T; array-ptr-cast let _array_ptr_transmute = unsafe { array_ref as *const [i32; 4] }; + //~^ useless_transmute let _array_ptr = array_ref as *const [i32; 4]; fn foo(_: usize) -> u8 { @@ -45,13 +50,16 @@ fn main() { // e is a function pointer type and U has type *T, while T: Sized; fptr-ptr-cast let _usize_ptr_transmute = unsafe { foo as *const usize }; + //~^ transmutes_expressible_as_ptr_casts let _usize_ptr_transmute = foo as *const usize; // e is a function pointer type and U is an integer; fptr-addr-cast let _usize_from_fn_ptr_transmute = unsafe { foo as usize }; + //~^ transmutes_expressible_as_ptr_casts let _usize_from_fn_ptr = foo as *const usize; let _usize_from_ref = unsafe { &1u32 as *const u32 as usize }; + //~^ transmutes_expressible_as_ptr_casts } // If a ref-to-ptr cast of this form where the pointer type points to a type other @@ -63,6 +71,7 @@ fn main() { // fall through into `do_check`. fn trigger_do_check_to_emit_error(in_param: &[i32; 1]) -> *const u8 { unsafe { in_param as *const [i32; 1] as *const u8 } + //~^ useless_transmute } #[repr(C)] @@ -81,4 +90,5 @@ fn issue_10449() { fn f() {} let _x: u8 = unsafe { *(f as *const u8) }; + //~^ transmutes_expressible_as_ptr_casts } diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.rs b/tests/ui/transmutes_expressible_as_ptr_casts.rs index 92eb765e5f94..68c4509a30d9 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ b/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -15,28 +15,33 @@ fn main() { // e is an integer and U is *U_0, while U_0: Sized; addr-ptr-cast let _ptr_i32_transmute = unsafe { transmute::(usize::MAX) }; + //~^ useless_transmute let ptr_i32 = usize::MAX as *const i32; // e has type *T, U is *U_0, and either U_0: Sized ... let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr_i32) }; + //~^ transmute_ptr_to_ptr let _ptr_i8 = ptr_i32 as *const i8; let slice_ptr = &[0, 1, 2, 3] as *const [i32]; // ... or pointer_kind(T) = pointer_kind(U_0); ptr-ptr-cast let _ptr_to_unsized_transmute = unsafe { transmute::<*const [i32], *const [u32]>(slice_ptr) }; + //~^ transmute_ptr_to_ptr let _ptr_to_unsized = slice_ptr as *const [u32]; // TODO: We could try testing vtable casts here too, but maybe // we should wait until std::raw::TraitObject is stabilized? // e has type *T and U is a numeric type, while T: Sized; ptr-addr-cast let _usize_from_int_ptr_transmute = unsafe { transmute::<*const i32, usize>(ptr_i32) }; + //~^ transmutes_expressible_as_ptr_casts let _usize_from_int_ptr = ptr_i32 as usize; let array_ref: &[i32; 4] = &[1, 2, 3, 4]; // e has type &[T; n] and U is *const T; array-ptr-cast let _array_ptr_transmute = unsafe { transmute::<&[i32; 4], *const [i32; 4]>(array_ref) }; + //~^ useless_transmute let _array_ptr = array_ref as *const [i32; 4]; fn foo(_: usize) -> u8 { @@ -45,13 +50,16 @@ fn main() { // e is a function pointer type and U has type *T, while T: Sized; fptr-ptr-cast let _usize_ptr_transmute = unsafe { transmute:: u8, *const usize>(foo) }; + //~^ transmutes_expressible_as_ptr_casts let _usize_ptr_transmute = foo as *const usize; // e is a function pointer type and U is an integer; fptr-addr-cast let _usize_from_fn_ptr_transmute = unsafe { transmute:: u8, usize>(foo) }; + //~^ transmutes_expressible_as_ptr_casts let _usize_from_fn_ptr = foo as *const usize; let _usize_from_ref = unsafe { transmute::<*const u32, usize>(&1u32) }; + //~^ transmutes_expressible_as_ptr_casts } // If a ref-to-ptr cast of this form where the pointer type points to a type other @@ -63,6 +71,7 @@ fn main() { // fall through into `do_check`. fn trigger_do_check_to_emit_error(in_param: &[i32; 1]) -> *const u8 { unsafe { transmute::<&[i32; 1], *const u8>(in_param) } + //~^ useless_transmute } #[repr(C)] @@ -81,4 +90,5 @@ fn issue_10449() { fn f() {} let _x: u8 = unsafe { *std::mem::transmute::(f) }; + //~^ transmutes_expressible_as_ptr_casts } diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.stderr b/tests/ui/transmutes_expressible_as_ptr_casts.stderr index a7988dc4b39b..07b02e077539 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.stderr +++ b/tests/ui/transmutes_expressible_as_ptr_casts.stderr @@ -8,7 +8,7 @@ LL | let _ptr_i32_transmute = unsafe { transmute::(usize: = help: to override `-D warnings` add `#[allow(clippy::useless_transmute)]` error: transmute from a pointer to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:21:38 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:22:38 | LL | let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as *const i8` @@ -17,13 +17,13 @@ LL | let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr = help: to override `-D warnings` add `#[allow(clippy::transmute_ptr_to_ptr)]` error: transmute from a pointer to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:27:46 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:29:46 | LL | let _ptr_to_unsized_transmute = unsafe { transmute::<*const [i32], *const [u32]>(slice_ptr) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `slice_ptr as *const [u32]` error: transmute from `*const i32` to `usize` which could be expressed as a pointer cast instead - --> $DIR/transmutes_expressible_as_ptr_casts.rs:33:50 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:36:50 | LL | let _usize_from_int_ptr_transmute = unsafe { transmute::<*const i32, usize>(ptr_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as usize` @@ -32,37 +32,37 @@ LL | let _usize_from_int_ptr_transmute = unsafe { transmute::<*const i32, us = help: to override `-D warnings` add `#[allow(clippy::transmutes_expressible_as_ptr_casts)]` error: transmute from a reference to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:39:41 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:43:41 | LL | let _array_ptr_transmute = unsafe { transmute::<&[i32; 4], *const [i32; 4]>(array_ref) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `array_ref as *const [i32; 4]` error: transmute from `fn(usize) -> u8` to `*const usize` which could be expressed as a pointer cast instead - --> $DIR/transmutes_expressible_as_ptr_casts.rs:47:41 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:52:41 | LL | let _usize_ptr_transmute = unsafe { transmute:: u8, *const usize>(foo) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as *const usize` error: transmute from `fn(usize) -> u8` to `usize` which could be expressed as a pointer cast instead - --> $DIR/transmutes_expressible_as_ptr_casts.rs:51:49 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:57:49 | LL | let _usize_from_fn_ptr_transmute = unsafe { transmute:: u8, usize>(foo) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as usize` error: transmute from `*const u32` to `usize` which could be expressed as a pointer cast instead - --> $DIR/transmutes_expressible_as_ptr_casts.rs:54:36 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:61:36 | LL | let _usize_from_ref = unsafe { transmute::<*const u32, usize>(&1u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&1u32 as *const u32 as usize` error: transmute from a reference to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:65:14 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:73:14 | LL | unsafe { transmute::<&[i32; 1], *const u8>(in_param) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `in_param as *const [i32; 1] as *const u8` error: transmute from `fn()` to `*const u8` which could be expressed as a pointer cast instead - --> $DIR/transmutes_expressible_as_ptr_casts.rs:83:28 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:92:28 | LL | let _x: u8 = unsafe { *std::mem::transmute::(f) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(f as *const u8)` diff --git a/tests/ui/trim_split_whitespace.fixed b/tests/ui/trim_split_whitespace.fixed index 6d3daf798a67..94e050fbda90 100644 --- a/tests/ui/trim_split_whitespace.fixed +++ b/tests/ui/trim_split_whitespace.fixed @@ -58,13 +58,23 @@ impl DerefStrAndCustomTrim { fn main() { // &str + //~v trim_split_whitespace let _ = " A B C ".split_whitespace(); // should trigger lint + + //~v trim_split_whitespace let _ = " A B C ".split_whitespace(); // should trigger lint + + //~v trim_split_whitespace let _ = " A B C ".split_whitespace(); // should trigger lint // String + //~v trim_split_whitespace let _ = (" A B C ").to_string().split_whitespace(); // should trigger lint + + //~v trim_split_whitespace let _ = (" A B C ").to_string().split_whitespace(); // should trigger lint + + //~v trim_split_whitespace let _ = (" A B C ").to_string().split_whitespace(); // should trigger lint // Custom @@ -72,6 +82,7 @@ fn main() { // Deref let s = DerefStr(" A B C "); + //~v trim_split_whitespace let _ = s.split_whitespace(); // should trigger lint // Deref + custom impl @@ -80,6 +91,7 @@ fn main() { // Deref + only custom split_ws() impl let s = DerefStrAndCustomSplit(" A B C "); + //~v trim_split_whitespace let _ = s.split_whitespace(); // should trigger lint // Expl: trim() is called on str (deref) and returns &str. // Thus split_ws() is called on str as well and the custom impl on S is unused diff --git a/tests/ui/trim_split_whitespace.rs b/tests/ui/trim_split_whitespace.rs index b49d9e8b3fab..bea2e04d62a9 100644 --- a/tests/ui/trim_split_whitespace.rs +++ b/tests/ui/trim_split_whitespace.rs @@ -58,13 +58,23 @@ impl DerefStrAndCustomTrim { fn main() { // &str + //~v trim_split_whitespace let _ = " A B C ".trim().split_whitespace(); // should trigger lint + + //~v trim_split_whitespace let _ = " A B C ".trim_start().split_whitespace(); // should trigger lint + + //~v trim_split_whitespace let _ = " A B C ".trim_end().split_whitespace(); // should trigger lint // String + //~v trim_split_whitespace let _ = (" A B C ").to_string().trim().split_whitespace(); // should trigger lint + + //~v trim_split_whitespace let _ = (" A B C ").to_string().trim_start().split_whitespace(); // should trigger lint + + //~v trim_split_whitespace let _ = (" A B C ").to_string().trim_end().split_whitespace(); // should trigger lint // Custom @@ -72,6 +82,7 @@ fn main() { // Deref let s = DerefStr(" A B C "); + //~v trim_split_whitespace let _ = s.trim().split_whitespace(); // should trigger lint // Deref + custom impl @@ -80,6 +91,7 @@ fn main() { // Deref + only custom split_ws() impl let s = DerefStrAndCustomSplit(" A B C "); + //~v trim_split_whitespace let _ = s.trim().split_whitespace(); // should trigger lint // Expl: trim() is called on str (deref) and returns &str. // Thus split_ws() is called on str as well and the custom impl on S is unused diff --git a/tests/ui/trim_split_whitespace.stderr b/tests/ui/trim_split_whitespace.stderr index a1c66eea0d14..9612c278e7d5 100644 --- a/tests/ui/trim_split_whitespace.stderr +++ b/tests/ui/trim_split_whitespace.stderr @@ -1,5 +1,5 @@ error: found call to `str::trim` before `str::split_whitespace` - --> $DIR/trim_split_whitespace.rs:61:23 + --> $DIR/trim_split_whitespace.rs:62:23 | LL | let _ = " A B C ".trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` @@ -8,43 +8,43 @@ LL | let _ = " A B C ".trim().split_whitespace(); // should trigger lint = help: to override `-D warnings` add `#[allow(clippy::trim_split_whitespace)]` error: found call to `str::trim_start` before `str::split_whitespace` - --> $DIR/trim_split_whitespace.rs:62:23 + --> $DIR/trim_split_whitespace.rs:65:23 | LL | let _ = " A B C ".trim_start().split_whitespace(); // should trigger lint | ^^^^^^^^^^^^^ help: remove `trim_start()` error: found call to `str::trim_end` before `str::split_whitespace` - --> $DIR/trim_split_whitespace.rs:63:23 + --> $DIR/trim_split_whitespace.rs:68:23 | LL | let _ = " A B C ".trim_end().split_whitespace(); // should trigger lint | ^^^^^^^^^^^ help: remove `trim_end()` error: found call to `str::trim` before `str::split_whitespace` - --> $DIR/trim_split_whitespace.rs:66:37 + --> $DIR/trim_split_whitespace.rs:72:37 | LL | let _ = (" A B C ").to_string().trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` error: found call to `str::trim_start` before `str::split_whitespace` - --> $DIR/trim_split_whitespace.rs:67:37 + --> $DIR/trim_split_whitespace.rs:75:37 | LL | let _ = (" A B C ").to_string().trim_start().split_whitespace(); // should trigger lint | ^^^^^^^^^^^^^ help: remove `trim_start()` error: found call to `str::trim_end` before `str::split_whitespace` - --> $DIR/trim_split_whitespace.rs:68:37 + --> $DIR/trim_split_whitespace.rs:78:37 | LL | let _ = (" A B C ").to_string().trim_end().split_whitespace(); // should trigger lint | ^^^^^^^^^^^ help: remove `trim_end()` error: found call to `str::trim` before `str::split_whitespace` - --> $DIR/trim_split_whitespace.rs:75:15 + --> $DIR/trim_split_whitespace.rs:86:15 | LL | let _ = s.trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` error: found call to `str::trim` before `str::split_whitespace` - --> $DIR/trim_split_whitespace.rs:83:15 + --> $DIR/trim_split_whitespace.rs:95:15 | LL | let _ = s.trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` diff --git a/tests/ui/trivially_copy_pass_by_ref.rs b/tests/ui/trivially_copy_pass_by_ref.rs index 043a7b63af3c..264a37990335 100644 --- a/tests/ui/trivially_copy_pass_by_ref.rs +++ b/tests/ui/trivially_copy_pass_by_ref.rs @@ -49,7 +49,7 @@ fn good_return_explicit_lt_struct<'a>(foo: &'a Foo) -> FooRef<'a> { FooRef { foo } } -fn bad(x: &u32, y: &Foo, z: &Baz) {} +fn bad(x: &u32, y: &Foo, z: &Baz) {} //~ trivially_copy_pass_by_ref //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by diff --git a/tests/ui/try_err.fixed b/tests/ui/try_err.fixed index aae4f8ac47f8..39cee4669e09 100644 --- a/tests/ui/try_err.fixed +++ b/tests/ui/try_err.fixed @@ -19,7 +19,7 @@ pub fn basic_test() -> Result { let err: i32 = 1; // To avoid warnings during rustfix if true { - return Err(err); + return Err(err); //~ try_err } Ok(0) } @@ -29,7 +29,7 @@ pub fn into_test() -> Result { let err: u8 = 1; // To avoid warnings during rustfix if true { - return Err(err.into()); + return Err(err.into()); //~ try_err } Ok(0) } @@ -49,7 +49,7 @@ pub fn closure_matches_test() -> Result { let err: i8 = 1; // To avoid warnings during rustfix if true { - return Err(err); + return Err(err); //~ try_err } Ok(i) }) @@ -68,7 +68,7 @@ pub fn closure_into_test() -> Result { let err: i8 = 1; // To avoid warnings during rustfix if true { - return Err(err.into()); + return Err(err.into()); //~ try_err } Ok(i) }) @@ -88,14 +88,14 @@ fn calling_macro() -> Result { inline!( match $(Ok::<_, i32>(5)) { Ok(_) => 0, - Err(_) => return Err(1), + Err(_) => return Err(1), //~ try_err } ); // `Err` arg is another macro inline!( match $(Ok::<_, i32>(5)) { Ok(_) => 0, - Err(_) => return Err(inline!(1)), + Err(_) => return Err(inline!(1)), //~ try_err } ); Ok(5) @@ -123,15 +123,17 @@ fn main() { pub fn macro_inside(fail: bool) -> Result { if fail { return Err(inline!(inline!(String::from("aasdfasdfasdfa")))); + //~^ try_err } Ok(0) } pub fn poll_write(n: usize) -> Poll> { if n == 0 { - return Poll::Ready(Err(io::ErrorKind::WriteZero.into())) + return Poll::Ready(Err(io::ErrorKind::WriteZero.into())) //~ try_err } else if n == 1 { return Poll::Ready(Err(io::Error::new(io::ErrorKind::InvalidInput, "error"))) + //~^ try_err }; Poll::Ready(Ok(n)) @@ -139,7 +141,7 @@ pub fn poll_write(n: usize) -> Poll> { pub fn poll_next(ready: bool) -> Poll>> { if !ready { - return Poll::Ready(Some(Err(io::ErrorKind::NotFound.into()))) + return Poll::Ready(Some(Err(io::ErrorKind::NotFound.into()))) //~ try_err } Poll::Ready(None) @@ -148,7 +150,7 @@ pub fn poll_next(ready: bool) -> Poll>> { // Tests that `return` is not duplicated pub fn try_return(x: bool) -> Result { if x { - return Err(42); + return Err(42); //~ try_err } Ok(0) } diff --git a/tests/ui/try_err.rs b/tests/ui/try_err.rs index 927eccf2d54c..6df619547014 100644 --- a/tests/ui/try_err.rs +++ b/tests/ui/try_err.rs @@ -19,7 +19,7 @@ pub fn basic_test() -> Result { let err: i32 = 1; // To avoid warnings during rustfix if true { - Err(err)?; + Err(err)?; //~ try_err } Ok(0) } @@ -29,7 +29,7 @@ pub fn into_test() -> Result { let err: u8 = 1; // To avoid warnings during rustfix if true { - Err(err)?; + Err(err)?; //~ try_err } Ok(0) } @@ -49,7 +49,7 @@ pub fn closure_matches_test() -> Result { let err: i8 = 1; // To avoid warnings during rustfix if true { - Err(err)?; + Err(err)?; //~ try_err } Ok(i) }) @@ -68,7 +68,7 @@ pub fn closure_into_test() -> Result { let err: i8 = 1; // To avoid warnings during rustfix if true { - Err(err)?; + Err(err)?; //~ try_err } Ok(i) }) @@ -88,14 +88,14 @@ fn calling_macro() -> Result { inline!( match $(Ok::<_, i32>(5)) { Ok(_) => 0, - Err(_) => Err(1)?, + Err(_) => Err(1)?, //~ try_err } ); // `Err` arg is another macro inline!( match $(Ok::<_, i32>(5)) { Ok(_) => 0, - Err(_) => Err(inline!(1))?, + Err(_) => Err(inline!(1))?, //~ try_err } ); Ok(5) @@ -123,15 +123,17 @@ fn main() { pub fn macro_inside(fail: bool) -> Result { if fail { Err(inline!(inline!(String::from("aasdfasdfasdfa"))))?; + //~^ try_err } Ok(0) } pub fn poll_write(n: usize) -> Poll> { if n == 0 { - Err(io::ErrorKind::WriteZero)? + Err(io::ErrorKind::WriteZero)? //~ try_err } else if n == 1 { Err(io::Error::new(io::ErrorKind::InvalidInput, "error"))? + //~^ try_err }; Poll::Ready(Ok(n)) @@ -139,7 +141,7 @@ pub fn poll_write(n: usize) -> Poll> { pub fn poll_next(ready: bool) -> Poll>> { if !ready { - Err(io::ErrorKind::NotFound)? + Err(io::ErrorKind::NotFound)? //~ try_err } Poll::Ready(None) @@ -148,7 +150,7 @@ pub fn poll_next(ready: bool) -> Poll>> { // Tests that `return` is not duplicated pub fn try_return(x: bool) -> Result { if x { - return Err(42)?; + return Err(42)?; //~ try_err } Ok(0) } diff --git a/tests/ui/try_err.stderr b/tests/ui/try_err.stderr index 887889ffd111..5f2aa6ae23db 100644 --- a/tests/ui/try_err.stderr +++ b/tests/ui/try_err.stderr @@ -51,25 +51,25 @@ LL | Err(inline!(inline!(String::from("aasdfasdfasdfa"))))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Err(inline!(inline!(String::from("aasdfasdfasdfa"))))` error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:132:9 + --> $DIR/try_err.rs:133:9 | LL | Err(io::ErrorKind::WriteZero)? | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Poll::Ready(Err(io::ErrorKind::WriteZero.into()))` error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:134:9 + --> $DIR/try_err.rs:135:9 | LL | Err(io::Error::new(io::ErrorKind::InvalidInput, "error"))? | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Poll::Ready(Err(io::Error::new(io::ErrorKind::InvalidInput, "error")))` error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:142:9 + --> $DIR/try_err.rs:144:9 | LL | Err(io::ErrorKind::NotFound)? | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Poll::Ready(Some(Err(io::ErrorKind::NotFound.into())))` error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:151:16 + --> $DIR/try_err.rs:153:16 | LL | return Err(42)?; | ^^^^^^^^ help: try: `Err(42)` diff --git a/tests/ui/tuple_array_conversions.rs b/tests/ui/tuple_array_conversions.rs index ca79cc104f22..cdd6b8a8e259 100644 --- a/tests/ui/tuple_array_conversions.rs +++ b/tests/ui/tuple_array_conversions.rs @@ -7,16 +7,20 @@ extern crate proc_macros; fn main() { let x = [1, 2]; - let x = (x[0], x[1]); - let x = [x.0, x.1]; + let x = (x[0], x[1]); //~ tuple_array_conversions + let x = [x.0, x.1]; //~ tuple_array_conversions let x = &[1, 2]; let x = (x[0], x[1]); let t1: &[(u32, u32)] = &[(1, 2), (3, 4)]; let v1: Vec<[u32; 2]> = t1.iter().map(|&(a, b)| [a, b]).collect(); + //~^ tuple_array_conversions t1.iter().for_each(|&(a, b)| _ = [a, b]); + //~^ tuple_array_conversions let t2: Vec<(u32, u32)> = v1.iter().map(|&[a, b]| (a, b)).collect(); + //~^ tuple_array_conversions t1.iter().for_each(|&(a, b)| _ = [a, b]); + //~^ tuple_array_conversions // Do not lint let v2: Vec<[u32; 2]> = t1.iter().map(|&t| t.into()).collect(); let t3: Vec<(u32, u32)> = v2.iter().map(|&v| v.into()).collect(); @@ -54,10 +58,10 @@ fn main() { } // FP #11082; needs discussion let (a, b) = (1.0f64, 2.0f64); - let _: &[f64] = &[a, b]; + let _: &[f64] = &[a, b]; //~ tuple_array_conversions // FP #11085; impossible to fix let [src, dest]: [_; 2] = [1, 2]; - (src, dest); + (src, dest); //~ tuple_array_conversions // FP #11100 fn issue_11100_array_to_tuple(this: [&mut i32; 2]) -> (&i32, &mut i32) { let [input, output] = this; @@ -101,8 +105,8 @@ fn msrv_too_low() { #[clippy::msrv = "1.71.0"] fn msrv_juust_right() { let x = [1, 2]; - let x = (x[0], x[1]); - let x = [x.0, x.1]; + let x = (x[0], x[1]); //~ tuple_array_conversions + let x = [x.0, x.1]; //~ tuple_array_conversions let x = &[1, 2]; let x = (x[0], x[1]); } diff --git a/tests/ui/tuple_array_conversions.stderr b/tests/ui/tuple_array_conversions.stderr index f8f5b3e75871..c9bf78a66c84 100644 --- a/tests/ui/tuple_array_conversions.stderr +++ b/tests/ui/tuple_array_conversions.stderr @@ -25,7 +25,7 @@ LL | let v1: Vec<[u32; 2]> = t1.iter().map(|&(a, b)| [a, b]).collect(); = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed error: it looks like you're trying to convert a tuple to an array - --> $DIR/tuple_array_conversions.rs:17:38 + --> $DIR/tuple_array_conversions.rs:18:38 | LL | t1.iter().for_each(|&(a, b)| _ = [a, b]); | ^^^^^^ @@ -33,7 +33,7 @@ LL | t1.iter().for_each(|&(a, b)| _ = [a, b]); = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed error: it looks like you're trying to convert an array to a tuple - --> $DIR/tuple_array_conversions.rs:18:55 + --> $DIR/tuple_array_conversions.rs:20:55 | LL | let t2: Vec<(u32, u32)> = v1.iter().map(|&[a, b]| (a, b)).collect(); | ^^^^^^ @@ -41,7 +41,7 @@ LL | let t2: Vec<(u32, u32)> = v1.iter().map(|&[a, b]| (a, b)).collect(); = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed error: it looks like you're trying to convert a tuple to an array - --> $DIR/tuple_array_conversions.rs:19:38 + --> $DIR/tuple_array_conversions.rs:22:38 | LL | t1.iter().for_each(|&(a, b)| _ = [a, b]); | ^^^^^^ @@ -49,7 +49,7 @@ LL | t1.iter().for_each(|&(a, b)| _ = [a, b]); = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed error: it looks like you're trying to convert a tuple to an array - --> $DIR/tuple_array_conversions.rs:57:22 + --> $DIR/tuple_array_conversions.rs:61:22 | LL | let _: &[f64] = &[a, b]; | ^^^^^^ @@ -57,7 +57,7 @@ LL | let _: &[f64] = &[a, b]; = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed error: it looks like you're trying to convert an array to a tuple - --> $DIR/tuple_array_conversions.rs:60:5 + --> $DIR/tuple_array_conversions.rs:64:5 | LL | (src, dest); | ^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | (src, dest); = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed error: it looks like you're trying to convert an array to a tuple - --> $DIR/tuple_array_conversions.rs:104:13 + --> $DIR/tuple_array_conversions.rs:108:13 | LL | let x = (x[0], x[1]); | ^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | let x = (x[0], x[1]); = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed error: it looks like you're trying to convert a tuple to an array - --> $DIR/tuple_array_conversions.rs:105:13 + --> $DIR/tuple_array_conversions.rs:109:13 | LL | let x = [x.0, x.1]; | ^^^^^^^^^^ diff --git a/tests/ui/type_id_on_box.fixed b/tests/ui/type_id_on_box.fixed index 538c38b70e6b..bf68725c5257 100644 --- a/tests/ui/type_id_on_box.fixed +++ b/tests/ui/type_id_on_box.fixed @@ -21,17 +21,18 @@ fn existential() -> impl Any { fn main() { let any_box: Box = Box::new(0usize); - let _ = (*any_box).type_id(); + let _ = (*any_box).type_id(); //~ type_id_on_box let _ = TypeId::of::>(); // Don't lint. We explicitly say "do this instead" if this is intentional let _ = (*any_box).type_id(); let any_box: &Box = &(Box::new(0usize) as Box); + //~v type_id_on_box let _ = (**any_box).type_id(); // 2 derefs are needed here to get to the `dyn Any` let b = existential(); let _ = b.type_id(); // Don't lint. let b: SomeBox = Box::new(0usize); - let _ = (*b).type_id(); + let _ = (*b).type_id(); //~ type_id_on_box let b = BadBox(Box::new(0usize)); let _ = b.type_id(); // Don't lint. This is a call to `::type_id`. Not `std::boxed::Box`! diff --git a/tests/ui/type_id_on_box.rs b/tests/ui/type_id_on_box.rs index f224d273bc23..21212bbf49d5 100644 --- a/tests/ui/type_id_on_box.rs +++ b/tests/ui/type_id_on_box.rs @@ -21,17 +21,18 @@ fn existential() -> impl Any { fn main() { let any_box: Box = Box::new(0usize); - let _ = any_box.type_id(); + let _ = any_box.type_id(); //~ type_id_on_box let _ = TypeId::of::>(); // Don't lint. We explicitly say "do this instead" if this is intentional let _ = (*any_box).type_id(); let any_box: &Box = &(Box::new(0usize) as Box); + //~v type_id_on_box let _ = any_box.type_id(); // 2 derefs are needed here to get to the `dyn Any` let b = existential(); let _ = b.type_id(); // Don't lint. let b: SomeBox = Box::new(0usize); - let _ = b.type_id(); + let _ = b.type_id(); //~ type_id_on_box let b = BadBox(Box::new(0usize)); let _ = b.type_id(); // Don't lint. This is a call to `::type_id`. Not `std::boxed::Box`! diff --git a/tests/ui/type_id_on_box.stderr b/tests/ui/type_id_on_box.stderr index 844dae158b8d..8d9306116fb2 100644 --- a/tests/ui/type_id_on_box.stderr +++ b/tests/ui/type_id_on_box.stderr @@ -12,7 +12,7 @@ LL | let _ = any_box.type_id(); = help: to override `-D warnings` add `#[allow(clippy::type_id_on_box)]` error: calling `.type_id()` on a `Box` - --> $DIR/type_id_on_box.rs:28:13 + --> $DIR/type_id_on_box.rs:29:13 | LL | let _ = any_box.type_id(); // 2 derefs are needed here to get to the `dyn Any` | -------^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _ = any_box.type_id(); // 2 derefs are needed here to get to the `d = note: if this is intentional, use `TypeId::of::>()` instead, which makes it more clear error: calling `.type_id()` on a `Box` - --> $DIR/type_id_on_box.rs:34:13 + --> $DIR/type_id_on_box.rs:35:13 | LL | let _ = b.type_id(); | -^^^^^^^^^^ diff --git a/tests/ui/types.fixed b/tests/ui/types.fixed index 6f1f55f0e62c..feab71164cef 100644 --- a/tests/ui/types.fixed +++ b/tests/ui/types.fixed @@ -9,5 +9,5 @@ const C_I64: i64 = C as i64; fn main() { // should suggest i64::from(c) let c: i32 = 42; - let c_i64: i64 = i64::from(c); + let c_i64: i64 = i64::from(c); //~ cast_lossless } diff --git a/tests/ui/types.rs b/tests/ui/types.rs index 960aee4600ca..55377f46de24 100644 --- a/tests/ui/types.rs +++ b/tests/ui/types.rs @@ -9,5 +9,5 @@ const C_I64: i64 = C as i64; fn main() { // should suggest i64::from(c) let c: i32 = 42; - let c_i64: i64 = c as i64; + let c_i64: i64 = c as i64; //~ cast_lossless } diff --git a/tests/ui/unchecked_duration_subtraction.fixed b/tests/ui/unchecked_duration_subtraction.fixed index a0c3330d1777..d2edb13e67f7 100644 --- a/tests/ui/unchecked_duration_subtraction.fixed +++ b/tests/ui/unchecked_duration_subtraction.fixed @@ -6,11 +6,14 @@ fn main() { let _first = Instant::now(); let second = Duration::from_secs(3); - let _ = _first.checked_sub(second).unwrap(); + let _ = _first.checked_sub(second).unwrap(); //~ unchecked_duration_subtraction let _ = Instant::now().checked_sub(Duration::from_secs(5)).unwrap(); + //~^ unchecked_duration_subtraction let _ = _first.checked_sub(Duration::from_secs(5)).unwrap(); + //~^ unchecked_duration_subtraction let _ = Instant::now().checked_sub(second).unwrap(); + //~^ unchecked_duration_subtraction } diff --git a/tests/ui/unchecked_duration_subtraction.rs b/tests/ui/unchecked_duration_subtraction.rs index fff1d13720d9..52f8637c754f 100644 --- a/tests/ui/unchecked_duration_subtraction.rs +++ b/tests/ui/unchecked_duration_subtraction.rs @@ -6,11 +6,14 @@ fn main() { let _first = Instant::now(); let second = Duration::from_secs(3); - let _ = _first - second; + let _ = _first - second; //~ unchecked_duration_subtraction let _ = Instant::now() - Duration::from_secs(5); + //~^ unchecked_duration_subtraction let _ = _first - Duration::from_secs(5); + //~^ unchecked_duration_subtraction let _ = Instant::now() - second; + //~^ unchecked_duration_subtraction } diff --git a/tests/ui/unchecked_duration_subtraction.stderr b/tests/ui/unchecked_duration_subtraction.stderr index 2b62bc964039..4f45f22ee275 100644 --- a/tests/ui/unchecked_duration_subtraction.stderr +++ b/tests/ui/unchecked_duration_subtraction.stderr @@ -14,13 +14,13 @@ LL | let _ = Instant::now() - Duration::from_secs(5); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(Duration::from_secs(5)).unwrap()` error: unchecked subtraction of a 'Duration' from an 'Instant' - --> $DIR/unchecked_duration_subtraction.rs:13:13 + --> $DIR/unchecked_duration_subtraction.rs:14:13 | LL | let _ = _first - Duration::from_secs(5); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(Duration::from_secs(5)).unwrap()` error: unchecked subtraction of a 'Duration' from an 'Instant' - --> $DIR/unchecked_duration_subtraction.rs:15:13 + --> $DIR/unchecked_duration_subtraction.rs:17:13 | LL | let _ = Instant::now() - second; | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(second).unwrap()` diff --git a/tests/ui/unconditional_recursion.rs b/tests/ui/unconditional_recursion.rs index 47fe62812086..0536342cdbe6 100644 --- a/tests/ui/unconditional_recursion.rs +++ b/tests/ui/unconditional_recursion.rs @@ -25,9 +25,11 @@ enum Foo2 { } impl PartialEq for Foo2 { + //~v unconditional_recursion fn ne(&self, other: &Self) -> bool { self != &Foo2::B // no error here } + //~v unconditional_recursion fn eq(&self, other: &Self) -> bool { self == &Foo2::B // no error here } @@ -39,10 +41,14 @@ enum Foo3 { } impl PartialEq for Foo3 { + //~| unconditional_recursion + //~v only_used_in_recursion fn ne(&self, other: &Self) -> bool { //~^ ERROR: function cannot return without recursing self.ne(other) } + //~| unconditional_recursion + //~v only_used_in_recursion fn eq(&self, other: &Self) -> bool { //~^ ERROR: function cannot return without recursing self.eq(other) @@ -103,11 +109,11 @@ struct S2; impl PartialEq for S2 { fn ne(&self, other: &Self) -> bool { //~^ ERROR: function cannot return without recursing - other != other + other != other //~ eq_op } fn eq(&self, other: &Self) -> bool { //~^ ERROR: function cannot return without recursing - other == other + other == other //~ eq_op } } @@ -116,11 +122,11 @@ struct S3; impl PartialEq for S3 { fn ne(&self, _other: &Self) -> bool { //~^ ERROR: function cannot return without recursing - self != self + self != self //~ eq_op } fn eq(&self, _other: &Self) -> bool { //~^ ERROR: function cannot return without recursing - self == self + self == self //~ eq_op } } @@ -146,6 +152,7 @@ impl PartialEq for S4 { macro_rules! impl_partial_eq { ($ty:ident) => { impl PartialEq for $ty { + //~v unconditional_recursion fn eq(&self, other: &Self) -> bool { self == other } diff --git a/tests/ui/unconditional_recursion.stderr b/tests/ui/unconditional_recursion.stderr index 93a5eac91d8e..164aa7bfecab 100644 --- a/tests/ui/unconditional_recursion.stderr +++ b/tests/ui/unconditional_recursion.stderr @@ -1,5 +1,5 @@ error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:42:5 + --> $DIR/unconditional_recursion.rs:46:5 | LL | fn ne(&self, other: &Self) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -12,7 +12,7 @@ LL | self.ne(other) = help: to override `-D warnings` add `#[allow(unconditional_recursion)]` error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:46:5 + --> $DIR/unconditional_recursion.rs:52:5 | LL | fn eq(&self, other: &Self) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -23,7 +23,7 @@ LL | self.eq(other) = help: a `loop` may express intention better if this is on purpose error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:211:5 + --> $DIR/unconditional_recursion.rs:217:5 | LL | fn to_string(&self) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -34,7 +34,7 @@ LL | self.to_string() = help: a `loop` may express intention better if this is on purpose error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:221:5 + --> $DIR/unconditional_recursion.rs:227:5 | LL | fn to_string(&self) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -45,7 +45,7 @@ LL | x.to_string() = help: a `loop` may express intention better if this is on purpose error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:232:5 + --> $DIR/unconditional_recursion.rs:238:5 | LL | fn to_string(&self) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -88,7 +88,7 @@ LL | self == other | ^^^^^^^^^^^^^ error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:28:5 + --> $DIR/unconditional_recursion.rs:29:5 | LL | / fn ne(&self, other: &Self) -> bool { LL | | self != &Foo2::B // no error here @@ -96,13 +96,13 @@ LL | | } | |_____^ | note: recursive call site - --> $DIR/unconditional_recursion.rs:29:9 + --> $DIR/unconditional_recursion.rs:30:9 | LL | self != &Foo2::B // no error here | ^^^^^^^^^^^^^^^^ error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:31:5 + --> $DIR/unconditional_recursion.rs:33:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | self == &Foo2::B // no error here @@ -110,13 +110,13 @@ LL | | } | |_____^ | note: recursive call site - --> $DIR/unconditional_recursion.rs:32:9 + --> $DIR/unconditional_recursion.rs:34:9 | LL | self == &Foo2::B // no error here | ^^^^^^^^^^^^^^^^ error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:42:5 + --> $DIR/unconditional_recursion.rs:46:5 | LL | / fn ne(&self, other: &Self) -> bool { LL | | @@ -125,19 +125,19 @@ LL | | } | |_____^ | note: recursive call site - --> $DIR/unconditional_recursion.rs:44:9 + --> $DIR/unconditional_recursion.rs:48:9 | LL | self.ne(other) | ^^^^^^^^^^^^^^ error: parameter is only used in recursion - --> $DIR/unconditional_recursion.rs:42:18 + --> $DIR/unconditional_recursion.rs:46:18 | LL | fn ne(&self, other: &Self) -> bool { | ^^^^^ help: if this is intentional, prefix it with an underscore: `_other` | note: parameter used here - --> $DIR/unconditional_recursion.rs:44:17 + --> $DIR/unconditional_recursion.rs:48:17 | LL | self.ne(other) | ^^^^^ @@ -145,7 +145,7 @@ LL | self.ne(other) = help: to override `-D warnings` add `#[allow(clippy::only_used_in_recursion)]` error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:46:5 + --> $DIR/unconditional_recursion.rs:52:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -154,25 +154,25 @@ LL | | } | |_____^ | note: recursive call site - --> $DIR/unconditional_recursion.rs:48:9 + --> $DIR/unconditional_recursion.rs:54:9 | LL | self.eq(other) | ^^^^^^^^^^^^^^ error: parameter is only used in recursion - --> $DIR/unconditional_recursion.rs:46:18 + --> $DIR/unconditional_recursion.rs:52:18 | LL | fn eq(&self, other: &Self) -> bool { | ^^^^^ help: if this is intentional, prefix it with an underscore: `_other` | note: parameter used here - --> $DIR/unconditional_recursion.rs:48:17 + --> $DIR/unconditional_recursion.rs:54:17 | LL | self.eq(other) | ^^^^^ error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:90:5 + --> $DIR/unconditional_recursion.rs:96:5 | LL | / fn ne(&self, other: &Self) -> bool { LL | | @@ -181,13 +181,13 @@ LL | | } | |_____^ | note: recursive call site - --> $DIR/unconditional_recursion.rs:92:9 + --> $DIR/unconditional_recursion.rs:98:9 | LL | other != self | ^^^^^^^^^^^^^ error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:94:5 + --> $DIR/unconditional_recursion.rs:100:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -196,13 +196,13 @@ LL | | } | |_____^ | note: recursive call site - --> $DIR/unconditional_recursion.rs:96:9 + --> $DIR/unconditional_recursion.rs:102:9 | LL | other == self | ^^^^^^^^^^^^^ error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:104:5 + --> $DIR/unconditional_recursion.rs:110:5 | LL | / fn ne(&self, other: &Self) -> bool { LL | | @@ -211,13 +211,13 @@ LL | | } | |_____^ | note: recursive call site - --> $DIR/unconditional_recursion.rs:106:9 + --> $DIR/unconditional_recursion.rs:112:9 | LL | other != other | ^^^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> $DIR/unconditional_recursion.rs:106:9 + --> $DIR/unconditional_recursion.rs:112:9 | LL | other != other | ^^^^^^^^^^^^^^ @@ -225,7 +225,7 @@ LL | other != other = note: `#[deny(clippy::eq_op)]` on by default error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:108:5 + --> $DIR/unconditional_recursion.rs:114:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -234,19 +234,19 @@ LL | | } | |_____^ | note: recursive call site - --> $DIR/unconditional_recursion.rs:110:9 + --> $DIR/unconditional_recursion.rs:116:9 | LL | other == other | ^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/unconditional_recursion.rs:110:9 + --> $DIR/unconditional_recursion.rs:116:9 | LL | other == other | ^^^^^^^^^^^^^^ error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:117:5 + --> $DIR/unconditional_recursion.rs:123:5 | LL | / fn ne(&self, _other: &Self) -> bool { LL | | @@ -255,19 +255,19 @@ LL | | } | |_____^ | note: recursive call site - --> $DIR/unconditional_recursion.rs:119:9 + --> $DIR/unconditional_recursion.rs:125:9 | LL | self != self | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> $DIR/unconditional_recursion.rs:119:9 + --> $DIR/unconditional_recursion.rs:125:9 | LL | self != self | ^^^^^^^^^^^^ error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:121:5 + --> $DIR/unconditional_recursion.rs:127:5 | LL | / fn eq(&self, _other: &Self) -> bool { LL | | @@ -276,19 +276,19 @@ LL | | } | |_____^ | note: recursive call site - --> $DIR/unconditional_recursion.rs:123:9 + --> $DIR/unconditional_recursion.rs:129:9 | LL | self == self | ^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/unconditional_recursion.rs:123:9 + --> $DIR/unconditional_recursion.rs:129:9 | LL | self == self | ^^^^^^^^^^^^ error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:149:13 + --> $DIR/unconditional_recursion.rs:156:13 | LL | / fn eq(&self, other: &Self) -> bool { LL | | self == other @@ -299,7 +299,7 @@ LL | impl_partial_eq!(S5); | -------------------- in this macro invocation | note: recursive call site - --> $DIR/unconditional_recursion.rs:150:17 + --> $DIR/unconditional_recursion.rs:157:17 | LL | self == other | ^^^^^^^^^^^^^ @@ -309,7 +309,7 @@ LL | impl_partial_eq!(S5); = note: this error originates in the macro `impl_partial_eq` (in Nightly builds, run with -Z macro-backtrace for more info) error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:178:5 + --> $DIR/unconditional_recursion.rs:184:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -320,13 +320,13 @@ LL | | } | |_____^ | note: recursive call site - --> $DIR/unconditional_recursion.rs:182:9 + --> $DIR/unconditional_recursion.rs:188:9 | LL | mine == theirs | ^^^^^^^^^^^^^^ error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:247:5 + --> $DIR/unconditional_recursion.rs:253:5 | LL | / fn new() -> Self { LL | | @@ -335,13 +335,13 @@ LL | | } | |_____^ | note: recursive call site - --> $DIR/unconditional_recursion.rs:249:9 + --> $DIR/unconditional_recursion.rs:255:9 | LL | Self::default() | ^^^^^^^^^^^^^^^ error: function cannot return without recursing - --> $DIR/unconditional_recursion.rs:286:5 + --> $DIR/unconditional_recursion.rs:292:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -352,7 +352,7 @@ LL | | } | |_____^ | note: recursive call site - --> $DIR/unconditional_recursion.rs:290:9 + --> $DIR/unconditional_recursion.rs:296:9 | LL | mine.eq(theirs) | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/unicode.fixed b/tests/ui/unicode.fixed index f9efb4ec34c6..92358773be12 100644 --- a/tests/ui/unicode.fixed +++ b/tests/ui/unicode.fixed @@ -3,16 +3,19 @@ #[warn(clippy::invisible_characters)] fn zero() { print!("Here >\u{200B}< is a ZWS, and \u{200B}another"); + //~^ invisible_characters print!("This\u{200B}is\u{200B}fine"); print!("Here >\u{AD}< is a SHY, and \u{AD}another"); + //~^ invisible_characters print!("This\u{ad}is\u{ad}fine"); print!("Here >\u{2060}< is a WJ, and \u{2060}another"); + //~^ invisible_characters print!("This\u{2060}is\u{2060}fine"); } #[warn(clippy::unicode_not_nfc)] fn canon() { - print!("̀àh?"); + print!("̀àh?"); //~ unicode_not_nfc print!("a\u{0300}h?"); // also ok } @@ -20,14 +23,14 @@ mod non_ascii_literal { #![deny(clippy::non_ascii_literal)] fn uni() { - print!("\u{dc}ben!"); + print!("\u{dc}ben!"); //~ non_ascii_literal print!("\u{DC}ben!"); // this is ok } // issue 8013 fn single_quote() { - const _EMPTY_BLOCK: char = '\u{25b1}'; - const _FULL_BLOCK: char = '\u{25b0}'; + const _EMPTY_BLOCK: char = '\u{25b1}'; //~ non_ascii_literal + const _FULL_BLOCK: char = '\u{25b0}'; //~ non_ascii_literal } #[test] @@ -48,6 +51,7 @@ mod non_ascii_literal { #[test] fn denied() { let _ = "\u{60b2}\u{3057}\u{3044}\u{304b}\u{306a}\u{3001}\u{3053}\u{3053}\u{306b}\u{65e5}\u{672c}\u{8a9e}\u{3092}\u{66f8}\u{304f}\u{3053}\u{3068}\u{306f}\u{3067}\u{304d}\u{306a}\u{3044}\u{3002}"; + //~^ non_ascii_literal } } } diff --git a/tests/ui/unicode.rs b/tests/ui/unicode.rs index bba613e228ed..f6f7fb693f29 100644 --- a/tests/ui/unicode.rs +++ b/tests/ui/unicode.rs @@ -3,16 +3,19 @@ #[warn(clippy::invisible_characters)] fn zero() { print!("Here >​< is a ZWS, and ​another"); + //~^ invisible_characters print!("This\u{200B}is\u{200B}fine"); print!("Here >­< is a SHY, and ­another"); + //~^ invisible_characters print!("This\u{ad}is\u{ad}fine"); print!("Here >⁠< is a WJ, and ⁠another"); + //~^ invisible_characters print!("This\u{2060}is\u{2060}fine"); } #[warn(clippy::unicode_not_nfc)] fn canon() { - print!("̀àh?"); + print!("̀àh?"); //~ unicode_not_nfc print!("a\u{0300}h?"); // also ok } @@ -20,14 +23,14 @@ mod non_ascii_literal { #![deny(clippy::non_ascii_literal)] fn uni() { - print!("Üben!"); + print!("Üben!"); //~ non_ascii_literal print!("\u{DC}ben!"); // this is ok } // issue 8013 fn single_quote() { - const _EMPTY_BLOCK: char = '▱'; - const _FULL_BLOCK: char = '▰'; + const _EMPTY_BLOCK: char = '▱'; //~ non_ascii_literal + const _FULL_BLOCK: char = '▰'; //~ non_ascii_literal } #[test] @@ -48,6 +51,7 @@ mod non_ascii_literal { #[test] fn denied() { let _ = "悲しいかな、ここに日本語を書くことはできない。"; + //~^ non_ascii_literal } } } diff --git a/tests/ui/unicode.stderr b/tests/ui/unicode.stderr index 0b6e20664e34..7fc06fc8c7c3 100644 --- a/tests/ui/unicode.stderr +++ b/tests/ui/unicode.stderr @@ -8,19 +8,19 @@ LL | print!("Here >​< is a ZWS, and ​another"); = help: to override `-D warnings` add `#[allow(clippy::invisible_characters)]` error: invisible character detected - --> $DIR/unicode.rs:7:12 + --> $DIR/unicode.rs:8:12 | LL | print!("Here >­< is a SHY, and ­another"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >\u{AD}< is a SHY, and \u{AD}another"` error: invisible character detected - --> $DIR/unicode.rs:9:12 + --> $DIR/unicode.rs:11:12 | LL | print!("Here >⁠< is a WJ, and ⁠another"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >\u{2060}< is a WJ, and \u{2060}another"` error: non-NFC Unicode sequence detected - --> $DIR/unicode.rs:15:12 + --> $DIR/unicode.rs:18:12 | LL | print!("̀àh?"); | ^^^^^ help: consider replacing the string with: `"̀àh?"` @@ -29,37 +29,37 @@ LL | print!("̀àh?"); = help: to override `-D warnings` add `#[allow(clippy::unicode_not_nfc)]` error: literal non-ASCII character detected - --> $DIR/unicode.rs:23:16 + --> $DIR/unicode.rs:26:16 | LL | print!("Üben!"); | ^^^^^^^ help: consider replacing the string with: `"\u{dc}ben!"` | note: the lint level is defined here - --> $DIR/unicode.rs:20:13 + --> $DIR/unicode.rs:23:13 | LL | #![deny(clippy::non_ascii_literal)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: literal non-ASCII character detected - --> $DIR/unicode.rs:29:36 + --> $DIR/unicode.rs:32:36 | LL | const _EMPTY_BLOCK: char = '▱'; | ^^^ help: consider replacing the string with: `'\u{25b1}'` error: literal non-ASCII character detected - --> $DIR/unicode.rs:30:35 + --> $DIR/unicode.rs:33:35 | LL | const _FULL_BLOCK: char = '▰'; | ^^^ help: consider replacing the string with: `'\u{25b0}'` error: literal non-ASCII character detected - --> $DIR/unicode.rs:50:21 + --> $DIR/unicode.rs:53:21 | LL | let _ = "悲しいかな、ここに日本語を書くことはできない。"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"\u{60b2}\u{3057}\u{3044}\u{304b}\u{306a}\u{3001}\u{3053}\u{3053}\u{306b}\u{65e5}\u{672c}\u{8a9e}\u{3092}\u{66f8}\u{304f}\u{3053}\u{3068}\u{306f}\u{3067}\u{304d}\u{306a}\u{3044}\u{3002}"` | note: the lint level is defined here - --> $DIR/unicode.rs:39:17 + --> $DIR/unicode.rs:42:17 | LL | #![deny(clippy::non_ascii_literal)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninhabited_references.rs b/tests/ui/uninhabited_references.rs index cd07b590a616..3d4919042c90 100644 --- a/tests/ui/uninhabited_references.rs +++ b/tests/ui/uninhabited_references.rs @@ -1,14 +1,16 @@ #![warn(clippy::uninhabited_references)] #![feature(never_type)] +//~v uninhabited_references fn ret_uninh_ref() -> &'static std::convert::Infallible { unsafe { std::mem::transmute(&()) } } macro_rules! ret_something { ($name:ident, $ty:ty) => { + //~v uninhabited_references fn $name(x: &$ty) -> &$ty { - &*x + &*x //~ uninhabited_references } }; } @@ -18,5 +20,5 @@ ret_something!(id_never, !); fn main() { let x = ret_uninh_ref(); - let _ = *x; + let _ = *x; //~ uninhabited_references } diff --git a/tests/ui/uninhabited_references.stderr b/tests/ui/uninhabited_references.stderr index 2cdf320b8092..65f10aa759a9 100644 --- a/tests/ui/uninhabited_references.stderr +++ b/tests/ui/uninhabited_references.stderr @@ -1,5 +1,5 @@ error: dereferencing a reference to an uninhabited type would be undefined behavior - --> $DIR/uninhabited_references.rs:4:23 + --> $DIR/uninhabited_references.rs:5:23 | LL | fn ret_uninh_ref() -> &'static std::convert::Infallible { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | fn ret_uninh_ref() -> &'static std::convert::Infallible { = help: to override `-D warnings` add `#[allow(clippy::uninhabited_references)]` error: dereferencing a reference to an uninhabited type would be undefined behavior - --> $DIR/uninhabited_references.rs:10:30 + --> $DIR/uninhabited_references.rs:12:30 | LL | fn $name(x: &$ty) -> &$ty { | ^^^^ @@ -19,7 +19,7 @@ LL | ret_something!(id_never, !); = note: this error originates in the macro `ret_something` (in Nightly builds, run with -Z macro-backtrace for more info) error: dereferencing a reference to an uninhabited type is undefined behavior - --> $DIR/uninhabited_references.rs:11:14 + --> $DIR/uninhabited_references.rs:13:14 | LL | &*x | ^^ @@ -30,7 +30,7 @@ LL | ret_something!(id_never, !); = note: this error originates in the macro `ret_something` (in Nightly builds, run with -Z macro-backtrace for more info) error: dereferencing a reference to an uninhabited type is undefined behavior - --> $DIR/uninhabited_references.rs:21:13 + --> $DIR/uninhabited_references.rs:23:13 | LL | let _ = *x; | ^^ diff --git a/tests/ui/uninlined_format_args.fixed b/tests/ui/uninlined_format_args.fixed index 3f5b0e52ece0..173a876892ce 100644 --- a/tests/ui/uninlined_format_args.fixed +++ b/tests/ui/uninlined_format_args.fixed @@ -42,75 +42,98 @@ fn tester(fn_arg: i32) { // let _ = ' '; // <- this is a single tab character let _: &[u8; 3] = b" "; // <- - println!("val='{local_i32}'"); + println!("val='{local_i32}'"); //~ uninlined_format_args + + //~v uninlined_format_args println!("val='{local_i32}'"); // 3 spaces + + //~v uninlined_format_args println!("val='{local_i32}'"); // tab + + //~v uninlined_format_args println!("val='{local_i32}'"); // space+tab + + //~v uninlined_format_args println!("val='{local_i32}'"); // tab+space + + //~v uninlined_format_args println!( "val='{local_i32}'" ); - println!("{local_i32}"); - println!("{fn_arg}"); - println!("{local_i32:?}"); - println!("{local_i32:#?}"); - println!("{local_i32:4}"); - println!("{local_i32:04}"); - println!("{local_i32:<3}"); - println!("{local_i32:#010x}"); - println!("{local_f64:.1}"); + println!("{local_i32}"); //~ uninlined_format_args + println!("{fn_arg}"); //~ uninlined_format_args + println!("{local_i32:?}"); //~ uninlined_format_args + println!("{local_i32:#?}"); //~ uninlined_format_args + println!("{local_i32:4}"); //~ uninlined_format_args + println!("{local_i32:04}"); //~ uninlined_format_args + println!("{local_i32:<3}"); //~ uninlined_format_args + println!("{local_i32:#010x}"); //~ uninlined_format_args + println!("{local_f64:.1}"); //~ uninlined_format_args println!("Hello {} is {:.*}", "x", local_i32, local_f64); println!("Hello {} is {:.*}", local_i32, 5, local_f64); println!("Hello {} is {2:.*}", local_i32, 5, local_f64); println!("{local_i32} {local_f64}"); + //~^ uninlined_format_args println!("{}, {}", local_i32, local_opt.unwrap()); - println!("{val}"); - println!("{val}"); + println!("{val}"); //~ uninlined_format_args + println!("{val}"); //~ uninlined_format_args println!("{} {1}", local_i32, 42); + println!("val='{local_i32}'"); //~ uninlined_format_args + println!("val='{local_i32}'"); //~ uninlined_format_args println!("val='{local_i32}'"); - println!("val='{local_i32}'"); - println!("val='{local_i32}'"); + //~^ uninlined_format_args println!("val='{fn_arg}'"); - println!("{local_i32}"); - println!("{local_i32:?}"); - println!("{local_i32:#?}"); - println!("{local_i32:04}"); - println!("{local_i32:<3}"); - println!("{local_i32:#010x}"); - println!("{local_f64:.1}"); - println!("{local_i32} {local_i32}"); + //~^ uninlined_format_args + println!("{local_i32}"); //~ uninlined_format_args + println!("{local_i32:?}"); //~ uninlined_format_args + println!("{local_i32:#?}"); //~ uninlined_format_args + println!("{local_i32:04}"); //~ uninlined_format_args + println!("{local_i32:<3}"); //~ uninlined_format_args + println!("{local_i32:#010x}"); //~ uninlined_format_args + println!("{local_f64:.1}"); //~ uninlined_format_args + println!("{local_i32} {local_i32}"); //~ uninlined_format_args println!("{local_f64} {local_i32} {local_i32} {local_f64}"); + //~^ uninlined_format_args println!("{local_i32} {local_f64}"); + //~^ uninlined_format_args println!("{local_f64} {local_i32}"); + //~^ uninlined_format_args println!("{local_f64} {local_i32} {local_f64} {local_i32}"); + //~^ uninlined_format_args println!("{1} {0}", "str", local_i32); - println!("{local_i32}"); + println!("{local_i32}"); //~ uninlined_format_args + println!("{local_i32:width$}"); //~ uninlined_format_args + println!("{local_i32:width$}"); //~ uninlined_format_args + println!("{local_i32:.prec$}"); //~ uninlined_format_args + println!("{local_i32:.prec$}"); //~ uninlined_format_args + println!("{val:val$}"); //~ uninlined_format_args + println!("{val:val$}"); //~ uninlined_format_args + println!("{val:val$.val$}"); //~ uninlined_format_args + println!("{val:val$.val$}"); //~ uninlined_format_args + println!("{val:val$.val$}"); //~ uninlined_format_args + println!("{val:val$.val$}"); //~ uninlined_format_args + println!("{val:val$.val$}"); //~ uninlined_format_args + println!("{val:val$.val$}"); //~ uninlined_format_args + println!("{val:val$.val$}"); //~ uninlined_format_args + println!("{val:val$.val$}"); //~ uninlined_format_args + println!("{width:width$}"); //~ uninlined_format_args + println!("{local_i32:width$}"); //~ uninlined_format_args + println!("{width:width$}"); //~ uninlined_format_args println!("{local_i32:width$}"); - println!("{local_i32:width$}"); - println!("{local_i32:.prec$}"); - println!("{local_i32:.prec$}"); - println!("{val:val$}"); - println!("{val:val$}"); - println!("{val:val$.val$}"); - println!("{val:val$.val$}"); - println!("{val:val$.val$}"); - println!("{val:val$.val$}"); - println!("{val:val$.val$}"); - println!("{val:val$.val$}"); - println!("{val:val$.val$}"); - println!("{val:val$.val$}"); - println!("{width:width$}"); - println!("{local_i32:width$}"); - println!("{width:width$}"); - println!("{local_i32:width$}"); - println!("{prec:.prec$}"); + //~^ uninlined_format_args + println!("{prec:.prec$}"); //~ uninlined_format_args + println!("{local_i32:.prec$}"); //~ uninlined_format_args + println!("{prec:.prec$}"); //~ uninlined_format_args println!("{local_i32:.prec$}"); - println!("{prec:.prec$}"); - println!("{local_i32:.prec$}"); - println!("{width:width$.prec$}"); - println!("{width:width$.prec$}"); + //~^ uninlined_format_args + println!("{width:width$.prec$}"); //~ uninlined_format_args + println!("{width:width$.prec$}"); //~ uninlined_format_args println!("{local_f64:width$.prec$}"); + //~^ uninlined_format_args println!("{local_f64:width$.prec$} {local_f64} {width} {prec}"); + //~^ uninlined_format_args + + //~v uninlined_format_args println!( "{local_i32:width$.prec$} {local_i32:prec$.width$} {width:local_i32$.prec$} {width:prec$.local_i32$} {prec:local_i32$.width$} {prec:width$.local_i32$}", ); @@ -122,8 +145,11 @@ fn tester(fn_arg: i32) { 1 + 2 ); println!("Width = {local_i32}, value with width = {local_f64:local_i32$}"); + //~^ uninlined_format_args println!("{local_i32:width$.prec$}"); + //~^ uninlined_format_args println!("{width:width$.prec$}"); + //~^ uninlined_format_args println!("{}", format!("{}", local_i32)); my_println!("{}", local_i32); my_println_args!("{}", local_i32); @@ -142,22 +168,25 @@ fn tester(fn_arg: i32) { ); println!(no_param_str!(), local_i32); + //~v uninlined_format_args println!( "{val}", ); println!("{val}"); + //~^ uninlined_format_args println!(with_span!("{0} {1}" "{1} {0}"), local_i32, local_f64); println!("{}", with_span!(span val)); if local_i32 > 0 { - panic!("p1 {local_i32}"); + panic!("p1 {local_i32}"); //~ uninlined_format_args } if local_i32 > 0 { - panic!("p2 {local_i32}"); + panic!("p2 {local_i32}"); //~ uninlined_format_args } if local_i32 > 0 { panic!("p3 {local_i32}"); + //~^ uninlined_format_args } if local_i32 > 0 { panic!("p4 {local_i32}"); @@ -177,7 +206,7 @@ fn _under_msrv() { #[clippy::msrv = "1.58"] fn _meets_msrv() { let local_i32 = 1; - println!("expand='{local_i32}'"); + println!("expand='{local_i32}'"); //~ uninlined_format_args } fn _do_not_fire() { diff --git a/tests/ui/uninlined_format_args.rs b/tests/ui/uninlined_format_args.rs index b311aa4912cd..7c04331a2a48 100644 --- a/tests/ui/uninlined_format_args.rs +++ b/tests/ui/uninlined_format_args.rs @@ -42,77 +42,100 @@ fn tester(fn_arg: i32) { // let _ = ' '; // <- this is a single tab character let _: &[u8; 3] = b" "; // <- - println!("val='{}'", local_i32); + println!("val='{}'", local_i32); //~ uninlined_format_args + + //~v uninlined_format_args println!("val='{ }'", local_i32); // 3 spaces + + //~v uninlined_format_args println!("val='{ }'", local_i32); // tab + + //~v uninlined_format_args println!("val='{ }'", local_i32); // space+tab + + //~v uninlined_format_args println!("val='{ }'", local_i32); // tab+space + + //~v uninlined_format_args println!( "val='{ }'", local_i32 ); - println!("{}", local_i32); - println!("{}", fn_arg); - println!("{:?}", local_i32); - println!("{:#?}", local_i32); - println!("{:4}", local_i32); - println!("{:04}", local_i32); - println!("{:<3}", local_i32); - println!("{:#010x}", local_i32); - println!("{:.1}", local_f64); + println!("{}", local_i32); //~ uninlined_format_args + println!("{}", fn_arg); //~ uninlined_format_args + println!("{:?}", local_i32); //~ uninlined_format_args + println!("{:#?}", local_i32); //~ uninlined_format_args + println!("{:4}", local_i32); //~ uninlined_format_args + println!("{:04}", local_i32); //~ uninlined_format_args + println!("{:<3}", local_i32); //~ uninlined_format_args + println!("{:#010x}", local_i32); //~ uninlined_format_args + println!("{:.1}", local_f64); //~ uninlined_format_args println!("Hello {} is {:.*}", "x", local_i32, local_f64); println!("Hello {} is {:.*}", local_i32, 5, local_f64); println!("Hello {} is {2:.*}", local_i32, 5, local_f64); println!("{} {}", local_i32, local_f64); + //~^ uninlined_format_args println!("{}, {}", local_i32, local_opt.unwrap()); - println!("{}", val); - println!("{}", v = val); + println!("{}", val); //~ uninlined_format_args + println!("{}", v = val); //~ uninlined_format_args println!("{} {1}", local_i32, 42); - println!("val='{\t }'", local_i32); - println!("val='{\n }'", local_i32); + println!("val='{\t }'", local_i32); //~ uninlined_format_args + println!("val='{\n }'", local_i32); //~ uninlined_format_args println!("val='{local_i32}'", local_i32 = local_i32); + //~^ uninlined_format_args println!("val='{local_i32}'", local_i32 = fn_arg); - println!("{0}", local_i32); - println!("{0:?}", local_i32); - println!("{0:#?}", local_i32); - println!("{0:04}", local_i32); - println!("{0:<3}", local_i32); - println!("{0:#010x}", local_i32); - println!("{0:.1}", local_f64); - println!("{0} {0}", local_i32); + //~^ uninlined_format_args + println!("{0}", local_i32); //~ uninlined_format_args + println!("{0:?}", local_i32); //~ uninlined_format_args + println!("{0:#?}", local_i32); //~ uninlined_format_args + println!("{0:04}", local_i32); //~ uninlined_format_args + println!("{0:<3}", local_i32); //~ uninlined_format_args + println!("{0:#010x}", local_i32); //~ uninlined_format_args + println!("{0:.1}", local_f64); //~ uninlined_format_args + println!("{0} {0}", local_i32); //~ uninlined_format_args println!("{1} {} {0} {}", local_i32, local_f64); + //~^ uninlined_format_args println!("{0} {1}", local_i32, local_f64); + //~^ uninlined_format_args println!("{1} {0}", local_i32, local_f64); + //~^ uninlined_format_args println!("{1} {0} {1} {0}", local_i32, local_f64); + //~^ uninlined_format_args println!("{1} {0}", "str", local_i32); - println!("{v}", v = local_i32); - println!("{local_i32:0$}", width); - println!("{local_i32:w$}", w = width); - println!("{local_i32:.0$}", prec); - println!("{local_i32:.p$}", p = prec); - println!("{:0$}", v = val); - println!("{0:0$}", v = val); - println!("{:0$.0$}", v = val); - println!("{0:0$.0$}", v = val); - println!("{0:0$.v$}", v = val); - println!("{0:v$.0$}", v = val); - println!("{v:0$.0$}", v = val); - println!("{v:v$.0$}", v = val); - println!("{v:0$.v$}", v = val); - println!("{v:v$.v$}", v = val); - println!("{:0$}", width); - println!("{:1$}", local_i32, width); - println!("{:w$}", w = width); + println!("{v}", v = local_i32); //~ uninlined_format_args + println!("{local_i32:0$}", width); //~ uninlined_format_args + println!("{local_i32:w$}", w = width); //~ uninlined_format_args + println!("{local_i32:.0$}", prec); //~ uninlined_format_args + println!("{local_i32:.p$}", p = prec); //~ uninlined_format_args + println!("{:0$}", v = val); //~ uninlined_format_args + println!("{0:0$}", v = val); //~ uninlined_format_args + println!("{:0$.0$}", v = val); //~ uninlined_format_args + println!("{0:0$.0$}", v = val); //~ uninlined_format_args + println!("{0:0$.v$}", v = val); //~ uninlined_format_args + println!("{0:v$.0$}", v = val); //~ uninlined_format_args + println!("{v:0$.0$}", v = val); //~ uninlined_format_args + println!("{v:v$.0$}", v = val); //~ uninlined_format_args + println!("{v:0$.v$}", v = val); //~ uninlined_format_args + println!("{v:v$.v$}", v = val); //~ uninlined_format_args + println!("{:0$}", width); //~ uninlined_format_args + println!("{:1$}", local_i32, width); //~ uninlined_format_args + println!("{:w$}", w = width); //~ uninlined_format_args println!("{:w$}", local_i32, w = width); - println!("{:.0$}", prec); - println!("{:.1$}", local_i32, prec); - println!("{:.p$}", p = prec); + //~^ uninlined_format_args + println!("{:.0$}", prec); //~ uninlined_format_args + println!("{:.1$}", local_i32, prec); //~ uninlined_format_args + println!("{:.p$}", p = prec); //~ uninlined_format_args println!("{:.p$}", local_i32, p = prec); - println!("{:0$.1$}", width, prec); - println!("{:0$.w$}", width, w = prec); + //~^ uninlined_format_args + println!("{:0$.1$}", width, prec); //~ uninlined_format_args + println!("{:0$.w$}", width, w = prec); //~ uninlined_format_args println!("{:1$.2$}", local_f64, width, prec); + //~^ uninlined_format_args println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec); + //~^ uninlined_format_args + + //~v uninlined_format_args println!( "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}", local_i32, width, prec, @@ -125,8 +148,11 @@ fn tester(fn_arg: i32) { 1 + 2 ); println!("Width = {}, value with width = {:0$}", local_i32, local_f64); + //~^ uninlined_format_args println!("{:w$.p$}", local_i32, w = width, p = prec); + //~^ uninlined_format_args println!("{:w$.p$}", w = width, p = prec); + //~^ uninlined_format_args println!("{}", format!("{}", local_i32)); my_println!("{}", local_i32); my_println_args!("{}", local_i32); @@ -145,24 +171,27 @@ fn tester(fn_arg: i32) { ); println!(no_param_str!(), local_i32); + //~v uninlined_format_args println!( "{}", // comment with a comma , in it val, ); println!("{}", /* comment with a comma , in it */ val); + //~^ uninlined_format_args println!(with_span!("{0} {1}" "{1} {0}"), local_i32, local_f64); println!("{}", with_span!(span val)); if local_i32 > 0 { - panic!("p1 {}", local_i32); + panic!("p1 {}", local_i32); //~ uninlined_format_args } if local_i32 > 0 { - panic!("p2 {0}", local_i32); + panic!("p2 {0}", local_i32); //~ uninlined_format_args } if local_i32 > 0 { panic!("p3 {local_i32}", local_i32 = local_i32); + //~^ uninlined_format_args } if local_i32 > 0 { panic!("p4 {local_i32}"); @@ -182,7 +211,7 @@ fn _under_msrv() { #[clippy::msrv = "1.58"] fn _meets_msrv() { let local_i32 = 1; - println!("expand='{}'", local_i32); + println!("expand='{}'", local_i32); //~ uninlined_format_args } fn _do_not_fire() { diff --git a/tests/ui/uninlined_format_args.stderr b/tests/ui/uninlined_format_args.stderr index 829d646b8669..abf49de98059 100644 --- a/tests/ui/uninlined_format_args.stderr +++ b/tests/ui/uninlined_format_args.stderr @@ -13,7 +13,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:46:5 + --> $DIR/uninlined_format_args.rs:48:5 | LL | println!("val='{ }'", local_i32); // 3 spaces | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + println!("val='{local_i32}'"); // 3 spaces | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:47:5 + --> $DIR/uninlined_format_args.rs:51:5 | LL | println!("val='{ }'", local_i32); // tab | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + println!("val='{local_i32}'"); // tab | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:48:5 + --> $DIR/uninlined_format_args.rs:54:5 | LL | println!("val='{ }'", local_i32); // space+tab | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + println!("val='{local_i32}'"); // space+tab | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:49:5 + --> $DIR/uninlined_format_args.rs:57:5 | LL | println!("val='{ }'", local_i32); // tab+space | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + println!("val='{local_i32}'"); // tab+space | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:50:5 + --> $DIR/uninlined_format_args.rs:60:5 | LL | / println!( LL | | "val='{ @@ -71,7 +71,7 @@ LL | | ); | |_____^ error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:55:5 + --> $DIR/uninlined_format_args.rs:65:5 | LL | println!("{}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -83,7 +83,7 @@ LL + println!("{local_i32}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:56:5 + --> $DIR/uninlined_format_args.rs:66:5 | LL | println!("{}", fn_arg); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -95,7 +95,7 @@ LL + println!("{fn_arg}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:57:5 + --> $DIR/uninlined_format_args.rs:67:5 | LL | println!("{:?}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -107,7 +107,7 @@ LL + println!("{local_i32:?}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:58:5 + --> $DIR/uninlined_format_args.rs:68:5 | LL | println!("{:#?}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -119,7 +119,7 @@ LL + println!("{local_i32:#?}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:59:5 + --> $DIR/uninlined_format_args.rs:69:5 | LL | println!("{:4}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -131,7 +131,7 @@ LL + println!("{local_i32:4}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:60:5 + --> $DIR/uninlined_format_args.rs:70:5 | LL | println!("{:04}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -143,7 +143,7 @@ LL + println!("{local_i32:04}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:61:5 + --> $DIR/uninlined_format_args.rs:71:5 | LL | println!("{:<3}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -155,7 +155,7 @@ LL + println!("{local_i32:<3}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:62:5 + --> $DIR/uninlined_format_args.rs:72:5 | LL | println!("{:#010x}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -167,7 +167,7 @@ LL + println!("{local_i32:#010x}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:63:5 + --> $DIR/uninlined_format_args.rs:73:5 | LL | println!("{:.1}", local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -179,7 +179,7 @@ LL + println!("{local_f64:.1}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:67:5 + --> $DIR/uninlined_format_args.rs:77:5 | LL | println!("{} {}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -191,7 +191,7 @@ LL + println!("{local_i32} {local_f64}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:69:5 + --> $DIR/uninlined_format_args.rs:80:5 | LL | println!("{}", val); | ^^^^^^^^^^^^^^^^^^^ @@ -203,7 +203,7 @@ LL + println!("{val}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:70:5 + --> $DIR/uninlined_format_args.rs:81:5 | LL | println!("{}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -215,7 +215,7 @@ LL + println!("{val}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:72:5 + --> $DIR/uninlined_format_args.rs:83:5 | LL | println!("val='{\t }'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -227,7 +227,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:73:5 + --> $DIR/uninlined_format_args.rs:84:5 | LL | println!("val='{\n }'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -239,7 +239,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:74:5 + --> $DIR/uninlined_format_args.rs:85:5 | LL | println!("val='{local_i32}'", local_i32 = local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -251,7 +251,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:75:5 + --> $DIR/uninlined_format_args.rs:87:5 | LL | println!("val='{local_i32}'", local_i32 = fn_arg); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -263,7 +263,7 @@ LL + println!("val='{fn_arg}'"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:76:5 + --> $DIR/uninlined_format_args.rs:89:5 | LL | println!("{0}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -275,7 +275,7 @@ LL + println!("{local_i32}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:77:5 + --> $DIR/uninlined_format_args.rs:90:5 | LL | println!("{0:?}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -287,7 +287,7 @@ LL + println!("{local_i32:?}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:78:5 + --> $DIR/uninlined_format_args.rs:91:5 | LL | println!("{0:#?}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -299,7 +299,7 @@ LL + println!("{local_i32:#?}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:79:5 + --> $DIR/uninlined_format_args.rs:92:5 | LL | println!("{0:04}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -311,7 +311,7 @@ LL + println!("{local_i32:04}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:80:5 + --> $DIR/uninlined_format_args.rs:93:5 | LL | println!("{0:<3}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -323,7 +323,7 @@ LL + println!("{local_i32:<3}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:81:5 + --> $DIR/uninlined_format_args.rs:94:5 | LL | println!("{0:#010x}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -335,7 +335,7 @@ LL + println!("{local_i32:#010x}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:82:5 + --> $DIR/uninlined_format_args.rs:95:5 | LL | println!("{0:.1}", local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -347,7 +347,7 @@ LL + println!("{local_f64:.1}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:83:5 + --> $DIR/uninlined_format_args.rs:96:5 | LL | println!("{0} {0}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -359,7 +359,7 @@ LL + println!("{local_i32} {local_i32}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:84:5 + --> $DIR/uninlined_format_args.rs:97:5 | LL | println!("{1} {} {0} {}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -371,7 +371,7 @@ LL + println!("{local_f64} {local_i32} {local_i32} {local_f64}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:85:5 + --> $DIR/uninlined_format_args.rs:99:5 | LL | println!("{0} {1}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -383,7 +383,7 @@ LL + println!("{local_i32} {local_f64}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:86:5 + --> $DIR/uninlined_format_args.rs:101:5 | LL | println!("{1} {0}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -395,7 +395,7 @@ LL + println!("{local_f64} {local_i32}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:87:5 + --> $DIR/uninlined_format_args.rs:103:5 | LL | println!("{1} {0} {1} {0}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -407,7 +407,7 @@ LL + println!("{local_f64} {local_i32} {local_f64} {local_i32}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:89:5 + --> $DIR/uninlined_format_args.rs:106:5 | LL | println!("{v}", v = local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -419,7 +419,7 @@ LL + println!("{local_i32}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:90:5 + --> $DIR/uninlined_format_args.rs:107:5 | LL | println!("{local_i32:0$}", width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -431,7 +431,7 @@ LL + println!("{local_i32:width$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:91:5 + --> $DIR/uninlined_format_args.rs:108:5 | LL | println!("{local_i32:w$}", w = width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -443,7 +443,7 @@ LL + println!("{local_i32:width$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:92:5 + --> $DIR/uninlined_format_args.rs:109:5 | LL | println!("{local_i32:.0$}", prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -455,7 +455,7 @@ LL + println!("{local_i32:.prec$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:93:5 + --> $DIR/uninlined_format_args.rs:110:5 | LL | println!("{local_i32:.p$}", p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -467,7 +467,7 @@ LL + println!("{local_i32:.prec$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:94:5 + --> $DIR/uninlined_format_args.rs:111:5 | LL | println!("{:0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -479,7 +479,7 @@ LL + println!("{val:val$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:95:5 + --> $DIR/uninlined_format_args.rs:112:5 | LL | println!("{0:0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -491,7 +491,7 @@ LL + println!("{val:val$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:96:5 + --> $DIR/uninlined_format_args.rs:113:5 | LL | println!("{:0$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -503,7 +503,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:97:5 + --> $DIR/uninlined_format_args.rs:114:5 | LL | println!("{0:0$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -515,7 +515,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:98:5 + --> $DIR/uninlined_format_args.rs:115:5 | LL | println!("{0:0$.v$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -527,7 +527,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:99:5 + --> $DIR/uninlined_format_args.rs:116:5 | LL | println!("{0:v$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -539,7 +539,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:100:5 + --> $DIR/uninlined_format_args.rs:117:5 | LL | println!("{v:0$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -551,7 +551,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:101:5 + --> $DIR/uninlined_format_args.rs:118:5 | LL | println!("{v:v$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -563,7 +563,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:102:5 + --> $DIR/uninlined_format_args.rs:119:5 | LL | println!("{v:0$.v$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -575,7 +575,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:103:5 + --> $DIR/uninlined_format_args.rs:120:5 | LL | println!("{v:v$.v$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -587,7 +587,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:104:5 + --> $DIR/uninlined_format_args.rs:121:5 | LL | println!("{:0$}", width); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -599,7 +599,7 @@ LL + println!("{width:width$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:105:5 + --> $DIR/uninlined_format_args.rs:122:5 | LL | println!("{:1$}", local_i32, width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -611,7 +611,7 @@ LL + println!("{local_i32:width$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:106:5 + --> $DIR/uninlined_format_args.rs:123:5 | LL | println!("{:w$}", w = width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -623,7 +623,7 @@ LL + println!("{width:width$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:107:5 + --> $DIR/uninlined_format_args.rs:124:5 | LL | println!("{:w$}", local_i32, w = width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -635,7 +635,7 @@ LL + println!("{local_i32:width$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:108:5 + --> $DIR/uninlined_format_args.rs:126:5 | LL | println!("{:.0$}", prec); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -647,7 +647,7 @@ LL + println!("{prec:.prec$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:109:5 + --> $DIR/uninlined_format_args.rs:127:5 | LL | println!("{:.1$}", local_i32, prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -659,7 +659,7 @@ LL + println!("{local_i32:.prec$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:110:5 + --> $DIR/uninlined_format_args.rs:128:5 | LL | println!("{:.p$}", p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -671,7 +671,7 @@ LL + println!("{prec:.prec$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:111:5 + --> $DIR/uninlined_format_args.rs:129:5 | LL | println!("{:.p$}", local_i32, p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -683,7 +683,7 @@ LL + println!("{local_i32:.prec$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:112:5 + --> $DIR/uninlined_format_args.rs:131:5 | LL | println!("{:0$.1$}", width, prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -695,7 +695,7 @@ LL + println!("{width:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:113:5 + --> $DIR/uninlined_format_args.rs:132:5 | LL | println!("{:0$.w$}", width, w = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -707,7 +707,7 @@ LL + println!("{width:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:114:5 + --> $DIR/uninlined_format_args.rs:133:5 | LL | println!("{:1$.2$}", local_f64, width, prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -719,7 +719,7 @@ LL + println!("{local_f64:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:115:5 + --> $DIR/uninlined_format_args.rs:135:5 | LL | println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -731,7 +731,7 @@ LL + println!("{local_f64:width$.prec$} {local_f64} {width} {prec}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:116:5 + --> $DIR/uninlined_format_args.rs:139:5 | LL | / println!( LL | | "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}", @@ -740,7 +740,7 @@ LL | | ); | |_____^ error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:127:5 + --> $DIR/uninlined_format_args.rs:150:5 | LL | println!("Width = {}, value with width = {:0$}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -752,7 +752,7 @@ LL + println!("Width = {local_i32}, value with width = {local_f64:local_i32$ | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:128:5 + --> $DIR/uninlined_format_args.rs:152:5 | LL | println!("{:w$.p$}", local_i32, w = width, p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -764,7 +764,7 @@ LL + println!("{local_i32:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:129:5 + --> $DIR/uninlined_format_args.rs:154:5 | LL | println!("{:w$.p$}", w = width, p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -776,7 +776,7 @@ LL + println!("{width:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:148:5 + --> $DIR/uninlined_format_args.rs:175:5 | LL | / println!( LL | | "{}", @@ -786,7 +786,7 @@ LL | | ); | |_____^ error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:153:5 + --> $DIR/uninlined_format_args.rs:180:5 | LL | println!("{}", /* comment with a comma , in it */ val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -798,7 +798,7 @@ LL + println!("{val}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:159:9 + --> $DIR/uninlined_format_args.rs:187:9 | LL | panic!("p1 {}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -810,7 +810,7 @@ LL + panic!("p1 {local_i32}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:162:9 + --> $DIR/uninlined_format_args.rs:190:9 | LL | panic!("p2 {0}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -822,7 +822,7 @@ LL + panic!("p2 {local_i32}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:165:9 + --> $DIR/uninlined_format_args.rs:193:9 | LL | panic!("p3 {local_i32}", local_i32 = local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -834,7 +834,7 @@ LL + panic!("p3 {local_i32}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:185:5 + --> $DIR/uninlined_format_args.rs:214:5 | LL | println!("expand='{}'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninlined_format_args_panic.edition2018.fixed b/tests/ui/uninlined_format_args_panic.edition2018.fixed index f0d570efdcee..df1225dfa3f2 100644 --- a/tests/ui/uninlined_format_args_panic.edition2018.fixed +++ b/tests/ui/uninlined_format_args_panic.edition2018.fixed @@ -7,16 +7,17 @@ fn main() { let var = 1; - println!("val='{var}'"); + println!("val='{var}'"); //~ uninlined_format_args if var > 0 { - panic!("p1 {}", var); + panic!("p1 {}", var); //~[edition2021] uninlined_format_args } if var > 0 { - panic!("p2 {0}", var); + panic!("p2 {0}", var); //~[edition2021] uninlined_format_args } if var > 0 { panic!("p3 {var}", var = var); + //~[edition2021]^ uninlined_format_args } #[allow(non_fmt_panics)] @@ -27,5 +28,7 @@ fn main() { } assert!(var == 1, "p5 {}", var); + //~[edition2021]^ uninlined_format_args debug_assert!(var == 1, "p6 {}", var); + //~[edition2021]^ uninlined_format_args } diff --git a/tests/ui/uninlined_format_args_panic.edition2021.fixed b/tests/ui/uninlined_format_args_panic.edition2021.fixed index 7c0f28c45764..5f657b55160c 100644 --- a/tests/ui/uninlined_format_args_panic.edition2021.fixed +++ b/tests/ui/uninlined_format_args_panic.edition2021.fixed @@ -7,16 +7,17 @@ fn main() { let var = 1; - println!("val='{var}'"); + println!("val='{var}'"); //~ uninlined_format_args if var > 0 { - panic!("p1 {var}"); + panic!("p1 {var}"); //~[edition2021] uninlined_format_args } if var > 0 { - panic!("p2 {var}"); + panic!("p2 {var}"); //~[edition2021] uninlined_format_args } if var > 0 { panic!("p3 {var}"); + //~[edition2021]^ uninlined_format_args } #[allow(non_fmt_panics)] @@ -27,5 +28,7 @@ fn main() { } assert!(var == 1, "p5 {var}"); + //~[edition2021]^ uninlined_format_args debug_assert!(var == 1, "p6 {var}"); + //~[edition2021]^ uninlined_format_args } diff --git a/tests/ui/uninlined_format_args_panic.edition2021.stderr b/tests/ui/uninlined_format_args_panic.edition2021.stderr index ec1e3a1cf117..2b17d6a31553 100644 --- a/tests/ui/uninlined_format_args_panic.edition2021.stderr +++ b/tests/ui/uninlined_format_args_panic.edition2021.stderr @@ -49,7 +49,7 @@ LL + panic!("p3 {var}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args_panic.rs:29:5 + --> $DIR/uninlined_format_args_panic.rs:30:5 | LL | assert!(var == 1, "p5 {}", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + assert!(var == 1, "p5 {var}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args_panic.rs:30:5 + --> $DIR/uninlined_format_args_panic.rs:32:5 | LL | debug_assert!(var == 1, "p6 {}", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninlined_format_args_panic.rs b/tests/ui/uninlined_format_args_panic.rs index fa594d9a96f0..b248d7a0acc6 100644 --- a/tests/ui/uninlined_format_args_panic.rs +++ b/tests/ui/uninlined_format_args_panic.rs @@ -7,16 +7,17 @@ fn main() { let var = 1; - println!("val='{}'", var); + println!("val='{}'", var); //~ uninlined_format_args if var > 0 { - panic!("p1 {}", var); + panic!("p1 {}", var); //~[edition2021] uninlined_format_args } if var > 0 { - panic!("p2 {0}", var); + panic!("p2 {0}", var); //~[edition2021] uninlined_format_args } if var > 0 { panic!("p3 {var}", var = var); + //~[edition2021]^ uninlined_format_args } #[allow(non_fmt_panics)] @@ -27,5 +28,7 @@ fn main() { } assert!(var == 1, "p5 {}", var); + //~[edition2021]^ uninlined_format_args debug_assert!(var == 1, "p6 {}", var); + //~[edition2021]^ uninlined_format_args } diff --git a/tests/ui/unit_arg.rs b/tests/ui/unit_arg.rs index 2e1390621a6c..495cd982ed35 100644 --- a/tests/ui/unit_arg.rs +++ b/tests/ui/unit_arg.rs @@ -60,23 +60,30 @@ impl Tr for B { } fn bad() { + //~v unit_arg foo({ 1; }); - foo(foo(1)); + foo(foo(1)); //~ unit_arg + + //~v unit_arg foo({ foo(1); foo(2); }); let b = Bar; + //~v unit_arg b.bar({ 1; }); - taking_multiple_units(foo(0), foo(1)); + taking_multiple_units(foo(0), foo(1)); //~ unit_arg + + //~v unit_arg taking_multiple_units(foo(0), { foo(1); foo(2); }); + //~v unit_arg taking_multiple_units( { foo(0); @@ -88,10 +95,10 @@ fn bad() { }, ); // here Some(foo(2)) isn't the top level statement expression, wrap the suggestion in a block - None.or(Some(foo(2))); + None.or(Some(foo(2))); //~ unit_arg // in this case, the suggestion can be inlined, no need for a surrounding block // foo(()); foo(()) instead of { foo(()); foo(()) } - foo(foo(())); + foo(foo(())); //~ unit_arg } fn ok() { @@ -128,7 +135,7 @@ mod issue_2945 { #[allow(dead_code)] fn returning_expr() -> Option<()> { - Some(foo(1)) + Some(foo(1)) //~ unit_arg } fn taking_multiple_units(a: (), b: ()) {} diff --git a/tests/ui/unit_arg.stderr b/tests/ui/unit_arg.stderr index 8656c8fddabc..31fc5352d57d 100644 --- a/tests/ui/unit_arg.stderr +++ b/tests/ui/unit_arg.stderr @@ -1,5 +1,5 @@ error: passing a unit value to a function - --> $DIR/unit_arg.rs:63:5 + --> $DIR/unit_arg.rs:64:5 | LL | / foo({ LL | | 1; @@ -21,7 +21,7 @@ LL ~ foo(()); | error: passing a unit value to a function - --> $DIR/unit_arg.rs:66:5 + --> $DIR/unit_arg.rs:67:5 | LL | foo(foo(1)); | ^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL ~ foo(()); | error: passing a unit value to a function - --> $DIR/unit_arg.rs:67:5 + --> $DIR/unit_arg.rs:70:5 | LL | / foo({ LL | | foo(1); @@ -55,7 +55,7 @@ LL ~ foo(()); | error: passing a unit value to a function - --> $DIR/unit_arg.rs:72:5 + --> $DIR/unit_arg.rs:76:5 | LL | / b.bar({ LL | | 1; @@ -75,7 +75,7 @@ LL ~ b.bar(()); | error: passing unit values to a function - --> $DIR/unit_arg.rs:75:5 + --> $DIR/unit_arg.rs:79:5 | LL | taking_multiple_units(foo(0), foo(1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL ~ taking_multiple_units((), ()); | error: passing unit values to a function - --> $DIR/unit_arg.rs:76:5 + --> $DIR/unit_arg.rs:82:5 | LL | / taking_multiple_units(foo(0), { LL | | foo(1); @@ -111,7 +111,7 @@ LL ~ taking_multiple_units((), ()); | error: passing unit values to a function - --> $DIR/unit_arg.rs:80:5 + --> $DIR/unit_arg.rs:87:5 | LL | / taking_multiple_units( LL | | { @@ -147,7 +147,7 @@ LL ~ ); | error: passing a unit value to a function - --> $DIR/unit_arg.rs:91:13 + --> $DIR/unit_arg.rs:98:13 | LL | None.or(Some(foo(2))); | ^^^^^^^^^^^^ @@ -161,7 +161,7 @@ LL ~ }); | error: passing a unit value to a function - --> $DIR/unit_arg.rs:94:5 + --> $DIR/unit_arg.rs:101:5 | LL | foo(foo(())); | ^^^^^^^^^^^^ @@ -173,7 +173,7 @@ LL ~ foo(()); | error: passing a unit value to a function - --> $DIR/unit_arg.rs:131:5 + --> $DIR/unit_arg.rs:138:5 | LL | Some(foo(1)) | ^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL | Some(foo(1)) help: move the expression in front of the call and replace it with the unit literal `()` | LL ~ foo(1); -LL + Some(()) +LL ~ Some(()) | error: aborting due to 10 previous errors diff --git a/tests/ui/unit_arg_empty_blocks.fixed b/tests/ui/unit_arg_empty_blocks.fixed index a947ded7b1e7..1f73c6c3d136 100644 --- a/tests/ui/unit_arg_empty_blocks.fixed +++ b/tests/ui/unit_arg_empty_blocks.fixed @@ -13,13 +13,13 @@ fn foo3(t1: T1, t2: T2, t3: T3) { } fn bad() { - foo(()); - foo3((), 2, 2); + foo(()); //~ unit_arg + foo3((), 2, 2); //~ unit_arg foo(0); - taking_two_units((), ()); + taking_two_units((), ()); //~ unit_arg foo(0); foo(1); - taking_three_units((), (), ()); + taking_three_units((), (), ()); //~ unit_arg } fn taking_two_units(a: (), b: ()) {} diff --git a/tests/ui/unit_arg_empty_blocks.rs b/tests/ui/unit_arg_empty_blocks.rs index 058c4f84a9e8..68fa95e3ebae 100644 --- a/tests/ui/unit_arg_empty_blocks.rs +++ b/tests/ui/unit_arg_empty_blocks.rs @@ -13,10 +13,10 @@ fn foo3(t1: T1, t2: T2, t3: T3) { } fn bad() { - foo({}); - foo3({}, 2, 2); - taking_two_units({}, foo(0)); - taking_three_units({}, foo(0), foo(1)); + foo({}); //~ unit_arg + foo3({}, 2, 2); //~ unit_arg + taking_two_units({}, foo(0)); //~ unit_arg + taking_three_units({}, foo(0), foo(1)); //~ unit_arg } fn taking_two_units(a: (), b: ()) {} diff --git a/tests/ui/unnecessary_cast.fixed b/tests/ui/unnecessary_cast.fixed index 18dd53bf2b42..5108deb7c849 100644 --- a/tests/ui/unnecessary_cast.fixed +++ b/tests/ui/unnecessary_cast.fixed @@ -15,7 +15,7 @@ type PtrConstU8 = *const u8; type PtrMutU8 = *mut u8; fn owo(ptr: *const T) -> *const T { - ptr + ptr //~ unnecessary_cast } fn uwu(ptr: *const T) -> *const U { @@ -50,22 +50,23 @@ fn bbb() -> UnsignedThirtyTwoBitInteger { #[rustfmt::skip] fn main() { // Test cast_unnecessary - 1_i32; - 1_f32; - false; + 1_i32; //~ unnecessary_cast + 1_f32; //~ unnecessary_cast + false; //~ unnecessary_cast &1i32 as &i32; - -1_i32; - - 1_i32; - -1_f32; - 1_i32; - 1_f32; + -1_i32; //~ unnecessary_cast + - 1_i32; //~ unnecessary_cast + -1_f32; //~ unnecessary_cast + 1_i32; //~ unnecessary_cast + 1_f32; //~ unnecessary_cast let _: *mut u8 = [1u8, 2].as_ptr() as *mut u8; + //~^ unnecessary_cast - [1u8, 2].as_ptr(); + [1u8, 2].as_ptr(); //~ unnecessary_cast [1u8, 2].as_ptr() as *mut u8; - [1u8, 2].as_mut_ptr(); + [1u8, 2].as_mut_ptr(); //~ unnecessary_cast [1u8, 2].as_mut_ptr() as *const u8; [1u8, 2].as_ptr() as PtrConstU8; [1u8, 2].as_ptr() as PtrMutU8; @@ -76,10 +77,12 @@ fn main() { let _: *const u8 = [1u8, 2].as_ptr() as *const _; let _: *mut u8 = [1u8, 2].as_mut_ptr() as *mut _; - owo::([1u32].as_ptr()); + owo::([1u32].as_ptr()); //~ unnecessary_cast uwu::([1u32].as_ptr()); + //~^ unnecessary_cast // this will not lint in the function body even though they have the same type, instead here uwu::([1u32].as_ptr()); + //~^ unnecessary_cast // macro version macro_rules! foo { @@ -114,9 +117,9 @@ fn main() { extern_fake_libc::getpid_SAFE_TRUTH() as i32; let pid = unsafe { fake_libc::getpid() }; pid as i32; - aaa(); + aaa(); //~ unnecessary_cast let x = aaa(); - aaa(); + aaa(); //~ unnecessary_cast // Will not lint currently. bbb() as u32; let x = bbb(); @@ -152,14 +155,14 @@ mod fixable { fn main() { // casting integer literal to float is unnecessary - 100_f32; - 100_f64; - 100_f64; - let _ = -100_f32; - let _ = -100_f64; - let _ = -100_f64; - 100_f32; - 100_f64; + 100_f32; //~ unnecessary_cast + 100_f64; //~ unnecessary_cast + 100_f64; //~ unnecessary_cast + let _ = -100_f32; //~ unnecessary_cast + let _ = -100_f64; //~ unnecessary_cast + let _ = -100_f64; //~ unnecessary_cast + 100_f32; //~ unnecessary_cast + 100_f64; //~ unnecessary_cast // Should not trigger #[rustfmt::skip] let v = vec!(1); @@ -171,41 +174,42 @@ mod fixable { 0o11 as f64; 0b11 as f64; - 1_u32; - 0x10_i32; - 0b10_usize; - 0o73_u16; - 1_000_000_000_u32; + 1_u32; //~ unnecessary_cast + 0x10_i32; //~ unnecessary_cast + 0b10_usize; //~ unnecessary_cast + 0o73_u16; //~ unnecessary_cast + 1_000_000_000_u32; //~ unnecessary_cast - 1.0_f64; - 0.5_f32; + 1.0_f64; //~ unnecessary_cast + 0.5_f32; //~ unnecessary_cast 1.0 as u16; - let _ = -1_i32; - let _ = -1.0_f32; + let _ = -1_i32; //~ unnecessary_cast + let _ = -1.0_f32; //~ unnecessary_cast let _ = 1 as I32Alias; let _ = &1 as &I32Alias; let x = 1i32; - let _ = &{ x }; + let _ = &{ x }; //~ unnecessary_cast } type I32Alias = i32; fn issue_9380() { - let _: i32 = -1_i32; + let _: i32 = -1_i32; //~ unnecessary_cast let _: f32 = -(1) as f32; - let _: i64 = -1_i64; + let _: i64 = -1_i64; //~ unnecessary_cast let _: i64 = -(1.0) as i64; let _ = -(1 + 1) as i64; } fn issue_9563() { - let _: f64 = (-8.0_f64).exp(); + let _: f64 = (-8.0_f64).exp(); //~ unnecessary_cast #[allow(clippy::precedence)] + //~v unnecessary_cast let _: f64 = -8.0_f64.exp(); // should suggest `-8.0_f64.exp()` here not to change code behavior } @@ -214,7 +218,7 @@ mod fixable { 0. } - let _num = foo(); + let _num = foo(); //~ unnecessary_cast } fn issue_9603() { diff --git a/tests/ui/unnecessary_cast.rs b/tests/ui/unnecessary_cast.rs index fcdd4c60ccd0..6a8878a6fb65 100644 --- a/tests/ui/unnecessary_cast.rs +++ b/tests/ui/unnecessary_cast.rs @@ -15,7 +15,7 @@ type PtrConstU8 = *const u8; type PtrMutU8 = *mut u8; fn owo(ptr: *const T) -> *const T { - ptr as *const T + ptr as *const T //~ unnecessary_cast } fn uwu(ptr: *const T) -> *const U { @@ -50,22 +50,23 @@ fn bbb() -> UnsignedThirtyTwoBitInteger { #[rustfmt::skip] fn main() { // Test cast_unnecessary - 1i32 as i32; - 1f32 as f32; - false as bool; + 1i32 as i32; //~ unnecessary_cast + 1f32 as f32; //~ unnecessary_cast + false as bool; //~ unnecessary_cast &1i32 as &i32; - -1_i32 as i32; - - 1_i32 as i32; - -1f32 as f32; - 1_i32 as i32; - 1_f32 as f32; + -1_i32 as i32; //~ unnecessary_cast + - 1_i32 as i32; //~ unnecessary_cast + -1f32 as f32; //~ unnecessary_cast + 1_i32 as i32; //~ unnecessary_cast + 1_f32 as f32; //~ unnecessary_cast let _: *mut u8 = [1u8, 2].as_ptr() as *const u8 as *mut u8; + //~^ unnecessary_cast - [1u8, 2].as_ptr() as *const u8; + [1u8, 2].as_ptr() as *const u8; //~ unnecessary_cast [1u8, 2].as_ptr() as *mut u8; - [1u8, 2].as_mut_ptr() as *mut u8; + [1u8, 2].as_mut_ptr() as *mut u8; //~ unnecessary_cast [1u8, 2].as_mut_ptr() as *const u8; [1u8, 2].as_ptr() as PtrConstU8; [1u8, 2].as_ptr() as PtrMutU8; @@ -76,10 +77,12 @@ fn main() { let _: *const u8 = [1u8, 2].as_ptr() as *const _; let _: *mut u8 = [1u8, 2].as_mut_ptr() as *mut _; - owo::([1u32].as_ptr()) as *const u32; + owo::([1u32].as_ptr()) as *const u32; //~ unnecessary_cast uwu::([1u32].as_ptr()) as *const u8; + //~^ unnecessary_cast // this will not lint in the function body even though they have the same type, instead here uwu::([1u32].as_ptr()) as *const u32; + //~^ unnecessary_cast // macro version macro_rules! foo { @@ -114,9 +117,9 @@ fn main() { extern_fake_libc::getpid_SAFE_TRUTH() as i32; let pid = unsafe { fake_libc::getpid() }; pid as i32; - aaa() as u32; + aaa() as u32; //~ unnecessary_cast let x = aaa(); - aaa() as u32; + aaa() as u32; //~ unnecessary_cast // Will not lint currently. bbb() as u32; let x = bbb(); @@ -152,14 +155,14 @@ mod fixable { fn main() { // casting integer literal to float is unnecessary - 100 as f32; - 100 as f64; - 100_i32 as f64; - let _ = -100 as f32; - let _ = -100 as f64; - let _ = -100_i32 as f64; - 100. as f32; - 100. as f64; + 100 as f32; //~ unnecessary_cast + 100 as f64; //~ unnecessary_cast + 100_i32 as f64; //~ unnecessary_cast + let _ = -100 as f32; //~ unnecessary_cast + let _ = -100 as f64; //~ unnecessary_cast + let _ = -100_i32 as f64; //~ unnecessary_cast + 100. as f32; //~ unnecessary_cast + 100. as f64; //~ unnecessary_cast // Should not trigger #[rustfmt::skip] let v = vec!(1); @@ -171,41 +174,42 @@ mod fixable { 0o11 as f64; 0b11 as f64; - 1 as u32; - 0x10 as i32; - 0b10 as usize; - 0o73 as u16; - 1_000_000_000 as u32; + 1 as u32; //~ unnecessary_cast + 0x10 as i32; //~ unnecessary_cast + 0b10 as usize; //~ unnecessary_cast + 0o73 as u16; //~ unnecessary_cast + 1_000_000_000 as u32; //~ unnecessary_cast - 1.0 as f64; - 0.5 as f32; + 1.0 as f64; //~ unnecessary_cast + 0.5 as f32; //~ unnecessary_cast 1.0 as u16; - let _ = -1 as i32; - let _ = -1.0 as f32; + let _ = -1 as i32; //~ unnecessary_cast + let _ = -1.0 as f32; //~ unnecessary_cast let _ = 1 as I32Alias; let _ = &1 as &I32Alias; let x = 1i32; - let _ = &(x as i32); + let _ = &(x as i32); //~ unnecessary_cast } type I32Alias = i32; fn issue_9380() { - let _: i32 = -(1) as i32; + let _: i32 = -(1) as i32; //~ unnecessary_cast let _: f32 = -(1) as f32; - let _: i64 = -(1) as i64; + let _: i64 = -(1) as i64; //~ unnecessary_cast let _: i64 = -(1.0) as i64; let _ = -(1 + 1) as i64; } fn issue_9563() { - let _: f64 = (-8.0 as f64).exp(); + let _: f64 = (-8.0 as f64).exp(); //~ unnecessary_cast #[allow(clippy::precedence)] + //~v unnecessary_cast let _: f64 = -(8.0 as f64).exp(); // should suggest `-8.0_f64.exp()` here not to change code behavior } @@ -214,7 +218,7 @@ mod fixable { 0. } - let _num = foo() as f32; + let _num = foo() as f32; //~ unnecessary_cast } fn issue_9603() { diff --git a/tests/ui/unnecessary_cast.stderr b/tests/ui/unnecessary_cast.stderr index d4786f66e447..4caeafd83520 100644 --- a/tests/ui/unnecessary_cast.stderr +++ b/tests/ui/unnecessary_cast.stderr @@ -62,181 +62,181 @@ LL | let _: *mut u8 = [1u8, 2].as_ptr() as *const u8 as *mut u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[1u8, 2].as_ptr()` error: casting raw pointers to the same type and constness is unnecessary (`*const u8` -> `*const u8`) - --> $DIR/unnecessary_cast.rs:66:5 + --> $DIR/unnecessary_cast.rs:67:5 | LL | [1u8, 2].as_ptr() as *const u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[1u8, 2].as_ptr()` error: casting raw pointers to the same type and constness is unnecessary (`*mut u8` -> `*mut u8`) - --> $DIR/unnecessary_cast.rs:68:5 + --> $DIR/unnecessary_cast.rs:69:5 | LL | [1u8, 2].as_mut_ptr() as *mut u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[1u8, 2].as_mut_ptr()` error: casting raw pointers to the same type and constness is unnecessary (`*const u32` -> `*const u32`) - --> $DIR/unnecessary_cast.rs:79:5 + --> $DIR/unnecessary_cast.rs:80:5 | LL | owo::([1u32].as_ptr()) as *const u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `owo::([1u32].as_ptr())` error: casting raw pointers to the same type and constness is unnecessary (`*const u8` -> `*const u8`) - --> $DIR/unnecessary_cast.rs:80:5 + --> $DIR/unnecessary_cast.rs:81:5 | LL | uwu::([1u32].as_ptr()) as *const u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `uwu::([1u32].as_ptr())` error: casting raw pointers to the same type and constness is unnecessary (`*const u32` -> `*const u32`) - --> $DIR/unnecessary_cast.rs:82:5 + --> $DIR/unnecessary_cast.rs:84:5 | LL | uwu::([1u32].as_ptr()) as *const u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `uwu::([1u32].as_ptr())` error: casting to the same type is unnecessary (`u32` -> `u32`) - --> $DIR/unnecessary_cast.rs:117:5 + --> $DIR/unnecessary_cast.rs:120:5 | LL | aaa() as u32; | ^^^^^^^^^^^^ help: try: `aaa()` error: casting to the same type is unnecessary (`u32` -> `u32`) - --> $DIR/unnecessary_cast.rs:119:5 + --> $DIR/unnecessary_cast.rs:122:5 | LL | aaa() as u32; | ^^^^^^^^^^^^ help: try: `aaa()` error: casting integer literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:155:9 + --> $DIR/unnecessary_cast.rs:158:9 | LL | 100 as f32; | ^^^^^^^^^^ help: try: `100_f32` error: casting integer literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:156:9 + --> $DIR/unnecessary_cast.rs:159:9 | LL | 100 as f64; | ^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:157:9 + --> $DIR/unnecessary_cast.rs:160:9 | LL | 100_i32 as f64; | ^^^^^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:158:17 + --> $DIR/unnecessary_cast.rs:161:17 | LL | let _ = -100 as f32; | ^^^^^^^^^^^ help: try: `-100_f32` error: casting integer literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:159:17 + --> $DIR/unnecessary_cast.rs:162:17 | LL | let _ = -100 as f64; | ^^^^^^^^^^^ help: try: `-100_f64` error: casting integer literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:160:17 + --> $DIR/unnecessary_cast.rs:163:17 | LL | let _ = -100_i32 as f64; | ^^^^^^^^^^^^^^^ help: try: `-100_f64` error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:161:9 + --> $DIR/unnecessary_cast.rs:164:9 | LL | 100. as f32; | ^^^^^^^^^^^ help: try: `100_f32` error: casting float literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:162:9 + --> $DIR/unnecessary_cast.rs:165:9 | LL | 100. as f64; | ^^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `u32` is unnecessary - --> $DIR/unnecessary_cast.rs:174:9 + --> $DIR/unnecessary_cast.rs:177:9 | LL | 1 as u32; | ^^^^^^^^ help: try: `1_u32` error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast.rs:175:9 + --> $DIR/unnecessary_cast.rs:178:9 | LL | 0x10 as i32; | ^^^^^^^^^^^ help: try: `0x10_i32` error: casting integer literal to `usize` is unnecessary - --> $DIR/unnecessary_cast.rs:176:9 + --> $DIR/unnecessary_cast.rs:179:9 | LL | 0b10 as usize; | ^^^^^^^^^^^^^ help: try: `0b10_usize` error: casting integer literal to `u16` is unnecessary - --> $DIR/unnecessary_cast.rs:177:9 + --> $DIR/unnecessary_cast.rs:180:9 | LL | 0o73 as u16; | ^^^^^^^^^^^ help: try: `0o73_u16` error: casting integer literal to `u32` is unnecessary - --> $DIR/unnecessary_cast.rs:178:9 + --> $DIR/unnecessary_cast.rs:181:9 | LL | 1_000_000_000 as u32; | ^^^^^^^^^^^^^^^^^^^^ help: try: `1_000_000_000_u32` error: casting float literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:180:9 + --> $DIR/unnecessary_cast.rs:183:9 | LL | 1.0 as f64; | ^^^^^^^^^^ help: try: `1.0_f64` error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:181:9 + --> $DIR/unnecessary_cast.rs:184:9 | LL | 0.5 as f32; | ^^^^^^^^^^ help: try: `0.5_f32` error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast.rs:185:17 + --> $DIR/unnecessary_cast.rs:188:17 | LL | let _ = -1 as i32; | ^^^^^^^^^ help: try: `-1_i32` error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:186:17 + --> $DIR/unnecessary_cast.rs:189:17 | LL | let _ = -1.0 as f32; | ^^^^^^^^^^^ help: try: `-1.0_f32` error: casting to the same type is unnecessary (`i32` -> `i32`) - --> $DIR/unnecessary_cast.rs:192:18 + --> $DIR/unnecessary_cast.rs:195:18 | LL | let _ = &(x as i32); | ^^^^^^^^^^ help: try: `{ x }` error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast.rs:198:22 + --> $DIR/unnecessary_cast.rs:201:22 | LL | let _: i32 = -(1) as i32; | ^^^^^^^^^^^ help: try: `-1_i32` error: casting integer literal to `i64` is unnecessary - --> $DIR/unnecessary_cast.rs:200:22 + --> $DIR/unnecessary_cast.rs:203:22 | LL | let _: i64 = -(1) as i64; | ^^^^^^^^^^^ help: try: `-1_i64` error: casting float literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:207:22 + --> $DIR/unnecessary_cast.rs:210:22 | LL | let _: f64 = (-8.0 as f64).exp(); | ^^^^^^^^^^^^^ help: try: `(-8.0_f64)` error: casting float literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:209:23 + --> $DIR/unnecessary_cast.rs:213:23 | LL | let _: f64 = -(8.0 as f64).exp(); // should suggest `-8.0_f64.exp()` here not to change code behavior | ^^^^^^^^^^^^ help: try: `8.0_f64` error: casting to the same type is unnecessary (`f32` -> `f32`) - --> $DIR/unnecessary_cast.rs:217:20 + --> $DIR/unnecessary_cast.rs:221:20 | LL | let _num = foo() as f32; | ^^^^^^^^^^^^ help: try: `foo()` diff --git a/tests/ui/unnecessary_filter_map.rs b/tests/ui/unnecessary_filter_map.rs index 1e0d7d12965c..ef7f8e741db9 100644 --- a/tests/ui/unnecessary_filter_map.rs +++ b/tests/ui/unnecessary_filter_map.rs @@ -158,4 +158,5 @@ fn issue11260() { // #11260 is about unnecessary_find_map, but the fix also kind of applies to // unnecessary_filter_map let _x = std::iter::once(1).filter_map(|n| (n > 1).then_some(n)); + //~^ unnecessary_filter_map } diff --git a/tests/ui/unnecessary_find_map.rs b/tests/ui/unnecessary_find_map.rs index 9972b68092ab..6fa95a84af8d 100644 --- a/tests/ui/unnecessary_find_map.rs +++ b/tests/ui/unnecessary_find_map.rs @@ -30,5 +30,6 @@ fn find_map_none_changes_item_type() -> Option { fn issue11260() { let y = Some(1); let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(n)); + //~^ unnecessary_find_map let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(y)); // different option, so can't be just `.find()` } diff --git a/tests/ui/unnecessary_fold.fixed b/tests/ui/unnecessary_fold.fixed index c5bc11b55ab5..9dc987a00edc 100644 --- a/tests/ui/unnecessary_fold.fixed +++ b/tests/ui/unnecessary_fold.fixed @@ -8,19 +8,25 @@ fn is_any(acc: bool, x: usize) -> bool { fn unnecessary_fold() { // Can be replaced by .any let _ = (0..3).any(|x| x > 2); + //~^ unnecessary_fold // Can be replaced by .any (checking suggestion) let _ = (0..3).fold(false, is_any); + //~^ redundant_closure // Can be replaced by .all let _ = (0..3).all(|x| x > 2); + //~^ unnecessary_fold // Can be replaced by .sum let _: i32 = (0..3).sum(); + //~^ unnecessary_fold // Can be replaced by .product let _: i32 = (0..3).product(); + //~^ unnecessary_fold } /// Should trigger the `UNNECESSARY_FOLD` lint, with an error span including exactly `.fold(...)` fn unnecessary_fold_span_for_multi_element_chain() { let _: bool = (0..3).map(|x| 2 * x).any(|x| x > 2); + //~^ unnecessary_fold } /// Calls which should not trigger the `UNNECESSARY_FOLD` lint @@ -50,7 +56,7 @@ fn unnecessary_fold_over_multiple_lines() { let _ = (0..3) .map(|x| x + 1) .filter(|x| x % 2 == 0) - .any(|x| x > 2); + .any(|x| x > 2); //~ unnecessary_fold } fn issue10000() { @@ -62,16 +68,25 @@ fn issue10000() { fn smoketest_map(mut map: HashMap) { map.insert(0, 0); assert_eq!(map.values().sum::(), 0); + //~^ unnecessary_fold // more cases: let _ = map.values().sum::(); + //~^ unnecessary_fold let _ = map.values().product::(); + //~^ unnecessary_fold let _: i32 = map.values().sum(); + //~^ unnecessary_fold let _: i32 = map.values().product(); + //~^ unnecessary_fold anything(map.values().sum::()); + //~^ unnecessary_fold anything(map.values().product::()); + //~^ unnecessary_fold num(map.values().sum()); + //~^ unnecessary_fold num(map.values().product()); + //~^ unnecessary_fold } smoketest_map(HashMap::new()); diff --git a/tests/ui/unnecessary_fold.rs b/tests/ui/unnecessary_fold.rs index 3a5136eeeaeb..de359a8282db 100644 --- a/tests/ui/unnecessary_fold.rs +++ b/tests/ui/unnecessary_fold.rs @@ -8,19 +8,25 @@ fn is_any(acc: bool, x: usize) -> bool { fn unnecessary_fold() { // Can be replaced by .any let _ = (0..3).fold(false, |acc, x| acc || x > 2); + //~^ unnecessary_fold // Can be replaced by .any (checking suggestion) let _ = (0..3).fold(false, |acc, x| is_any(acc, x)); + //~^ redundant_closure // Can be replaced by .all let _ = (0..3).fold(true, |acc, x| acc && x > 2); + //~^ unnecessary_fold // Can be replaced by .sum let _: i32 = (0..3).fold(0, |acc, x| acc + x); + //~^ unnecessary_fold // Can be replaced by .product let _: i32 = (0..3).fold(1, |acc, x| acc * x); + //~^ unnecessary_fold } /// Should trigger the `UNNECESSARY_FOLD` lint, with an error span including exactly `.fold(...)` fn unnecessary_fold_span_for_multi_element_chain() { let _: bool = (0..3).map(|x| 2 * x).fold(false, |acc, x| acc || x > 2); + //~^ unnecessary_fold } /// Calls which should not trigger the `UNNECESSARY_FOLD` lint @@ -50,7 +56,7 @@ fn unnecessary_fold_over_multiple_lines() { let _ = (0..3) .map(|x| x + 1) .filter(|x| x % 2 == 0) - .fold(false, |acc, x| acc || x > 2); + .fold(false, |acc, x| acc || x > 2); //~ unnecessary_fold } fn issue10000() { @@ -62,16 +68,25 @@ fn issue10000() { fn smoketest_map(mut map: HashMap) { map.insert(0, 0); assert_eq!(map.values().fold(0, |x, y| x + y), 0); + //~^ unnecessary_fold // more cases: let _ = map.values().fold(0, |x, y| x + y); + //~^ unnecessary_fold let _ = map.values().fold(1, |x, y| x * y); + //~^ unnecessary_fold let _: i32 = map.values().fold(0, |x, y| x + y); + //~^ unnecessary_fold let _: i32 = map.values().fold(1, |x, y| x * y); + //~^ unnecessary_fold anything(map.values().fold(0, |x, y| x + y)); + //~^ unnecessary_fold anything(map.values().fold(1, |x, y| x * y)); + //~^ unnecessary_fold num(map.values().fold(0, |x, y| x + y)); + //~^ unnecessary_fold num(map.values().fold(1, |x, y| x * y)); + //~^ unnecessary_fold } smoketest_map(HashMap::new()); diff --git a/tests/ui/unnecessary_fold.stderr b/tests/ui/unnecessary_fold.stderr index 123d4a3be755..24195d56f29d 100644 --- a/tests/ui/unnecessary_fold.stderr +++ b/tests/ui/unnecessary_fold.stderr @@ -8,7 +8,7 @@ LL | let _ = (0..3).fold(false, |acc, x| acc || x > 2); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_fold)]` error: redundant closure - --> $DIR/unnecessary_fold.rs:12:32 + --> $DIR/unnecessary_fold.rs:13:32 | LL | let _ = (0..3).fold(false, |acc, x| is_any(acc, x)); | ^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `is_any` @@ -17,85 +17,85 @@ LL | let _ = (0..3).fold(false, |acc, x| is_any(acc, x)); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure)]` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:14:20 + --> $DIR/unnecessary_fold.rs:16:20 | LL | let _ = (0..3).fold(true, |acc, x| acc && x > 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `all(|x| x > 2)` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:16:25 + --> $DIR/unnecessary_fold.rs:19:25 | LL | let _: i32 = (0..3).fold(0, |acc, x| acc + x); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `sum()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:18:25 + --> $DIR/unnecessary_fold.rs:22:25 | LL | let _: i32 = (0..3).fold(1, |acc, x| acc * x); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `product()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:23:41 + --> $DIR/unnecessary_fold.rs:28:41 | LL | let _: bool = (0..3).map(|x| 2 * x).fold(false, |acc, x| acc || x > 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `any(|x| x > 2)` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:53:10 + --> $DIR/unnecessary_fold.rs:59:10 | LL | .fold(false, |acc, x| acc || x > 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `any(|x| x > 2)` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:64:33 + --> $DIR/unnecessary_fold.rs:70:33 | LL | assert_eq!(map.values().fold(0, |x, y| x + y), 0); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `sum::()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:67:30 + --> $DIR/unnecessary_fold.rs:74:30 | LL | let _ = map.values().fold(0, |x, y| x + y); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `sum::()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:68:30 + --> $DIR/unnecessary_fold.rs:76:30 | LL | let _ = map.values().fold(1, |x, y| x * y); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `product::()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:69:35 + --> $DIR/unnecessary_fold.rs:78:35 | LL | let _: i32 = map.values().fold(0, |x, y| x + y); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `sum()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:70:35 + --> $DIR/unnecessary_fold.rs:80:35 | LL | let _: i32 = map.values().fold(1, |x, y| x * y); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `product()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:71:31 + --> $DIR/unnecessary_fold.rs:82:31 | LL | anything(map.values().fold(0, |x, y| x + y)); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `sum::()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:72:31 + --> $DIR/unnecessary_fold.rs:84:31 | LL | anything(map.values().fold(1, |x, y| x * y)); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `product::()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:73:26 + --> $DIR/unnecessary_fold.rs:86:26 | LL | num(map.values().fold(0, |x, y| x + y)); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `sum()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:74:26 + --> $DIR/unnecessary_fold.rs:88:26 | LL | num(map.values().fold(1, |x, y| x * y)); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `product()` diff --git a/tests/ui/unnecessary_iter_cloned.fixed b/tests/ui/unnecessary_iter_cloned.fixed index ad0e5fab029e..951ebfe4c795 100644 --- a/tests/ui/unnecessary_iter_cloned.fixed +++ b/tests/ui/unnecessary_iter_cloned.fixed @@ -26,6 +26,7 @@ fn main() { // `check_files` and its variants are based on: // https://github.com/breard-r/acmed/blob/1f0dcc32aadbc5e52de6d23b9703554c0f925113/acmed/src/storage.rs#L262 fn check_files(files: &[(FileType, &std::path::Path)]) -> bool { + //~v unnecessary_to_owned for (t, path) in files { let other = match get_file_path(t) { Ok(p) => p, @@ -41,6 +42,7 @@ fn check_files(files: &[(FileType, &std::path::Path)]) -> bool { } fn check_files_vec(files: Vec<(FileType, &std::path::Path)>) -> bool { + //~v unnecessary_to_owned for (t, path) in files.iter() { let other = match get_file_path(t) { Ok(p) => p, diff --git a/tests/ui/unnecessary_iter_cloned.rs b/tests/ui/unnecessary_iter_cloned.rs index d3d59c4c70f5..df86caf3766a 100644 --- a/tests/ui/unnecessary_iter_cloned.rs +++ b/tests/ui/unnecessary_iter_cloned.rs @@ -26,6 +26,7 @@ fn main() { // `check_files` and its variants are based on: // https://github.com/breard-r/acmed/blob/1f0dcc32aadbc5e52de6d23b9703554c0f925113/acmed/src/storage.rs#L262 fn check_files(files: &[(FileType, &std::path::Path)]) -> bool { + //~v unnecessary_to_owned for (t, path) in files.iter().copied() { let other = match get_file_path(&t) { Ok(p) => p, @@ -41,6 +42,7 @@ fn check_files(files: &[(FileType, &std::path::Path)]) -> bool { } fn check_files_vec(files: Vec<(FileType, &std::path::Path)>) -> bool { + //~v unnecessary_to_owned for (t, path) in files.iter().copied() { let other = match get_file_path(&t) { Ok(p) => p, diff --git a/tests/ui/unnecessary_iter_cloned.stderr b/tests/ui/unnecessary_iter_cloned.stderr index ba40c6c14db2..93cf5f7928c8 100644 --- a/tests/ui/unnecessary_iter_cloned.stderr +++ b/tests/ui/unnecessary_iter_cloned.stderr @@ -1,5 +1,5 @@ error: unnecessary use of `copied` - --> $DIR/unnecessary_iter_cloned.rs:29:22 + --> $DIR/unnecessary_iter_cloned.rs:30:22 | LL | for (t, path) in files.iter().copied() { | ^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL + let other = match get_file_path(t) { | error: unnecessary use of `copied` - --> $DIR/unnecessary_iter_cloned.rs:44:22 + --> $DIR/unnecessary_iter_cloned.rs:46:22 | LL | for (t, path) in files.iter().copied() { | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_join.fixed b/tests/ui/unnecessary_join.fixed index dab09be7ebd0..37c7a3c75207 100644 --- a/tests/ui/unnecessary_join.fixed +++ b/tests/ui/unnecessary_join.fixed @@ -7,6 +7,7 @@ fn main() { let output = vector .iter() .map(|item| item.to_uppercase()) + //~v unnecessary_join .collect::(); println!("{}", output); @@ -15,6 +16,7 @@ fn main() { let output = vector .iter() .map(|item| item.to_uppercase()) + //~v unnecessary_join .collect::(); println!("{}", output); diff --git a/tests/ui/unnecessary_join.rs b/tests/ui/unnecessary_join.rs index d042d9e5c212..6a8e152ad4ca 100644 --- a/tests/ui/unnecessary_join.rs +++ b/tests/ui/unnecessary_join.rs @@ -7,6 +7,7 @@ fn main() { let output = vector .iter() .map(|item| item.to_uppercase()) + //~v unnecessary_join .collect::>() .join(""); println!("{}", output); @@ -16,6 +17,7 @@ fn main() { let output = vector .iter() .map(|item| item.to_uppercase()) + //~v unnecessary_join .collect::>() .join(""); println!("{}", output); diff --git a/tests/ui/unnecessary_join.stderr b/tests/ui/unnecessary_join.stderr index 205a714b694a..12f10781342c 100644 --- a/tests/ui/unnecessary_join.stderr +++ b/tests/ui/unnecessary_join.stderr @@ -1,5 +1,5 @@ error: called `.collect::>().join("")` on an iterator - --> $DIR/unnecessary_join.rs:10:10 + --> $DIR/unnecessary_join.rs:11:10 | LL | .collect::>() | __________^ @@ -10,7 +10,7 @@ LL | | .join(""); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_join)]` error: called `.collect::>().join("")` on an iterator - --> $DIR/unnecessary_join.rs:19:10 + --> $DIR/unnecessary_join.rs:21:10 | LL | .collect::>() | __________^ diff --git a/tests/ui/unnecessary_lazy_eval.fixed b/tests/ui/unnecessary_lazy_eval.fixed index d8031c484e5e..3a332f3c6550 100644 --- a/tests/ui/unnecessary_lazy_eval.fixed +++ b/tests/ui/unnecessary_lazy_eval.fixed @@ -81,42 +81,65 @@ fn main() { // Should lint - Option let _ = opt.unwrap_or(2); + //~^ unnecessary_lazy_evaluations let _ = opt.unwrap_or(astronomers_pi); + //~^ unnecessary_lazy_evaluations let _ = opt.unwrap_or(ext_str.some_field); + //~^ unnecessary_lazy_evaluations let _ = opt.unwrap_or_else(|| ext_arr[0]); let _ = opt.and(ext_opt); + //~^ unnecessary_lazy_evaluations let _ = opt.or(ext_opt); - let _ = opt.or(None); + //~^ unnecessary_lazy_evaluations + let _ = opt.or(None); //~ unnecessary_lazy_evaluations let _ = opt.get_or_insert(2); - let _ = opt.ok_or(2); + //~^ unnecessary_lazy_evaluations + let _ = opt.ok_or(2); //~ unnecessary_lazy_evaluations let _ = nested_tuple_opt.unwrap_or(Some((1, 2))); + //~^ unnecessary_lazy_evaluations let _ = cond.then_some(astronomers_pi); - let _ = true.then_some({}); - let _ = true.then_some({}); + //~^ unnecessary_lazy_evaluations + let _ = true.then_some({}); //~ unnecessary_lazy_evaluations + let _ = true.then_some({}); //~ unnecessary_lazy_evaluations // Should lint - Builtin deref let r = &1; let _ = Some(1).unwrap_or(*r); + //~^ unnecessary_lazy_evaluations let b = Box::new(1); let _ = Some(1).unwrap_or(*b); + //~^ unnecessary_lazy_evaluations // Should lint - Builtin deref through autoderef let _ = Some(1).as_ref().unwrap_or(&r); + //~^ unnecessary_lazy_evaluations let _ = Some(1).as_ref().unwrap_or(&b); + //~^ unnecessary_lazy_evaluations // Cases when unwrap is not called on a simple variable let _ = Some(10).unwrap_or(2); + //~^ unnecessary_lazy_evaluations let _ = Some(10).and(ext_opt); + //~^ unnecessary_lazy_evaluations let _: Option = None.or(ext_opt); + //~^ unnecessary_lazy_evaluations let _ = None.get_or_insert(2); + //~^ unnecessary_lazy_evaluations let _: Result = None.ok_or(2); + //~^ unnecessary_lazy_evaluations let _: Option = None.or(None); + //~^ unnecessary_lazy_evaluations let mut deep = Deep(Some(42)); let _ = deep.0.unwrap_or(2); + //~^ unnecessary_lazy_evaluations let _ = deep.0.and(ext_opt); + //~^ unnecessary_lazy_evaluations let _ = deep.0.or(None); + //~^ unnecessary_lazy_evaluations let _ = deep.0.get_or_insert(2); + //~^ unnecessary_lazy_evaluations let _ = deep.0.ok_or(2); + //~^ unnecessary_lazy_evaluations // Should not lint - Option let _ = opt.unwrap_or_else(|| ext_str.return_some_field()); @@ -148,16 +171,22 @@ fn main() { // should lint, bind_instead_of_map doesn't apply let _: Option = None.or(Some(3)); + //~^ unnecessary_lazy_evaluations let _ = deep.0.or(Some(3)); + //~^ unnecessary_lazy_evaluations let _ = opt.or(Some(3)); + //~^ unnecessary_lazy_evaluations // Should lint - Result let res: Result = Err(5); let res2: Result = Err(SomeStruct { some_field: 5 }); let _ = res2.unwrap_or(2); + //~^ unnecessary_lazy_evaluations let _ = res2.unwrap_or(astronomers_pi); + //~^ unnecessary_lazy_evaluations let _ = res2.unwrap_or(ext_str.some_field); + //~^ unnecessary_lazy_evaluations // Should not lint - Result let _ = res.unwrap_or_else(|err| err); @@ -180,12 +209,20 @@ fn main() { // should lint, bind_instead_of_map doesn't apply let _: Result = res.and(Err(2)); + //~^ unnecessary_lazy_evaluations let _: Result = res.and(Err(astronomers_pi)); + //~^ unnecessary_lazy_evaluations let _: Result = res.and(Err(ext_str.some_field)); + //~^ unnecessary_lazy_evaluations let _: Result = res.or(Ok(2)); + //~^ unnecessary_lazy_evaluations let _: Result = res.or(Ok(astronomers_pi)); + //~^ unnecessary_lazy_evaluations let _: Result = res.or(Ok(ext_str.some_field)); + //~^ unnecessary_lazy_evaluations + + //~v unnecessary_lazy_evaluations let _: Result = res. // some lines // some lines diff --git a/tests/ui/unnecessary_lazy_eval.rs b/tests/ui/unnecessary_lazy_eval.rs index ea55b1d9a905..182ea1dbd97a 100644 --- a/tests/ui/unnecessary_lazy_eval.rs +++ b/tests/ui/unnecessary_lazy_eval.rs @@ -81,42 +81,65 @@ fn main() { // Should lint - Option let _ = opt.unwrap_or_else(|| 2); + //~^ unnecessary_lazy_evaluations let _ = opt.unwrap_or_else(|| astronomers_pi); + //~^ unnecessary_lazy_evaluations let _ = opt.unwrap_or_else(|| ext_str.some_field); + //~^ unnecessary_lazy_evaluations let _ = opt.unwrap_or_else(|| ext_arr[0]); let _ = opt.and_then(|_| ext_opt); + //~^ unnecessary_lazy_evaluations let _ = opt.or_else(|| ext_opt); - let _ = opt.or_else(|| None); + //~^ unnecessary_lazy_evaluations + let _ = opt.or_else(|| None); //~ unnecessary_lazy_evaluations let _ = opt.get_or_insert_with(|| 2); - let _ = opt.ok_or_else(|| 2); + //~^ unnecessary_lazy_evaluations + let _ = opt.ok_or_else(|| 2); //~ unnecessary_lazy_evaluations let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2))); + //~^ unnecessary_lazy_evaluations let _ = cond.then(|| astronomers_pi); - let _ = true.then(|| -> _ {}); - let _ = true.then(|| {}); + //~^ unnecessary_lazy_evaluations + let _ = true.then(|| -> _ {}); //~ unnecessary_lazy_evaluations + let _ = true.then(|| {}); //~ unnecessary_lazy_evaluations // Should lint - Builtin deref let r = &1; let _ = Some(1).unwrap_or_else(|| *r); + //~^ unnecessary_lazy_evaluations let b = Box::new(1); let _ = Some(1).unwrap_or_else(|| *b); + //~^ unnecessary_lazy_evaluations // Should lint - Builtin deref through autoderef let _ = Some(1).as_ref().unwrap_or_else(|| &r); + //~^ unnecessary_lazy_evaluations let _ = Some(1).as_ref().unwrap_or_else(|| &b); + //~^ unnecessary_lazy_evaluations // Cases when unwrap is not called on a simple variable let _ = Some(10).unwrap_or_else(|| 2); + //~^ unnecessary_lazy_evaluations let _ = Some(10).and_then(|_| ext_opt); + //~^ unnecessary_lazy_evaluations let _: Option = None.or_else(|| ext_opt); + //~^ unnecessary_lazy_evaluations let _ = None.get_or_insert_with(|| 2); + //~^ unnecessary_lazy_evaluations let _: Result = None.ok_or_else(|| 2); + //~^ unnecessary_lazy_evaluations let _: Option = None.or_else(|| None); + //~^ unnecessary_lazy_evaluations let mut deep = Deep(Some(42)); let _ = deep.0.unwrap_or_else(|| 2); + //~^ unnecessary_lazy_evaluations let _ = deep.0.and_then(|_| ext_opt); + //~^ unnecessary_lazy_evaluations let _ = deep.0.or_else(|| None); + //~^ unnecessary_lazy_evaluations let _ = deep.0.get_or_insert_with(|| 2); + //~^ unnecessary_lazy_evaluations let _ = deep.0.ok_or_else(|| 2); + //~^ unnecessary_lazy_evaluations // Should not lint - Option let _ = opt.unwrap_or_else(|| ext_str.return_some_field()); @@ -148,16 +171,22 @@ fn main() { // should lint, bind_instead_of_map doesn't apply let _: Option = None.or_else(|| Some(3)); + //~^ unnecessary_lazy_evaluations let _ = deep.0.or_else(|| Some(3)); + //~^ unnecessary_lazy_evaluations let _ = opt.or_else(|| Some(3)); + //~^ unnecessary_lazy_evaluations // Should lint - Result let res: Result = Err(5); let res2: Result = Err(SomeStruct { some_field: 5 }); let _ = res2.unwrap_or_else(|_| 2); + //~^ unnecessary_lazy_evaluations let _ = res2.unwrap_or_else(|_| astronomers_pi); + //~^ unnecessary_lazy_evaluations let _ = res2.unwrap_or_else(|_| ext_str.some_field); + //~^ unnecessary_lazy_evaluations // Should not lint - Result let _ = res.unwrap_or_else(|err| err); @@ -180,12 +209,20 @@ fn main() { // should lint, bind_instead_of_map doesn't apply let _: Result = res.and_then(|_| Err(2)); + //~^ unnecessary_lazy_evaluations let _: Result = res.and_then(|_| Err(astronomers_pi)); + //~^ unnecessary_lazy_evaluations let _: Result = res.and_then(|_| Err(ext_str.some_field)); + //~^ unnecessary_lazy_evaluations let _: Result = res.or_else(|_| Ok(2)); + //~^ unnecessary_lazy_evaluations let _: Result = res.or_else(|_| Ok(astronomers_pi)); + //~^ unnecessary_lazy_evaluations let _: Result = res.or_else(|_| Ok(ext_str.some_field)); + //~^ unnecessary_lazy_evaluations + + //~v unnecessary_lazy_evaluations let _: Result = res. // some lines // some lines diff --git a/tests/ui/unnecessary_lazy_eval.stderr b/tests/ui/unnecessary_lazy_eval.stderr index 6ff2691a4616..2001ad9936ba 100644 --- a/tests/ui/unnecessary_lazy_eval.stderr +++ b/tests/ui/unnecessary_lazy_eval.stderr @@ -10,7 +10,7 @@ LL | let _ = opt.unwrap_or_else(|| 2); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_lazy_evaluations)]` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:84:13 + --> $DIR/unnecessary_lazy_eval.rs:85:13 | LL | let _ = opt.unwrap_or_else(|| astronomers_pi); | ^^^^--------------------------------- @@ -18,7 +18,7 @@ LL | let _ = opt.unwrap_or_else(|| astronomers_pi); | help: use `unwrap_or(..)` instead: `unwrap_or(astronomers_pi)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:85:13 + --> $DIR/unnecessary_lazy_eval.rs:87:13 | LL | let _ = opt.unwrap_or_else(|| ext_str.some_field); | ^^^^------------------------------------- @@ -26,7 +26,7 @@ LL | let _ = opt.unwrap_or_else(|| ext_str.some_field); | help: use `unwrap_or(..)` instead: `unwrap_or(ext_str.some_field)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:87:13 + --> $DIR/unnecessary_lazy_eval.rs:90:13 | LL | let _ = opt.and_then(|_| ext_opt); | ^^^^--------------------- @@ -34,7 +34,7 @@ LL | let _ = opt.and_then(|_| ext_opt); | help: use `and(..)` instead: `and(ext_opt)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:88:13 + --> $DIR/unnecessary_lazy_eval.rs:92:13 | LL | let _ = opt.or_else(|| ext_opt); | ^^^^------------------- @@ -42,7 +42,7 @@ LL | let _ = opt.or_else(|| ext_opt); | help: use `or(..)` instead: `or(ext_opt)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:89:13 + --> $DIR/unnecessary_lazy_eval.rs:94:13 | LL | let _ = opt.or_else(|| None); | ^^^^---------------- @@ -50,7 +50,7 @@ LL | let _ = opt.or_else(|| None); | help: use `or(..)` instead: `or(None)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:90:13 + --> $DIR/unnecessary_lazy_eval.rs:95:13 | LL | let _ = opt.get_or_insert_with(|| 2); | ^^^^------------------------ @@ -58,7 +58,7 @@ LL | let _ = opt.get_or_insert_with(|| 2); | help: use `get_or_insert(..)` instead: `get_or_insert(2)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:91:13 + --> $DIR/unnecessary_lazy_eval.rs:97:13 | LL | let _ = opt.ok_or_else(|| 2); | ^^^^---------------- @@ -66,7 +66,7 @@ LL | let _ = opt.ok_or_else(|| 2); | help: use `ok_or(..)` instead: `ok_or(2)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:92:13 + --> $DIR/unnecessary_lazy_eval.rs:98:13 | LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2))); | ^^^^^^^^^^^^^^^^^------------------------------- @@ -74,7 +74,7 @@ LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2))); | help: use `unwrap_or(..)` instead: `unwrap_or(Some((1, 2)))` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:93:13 + --> $DIR/unnecessary_lazy_eval.rs:100:13 | LL | let _ = cond.then(|| astronomers_pi); | ^^^^^----------------------- @@ -82,7 +82,7 @@ LL | let _ = cond.then(|| astronomers_pi); | help: use `then_some(..)` instead: `then_some(astronomers_pi)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:94:13 + --> $DIR/unnecessary_lazy_eval.rs:102:13 | LL | let _ = true.then(|| -> _ {}); | ^^^^^---------------- @@ -90,7 +90,7 @@ LL | let _ = true.then(|| -> _ {}); | help: use `then_some(..)` instead: `then_some({})` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:95:13 + --> $DIR/unnecessary_lazy_eval.rs:103:13 | LL | let _ = true.then(|| {}); | ^^^^^----------- @@ -98,7 +98,7 @@ LL | let _ = true.then(|| {}); | help: use `then_some(..)` instead: `then_some({})` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:99:13 + --> $DIR/unnecessary_lazy_eval.rs:107:13 | LL | let _ = Some(1).unwrap_or_else(|| *r); | ^^^^^^^^--------------------- @@ -106,7 +106,7 @@ LL | let _ = Some(1).unwrap_or_else(|| *r); | help: use `unwrap_or(..)` instead: `unwrap_or(*r)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:101:13 + --> $DIR/unnecessary_lazy_eval.rs:110:13 | LL | let _ = Some(1).unwrap_or_else(|| *b); | ^^^^^^^^--------------------- @@ -114,7 +114,7 @@ LL | let _ = Some(1).unwrap_or_else(|| *b); | help: use `unwrap_or(..)` instead: `unwrap_or(*b)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:103:13 + --> $DIR/unnecessary_lazy_eval.rs:113:13 | LL | let _ = Some(1).as_ref().unwrap_or_else(|| &r); | ^^^^^^^^^^^^^^^^^--------------------- @@ -122,7 +122,7 @@ LL | let _ = Some(1).as_ref().unwrap_or_else(|| &r); | help: use `unwrap_or(..)` instead: `unwrap_or(&r)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:104:13 + --> $DIR/unnecessary_lazy_eval.rs:115:13 | LL | let _ = Some(1).as_ref().unwrap_or_else(|| &b); | ^^^^^^^^^^^^^^^^^--------------------- @@ -130,7 +130,7 @@ LL | let _ = Some(1).as_ref().unwrap_or_else(|| &b); | help: use `unwrap_or(..)` instead: `unwrap_or(&b)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:107:13 + --> $DIR/unnecessary_lazy_eval.rs:119:13 | LL | let _ = Some(10).unwrap_or_else(|| 2); | ^^^^^^^^^-------------------- @@ -138,7 +138,7 @@ LL | let _ = Some(10).unwrap_or_else(|| 2); | help: use `unwrap_or(..)` instead: `unwrap_or(2)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:108:13 + --> $DIR/unnecessary_lazy_eval.rs:121:13 | LL | let _ = Some(10).and_then(|_| ext_opt); | ^^^^^^^^^--------------------- @@ -146,7 +146,7 @@ LL | let _ = Some(10).and_then(|_| ext_opt); | help: use `and(..)` instead: `and(ext_opt)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:109:28 + --> $DIR/unnecessary_lazy_eval.rs:123:28 | LL | let _: Option = None.or_else(|| ext_opt); | ^^^^^------------------- @@ -154,7 +154,7 @@ LL | let _: Option = None.or_else(|| ext_opt); | help: use `or(..)` instead: `or(ext_opt)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:110:13 + --> $DIR/unnecessary_lazy_eval.rs:125:13 | LL | let _ = None.get_or_insert_with(|| 2); | ^^^^^------------------------ @@ -162,7 +162,7 @@ LL | let _ = None.get_or_insert_with(|| 2); | help: use `get_or_insert(..)` instead: `get_or_insert(2)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:111:35 + --> $DIR/unnecessary_lazy_eval.rs:127:35 | LL | let _: Result = None.ok_or_else(|| 2); | ^^^^^---------------- @@ -170,7 +170,7 @@ LL | let _: Result = None.ok_or_else(|| 2); | help: use `ok_or(..)` instead: `ok_or(2)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:112:28 + --> $DIR/unnecessary_lazy_eval.rs:129:28 | LL | let _: Option = None.or_else(|| None); | ^^^^^---------------- @@ -178,7 +178,7 @@ LL | let _: Option = None.or_else(|| None); | help: use `or(..)` instead: `or(None)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:115:13 + --> $DIR/unnecessary_lazy_eval.rs:133:13 | LL | let _ = deep.0.unwrap_or_else(|| 2); | ^^^^^^^-------------------- @@ -186,7 +186,7 @@ LL | let _ = deep.0.unwrap_or_else(|| 2); | help: use `unwrap_or(..)` instead: `unwrap_or(2)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:116:13 + --> $DIR/unnecessary_lazy_eval.rs:135:13 | LL | let _ = deep.0.and_then(|_| ext_opt); | ^^^^^^^--------------------- @@ -194,7 +194,7 @@ LL | let _ = deep.0.and_then(|_| ext_opt); | help: use `and(..)` instead: `and(ext_opt)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:117:13 + --> $DIR/unnecessary_lazy_eval.rs:137:13 | LL | let _ = deep.0.or_else(|| None); | ^^^^^^^---------------- @@ -202,7 +202,7 @@ LL | let _ = deep.0.or_else(|| None); | help: use `or(..)` instead: `or(None)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:118:13 + --> $DIR/unnecessary_lazy_eval.rs:139:13 | LL | let _ = deep.0.get_or_insert_with(|| 2); | ^^^^^^^------------------------ @@ -210,7 +210,7 @@ LL | let _ = deep.0.get_or_insert_with(|| 2); | help: use `get_or_insert(..)` instead: `get_or_insert(2)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:119:13 + --> $DIR/unnecessary_lazy_eval.rs:141:13 | LL | let _ = deep.0.ok_or_else(|| 2); | ^^^^^^^---------------- @@ -218,7 +218,7 @@ LL | let _ = deep.0.ok_or_else(|| 2); | help: use `ok_or(..)` instead: `ok_or(2)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:150:28 + --> $DIR/unnecessary_lazy_eval.rs:173:28 | LL | let _: Option = None.or_else(|| Some(3)); | ^^^^^------------------- @@ -226,7 +226,7 @@ LL | let _: Option = None.or_else(|| Some(3)); | help: use `or(..)` instead: `or(Some(3))` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:151:13 + --> $DIR/unnecessary_lazy_eval.rs:175:13 | LL | let _ = deep.0.or_else(|| Some(3)); | ^^^^^^^------------------- @@ -234,7 +234,7 @@ LL | let _ = deep.0.or_else(|| Some(3)); | help: use `or(..)` instead: `or(Some(3))` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:152:13 + --> $DIR/unnecessary_lazy_eval.rs:177:13 | LL | let _ = opt.or_else(|| Some(3)); | ^^^^------------------- @@ -242,7 +242,7 @@ LL | let _ = opt.or_else(|| Some(3)); | help: use `or(..)` instead: `or(Some(3))` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:158:13 + --> $DIR/unnecessary_lazy_eval.rs:184:13 | LL | let _ = res2.unwrap_or_else(|_| 2); | ^^^^^--------------------- @@ -250,7 +250,7 @@ LL | let _ = res2.unwrap_or_else(|_| 2); | help: use `unwrap_or(..)` instead: `unwrap_or(2)` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:159:13 + --> $DIR/unnecessary_lazy_eval.rs:186:13 | LL | let _ = res2.unwrap_or_else(|_| astronomers_pi); | ^^^^^---------------------------------- @@ -258,7 +258,7 @@ LL | let _ = res2.unwrap_or_else(|_| astronomers_pi); | help: use `unwrap_or(..)` instead: `unwrap_or(astronomers_pi)` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:160:13 + --> $DIR/unnecessary_lazy_eval.rs:188:13 | LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field); | ^^^^^-------------------------------------- @@ -266,7 +266,7 @@ LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field); | help: use `unwrap_or(..)` instead: `unwrap_or(ext_str.some_field)` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:182:35 + --> $DIR/unnecessary_lazy_eval.rs:211:35 | LL | let _: Result = res.and_then(|_| Err(2)); | ^^^^-------------------- @@ -274,7 +274,7 @@ LL | let _: Result = res.and_then(|_| Err(2)); | help: use `and(..)` instead: `and(Err(2))` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:183:35 + --> $DIR/unnecessary_lazy_eval.rs:213:35 | LL | let _: Result = res.and_then(|_| Err(astronomers_pi)); | ^^^^--------------------------------- @@ -282,7 +282,7 @@ LL | let _: Result = res.and_then(|_| Err(astronomers_pi)); | help: use `and(..)` instead: `and(Err(astronomers_pi))` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:184:35 + --> $DIR/unnecessary_lazy_eval.rs:215:35 | LL | let _: Result = res.and_then(|_| Err(ext_str.some_field)); | ^^^^------------------------------------- @@ -290,7 +290,7 @@ LL | let _: Result = res.and_then(|_| Err(ext_str.some_field)) | help: use `and(..)` instead: `and(Err(ext_str.some_field))` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:186:35 + --> $DIR/unnecessary_lazy_eval.rs:218:35 | LL | let _: Result = res.or_else(|_| Ok(2)); | ^^^^------------------ @@ -298,7 +298,7 @@ LL | let _: Result = res.or_else(|_| Ok(2)); | help: use `or(..)` instead: `or(Ok(2))` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:187:35 + --> $DIR/unnecessary_lazy_eval.rs:220:35 | LL | let _: Result = res.or_else(|_| Ok(astronomers_pi)); | ^^^^------------------------------- @@ -306,7 +306,7 @@ LL | let _: Result = res.or_else(|_| Ok(astronomers_pi)); | help: use `or(..)` instead: `or(Ok(astronomers_pi))` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:188:35 + --> $DIR/unnecessary_lazy_eval.rs:222:35 | LL | let _: Result = res.or_else(|_| Ok(ext_str.some_field)); | ^^^^----------------------------------- @@ -314,7 +314,7 @@ LL | let _: Result = res.or_else(|_| Ok(ext_str.some_field)); | help: use `or(..)` instead: `or(Ok(ext_str.some_field))` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:189:35 + --> $DIR/unnecessary_lazy_eval.rs:226:35 | LL | let _: Result = res. | ___________________________________^ @@ -329,7 +329,7 @@ LL | | or_else(|_| Ok(ext_str.some_field)); | help: use `or(..)` instead: `or(Ok(ext_str.some_field))` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:219:14 + --> $DIR/unnecessary_lazy_eval.rs:256:14 | LL | let _x = false.then(|| i32::MAX + 1); | ^^^^^^--------------------- @@ -337,7 +337,7 @@ LL | let _x = false.then(|| i32::MAX + 1); | help: use `then_some(..)` instead: `then_some(i32::MAX + 1)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:221:14 + --> $DIR/unnecessary_lazy_eval.rs:258:14 | LL | let _x = false.then(|| i32::MAX * 2); | ^^^^^^--------------------- @@ -345,7 +345,7 @@ LL | let _x = false.then(|| i32::MAX * 2); | help: use `then_some(..)` instead: `then_some(i32::MAX * 2)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:223:14 + --> $DIR/unnecessary_lazy_eval.rs:260:14 | LL | let _x = false.then(|| i32::MAX - 1); | ^^^^^^--------------------- @@ -353,7 +353,7 @@ LL | let _x = false.then(|| i32::MAX - 1); | help: use `then_some(..)` instead: `then_some(i32::MAX - 1)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:225:14 + --> $DIR/unnecessary_lazy_eval.rs:262:14 | LL | let _x = false.then(|| i32::MIN - 1); | ^^^^^^--------------------- @@ -361,7 +361,7 @@ LL | let _x = false.then(|| i32::MIN - 1); | help: use `then_some(..)` instead: `then_some(i32::MIN - 1)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:227:14 + --> $DIR/unnecessary_lazy_eval.rs:264:14 | LL | let _x = false.then(|| (1 + 2 * 3 - 2 / 3 + 9) << 2); | ^^^^^^------------------------------------- @@ -369,7 +369,7 @@ LL | let _x = false.then(|| (1 + 2 * 3 - 2 / 3 + 9) << 2); | help: use `then_some(..)` instead: `then_some((1 + 2 * 3 - 2 / 3 + 9) << 2)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:229:14 + --> $DIR/unnecessary_lazy_eval.rs:266:14 | LL | let _x = false.then(|| 255u8 << 7); | ^^^^^^------------------- @@ -377,7 +377,7 @@ LL | let _x = false.then(|| 255u8 << 7); | help: use `then_some(..)` instead: `then_some(255u8 << 7)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:231:14 + --> $DIR/unnecessary_lazy_eval.rs:268:14 | LL | let _x = false.then(|| 255u8 << 8); | ^^^^^^------------------- @@ -385,7 +385,7 @@ LL | let _x = false.then(|| 255u8 << 8); | help: use `then_some(..)` instead: `then_some(255u8 << 8)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:233:14 + --> $DIR/unnecessary_lazy_eval.rs:270:14 | LL | let _x = false.then(|| 255u8 >> 8); | ^^^^^^------------------- @@ -393,7 +393,7 @@ LL | let _x = false.then(|| 255u8 >> 8); | help: use `then_some(..)` instead: `then_some(255u8 >> 8)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:236:14 + --> $DIR/unnecessary_lazy_eval.rs:273:14 | LL | let _x = false.then(|| i32::MAX + -1); | ^^^^^^---------------------- @@ -401,7 +401,7 @@ LL | let _x = false.then(|| i32::MAX + -1); | help: use `then_some(..)` instead: `then_some(i32::MAX + -1)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:238:14 + --> $DIR/unnecessary_lazy_eval.rs:275:14 | LL | let _x = false.then(|| -i32::MAX); | ^^^^^^------------------ @@ -409,7 +409,7 @@ LL | let _x = false.then(|| -i32::MAX); | help: use `then_some(..)` instead: `then_some(-i32::MAX)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:240:14 + --> $DIR/unnecessary_lazy_eval.rs:277:14 | LL | let _x = false.then(|| -i32::MIN); | ^^^^^^------------------ @@ -417,7 +417,7 @@ LL | let _x = false.then(|| -i32::MIN); | help: use `then_some(..)` instead: `then_some(-i32::MIN)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:243:14 + --> $DIR/unnecessary_lazy_eval.rs:280:14 | LL | let _x = false.then(|| 255 >> -7); | ^^^^^^------------------ @@ -425,7 +425,7 @@ LL | let _x = false.then(|| 255 >> -7); | help: use `then_some(..)` instead: `then_some(255 >> -7)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:245:14 + --> $DIR/unnecessary_lazy_eval.rs:282:14 | LL | let _x = false.then(|| 255 << -1); | ^^^^^^------------------ @@ -433,7 +433,7 @@ LL | let _x = false.then(|| 255 << -1); | help: use `then_some(..)` instead: `then_some(255 << -1)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:247:14 + --> $DIR/unnecessary_lazy_eval.rs:284:14 | LL | let _x = false.then(|| 1 / 0); | ^^^^^^-------------- @@ -441,7 +441,7 @@ LL | let _x = false.then(|| 1 / 0); | help: use `then_some(..)` instead: `then_some(1 / 0)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:249:14 + --> $DIR/unnecessary_lazy_eval.rs:286:14 | LL | let _x = false.then(|| x << -1); | ^^^^^^---------------- @@ -449,7 +449,7 @@ LL | let _x = false.then(|| x << -1); | help: use `then_some(..)` instead: `then_some(x << -1)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:251:14 + --> $DIR/unnecessary_lazy_eval.rs:288:14 | LL | let _x = false.then(|| x << 2); | ^^^^^^--------------- @@ -457,7 +457,7 @@ LL | let _x = false.then(|| x << 2); | help: use `then_some(..)` instead: `then_some(x << 2)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:261:14 + --> $DIR/unnecessary_lazy_eval.rs:298:14 | LL | let _x = false.then(|| x / 0); | ^^^^^^-------------- @@ -465,7 +465,7 @@ LL | let _x = false.then(|| x / 0); | help: use `then_some(..)` instead: `then_some(x / 0)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:263:14 + --> $DIR/unnecessary_lazy_eval.rs:300:14 | LL | let _x = false.then(|| x % 0); | ^^^^^^-------------- @@ -473,7 +473,7 @@ LL | let _x = false.then(|| x % 0); | help: use `then_some(..)` instead: `then_some(x % 0)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:266:14 + --> $DIR/unnecessary_lazy_eval.rs:303:14 | LL | let _x = false.then(|| 1 / -1); | ^^^^^^--------------- @@ -481,7 +481,7 @@ LL | let _x = false.then(|| 1 / -1); | help: use `then_some(..)` instead: `then_some(1 / -1)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:268:14 + --> $DIR/unnecessary_lazy_eval.rs:305:14 | LL | let _x = false.then(|| i32::MIN / -1); | ^^^^^^---------------------- @@ -489,7 +489,7 @@ LL | let _x = false.then(|| i32::MIN / -1); | help: use `then_some(..)` instead: `then_some(i32::MIN / -1)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:271:14 + --> $DIR/unnecessary_lazy_eval.rs:308:14 | LL | let _x = false.then(|| i32::MIN / 0); | ^^^^^^--------------------- @@ -497,7 +497,7 @@ LL | let _x = false.then(|| i32::MIN / 0); | help: use `then_some(..)` instead: `then_some(i32::MIN / 0)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:273:14 + --> $DIR/unnecessary_lazy_eval.rs:310:14 | LL | let _x = false.then(|| 4 / 2); | ^^^^^^-------------- @@ -505,7 +505,7 @@ LL | let _x = false.then(|| 4 / 2); | help: use `then_some(..)` instead: `then_some(4 / 2)` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:281:14 + --> $DIR/unnecessary_lazy_eval.rs:318:14 | LL | let _x = false.then(|| f1 + f2); | ^^^^^^---------------- diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.rs b/tests/ui/unnecessary_lazy_eval_unfixable.rs index 412d4aaafb4a..26b6114ce091 100644 --- a/tests/ui/unnecessary_lazy_eval_unfixable.rs +++ b/tests/ui/unnecessary_lazy_eval_unfixable.rs @@ -29,4 +29,5 @@ fn main() { fn issue11672() { // Return type annotation helps type inference and removing it can break code let _ = true.then(|| -> &[u8] { &[] }); + //~^ unnecessary_lazy_evaluations } diff --git a/tests/ui/unnecessary_literal_unwrap.fixed b/tests/ui/unnecessary_literal_unwrap.fixed index b17343aa9ba5..268b454360d7 100644 --- a/tests/ui/unnecessary_literal_unwrap.fixed +++ b/tests/ui/unnecessary_literal_unwrap.fixed @@ -8,74 +8,106 @@ )] fn unwrap_option_some() { + let _val = 1; //~ unnecessary_literal_unwrap let _val = 1; - let _val = 1; + //~^ unnecessary_literal_unwrap + 1; //~ unnecessary_literal_unwrap 1; - 1; + //~^ unnecessary_literal_unwrap } #[rustfmt::skip] // force rustfmt not to remove braces in `|| { 234 }` fn unwrap_option_none() { - let _val = panic!(); + let _val = panic!(); //~ unnecessary_literal_unwrap let _val = panic!("this always happens"); + //~^ unnecessary_literal_unwrap let _val: String = String::default(); + //~^ unnecessary_literal_unwrap let _val: u16 = 234; + //~^ unnecessary_literal_unwrap let _val: u16 = 234; + //~^ unnecessary_literal_unwrap let _val: u16 = { 234 }; + //~^ unnecessary_literal_unwrap let _val: u16 = { 234 }; + //~^ unnecessary_literal_unwrap - panic!(); + panic!(); //~ unnecessary_literal_unwrap panic!("this always happens"); + //~^ unnecessary_literal_unwrap String::default(); + //~^ unnecessary_literal_unwrap + 234; //~ unnecessary_literal_unwrap 234; - 234; + //~^ unnecessary_literal_unwrap { 234 }; + //~^ unnecessary_literal_unwrap { 234 }; + //~^ unnecessary_literal_unwrap } fn unwrap_result_ok() { let _val = 1; + //~^ unnecessary_literal_unwrap let _val = 1; + //~^ unnecessary_literal_unwrap let _val = panic!("{:?}", 1); + //~^ unnecessary_literal_unwrap let _val = panic!("{1}: {:?}", 1, "this always happens"); + //~^ unnecessary_literal_unwrap + 1; //~ unnecessary_literal_unwrap 1; - 1; - panic!("{:?}", 1); + //~^ unnecessary_literal_unwrap + panic!("{:?}", 1); //~ unnecessary_literal_unwrap panic!("{1}: {:?}", 1, "this always happens"); + //~^ unnecessary_literal_unwrap } fn unwrap_result_err() { let _val = 1; + //~^ unnecessary_literal_unwrap let _val = 1; + //~^ unnecessary_literal_unwrap let _val = panic!("{:?}", 1); + //~^ unnecessary_literal_unwrap let _val = panic!("{1}: {:?}", 1, "this always happens"); + //~^ unnecessary_literal_unwrap + 1; //~ unnecessary_literal_unwrap 1; - 1; - panic!("{:?}", 1); + //~^ unnecessary_literal_unwrap + panic!("{:?}", 1); //~ unnecessary_literal_unwrap panic!("{1}: {:?}", 1, "this always happens"); + //~^ unnecessary_literal_unwrap } fn unwrap_methods_option() { + let _val = 1; //~ unnecessary_literal_unwrap let _val = 1; + //~^ unnecessary_literal_unwrap let _val = 1; - let _val = 1; + //~^ unnecessary_literal_unwrap - 1; - 1; - 1; + 1; //~ unnecessary_literal_unwrap + 1; //~ unnecessary_literal_unwrap + 1; //~ unnecessary_literal_unwrap } fn unwrap_methods_result() { let _val = 1; + //~^ unnecessary_literal_unwrap let _val = 1; + //~^ unnecessary_literal_unwrap let _val = 1; + //~^ unnecessary_literal_unwrap + 1; //~ unnecessary_literal_unwrap 1; + //~^ unnecessary_literal_unwrap 1; - 1; + //~^ unnecessary_literal_unwrap } fn unwrap_from_binding() { @@ -90,12 +122,20 @@ fn unwrap_from_binding() { fn unwrap_unchecked() { let _ = 1; + //~^ unnecessary_literal_unwrap + + //~v unnecessary_literal_unwrap let _ = unsafe { 1 + *(&1 as *const i32) }; // needs to keep the unsafe block let _ = 1 + 1; + //~^ unnecessary_literal_unwrap let _ = 1; + //~^ unnecessary_literal_unwrap let _ = unsafe { 1 + *(&1 as *const i32) }; + //~^ unnecessary_literal_unwrap let _ = 1 + 1; + //~^ unnecessary_literal_unwrap let _ = 123; + //~^ unnecessary_literal_unwrap } fn main() { diff --git a/tests/ui/unnecessary_literal_unwrap.rs b/tests/ui/unnecessary_literal_unwrap.rs index 7bd8deea4d1b..dbda997a3606 100644 --- a/tests/ui/unnecessary_literal_unwrap.rs +++ b/tests/ui/unnecessary_literal_unwrap.rs @@ -8,74 +8,106 @@ )] fn unwrap_option_some() { - let _val = Some(1).unwrap(); + let _val = Some(1).unwrap(); //~ unnecessary_literal_unwrap let _val = Some(1).expect("this never happens"); + //~^ unnecessary_literal_unwrap - Some(1).unwrap(); + Some(1).unwrap(); //~ unnecessary_literal_unwrap Some(1).expect("this never happens"); + //~^ unnecessary_literal_unwrap } #[rustfmt::skip] // force rustfmt not to remove braces in `|| { 234 }` fn unwrap_option_none() { - let _val = None::<()>.unwrap(); + let _val = None::<()>.unwrap(); //~ unnecessary_literal_unwrap let _val = None::<()>.expect("this always happens"); + //~^ unnecessary_literal_unwrap let _val: String = None.unwrap_or_default(); + //~^ unnecessary_literal_unwrap let _val: u16 = None.unwrap_or(234); + //~^ unnecessary_literal_unwrap let _val: u16 = None.unwrap_or_else(|| 234); + //~^ unnecessary_literal_unwrap let _val: u16 = None.unwrap_or_else(|| { 234 }); + //~^ unnecessary_literal_unwrap let _val: u16 = None.unwrap_or_else(|| -> u16 { 234 }); + //~^ unnecessary_literal_unwrap - None::<()>.unwrap(); + None::<()>.unwrap(); //~ unnecessary_literal_unwrap None::<()>.expect("this always happens"); + //~^ unnecessary_literal_unwrap None::.unwrap_or_default(); - None::.unwrap_or(234); + //~^ unnecessary_literal_unwrap + None::.unwrap_or(234); //~ unnecessary_literal_unwrap None::.unwrap_or_else(|| 234); + //~^ unnecessary_literal_unwrap None::.unwrap_or_else(|| { 234 }); + //~^ unnecessary_literal_unwrap None::.unwrap_or_else(|| -> u16 { 234 }); + //~^ unnecessary_literal_unwrap } fn unwrap_result_ok() { let _val = Ok::<_, ()>(1).unwrap(); + //~^ unnecessary_literal_unwrap let _val = Ok::<_, ()>(1).expect("this never happens"); + //~^ unnecessary_literal_unwrap let _val = Ok::<_, ()>(1).unwrap_err(); + //~^ unnecessary_literal_unwrap let _val = Ok::<_, ()>(1).expect_err("this always happens"); + //~^ unnecessary_literal_unwrap - Ok::<_, ()>(1).unwrap(); + Ok::<_, ()>(1).unwrap(); //~ unnecessary_literal_unwrap Ok::<_, ()>(1).expect("this never happens"); - Ok::<_, ()>(1).unwrap_err(); + //~^ unnecessary_literal_unwrap + Ok::<_, ()>(1).unwrap_err(); //~ unnecessary_literal_unwrap Ok::<_, ()>(1).expect_err("this always happens"); + //~^ unnecessary_literal_unwrap } fn unwrap_result_err() { let _val = Err::<(), _>(1).unwrap_err(); + //~^ unnecessary_literal_unwrap let _val = Err::<(), _>(1).expect_err("this never happens"); + //~^ unnecessary_literal_unwrap let _val = Err::<(), _>(1).unwrap(); + //~^ unnecessary_literal_unwrap let _val = Err::<(), _>(1).expect("this always happens"); + //~^ unnecessary_literal_unwrap - Err::<(), _>(1).unwrap_err(); + Err::<(), _>(1).unwrap_err(); //~ unnecessary_literal_unwrap Err::<(), _>(1).expect_err("this never happens"); - Err::<(), _>(1).unwrap(); + //~^ unnecessary_literal_unwrap + Err::<(), _>(1).unwrap(); //~ unnecessary_literal_unwrap Err::<(), _>(1).expect("this always happens"); + //~^ unnecessary_literal_unwrap } fn unwrap_methods_option() { - let _val = Some(1).unwrap_or(2); + let _val = Some(1).unwrap_or(2); //~ unnecessary_literal_unwrap let _val = Some(1).unwrap_or_default(); + //~^ unnecessary_literal_unwrap let _val = Some(1).unwrap_or_else(|| 2); + //~^ unnecessary_literal_unwrap - Some(1).unwrap_or(2); - Some(1).unwrap_or_default(); - Some(1).unwrap_or_else(|| 2); + Some(1).unwrap_or(2); //~ unnecessary_literal_unwrap + Some(1).unwrap_or_default(); //~ unnecessary_literal_unwrap + Some(1).unwrap_or_else(|| 2); //~ unnecessary_literal_unwrap } fn unwrap_methods_result() { let _val = Ok::<_, ()>(1).unwrap_or(2); + //~^ unnecessary_literal_unwrap let _val = Ok::<_, ()>(1).unwrap_or_default(); + //~^ unnecessary_literal_unwrap let _val = Ok::<_, ()>(1).unwrap_or_else(|_| 2); + //~^ unnecessary_literal_unwrap - Ok::<_, ()>(1).unwrap_or(2); + Ok::<_, ()>(1).unwrap_or(2); //~ unnecessary_literal_unwrap Ok::<_, ()>(1).unwrap_or_default(); + //~^ unnecessary_literal_unwrap Ok::<_, ()>(1).unwrap_or_else(|_| 2); + //~^ unnecessary_literal_unwrap } fn unwrap_from_binding() { @@ -90,12 +122,20 @@ fn unwrap_from_binding() { fn unwrap_unchecked() { let _ = unsafe { Some(1).unwrap_unchecked() }; + //~^ unnecessary_literal_unwrap + + //~v unnecessary_literal_unwrap let _ = unsafe { Some(1).unwrap_unchecked() + *(&1 as *const i32) }; // needs to keep the unsafe block let _ = unsafe { Some(1).unwrap_unchecked() } + 1; + //~^ unnecessary_literal_unwrap let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() }; + //~^ unnecessary_literal_unwrap let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() + *(&1 as *const i32) }; + //~^ unnecessary_literal_unwrap let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() } + 1; + //~^ unnecessary_literal_unwrap let _ = unsafe { Err::<(), i32>(123).unwrap_err_unchecked() }; + //~^ unnecessary_literal_unwrap } fn main() { diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr index 4940091be60a..7199be4015ac 100644 --- a/tests/ui/unnecessary_literal_unwrap.stderr +++ b/tests/ui/unnecessary_literal_unwrap.stderr @@ -25,7 +25,7 @@ LL + let _val = 1; | error: used `unwrap()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:14:5 + --> $DIR/unnecessary_literal_unwrap.rs:15:5 | LL | Some(1).unwrap(); | ^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + 1; | error: used `expect()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:15:5 + --> $DIR/unnecessary_literal_unwrap.rs:16:5 | LL | Some(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,13 +49,13 @@ LL + 1; | error: used `unwrap()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:20:16 + --> $DIR/unnecessary_literal_unwrap.rs:22:16 | LL | let _val = None::<()>.unwrap(); | ^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap()`: `panic!()` error: used `expect()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:21:16 + --> $DIR/unnecessary_literal_unwrap.rs:23:16 | LL | let _val = None::<()>.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -66,13 +66,13 @@ LL | let _val = panic!("this always happens"); | ~~~~~~~ ~ error: used `unwrap_or_default()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:22:24 + --> $DIR/unnecessary_literal_unwrap.rs:25:24 | LL | let _val: String = None.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `String::default()` error: used `unwrap_or()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:23:21 + --> $DIR/unnecessary_literal_unwrap.rs:27:21 | LL | let _val: u16 = None.unwrap_or(234); | ^^^^^^^^^^^^^^^^^^^ @@ -84,7 +84,7 @@ LL + let _val: u16 = 234; | error: used `unwrap_or_else()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:24:21 + --> $DIR/unnecessary_literal_unwrap.rs:29:21 | LL | let _val: u16 = None.unwrap_or_else(|| 234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL + let _val: u16 = 234; | error: used `unwrap_or_else()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:25:21 + --> $DIR/unnecessary_literal_unwrap.rs:31:21 | LL | let _val: u16 = None.unwrap_or_else(|| { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL + let _val: u16 = { 234 }; | error: used `unwrap_or_else()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:26:21 + --> $DIR/unnecessary_literal_unwrap.rs:33:21 | LL | let _val: u16 = None.unwrap_or_else(|| -> u16 { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,13 +120,13 @@ LL + let _val: u16 = { 234 }; | error: used `unwrap()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:28:5 + --> $DIR/unnecessary_literal_unwrap.rs:36:5 | LL | None::<()>.unwrap(); | ^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap()`: `panic!()` error: used `expect()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:29:5 + --> $DIR/unnecessary_literal_unwrap.rs:37:5 | LL | None::<()>.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -137,13 +137,13 @@ LL | panic!("this always happens"); | ~~~~~~~ ~ error: used `unwrap_or_default()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:30:5 + --> $DIR/unnecessary_literal_unwrap.rs:39:5 | LL | None::.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `String::default()` error: used `unwrap_or()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:31:5 + --> $DIR/unnecessary_literal_unwrap.rs:41:5 | LL | None::.unwrap_or(234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -155,7 +155,7 @@ LL + 234; | error: used `unwrap_or_else()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:32:5 + --> $DIR/unnecessary_literal_unwrap.rs:42:5 | LL | None::.unwrap_or_else(|| 234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -167,7 +167,7 @@ LL + 234; | error: used `unwrap_or_else()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:33:5 + --> $DIR/unnecessary_literal_unwrap.rs:44:5 | LL | None::.unwrap_or_else(|| { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -179,7 +179,7 @@ LL + { 234 }; | error: used `unwrap_or_else()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:34:5 + --> $DIR/unnecessary_literal_unwrap.rs:46:5 | LL | None::.unwrap_or_else(|| -> u16 { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -191,7 +191,7 @@ LL + { 234 }; | error: used `unwrap()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:38:16 + --> $DIR/unnecessary_literal_unwrap.rs:51:16 | LL | let _val = Ok::<_, ()>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -203,7 +203,7 @@ LL + let _val = 1; | error: used `expect()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:39:16 + --> $DIR/unnecessary_literal_unwrap.rs:53:16 | LL | let _val = Ok::<_, ()>(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -215,7 +215,7 @@ LL + let _val = 1; | error: used `unwrap_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:40:16 + --> $DIR/unnecessary_literal_unwrap.rs:55:16 | LL | let _val = Ok::<_, ()>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -226,7 +226,7 @@ LL | let _val = panic!("{:?}", 1); | ~~~~~~~~~~~~~~ ~ error: used `expect_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:41:16 + --> $DIR/unnecessary_literal_unwrap.rs:57:16 | LL | let _val = Ok::<_, ()>(1).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -237,7 +237,7 @@ LL | let _val = panic!("{1}: {:?}", 1, "this always happens"); | ~~~~~~~~~~~~~~~~~~~ ~ error: used `unwrap()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:43:5 + --> $DIR/unnecessary_literal_unwrap.rs:60:5 | LL | Ok::<_, ()>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -249,7 +249,7 @@ LL + 1; | error: used `expect()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:44:5 + --> $DIR/unnecessary_literal_unwrap.rs:61:5 | LL | Ok::<_, ()>(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -261,7 +261,7 @@ LL + 1; | error: used `unwrap_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:45:5 + --> $DIR/unnecessary_literal_unwrap.rs:63:5 | LL | Ok::<_, ()>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -272,7 +272,7 @@ LL | panic!("{:?}", 1); | ~~~~~~~~~~~~~~ ~ error: used `expect_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:46:5 + --> $DIR/unnecessary_literal_unwrap.rs:64:5 | LL | Ok::<_, ()>(1).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -283,7 +283,7 @@ LL | panic!("{1}: {:?}", 1, "this always happens"); | ~~~~~~~~~~~~~~~~~~~ ~ error: used `unwrap_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:50:16 + --> $DIR/unnecessary_literal_unwrap.rs:69:16 | LL | let _val = Err::<(), _>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -295,7 +295,7 @@ LL + let _val = 1; | error: used `expect_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:51:16 + --> $DIR/unnecessary_literal_unwrap.rs:71:16 | LL | let _val = Err::<(), _>(1).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -307,7 +307,7 @@ LL + let _val = 1; | error: used `unwrap()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:52:16 + --> $DIR/unnecessary_literal_unwrap.rs:73:16 | LL | let _val = Err::<(), _>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -318,7 +318,7 @@ LL | let _val = panic!("{:?}", 1); | ~~~~~~~~~~~~~~ ~ error: used `expect()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:53:16 + --> $DIR/unnecessary_literal_unwrap.rs:75:16 | LL | let _val = Err::<(), _>(1).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -329,7 +329,7 @@ LL | let _val = panic!("{1}: {:?}", 1, "this always happens"); | ~~~~~~~~~~~~~~~~~~~ ~ error: used `unwrap_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:55:5 + --> $DIR/unnecessary_literal_unwrap.rs:78:5 | LL | Err::<(), _>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -341,7 +341,7 @@ LL + 1; | error: used `expect_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:56:5 + --> $DIR/unnecessary_literal_unwrap.rs:79:5 | LL | Err::<(), _>(1).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -353,7 +353,7 @@ LL + 1; | error: used `unwrap()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:57:5 + --> $DIR/unnecessary_literal_unwrap.rs:81:5 | LL | Err::<(), _>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -364,7 +364,7 @@ LL | panic!("{:?}", 1); | ~~~~~~~~~~~~~~ ~ error: used `expect()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:58:5 + --> $DIR/unnecessary_literal_unwrap.rs:82:5 | LL | Err::<(), _>(1).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -375,7 +375,7 @@ LL | panic!("{1}: {:?}", 1, "this always happens"); | ~~~~~~~~~~~~~~~~~~~ ~ error: used `unwrap_or()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:62:16 + --> $DIR/unnecessary_literal_unwrap.rs:87:16 | LL | let _val = Some(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^ @@ -387,7 +387,7 @@ LL + let _val = 1; | error: used `unwrap_or_default()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:63:16 + --> $DIR/unnecessary_literal_unwrap.rs:88:16 | LL | let _val = Some(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -399,7 +399,7 @@ LL + let _val = 1; | error: used `unwrap_or_else()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:64:16 + --> $DIR/unnecessary_literal_unwrap.rs:90:16 | LL | let _val = Some(1).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -411,7 +411,7 @@ LL + let _val = 1; | error: used `unwrap_or()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:66:5 + --> $DIR/unnecessary_literal_unwrap.rs:93:5 | LL | Some(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^ @@ -423,7 +423,7 @@ LL + 1; | error: used `unwrap_or_default()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:67:5 + --> $DIR/unnecessary_literal_unwrap.rs:94:5 | LL | Some(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -435,7 +435,7 @@ LL + 1; | error: used `unwrap_or_else()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:68:5 + --> $DIR/unnecessary_literal_unwrap.rs:95:5 | LL | Some(1).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -447,7 +447,7 @@ LL + 1; | error: used `unwrap_or()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:72:16 + --> $DIR/unnecessary_literal_unwrap.rs:99:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -459,7 +459,7 @@ LL + let _val = 1; | error: used `unwrap_or_default()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:73:16 + --> $DIR/unnecessary_literal_unwrap.rs:101:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -471,7 +471,7 @@ LL + let _val = 1; | error: used `unwrap_or_else()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:74:16 + --> $DIR/unnecessary_literal_unwrap.rs:103:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -483,7 +483,7 @@ LL + let _val = 1; | error: used `unwrap_or()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:76:5 + --> $DIR/unnecessary_literal_unwrap.rs:106:5 | LL | Ok::<_, ()>(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -495,7 +495,7 @@ LL + 1; | error: used `unwrap_or_default()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:77:5 + --> $DIR/unnecessary_literal_unwrap.rs:107:5 | LL | Ok::<_, ()>(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -507,7 +507,7 @@ LL + 1; | error: used `unwrap_or_else()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:78:5 + --> $DIR/unnecessary_literal_unwrap.rs:109:5 | LL | Ok::<_, ()>(1).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -519,7 +519,7 @@ LL + 1; | error: used `unwrap_unchecked()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:92:22 + --> $DIR/unnecessary_literal_unwrap.rs:124:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -531,7 +531,7 @@ LL + let _ = 1; | error: used `unwrap_unchecked()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:93:22 + --> $DIR/unnecessary_literal_unwrap.rs:128:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() + *(&1 as *const i32) }; // needs to keep the unsafe block | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -543,7 +543,7 @@ LL + let _ = unsafe { 1 + *(&1 as *const i32) }; // needs to keep the unsafe | error: used `unwrap_unchecked()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:94:22 + --> $DIR/unnecessary_literal_unwrap.rs:129:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() } + 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -555,7 +555,7 @@ LL + let _ = 1 + 1; | error: used `unwrap_unchecked()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:95:22 + --> $DIR/unnecessary_literal_unwrap.rs:131:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -567,7 +567,7 @@ LL + let _ = 1; | error: used `unwrap_unchecked()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:96:22 + --> $DIR/unnecessary_literal_unwrap.rs:133:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() + *(&1 as *const i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -579,7 +579,7 @@ LL + let _ = unsafe { 1 + *(&1 as *const i32) }; | error: used `unwrap_unchecked()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:97:22 + --> $DIR/unnecessary_literal_unwrap.rs:135:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() } + 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -591,7 +591,7 @@ LL + let _ = 1 + 1; | error: used `unwrap_err_unchecked()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:98:22 + --> $DIR/unnecessary_literal_unwrap.rs:137:22 | LL | let _ = unsafe { Err::<(), i32>(123).unwrap_err_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_map_on_constructor.fixed b/tests/ui/unnecessary_map_on_constructor.fixed index d0ba7ed749e4..37d94c19e3a6 100644 --- a/tests/ui/unnecessary_map_on_constructor.fixed +++ b/tests/ui/unnecessary_map_on_constructor.fixed @@ -29,15 +29,22 @@ fn main() { let b: SimpleResult = Ok(x); let c: SimpleResult = Err(err); - let a = Some(fun(x)); + let a = Some(fun(x)); //~ unnecessary_map_on_constructor let b: SimpleResult = Ok(fun(x)); + //~^ unnecessary_map_on_constructor let c: SimpleResult = Err(notfun(err)); + //~^ unnecessary_map_on_constructor let a = Option::Some(fun(x)); + //~^ unnecessary_map_on_constructor let b: SimpleResult = SimpleResult::Ok(fun(x)); + //~^ unnecessary_map_on_constructor let c: SimpleResult = SimpleResult::Err(notfun(err)); + //~^ unnecessary_map_on_constructor let b: std::result::Result = Ok(fun(x)); + //~^ unnecessary_map_on_constructor let c: std::result::Result = Err(notfun(err)); + //~^ unnecessary_map_on_constructor let a = Some(fun(x)); let b: SimpleResult = Ok(fun(x)); diff --git a/tests/ui/unnecessary_map_on_constructor.rs b/tests/ui/unnecessary_map_on_constructor.rs index e89e7aad4c40..5109236e4ad6 100644 --- a/tests/ui/unnecessary_map_on_constructor.rs +++ b/tests/ui/unnecessary_map_on_constructor.rs @@ -29,15 +29,22 @@ fn main() { let b: SimpleResult = Ok(x); let c: SimpleResult = Err(err); - let a = Some(x).map(fun); + let a = Some(x).map(fun); //~ unnecessary_map_on_constructor let b: SimpleResult = Ok(x).map(fun); + //~^ unnecessary_map_on_constructor let c: SimpleResult = Err(err).map_err(notfun); + //~^ unnecessary_map_on_constructor let a = Option::Some(x).map(fun); + //~^ unnecessary_map_on_constructor let b: SimpleResult = SimpleResult::Ok(x).map(fun); + //~^ unnecessary_map_on_constructor let c: SimpleResult = SimpleResult::Err(err).map_err(notfun); + //~^ unnecessary_map_on_constructor let b: std::result::Result = Ok(x).map(fun); + //~^ unnecessary_map_on_constructor let c: std::result::Result = Err(err).map_err(notfun); + //~^ unnecessary_map_on_constructor let a = Some(fun(x)); let b: SimpleResult = Ok(fun(x)); diff --git a/tests/ui/unnecessary_map_on_constructor.stderr b/tests/ui/unnecessary_map_on_constructor.stderr index d522b68d8726..1137cc0d4b9d 100644 --- a/tests/ui/unnecessary_map_on_constructor.stderr +++ b/tests/ui/unnecessary_map_on_constructor.stderr @@ -14,37 +14,37 @@ LL | let b: SimpleResult = Ok(x).map(fun); | ^^^^^^^^^^^^^^ help: try: `Ok(fun(x))` error: unnecessary map_err on constructor Err(_) - --> $DIR/unnecessary_map_on_constructor.rs:34:27 + --> $DIR/unnecessary_map_on_constructor.rs:35:27 | LL | let c: SimpleResult = Err(err).map_err(notfun); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Err(notfun(err))` error: unnecessary map on constructor Option::Some(_) - --> $DIR/unnecessary_map_on_constructor.rs:36:13 + --> $DIR/unnecessary_map_on_constructor.rs:38:13 | LL | let a = Option::Some(x).map(fun); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Option::Some(fun(x))` error: unnecessary map on constructor SimpleResult::Ok(_) - --> $DIR/unnecessary_map_on_constructor.rs:37:27 + --> $DIR/unnecessary_map_on_constructor.rs:40:27 | LL | let b: SimpleResult = SimpleResult::Ok(x).map(fun); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `SimpleResult::Ok(fun(x))` error: unnecessary map_err on constructor SimpleResult::Err(_) - --> $DIR/unnecessary_map_on_constructor.rs:38:27 + --> $DIR/unnecessary_map_on_constructor.rs:42:27 | LL | let c: SimpleResult = SimpleResult::Err(err).map_err(notfun); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `SimpleResult::Err(notfun(err))` error: unnecessary map on constructor Ok(_) - --> $DIR/unnecessary_map_on_constructor.rs:39:52 + --> $DIR/unnecessary_map_on_constructor.rs:44:52 | LL | let b: std::result::Result = Ok(x).map(fun); | ^^^^^^^^^^^^^^ help: try: `Ok(fun(x))` error: unnecessary map_err on constructor Err(_) - --> $DIR/unnecessary_map_on_constructor.rs:40:52 + --> $DIR/unnecessary_map_on_constructor.rs:46:52 | LL | let c: std::result::Result = Err(err).map_err(notfun); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Err(notfun(err))` diff --git a/tests/ui/unnecessary_operation.fixed b/tests/ui/unnecessary_operation.fixed index 11761c6c90e3..de91d31940a8 100644 --- a/tests/ui/unnecessary_operation.fixed +++ b/tests/ui/unnecessary_operation.fixed @@ -67,24 +67,27 @@ where } fn main() { + get_number(); //~ unnecessary_operation + get_number(); //~ unnecessary_operation + get_struct(); //~ unnecessary_operation + get_number(); //~ unnecessary_operation + get_number(); //~ unnecessary_operation + 5;get_number(); //~ unnecessary_operation + get_number(); //~ unnecessary_operation + get_number(); //~ unnecessary_operation + 5;6;get_number(); //~ unnecessary_operation + get_number(); //~ unnecessary_operation + get_number(); //~ unnecessary_operation + 5;get_number(); //~ unnecessary_operation + 42;get_number(); //~ unnecessary_operation + assert!([42, 55].len() > get_usize()); //~ unnecessary_operation + 42;get_number(); //~ unnecessary_operation + get_number(); //~ unnecessary_operation + assert!([42; 55].len() > get_usize()); //~ unnecessary_operation + + //~v unnecessary_operation get_number(); - get_number(); - get_struct(); - get_number(); - get_number(); - 5;get_number(); - get_number(); - get_number(); - 5;6;get_number(); - get_number(); - get_number(); - 5;get_number(); - 42;get_number(); - assert!([42, 55].len() > get_usize()); - 42;get_number(); - get_number(); - assert!([42; 55].len() > get_usize()); - get_number(); + //~v unnecessary_operation String::from("blah"); // Do not warn diff --git a/tests/ui/unnecessary_operation.rs b/tests/ui/unnecessary_operation.rs index de0081289ac3..6be74dc7c274 100644 --- a/tests/ui/unnecessary_operation.rs +++ b/tests/ui/unnecessary_operation.rs @@ -67,26 +67,29 @@ where } fn main() { - Tuple(get_number()); - Struct { field: get_number() }; - Struct { ..get_struct() }; - Enum::Tuple(get_number()); - Enum::Struct { field: get_number() }; - 5 + get_number(); - *&get_number(); - &get_number(); - (5, 6, get_number()); - get_number()..; - ..get_number(); - 5..get_number(); - [42, get_number()]; - [42, 55][get_usize()]; - (42, get_number()).1; - [get_number(); 55]; - [42; 55][get_usize()]; + Tuple(get_number()); //~ unnecessary_operation + Struct { field: get_number() }; //~ unnecessary_operation + Struct { ..get_struct() }; //~ unnecessary_operation + Enum::Tuple(get_number()); //~ unnecessary_operation + Enum::Struct { field: get_number() }; //~ unnecessary_operation + 5 + get_number(); //~ unnecessary_operation + *&get_number(); //~ unnecessary_operation + &get_number(); //~ unnecessary_operation + (5, 6, get_number()); //~ unnecessary_operation + get_number()..; //~ unnecessary_operation + ..get_number(); //~ unnecessary_operation + 5..get_number(); //~ unnecessary_operation + [42, get_number()]; //~ unnecessary_operation + [42, 55][get_usize()]; //~ unnecessary_operation + (42, get_number()).1; //~ unnecessary_operation + [get_number(); 55]; //~ unnecessary_operation + [42; 55][get_usize()]; //~ unnecessary_operation + + //~v unnecessary_operation { get_number() }; + //~v unnecessary_operation FooString { s: String::from("blah"), }; diff --git a/tests/ui/unnecessary_operation.stderr b/tests/ui/unnecessary_operation.stderr index eeee9ad60068..004dfdd4faec 100644 --- a/tests/ui/unnecessary_operation.stderr +++ b/tests/ui/unnecessary_operation.stderr @@ -104,7 +104,7 @@ LL | [42; 55][get_usize()]; | ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42; 55].len() > get_usize());` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:87:5 + --> $DIR/unnecessary_operation.rs:89:5 | LL | / { LL | | get_number() @@ -112,7 +112,7 @@ LL | | }; | |______^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:90:5 + --> $DIR/unnecessary_operation.rs:93:5 | LL | / FooString { LL | | s: String::from("blah"), diff --git a/tests/ui/unnecessary_owned_empty_strings.fixed b/tests/ui/unnecessary_owned_empty_strings.fixed index 75cd63db8a1a..dc0e495be30f 100644 --- a/tests/ui/unnecessary_owned_empty_strings.fixed +++ b/tests/ui/unnecessary_owned_empty_strings.fixed @@ -8,10 +8,12 @@ fn ref_string_argument(_value: &String) {} fn main() { // should be linted ref_str_argument(""); + //~^ unnecessary_owned_empty_strings // should be linted #[allow(clippy::manual_string_new)] ref_str_argument(""); + //~^ unnecessary_owned_empty_strings // should not be linted ref_str_argument(""); diff --git a/tests/ui/unnecessary_owned_empty_strings.rs b/tests/ui/unnecessary_owned_empty_strings.rs index 2edc0bd86d38..e2c5de447444 100644 --- a/tests/ui/unnecessary_owned_empty_strings.rs +++ b/tests/ui/unnecessary_owned_empty_strings.rs @@ -8,10 +8,12 @@ fn ref_string_argument(_value: &String) {} fn main() { // should be linted ref_str_argument(&String::new()); + //~^ unnecessary_owned_empty_strings // should be linted #[allow(clippy::manual_string_new)] ref_str_argument(&String::from("")); + //~^ unnecessary_owned_empty_strings // should not be linted ref_str_argument(""); diff --git a/tests/ui/unnecessary_owned_empty_strings.stderr b/tests/ui/unnecessary_owned_empty_strings.stderr index 58d925b1096d..2e212e63edb0 100644 --- a/tests/ui/unnecessary_owned_empty_strings.stderr +++ b/tests/ui/unnecessary_owned_empty_strings.stderr @@ -8,7 +8,7 @@ LL | ref_str_argument(&String::new()); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_owned_empty_strings)]` error: usage of `&String::from("")` for a function expecting a `&str` argument - --> $DIR/unnecessary_owned_empty_strings.rs:14:22 + --> $DIR/unnecessary_owned_empty_strings.rs:15:22 | LL | ref_str_argument(&String::from("")); | ^^^^^^^^^^^^^^^^^ help: try: `""` diff --git a/tests/ui/unnecessary_safety_comment.rs b/tests/ui/unnecessary_safety_comment.rs index bdc6fa0f46bb..80591bad6f85 100644 --- a/tests/ui/unnecessary_safety_comment.rs +++ b/tests/ui/unnecessary_safety_comment.rs @@ -35,7 +35,7 @@ mod unnecessary_from_macro { macro_rules! with_safety_comment { ($t:ty) => { // Safety: unnecessary - impl T for $t {} + impl T for $t {} //~ unnecessary_safety_comment }; } diff --git a/tests/ui/unnecessary_self_imports.fixed b/tests/ui/unnecessary_self_imports.fixed index c265dcd2414f..e4df0e775937 100644 --- a/tests/ui/unnecessary_self_imports.fixed +++ b/tests/ui/unnecessary_self_imports.fixed @@ -2,8 +2,8 @@ #![allow(unused_imports, dead_code)] use std::collections::hash_map::{self, *}; -use std::fs as alias; +use std::fs as alias; //~ unnecessary_self_imports use std::io::{self, Read}; -use std::rc; +use std::rc; //~ unnecessary_self_imports fn main() {} diff --git a/tests/ui/unnecessary_self_imports.rs b/tests/ui/unnecessary_self_imports.rs index c3fcf7c951a1..d90bda65b7bf 100644 --- a/tests/ui/unnecessary_self_imports.rs +++ b/tests/ui/unnecessary_self_imports.rs @@ -2,8 +2,8 @@ #![allow(unused_imports, dead_code)] use std::collections::hash_map::{self, *}; -use std::fs::{self as alias}; +use std::fs::{self as alias}; //~ unnecessary_self_imports use std::io::{self, Read}; -use std::rc::{self}; +use std::rc::{self}; //~ unnecessary_self_imports fn main() {} diff --git a/tests/ui/unnecessary_sort_by.fixed b/tests/ui/unnecessary_sort_by.fixed index 6b667e00c978..5040f0d656b7 100644 --- a/tests/ui/unnecessary_sort_by.fixed +++ b/tests/ui/unnecessary_sort_by.fixed @@ -9,14 +9,18 @@ fn unnecessary_sort_by() { let mut vec: Vec = vec![3, 6, 1, 2, 5]; // Forward examples - vec.sort(); - vec.sort_unstable(); + vec.sort(); //~ unnecessary_sort_by + vec.sort_unstable(); //~ unnecessary_sort_by vec.sort_by_key(|a| (a + 5).abs()); + //~^ unnecessary_sort_by vec.sort_unstable_by_key(|a| id(-a)); + //~^ unnecessary_sort_by // Reverse examples vec.sort_by(|a, b| b.cmp(a)); // not linted to avoid suggesting `Reverse(b)` which would borrow vec.sort_by_key(|b| std::cmp::Reverse((b + 5).abs())); + //~^ unnecessary_sort_by vec.sort_unstable_by_key(|b| std::cmp::Reverse(id(-b))); + //~^ unnecessary_sort_by // Negative examples (shouldn't be changed) let c = &7; vec.sort_by(|a, b| (b - a).cmp(&(a - b))); @@ -27,7 +31,9 @@ fn unnecessary_sort_by() { // Vectors of references are fine as long as the resulting key does not borrow let mut vec: Vec<&&&isize> = vec![&&&3, &&&6, &&&1, &&&2, &&&5]; vec.sort_by_key(|a| (***a).abs()); + //~^ unnecessary_sort_by vec.sort_unstable_by_key(|a| (***a).abs()); + //~^ unnecessary_sort_by // `Reverse(b)` would borrow in the following cases, don't lint vec.sort_by(|a, b| b.cmp(a)); vec.sort_unstable_by(|a, b| b.cmp(a)); @@ -87,10 +93,14 @@ mod issue_6001 { // Forward args.sort_by_key(|a| a.name()); + //~^ unnecessary_sort_by args.sort_unstable_by_key(|a| a.name()); + //~^ unnecessary_sort_by // Reverse args.sort_by_key(|b| std::cmp::Reverse(b.name())); + //~^ unnecessary_sort_by args.sort_unstable_by_key(|b| std::cmp::Reverse(b.name())); + //~^ unnecessary_sort_by } } diff --git a/tests/ui/unnecessary_sort_by.rs b/tests/ui/unnecessary_sort_by.rs index 0ff20fb9ef28..4ee1da53cfe2 100644 --- a/tests/ui/unnecessary_sort_by.rs +++ b/tests/ui/unnecessary_sort_by.rs @@ -9,14 +9,18 @@ fn unnecessary_sort_by() { let mut vec: Vec = vec![3, 6, 1, 2, 5]; // Forward examples - vec.sort_by(|a, b| a.cmp(b)); - vec.sort_unstable_by(|a, b| a.cmp(b)); + vec.sort_by(|a, b| a.cmp(b)); //~ unnecessary_sort_by + vec.sort_unstable_by(|a, b| a.cmp(b)); //~ unnecessary_sort_by vec.sort_by(|a, b| (a + 5).abs().cmp(&(b + 5).abs())); + //~^ unnecessary_sort_by vec.sort_unstable_by(|a, b| id(-a).cmp(&id(-b))); + //~^ unnecessary_sort_by // Reverse examples vec.sort_by(|a, b| b.cmp(a)); // not linted to avoid suggesting `Reverse(b)` which would borrow vec.sort_by(|a, b| (b + 5).abs().cmp(&(a + 5).abs())); + //~^ unnecessary_sort_by vec.sort_unstable_by(|a, b| id(-b).cmp(&id(-a))); + //~^ unnecessary_sort_by // Negative examples (shouldn't be changed) let c = &7; vec.sort_by(|a, b| (b - a).cmp(&(a - b))); @@ -27,7 +31,9 @@ fn unnecessary_sort_by() { // Vectors of references are fine as long as the resulting key does not borrow let mut vec: Vec<&&&isize> = vec![&&&3, &&&6, &&&1, &&&2, &&&5]; vec.sort_by(|a, b| (***a).abs().cmp(&(***b).abs())); + //~^ unnecessary_sort_by vec.sort_unstable_by(|a, b| (***a).abs().cmp(&(***b).abs())); + //~^ unnecessary_sort_by // `Reverse(b)` would borrow in the following cases, don't lint vec.sort_by(|a, b| b.cmp(a)); vec.sort_unstable_by(|a, b| b.cmp(a)); @@ -87,10 +93,14 @@ mod issue_6001 { // Forward args.sort_by(|a, b| a.name().cmp(&b.name())); + //~^ unnecessary_sort_by args.sort_unstable_by(|a, b| a.name().cmp(&b.name())); + //~^ unnecessary_sort_by // Reverse args.sort_by(|a, b| b.name().cmp(&a.name())); + //~^ unnecessary_sort_by args.sort_unstable_by(|a, b| b.name().cmp(&a.name())); + //~^ unnecessary_sort_by } } diff --git a/tests/ui/unnecessary_sort_by.stderr b/tests/ui/unnecessary_sort_by.stderr index f4409113a45f..5d9a55f34e4a 100644 --- a/tests/ui/unnecessary_sort_by.stderr +++ b/tests/ui/unnecessary_sort_by.stderr @@ -20,55 +20,55 @@ LL | vec.sort_by(|a, b| (a + 5).abs().cmp(&(b + 5).abs())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_by_key(|a| (a + 5).abs())` error: consider using `sort_by_key` - --> $DIR/unnecessary_sort_by.rs:15:5 + --> $DIR/unnecessary_sort_by.rs:16:5 | LL | vec.sort_unstable_by(|a, b| id(-a).cmp(&id(-b))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable_by_key(|a| id(-a))` error: consider using `sort_by_key` - --> $DIR/unnecessary_sort_by.rs:18:5 + --> $DIR/unnecessary_sort_by.rs:20:5 | LL | vec.sort_by(|a, b| (b + 5).abs().cmp(&(a + 5).abs())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_by_key(|b| std::cmp::Reverse((b + 5).abs()))` error: consider using `sort_by_key` - --> $DIR/unnecessary_sort_by.rs:19:5 + --> $DIR/unnecessary_sort_by.rs:22:5 | LL | vec.sort_unstable_by(|a, b| id(-b).cmp(&id(-a))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable_by_key(|b| std::cmp::Reverse(id(-b)))` error: consider using `sort_by_key` - --> $DIR/unnecessary_sort_by.rs:29:5 + --> $DIR/unnecessary_sort_by.rs:33:5 | LL | vec.sort_by(|a, b| (***a).abs().cmp(&(***b).abs())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_by_key(|a| (***a).abs())` error: consider using `sort_by_key` - --> $DIR/unnecessary_sort_by.rs:30:5 + --> $DIR/unnecessary_sort_by.rs:35:5 | LL | vec.sort_unstable_by(|a, b| (***a).abs().cmp(&(***b).abs())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable_by_key(|a| (***a).abs())` error: consider using `sort_by_key` - --> $DIR/unnecessary_sort_by.rs:89:9 + --> $DIR/unnecessary_sort_by.rs:95:9 | LL | args.sort_by(|a, b| a.name().cmp(&b.name())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_by_key(|a| a.name())` error: consider using `sort_by_key` - --> $DIR/unnecessary_sort_by.rs:90:9 + --> $DIR/unnecessary_sort_by.rs:97:9 | LL | args.sort_unstable_by(|a, b| a.name().cmp(&b.name())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_unstable_by_key(|a| a.name())` error: consider using `sort_by_key` - --> $DIR/unnecessary_sort_by.rs:92:9 + --> $DIR/unnecessary_sort_by.rs:100:9 | LL | args.sort_by(|a, b| b.name().cmp(&a.name())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_by_key(|b| std::cmp::Reverse(b.name()))` error: consider using `sort_by_key` - --> $DIR/unnecessary_sort_by.rs:93:9 + --> $DIR/unnecessary_sort_by.rs:102:9 | LL | args.sort_unstable_by(|a, b| b.name().cmp(&a.name())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_unstable_by_key(|b| std::cmp::Reverse(b.name()))` diff --git a/tests/ui/unnecessary_struct_initialization.fixed b/tests/ui/unnecessary_struct_initialization.fixed index f3cf65da2d6a..20b7e6ee9030 100644 --- a/tests/ui/unnecessary_struct_initialization.fixed +++ b/tests/ui/unnecessary_struct_initialization.fixed @@ -29,17 +29,17 @@ struct V { impl Clone for V { fn clone(&self) -> Self { // Lint: `Self` implements `Copy` - *self + *self //~ unnecessary_struct_initialization } } fn main() { // Should lint: `a` would be consumed anyway let a = S { f: String::from("foo") }; - let mut b = a; + let mut b = a; //~ unnecessary_struct_initialization // Should lint: `b` would be consumed, and is mutable - let c = &mut b; + let c = &mut b; //~ unnecessary_struct_initialization // Should not lint as `d` is not mutable let d = S { f: String::from("foo") }; @@ -47,9 +47,10 @@ fn main() { // Should lint as `f` would be consumed anyway let f = S { f: String::from("foo") }; - let g = &f; + let g = &f; //~ unnecessary_struct_initialization // Should lint: the result of an expression is mutable + //~v unnecessary_struct_initialization let h = &mut *Box::new(S { f: String::from("foo") }); // Should not lint: `m` would be both alive and borrowed @@ -67,5 +68,6 @@ fn main() { assert_eq!(m.f, 17); // Should lint: the result of an expression is mutable and temporary + //~v unnecessary_struct_initialization let p = &mut *Box::new(T { f: 5 }); } diff --git a/tests/ui/unnecessary_struct_initialization.rs b/tests/ui/unnecessary_struct_initialization.rs index bd5302f9d85d..0a2c571609af 100644 --- a/tests/ui/unnecessary_struct_initialization.rs +++ b/tests/ui/unnecessary_struct_initialization.rs @@ -29,17 +29,17 @@ struct V { impl Clone for V { fn clone(&self) -> Self { // Lint: `Self` implements `Copy` - Self { ..*self } + Self { ..*self } //~ unnecessary_struct_initialization } } fn main() { // Should lint: `a` would be consumed anyway let a = S { f: String::from("foo") }; - let mut b = S { ..a }; + let mut b = S { ..a }; //~ unnecessary_struct_initialization // Should lint: `b` would be consumed, and is mutable - let c = &mut S { ..b }; + let c = &mut S { ..b }; //~ unnecessary_struct_initialization // Should not lint as `d` is not mutable let d = S { f: String::from("foo") }; @@ -47,9 +47,10 @@ fn main() { // Should lint as `f` would be consumed anyway let f = S { f: String::from("foo") }; - let g = &S { ..f }; + let g = &S { ..f }; //~ unnecessary_struct_initialization // Should lint: the result of an expression is mutable + //~v unnecessary_struct_initialization let h = &mut S { ..*Box::new(S { f: String::from("foo") }) }; @@ -69,6 +70,7 @@ fn main() { assert_eq!(m.f, 17); // Should lint: the result of an expression is mutable and temporary + //~v unnecessary_struct_initialization let p = &mut T { ..*Box::new(T { f: 5 }) }; diff --git a/tests/ui/unnecessary_struct_initialization.stderr b/tests/ui/unnecessary_struct_initialization.stderr index d8e0ce6ccaf2..77dc784b360e 100644 --- a/tests/ui/unnecessary_struct_initialization.stderr +++ b/tests/ui/unnecessary_struct_initialization.stderr @@ -26,7 +26,7 @@ LL | let g = &S { ..f }; | ^^^^^^^^^ help: replace with: `f` error: unnecessary struct building - --> $DIR/unnecessary_struct_initialization.rs:53:18 + --> $DIR/unnecessary_struct_initialization.rs:54:18 | LL | let h = &mut S { | __________________^ @@ -35,7 +35,7 @@ LL | | }; | |_____^ help: replace with: `*Box::new(S { f: String::from("foo") })` error: unnecessary struct building - --> $DIR/unnecessary_struct_initialization.rs:72:18 + --> $DIR/unnecessary_struct_initialization.rs:74:18 | LL | let p = &mut T { | __________________^ diff --git a/tests/ui/unnecessary_to_owned.fixed b/tests/ui/unnecessary_to_owned.fixed index 7f01c981a938..c457f4529635 100644 --- a/tests/ui/unnecessary_to_owned.fixed +++ b/tests/ui/unnecessary_to_owned.fixed @@ -62,82 +62,123 @@ fn main() { let x_ref = &x; require_c_str(&Cow::from(c_str)); - require_c_str(c_str); + //~^ unnecessary_to_owned + require_c_str(c_str); //~ unnecessary_to_owned - require_os_str(os_str); + require_os_str(os_str); //~ unnecessary_to_owned require_os_str(&Cow::from(os_str)); - require_os_str(os_str); + //~^ unnecessary_to_owned + require_os_str(os_str); //~ unnecessary_to_owned - require_path(path); + require_path(path); //~ unnecessary_to_owned require_path(&Cow::from(path)); - require_path(path); + //~^ unnecessary_to_owned + require_path(path); //~ unnecessary_to_owned - require_str(s); + require_str(s); //~ unnecessary_to_owned require_str(&Cow::from(s)); - require_str(s); - require_str(x_ref.as_ref()); + //~^ unnecessary_to_owned + require_str(s); //~ unnecessary_to_owned + require_str(x_ref.as_ref()); //~ unnecessary_to_owned - require_slice(slice); + require_slice(slice); //~ unnecessary_to_owned require_slice(&Cow::from(slice)); - require_slice(array.as_ref()); - require_slice(array_ref.as_ref()); - require_slice(slice); + //~^ unnecessary_to_owned + require_slice(array.as_ref()); //~ unnecessary_to_owned + require_slice(array_ref.as_ref()); //~ unnecessary_to_owned + require_slice(slice); //~ unnecessary_to_owned require_slice(&x_ref.to_owned()); // No longer flagged because of #8759. require_x(&Cow::::Owned(x.clone())); + //~^ unnecessary_to_owned require_x(&x_ref.to_owned()); // No longer flagged because of #8759. - require_deref_c_str(c_str); + require_deref_c_str(c_str); //~ unnecessary_to_owned require_deref_os_str(os_str); - require_deref_path(path); - require_deref_str(s); - require_deref_slice(slice); + //~^ unnecessary_to_owned + require_deref_path(path); //~ unnecessary_to_owned + require_deref_str(s); //~ unnecessary_to_owned + require_deref_slice(slice); //~ unnecessary_to_owned require_impl_deref_c_str(c_str); + //~^ unnecessary_to_owned require_impl_deref_os_str(os_str); + //~^ unnecessary_to_owned require_impl_deref_path(path); - require_impl_deref_str(s); + //~^ unnecessary_to_owned + require_impl_deref_str(s); //~ unnecessary_to_owned require_impl_deref_slice(slice); + //~^ unnecessary_to_owned require_deref_str_slice(s, slice); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_deref_slice_str(slice, s); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned - require_as_ref_c_str(c_str); + require_as_ref_c_str(c_str); //~ unnecessary_to_owned require_as_ref_os_str(os_str); - require_as_ref_path(path); - require_as_ref_str(s); - require_as_ref_str(&x); - require_as_ref_slice(array); + //~^ unnecessary_to_owned + require_as_ref_path(path); //~ unnecessary_to_owned + require_as_ref_str(s); //~ unnecessary_to_owned + require_as_ref_str(&x); //~ unnecessary_to_owned + require_as_ref_slice(array); //~ unnecessary_to_owned require_as_ref_slice(array_ref); - require_as_ref_slice(slice); + //~^ unnecessary_to_owned + require_as_ref_slice(slice); //~ unnecessary_to_owned require_impl_as_ref_c_str(c_str); + //~^ unnecessary_to_owned require_impl_as_ref_os_str(os_str); + //~^ unnecessary_to_owned require_impl_as_ref_path(path); - require_impl_as_ref_str(s); - require_impl_as_ref_str(&x); + //~^ unnecessary_to_owned + require_impl_as_ref_str(s); //~ unnecessary_to_owned + require_impl_as_ref_str(&x); //~ unnecessary_to_owned require_impl_as_ref_slice(array); + //~^ unnecessary_to_owned require_impl_as_ref_slice(array_ref); + //~^ unnecessary_to_owned require_impl_as_ref_slice(slice); + //~^ unnecessary_to_owned require_as_ref_str_slice(s, array); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_str_slice(s, array_ref); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_str_slice(s, slice); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_slice_str(array, s); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_slice_str(array_ref, s); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_slice_str(slice, s); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned - let _ = x.join(x_ref); + let _ = x.join(x_ref); //~ unnecessary_to_owned - let _ = slice.iter().copied(); - let _ = slice.iter().copied(); + let _ = slice.iter().copied(); //~ unnecessary_to_owned + let _ = slice.iter().copied(); //~ unnecessary_to_owned let _ = [std::path::PathBuf::new()][..].iter().cloned(); + //~^ unnecessary_to_owned let _ = [std::path::PathBuf::new()][..].iter().cloned(); + //~^ unnecessary_to_owned let _ = slice.iter().copied(); + //~^ unnecessary_to_owned let _ = slice.iter().copied(); + //~^ unnecessary_to_owned let _ = [std::path::PathBuf::new()][..].iter().cloned(); + //~^ unnecessary_to_owned let _ = [std::path::PathBuf::new()][..].iter().cloned(); + //~^ unnecessary_to_owned let _ = check_files(&[FileType::Account]); @@ -153,10 +194,14 @@ fn main() { // The following should be flagged by `redundant_clone`, but not by this lint. require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap()); + //~^ redundant_clone require_os_str(&OsString::from("x")); + //~^ redundant_clone require_path(&std::path::PathBuf::from("x")); - require_str(&String::from("x")); + //~^ redundant_clone + require_str(&String::from("x")); //~ redundant_clone require_slice(&[String::from("x")]); + //~^ redundant_clone } fn require_c_str(_: &CStr) {} @@ -199,6 +244,7 @@ fn require_as_ref_slice_str, V: AsRef>(_: U, _: V) {} // `check_files` is based on: // https://github.com/breard-r/acmed/blob/1f0dcc32aadbc5e52de6d23b9703554c0f925113/acmed/src/storage.rs#L262 fn check_files(file_types: &[FileType]) -> bool { + //~v unnecessary_to_owned for t in file_types { let path = match get_file_path(t) { Ok(p) => p, @@ -223,11 +269,13 @@ fn require_string(_: &String) {} fn _msrv_1_35() { // `copied` was stabilized in 1.36, so clippy should use `cloned`. let _ = &["x"][..].iter().cloned(); + //~^ unnecessary_to_owned } #[clippy::msrv = "1.36"] fn _msrv_1_36() { let _ = &["x"][..].iter().copied(); + //~^ unnecessary_to_owned } // https://github.com/rust-lang/rust-clippy/issues/8507 @@ -275,7 +323,7 @@ mod issue_8507 { // Should lint because Y is copy. fn test_y(y: Y) -> Box { - Box::new(build(y)) + Box::new(build(y)) //~ unnecessary_to_owned } } @@ -384,7 +432,7 @@ mod issue_9351 { // Should lint fn single_return() -> impl AsRef { - id("abc") + id("abc") //~ unnecessary_to_owned } // Should not lint @@ -528,5 +576,6 @@ mod issue_11952 { fn bar() { IntoFuture::into_future(foo([], &0)); + //~^ unnecessary_to_owned } } diff --git a/tests/ui/unnecessary_to_owned.rs b/tests/ui/unnecessary_to_owned.rs index a270ed1e1c21..8147d4dd56e6 100644 --- a/tests/ui/unnecessary_to_owned.rs +++ b/tests/ui/unnecessary_to_owned.rs @@ -62,82 +62,123 @@ fn main() { let x_ref = &x; require_c_str(&Cow::from(c_str).into_owned()); - require_c_str(&c_str.to_owned()); + //~^ unnecessary_to_owned + require_c_str(&c_str.to_owned()); //~ unnecessary_to_owned - require_os_str(&os_str.to_os_string()); + require_os_str(&os_str.to_os_string()); //~ unnecessary_to_owned require_os_str(&Cow::from(os_str).into_owned()); - require_os_str(&os_str.to_owned()); + //~^ unnecessary_to_owned + require_os_str(&os_str.to_owned()); //~ unnecessary_to_owned - require_path(&path.to_path_buf()); + require_path(&path.to_path_buf()); //~ unnecessary_to_owned require_path(&Cow::from(path).into_owned()); - require_path(&path.to_owned()); + //~^ unnecessary_to_owned + require_path(&path.to_owned()); //~ unnecessary_to_owned - require_str(&s.to_string()); + require_str(&s.to_string()); //~ unnecessary_to_owned require_str(&Cow::from(s).into_owned()); - require_str(&s.to_owned()); - require_str(&x_ref.to_string()); + //~^ unnecessary_to_owned + require_str(&s.to_owned()); //~ unnecessary_to_owned + require_str(&x_ref.to_string()); //~ unnecessary_to_owned - require_slice(&slice.to_vec()); + require_slice(&slice.to_vec()); //~ unnecessary_to_owned require_slice(&Cow::from(slice).into_owned()); - require_slice(&array.to_owned()); - require_slice(&array_ref.to_owned()); - require_slice(&slice.to_owned()); + //~^ unnecessary_to_owned + require_slice(&array.to_owned()); //~ unnecessary_to_owned + require_slice(&array_ref.to_owned()); //~ unnecessary_to_owned + require_slice(&slice.to_owned()); //~ unnecessary_to_owned require_slice(&x_ref.to_owned()); // No longer flagged because of #8759. require_x(&Cow::::Owned(x.clone()).into_owned()); + //~^ unnecessary_to_owned require_x(&x_ref.to_owned()); // No longer flagged because of #8759. - require_deref_c_str(c_str.to_owned()); + require_deref_c_str(c_str.to_owned()); //~ unnecessary_to_owned require_deref_os_str(os_str.to_owned()); - require_deref_path(path.to_owned()); - require_deref_str(s.to_owned()); - require_deref_slice(slice.to_owned()); + //~^ unnecessary_to_owned + require_deref_path(path.to_owned()); //~ unnecessary_to_owned + require_deref_str(s.to_owned()); //~ unnecessary_to_owned + require_deref_slice(slice.to_owned()); //~ unnecessary_to_owned require_impl_deref_c_str(c_str.to_owned()); + //~^ unnecessary_to_owned require_impl_deref_os_str(os_str.to_owned()); + //~^ unnecessary_to_owned require_impl_deref_path(path.to_owned()); - require_impl_deref_str(s.to_owned()); + //~^ unnecessary_to_owned + require_impl_deref_str(s.to_owned()); //~ unnecessary_to_owned require_impl_deref_slice(slice.to_owned()); + //~^ unnecessary_to_owned require_deref_str_slice(s.to_owned(), slice.to_owned()); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_deref_slice_str(slice.to_owned(), s.to_owned()); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned - require_as_ref_c_str(c_str.to_owned()); + require_as_ref_c_str(c_str.to_owned()); //~ unnecessary_to_owned require_as_ref_os_str(os_str.to_owned()); - require_as_ref_path(path.to_owned()); - require_as_ref_str(s.to_owned()); - require_as_ref_str(x.to_owned()); - require_as_ref_slice(array.to_owned()); + //~^ unnecessary_to_owned + require_as_ref_path(path.to_owned()); //~ unnecessary_to_owned + require_as_ref_str(s.to_owned()); //~ unnecessary_to_owned + require_as_ref_str(x.to_owned()); //~ unnecessary_to_owned + require_as_ref_slice(array.to_owned()); //~ unnecessary_to_owned require_as_ref_slice(array_ref.to_owned()); - require_as_ref_slice(slice.to_owned()); + //~^ unnecessary_to_owned + require_as_ref_slice(slice.to_owned()); //~ unnecessary_to_owned require_impl_as_ref_c_str(c_str.to_owned()); + //~^ unnecessary_to_owned require_impl_as_ref_os_str(os_str.to_owned()); + //~^ unnecessary_to_owned require_impl_as_ref_path(path.to_owned()); - require_impl_as_ref_str(s.to_owned()); - require_impl_as_ref_str(x.to_owned()); + //~^ unnecessary_to_owned + require_impl_as_ref_str(s.to_owned()); //~ unnecessary_to_owned + require_impl_as_ref_str(x.to_owned()); //~ unnecessary_to_owned require_impl_as_ref_slice(array.to_owned()); + //~^ unnecessary_to_owned require_impl_as_ref_slice(array_ref.to_owned()); + //~^ unnecessary_to_owned require_impl_as_ref_slice(slice.to_owned()); + //~^ unnecessary_to_owned require_as_ref_str_slice(s.to_owned(), array.to_owned()); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_str_slice(s.to_owned(), array_ref.to_owned()); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_str_slice(s.to_owned(), slice.to_owned()); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_slice_str(array.to_owned(), s.to_owned()); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_slice_str(array_ref.to_owned(), s.to_owned()); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_slice_str(slice.to_owned(), s.to_owned()); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned - let _ = x.join(&x_ref.to_string()); + let _ = x.join(&x_ref.to_string()); //~ unnecessary_to_owned - let _ = slice.to_vec().into_iter(); - let _ = slice.to_owned().into_iter(); + let _ = slice.to_vec().into_iter(); //~ unnecessary_to_owned + let _ = slice.to_owned().into_iter(); //~ unnecessary_to_owned let _ = [std::path::PathBuf::new()][..].to_vec().into_iter(); + //~^ unnecessary_to_owned let _ = [std::path::PathBuf::new()][..].to_owned().into_iter(); + //~^ unnecessary_to_owned let _ = IntoIterator::into_iter(slice.to_vec()); + //~^ unnecessary_to_owned let _ = IntoIterator::into_iter(slice.to_owned()); + //~^ unnecessary_to_owned let _ = IntoIterator::into_iter([std::path::PathBuf::new()][..].to_vec()); + //~^ unnecessary_to_owned let _ = IntoIterator::into_iter([std::path::PathBuf::new()][..].to_owned()); + //~^ unnecessary_to_owned let _ = check_files(&[FileType::Account]); @@ -153,10 +194,14 @@ fn main() { // The following should be flagged by `redundant_clone`, but not by this lint. require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()); + //~^ redundant_clone require_os_str(&OsString::from("x").to_os_string()); + //~^ redundant_clone require_path(&std::path::PathBuf::from("x").to_path_buf()); - require_str(&String::from("x").to_string()); + //~^ redundant_clone + require_str(&String::from("x").to_string()); //~ redundant_clone require_slice(&[String::from("x")].to_owned()); + //~^ redundant_clone } fn require_c_str(_: &CStr) {} @@ -199,6 +244,7 @@ fn require_as_ref_slice_str, V: AsRef>(_: U, _: V) {} // `check_files` is based on: // https://github.com/breard-r/acmed/blob/1f0dcc32aadbc5e52de6d23b9703554c0f925113/acmed/src/storage.rs#L262 fn check_files(file_types: &[FileType]) -> bool { + //~v unnecessary_to_owned for t in file_types.to_vec() { let path = match get_file_path(&t) { Ok(p) => p, @@ -223,11 +269,13 @@ fn require_string(_: &String) {} fn _msrv_1_35() { // `copied` was stabilized in 1.36, so clippy should use `cloned`. let _ = &["x"][..].to_vec().into_iter(); + //~^ unnecessary_to_owned } #[clippy::msrv = "1.36"] fn _msrv_1_36() { let _ = &["x"][..].to_vec().into_iter(); + //~^ unnecessary_to_owned } // https://github.com/rust-lang/rust-clippy/issues/8507 @@ -275,7 +323,7 @@ mod issue_8507 { // Should lint because Y is copy. fn test_y(y: Y) -> Box { - Box::new(build(y.to_string())) + Box::new(build(y.to_string())) //~ unnecessary_to_owned } } @@ -384,7 +432,7 @@ mod issue_9351 { // Should lint fn single_return() -> impl AsRef { - id("abc".to_string()) + id("abc".to_string()) //~ unnecessary_to_owned } // Should not lint @@ -528,5 +576,6 @@ mod issue_11952 { fn bar() { IntoFuture::into_future(foo([].to_vec(), &0)); + //~^ unnecessary_to_owned } } diff --git a/tests/ui/unnecessary_to_owned.stderr b/tests/ui/unnecessary_to_owned.stderr index 95ff5f2ec2cf..2919a8101a55 100644 --- a/tests/ui/unnecessary_to_owned.stderr +++ b/tests/ui/unnecessary_to_owned.stderr @@ -1,11 +1,11 @@ error: redundant clone - --> $DIR/unnecessary_to_owned.rs:155:64 + --> $DIR/unnecessary_to_owned.rs:196:64 | LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/unnecessary_to_owned.rs:155:20 + --> $DIR/unnecessary_to_owned.rs:196:20 | LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,49 +13,49 @@ LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()) = help: to override `-D warnings` add `#[allow(clippy::redundant_clone)]` error: redundant clone - --> $DIR/unnecessary_to_owned.rs:156:40 + --> $DIR/unnecessary_to_owned.rs:198:40 | LL | require_os_str(&OsString::from("x").to_os_string()); | ^^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/unnecessary_to_owned.rs:156:21 + --> $DIR/unnecessary_to_owned.rs:198:21 | LL | require_os_str(&OsString::from("x").to_os_string()); | ^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/unnecessary_to_owned.rs:157:48 + --> $DIR/unnecessary_to_owned.rs:200:48 | LL | require_path(&std::path::PathBuf::from("x").to_path_buf()); | ^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/unnecessary_to_owned.rs:157:19 + --> $DIR/unnecessary_to_owned.rs:200:19 | LL | require_path(&std::path::PathBuf::from("x").to_path_buf()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/unnecessary_to_owned.rs:158:35 + --> $DIR/unnecessary_to_owned.rs:202:35 | LL | require_str(&String::from("x").to_string()); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/unnecessary_to_owned.rs:158:18 + --> $DIR/unnecessary_to_owned.rs:202:18 | LL | require_str(&String::from("x").to_string()); | ^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/unnecessary_to_owned.rs:159:39 + --> $DIR/unnecessary_to_owned.rs:203:39 | LL | require_slice(&[String::from("x")].to_owned()); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/unnecessary_to_owned.rs:159:20 + --> $DIR/unnecessary_to_owned.rs:203:20 | LL | require_slice(&[String::from("x")].to_owned()); | ^^^^^^^^^^^^^^^^^^^ @@ -70,415 +70,415 @@ LL | require_c_str(&Cow::from(c_str).into_owned()); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_to_owned)]` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:65:19 + --> $DIR/unnecessary_to_owned.rs:66:19 | LL | require_c_str(&c_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_os_string` - --> $DIR/unnecessary_to_owned.rs:67:20 + --> $DIR/unnecessary_to_owned.rs:68:20 | LL | require_os_str(&os_str.to_os_string()); | ^^^^^^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:68:38 + --> $DIR/unnecessary_to_owned.rs:69:38 | LL | require_os_str(&Cow::from(os_str).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:69:20 + --> $DIR/unnecessary_to_owned.rs:71:20 | LL | require_os_str(&os_str.to_owned()); | ^^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_path_buf` - --> $DIR/unnecessary_to_owned.rs:71:18 + --> $DIR/unnecessary_to_owned.rs:73:18 | LL | require_path(&path.to_path_buf()); | ^^^^^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:72:34 + --> $DIR/unnecessary_to_owned.rs:74:34 | LL | require_path(&Cow::from(path).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:73:18 + --> $DIR/unnecessary_to_owned.rs:76:18 | LL | require_path(&path.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:75:17 + --> $DIR/unnecessary_to_owned.rs:78:17 | LL | require_str(&s.to_string()); | ^^^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:76:30 + --> $DIR/unnecessary_to_owned.rs:79:30 | LL | require_str(&Cow::from(s).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:77:17 + --> $DIR/unnecessary_to_owned.rs:81:17 | LL | require_str(&s.to_owned()); | ^^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:78:17 + --> $DIR/unnecessary_to_owned.rs:82:17 | LL | require_str(&x_ref.to_string()); | ^^^^^^^^^^^^^^^^^^ help: use: `x_ref.as_ref()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:80:19 + --> $DIR/unnecessary_to_owned.rs:84:19 | LL | require_slice(&slice.to_vec()); | ^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:81:36 + --> $DIR/unnecessary_to_owned.rs:85:36 | LL | require_slice(&Cow::from(slice).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:82:19 + --> $DIR/unnecessary_to_owned.rs:87:19 | LL | require_slice(&array.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `array.as_ref()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:83:19 + --> $DIR/unnecessary_to_owned.rs:88:19 | LL | require_slice(&array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref.as_ref()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:84:19 + --> $DIR/unnecessary_to_owned.rs:89:19 | LL | require_slice(&slice.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:87:42 + --> $DIR/unnecessary_to_owned.rs:92:42 | LL | require_x(&Cow::::Owned(x.clone()).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:90:25 + --> $DIR/unnecessary_to_owned.rs:96:25 | LL | require_deref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:91:26 + --> $DIR/unnecessary_to_owned.rs:97:26 | LL | require_deref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:92:24 + --> $DIR/unnecessary_to_owned.rs:99:24 | LL | require_deref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:93:23 + --> $DIR/unnecessary_to_owned.rs:100:23 | LL | require_deref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:94:25 + --> $DIR/unnecessary_to_owned.rs:101:25 | LL | require_deref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:96:30 + --> $DIR/unnecessary_to_owned.rs:103:30 | LL | require_impl_deref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:97:31 + --> $DIR/unnecessary_to_owned.rs:105:31 | LL | require_impl_deref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:98:29 + --> $DIR/unnecessary_to_owned.rs:107:29 | LL | require_impl_deref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:99:28 + --> $DIR/unnecessary_to_owned.rs:109:28 | LL | require_impl_deref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:100:30 + --> $DIR/unnecessary_to_owned.rs:110:30 | LL | require_impl_deref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:102:29 + --> $DIR/unnecessary_to_owned.rs:113:29 | LL | require_deref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:102:43 + --> $DIR/unnecessary_to_owned.rs:113:43 | LL | require_deref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:103:29 + --> $DIR/unnecessary_to_owned.rs:116:29 | LL | require_deref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:103:47 + --> $DIR/unnecessary_to_owned.rs:116:47 | LL | require_deref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:105:26 + --> $DIR/unnecessary_to_owned.rs:120:26 | LL | require_as_ref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:106:27 + --> $DIR/unnecessary_to_owned.rs:121:27 | LL | require_as_ref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:107:25 + --> $DIR/unnecessary_to_owned.rs:123:25 | LL | require_as_ref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:108:24 + --> $DIR/unnecessary_to_owned.rs:124:24 | LL | require_as_ref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:109:24 + --> $DIR/unnecessary_to_owned.rs:125:24 | LL | require_as_ref_str(x.to_owned()); | ^^^^^^^^^^^^ help: use: `&x` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:110:26 + --> $DIR/unnecessary_to_owned.rs:126:26 | LL | require_as_ref_slice(array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:111:26 + --> $DIR/unnecessary_to_owned.rs:127:26 | LL | require_as_ref_slice(array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:112:26 + --> $DIR/unnecessary_to_owned.rs:129:26 | LL | require_as_ref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:114:31 + --> $DIR/unnecessary_to_owned.rs:131:31 | LL | require_impl_as_ref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:115:32 + --> $DIR/unnecessary_to_owned.rs:133:32 | LL | require_impl_as_ref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:116:30 + --> $DIR/unnecessary_to_owned.rs:135:30 | LL | require_impl_as_ref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:117:29 + --> $DIR/unnecessary_to_owned.rs:137:29 | LL | require_impl_as_ref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:118:29 + --> $DIR/unnecessary_to_owned.rs:138:29 | LL | require_impl_as_ref_str(x.to_owned()); | ^^^^^^^^^^^^ help: use: `&x` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:119:31 + --> $DIR/unnecessary_to_owned.rs:139:31 | LL | require_impl_as_ref_slice(array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:120:31 + --> $DIR/unnecessary_to_owned.rs:141:31 | LL | require_impl_as_ref_slice(array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:121:31 + --> $DIR/unnecessary_to_owned.rs:143:31 | LL | require_impl_as_ref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:123:30 + --> $DIR/unnecessary_to_owned.rs:146:30 | LL | require_as_ref_str_slice(s.to_owned(), array.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:123:44 + --> $DIR/unnecessary_to_owned.rs:146:44 | LL | require_as_ref_str_slice(s.to_owned(), array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:124:30 + --> $DIR/unnecessary_to_owned.rs:149:30 | LL | require_as_ref_str_slice(s.to_owned(), array_ref.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:124:44 + --> $DIR/unnecessary_to_owned.rs:149:44 | LL | require_as_ref_str_slice(s.to_owned(), array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:125:30 + --> $DIR/unnecessary_to_owned.rs:152:30 | LL | require_as_ref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:125:44 + --> $DIR/unnecessary_to_owned.rs:152:44 | LL | require_as_ref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:126:30 + --> $DIR/unnecessary_to_owned.rs:155:30 | LL | require_as_ref_slice_str(array.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:126:48 + --> $DIR/unnecessary_to_owned.rs:155:48 | LL | require_as_ref_slice_str(array.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:127:30 + --> $DIR/unnecessary_to_owned.rs:158:30 | LL | require_as_ref_slice_str(array_ref.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:127:52 + --> $DIR/unnecessary_to_owned.rs:158:52 | LL | require_as_ref_slice_str(array_ref.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:128:30 + --> $DIR/unnecessary_to_owned.rs:161:30 | LL | require_as_ref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:128:48 + --> $DIR/unnecessary_to_owned.rs:161:48 | LL | require_as_ref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:130:20 + --> $DIR/unnecessary_to_owned.rs:165:20 | LL | let _ = x.join(&x_ref.to_string()); | ^^^^^^^^^^^^^^^^^^ help: use: `x_ref` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:132:13 + --> $DIR/unnecessary_to_owned.rs:167:13 | LL | let _ = slice.to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:133:13 + --> $DIR/unnecessary_to_owned.rs:168:13 | LL | let _ = slice.to_owned().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:134:13 + --> $DIR/unnecessary_to_owned.rs:169:13 | LL | let _ = [std::path::PathBuf::new()][..].to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:135:13 + --> $DIR/unnecessary_to_owned.rs:171:13 | LL | let _ = [std::path::PathBuf::new()][..].to_owned().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:137:13 + --> $DIR/unnecessary_to_owned.rs:174:13 | LL | let _ = IntoIterator::into_iter(slice.to_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:138:13 + --> $DIR/unnecessary_to_owned.rs:176:13 | LL | let _ = IntoIterator::into_iter(slice.to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:139:13 + --> $DIR/unnecessary_to_owned.rs:178:13 | LL | let _ = IntoIterator::into_iter([std::path::PathBuf::new()][..].to_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:140:13 + --> $DIR/unnecessary_to_owned.rs:180:13 | LL | let _ = IntoIterator::into_iter([std::path::PathBuf::new()][..].to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:202:14 + --> $DIR/unnecessary_to_owned.rs:248:14 | LL | for t in file_types.to_vec() { | ^^^^^^^^^^^^^^^^^^^ @@ -494,31 +494,31 @@ LL + let path = match get_file_path(t) { | error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:225:14 + --> $DIR/unnecessary_to_owned.rs:271:14 | LL | let _ = &["x"][..].to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().cloned()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:230:14 + --> $DIR/unnecessary_to_owned.rs:277:14 | LL | let _ = &["x"][..].to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().copied()` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:278:24 + --> $DIR/unnecessary_to_owned.rs:326:24 | LL | Box::new(build(y.to_string())) | ^^^^^^^^^^^^^ help: use: `y` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:387:12 + --> $DIR/unnecessary_to_owned.rs:435:12 | LL | id("abc".to_string()) | ^^^^^^^^^^^^^^^^^ help: use: `"abc"` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:530:37 + --> $DIR/unnecessary_to_owned.rs:578:37 | LL | IntoFuture::into_future(foo([].to_vec(), &0)); | ^^^^^^^^^^^ help: use: `[]` diff --git a/tests/ui/unnecessary_unsafety_doc.rs b/tests/ui/unnecessary_unsafety_doc.rs index 5ad117eb8db6..3bf2e7ff0046 100644 --- a/tests/ui/unnecessary_unsafety_doc.rs +++ b/tests/ui/unnecessary_unsafety_doc.rs @@ -16,6 +16,7 @@ pub fn destroy_the_planet() { /// # Safety /// /// This function shouldn't be called unless the horsemen are ready +//~v unnecessary_safety_doc pub fn apocalypse(universe: &mut ()) { unimplemented!(); } @@ -42,6 +43,7 @@ mod private_mod { /// # Safety /// /// Unnecessary safety! + //~v unnecessary_safety_doc pub fn republished() { unimplemented!(); } @@ -55,7 +57,7 @@ pub trait SafeTraitSafeMethods { /// # Safety /// /// Unnecessary! - fn documented(self); + fn documented(self); //~ unnecessary_safety_doc } pub trait SafeTrait { @@ -65,6 +67,7 @@ pub trait SafeTrait { /// # Safety /// /// Unnecessary! +//~v unnecessary_safety_doc pub trait DocumentedSafeTrait { fn method2(); } @@ -93,6 +96,7 @@ impl Struct { /// # Safety /// /// Unnecessary! + //~v unnecessary_safety_doc pub fn documented() -> Self { unimplemented!(); } @@ -120,6 +124,7 @@ macro_rules! very_safe { /// # Safety /// /// Driving is very safe already! + //~v unnecessary_safety_doc pub fn drive() { whee() } @@ -148,6 +153,7 @@ pub mod __macro { } /// # Implementation safety +//~v unnecessary_safety_doc pub trait DocumentedSafeTraitWithImplementationHeader { fn method(); } diff --git a/tests/ui/unnecessary_unsafety_doc.stderr b/tests/ui/unnecessary_unsafety_doc.stderr index 817eb3e26eed..e4d4568fdd84 100644 --- a/tests/ui/unnecessary_unsafety_doc.stderr +++ b/tests/ui/unnecessary_unsafety_doc.stderr @@ -1,5 +1,5 @@ error: safe function's docs have unnecessary `# Safety` section - --> $DIR/unnecessary_unsafety_doc.rs:19:1 + --> $DIR/unnecessary_unsafety_doc.rs:20:1 | LL | pub fn apocalypse(universe: &mut ()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,31 +8,31 @@ LL | pub fn apocalypse(universe: &mut ()) { = help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_doc)]` error: safe function's docs have unnecessary `# Safety` section - --> $DIR/unnecessary_unsafety_doc.rs:45:5 + --> $DIR/unnecessary_unsafety_doc.rs:47:5 | LL | pub fn republished() { | ^^^^^^^^^^^^^^^^^^^^ error: safe function's docs have unnecessary `# Safety` section - --> $DIR/unnecessary_unsafety_doc.rs:58:5 + --> $DIR/unnecessary_unsafety_doc.rs:60:5 | LL | fn documented(self); | ^^^^^^^^^^^^^^^^^^^^ error: docs for safe trait have unnecessary `# Safety` section - --> $DIR/unnecessary_unsafety_doc.rs:68:1 + --> $DIR/unnecessary_unsafety_doc.rs:71:1 | LL | pub trait DocumentedSafeTrait { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: safe function's docs have unnecessary `# Safety` section - --> $DIR/unnecessary_unsafety_doc.rs:96:5 + --> $DIR/unnecessary_unsafety_doc.rs:100:5 | LL | pub fn documented() -> Self { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: safe function's docs have unnecessary `# Safety` section - --> $DIR/unnecessary_unsafety_doc.rs:123:9 + --> $DIR/unnecessary_unsafety_doc.rs:128:9 | LL | pub fn drive() { | ^^^^^^^^^^^^^^ @@ -43,7 +43,7 @@ LL | very_safe!(); = note: this error originates in the macro `very_safe` (in Nightly builds, run with -Z macro-backtrace for more info) error: docs for safe trait have unnecessary `# Safety` section - --> $DIR/unnecessary_unsafety_doc.rs:151:1 + --> $DIR/unnecessary_unsafety_doc.rs:157:1 | LL | pub trait DocumentedSafeTraitWithImplementationHeader { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unneeded_field_pattern.rs b/tests/ui/unneeded_field_pattern.rs index 0dc21f4ce945..dcf7bce69bf5 100644 --- a/tests/ui/unneeded_field_pattern.rs +++ b/tests/ui/unneeded_field_pattern.rs @@ -15,9 +15,9 @@ fn main() { let f = Foo { a: 0, b: 0, c: 0 }; match f { - Foo { a: _, b: 0, .. } => {}, + Foo { a: _, b: 0, .. } => {}, //~ unneeded_field_pattern - Foo { a: _, b: _, c: _ } => {}, + Foo { a: _, b: _, c: _ } => {}, //~ unneeded_field_pattern } match f { Foo { b: 0, .. } => {}, // should be OK diff --git a/tests/ui/unneeded_wildcard_pattern.fixed b/tests/ui/unneeded_wildcard_pattern.fixed index cbf91ed4910a..67bf0aa2106e 100644 --- a/tests/ui/unneeded_wildcard_pattern.fixed +++ b/tests/ui/unneeded_wildcard_pattern.fixed @@ -9,12 +9,12 @@ extern crate proc_macros; fn main() { let t = (0, 1, 2, 3); - if let (0, ..) = t {}; - if let (0, ..) = t {}; - if let (.., 0) = t {}; - if let (.., 0) = t {}; - if let (0, ..) = t {}; - if let (0, ..) = t {}; + if let (0, ..) = t {}; //~ unneeded_wildcard_pattern + if let (0, ..) = t {}; //~ unneeded_wildcard_pattern + if let (.., 0) = t {}; //~ unneeded_wildcard_pattern + if let (.., 0) = t {}; //~ unneeded_wildcard_pattern + if let (0, ..) = t {}; //~ unneeded_wildcard_pattern + if let (0, ..) = t {}; //~ unneeded_wildcard_pattern if let (_, 0, ..) = t {}; if let (.., 0, _) = t {}; if let (0, _, _, _) = t {}; @@ -23,19 +23,19 @@ fn main() { #[rustfmt::skip] { - if let (0, ..,) = t {}; + if let (0, ..,) = t {}; //~ unneeded_wildcard_pattern } struct S(usize, usize, usize, usize); let s = S(0, 1, 2, 3); - if let S(0, ..) = s {}; - if let S(0, ..) = s {}; - if let S(.., 0) = s {}; - if let S(.., 0) = s {}; - if let S(0, ..) = s {}; - if let S(0, ..) = s {}; + if let S(0, ..) = s {}; //~ unneeded_wildcard_pattern + if let S(0, ..) = s {}; //~ unneeded_wildcard_pattern + if let S(.., 0) = s {}; //~ unneeded_wildcard_pattern + if let S(.., 0) = s {}; //~ unneeded_wildcard_pattern + if let S(0, ..) = s {}; //~ unneeded_wildcard_pattern + if let S(0, ..) = s {}; //~ unneeded_wildcard_pattern if let S(_, 0, ..) = s {}; if let S(.., 0, _) = s {}; if let S(0, _, _, _) = s {}; @@ -44,7 +44,7 @@ fn main() { #[rustfmt::skip] { - if let S(0, ..,) = s {}; + if let S(0, ..,) = s {}; //~ unneeded_wildcard_pattern } external! { let t = (0, 1, 2, 3); diff --git a/tests/ui/unneeded_wildcard_pattern.rs b/tests/ui/unneeded_wildcard_pattern.rs index 10df2b93d5e0..cb9975401bd5 100644 --- a/tests/ui/unneeded_wildcard_pattern.rs +++ b/tests/ui/unneeded_wildcard_pattern.rs @@ -9,12 +9,12 @@ extern crate proc_macros; fn main() { let t = (0, 1, 2, 3); - if let (0, .., _) = t {}; - if let (0, _, ..) = t {}; - if let (_, .., 0) = t {}; - if let (.., _, 0) = t {}; - if let (0, _, _, ..) = t {}; - if let (0, .., _, _) = t {}; + if let (0, .., _) = t {}; //~ unneeded_wildcard_pattern + if let (0, _, ..) = t {}; //~ unneeded_wildcard_pattern + if let (_, .., 0) = t {}; //~ unneeded_wildcard_pattern + if let (.., _, 0) = t {}; //~ unneeded_wildcard_pattern + if let (0, _, _, ..) = t {}; //~ unneeded_wildcard_pattern + if let (0, .., _, _) = t {}; //~ unneeded_wildcard_pattern if let (_, 0, ..) = t {}; if let (.., 0, _) = t {}; if let (0, _, _, _) = t {}; @@ -23,19 +23,19 @@ fn main() { #[rustfmt::skip] { - if let (0, .., _, _,) = t {}; + if let (0, .., _, _,) = t {}; //~ unneeded_wildcard_pattern } struct S(usize, usize, usize, usize); let s = S(0, 1, 2, 3); - if let S(0, .., _) = s {}; - if let S(0, _, ..) = s {}; - if let S(_, .., 0) = s {}; - if let S(.., _, 0) = s {}; - if let S(0, _, _, ..) = s {}; - if let S(0, .., _, _) = s {}; + if let S(0, .., _) = s {}; //~ unneeded_wildcard_pattern + if let S(0, _, ..) = s {}; //~ unneeded_wildcard_pattern + if let S(_, .., 0) = s {}; //~ unneeded_wildcard_pattern + if let S(.., _, 0) = s {}; //~ unneeded_wildcard_pattern + if let S(0, _, _, ..) = s {}; //~ unneeded_wildcard_pattern + if let S(0, .., _, _) = s {}; //~ unneeded_wildcard_pattern if let S(_, 0, ..) = s {}; if let S(.., 0, _) = s {}; if let S(0, _, _, _) = s {}; @@ -44,7 +44,7 @@ fn main() { #[rustfmt::skip] { - if let S(0, .., _, _,) = s {}; + if let S(0, .., _, _,) = s {}; //~ unneeded_wildcard_pattern } external! { let t = (0, 1, 2, 3); diff --git a/tests/ui/unnested_or_patterns.fixed b/tests/ui/unnested_or_patterns.fixed index 53ec556d1008..69390ae90dc6 100644 --- a/tests/ui/unnested_or_patterns.fixed +++ b/tests/ui/unnested_or_patterns.fixed @@ -13,28 +13,38 @@ fn main() { // Should be ignored by this lint, as nesting requires more characters. if let &0 | &2 = &0 {} - if let box (0 | 2) = Box::new(0) {} + if let box (0 | 2) = Box::new(0) {} //~ unnested_or_patterns if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} + //~^ unnested_or_patterns const C0: Option = Some(1); - if let Some(1 | 2) | C0 = None {} - if let &mut (0 | 2) = &mut 0 {} - if let x @ (0 | 2) = 0 {} + if let Some(1 | 2) | C0 = None {} //~ unnested_or_patterns + if let &mut (0 | 2) = &mut 0 {} //~ unnested_or_patterns + if let x @ (0 | 2) = 0 {} //~ unnested_or_patterns if let (0, 1 | 2 | 3) = (0, 0) {} + //~^ unnested_or_patterns if let (1 | 2 | 3, 0) = (0, 0) {} + //~^ unnested_or_patterns if let (x, ..) | (x, 1 | 2) = (0, 1) {} - if let [0 | 1] = [0] {} - if let [x, 0 | 1] = [0, 1] {} + //~^ unnested_or_patterns + if let [0 | 1] = [0] {} //~ unnested_or_patterns + if let [x, 0 | 1] = [0, 1] {} //~ unnested_or_patterns if let [x, 0 | 1 | 2] = [0, 1] {} + //~^ unnested_or_patterns if let [x, ..] | [x, 1 | 2] = [0, 1] {} + //~^ unnested_or_patterns struct TS(u8, u8); if let TS(0 | 1, x) = TS(0, 0) {} + //~^ unnested_or_patterns if let TS(1 | 2 | 3, 0) = TS(0, 0) {} + //~^ unnested_or_patterns if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {} + //~^ unnested_or_patterns struct S { x: u8, y: u8, } if let S { x: 0 | 1, y } = (S { x: 0, y: 1 }) {} + //~^ unnested_or_patterns if let S { x: 0, y, .. } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} } @@ -45,5 +55,5 @@ fn msrv_1_52() { #[clippy::msrv = "1.53"] fn msrv_1_53() { - if let [1 | 53] = [0] {} + if let [1 | 53] = [0] {} //~ unnested_or_patterns } diff --git a/tests/ui/unnested_or_patterns.rs b/tests/ui/unnested_or_patterns.rs index e5e378e922af..ba417039649d 100644 --- a/tests/ui/unnested_or_patterns.rs +++ b/tests/ui/unnested_or_patterns.rs @@ -13,28 +13,38 @@ fn main() { // Should be ignored by this lint, as nesting requires more characters. if let &0 | &2 = &0 {} - if let box 0 | box 2 = Box::new(0) {} + if let box 0 | box 2 = Box::new(0) {} //~ unnested_or_patterns if let box ((0 | 1)) | box (2 | 3) | box 4 = Box::new(0) {} + //~^ unnested_or_patterns const C0: Option = Some(1); - if let Some(1) | C0 | Some(2) = None {} - if let &mut 0 | &mut 2 = &mut 0 {} - if let x @ 0 | x @ 2 = 0 {} + if let Some(1) | C0 | Some(2) = None {} //~ unnested_or_patterns + if let &mut 0 | &mut 2 = &mut 0 {} //~ unnested_or_patterns + if let x @ 0 | x @ 2 = 0 {} //~ unnested_or_patterns if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {} + //~^ unnested_or_patterns if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {} + //~^ unnested_or_patterns if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {} - if let [0] | [1] = [0] {} - if let [x, 0] | [x, 1] = [0, 1] {} + //~^ unnested_or_patterns + if let [0] | [1] = [0] {} //~ unnested_or_patterns + if let [x, 0] | [x, 1] = [0, 1] {} //~ unnested_or_patterns if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {} + //~^ unnested_or_patterns if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {} + //~^ unnested_or_patterns struct TS(u8, u8); if let TS(0, x) | TS(1, x) = TS(0, 0) {} + //~^ unnested_or_patterns if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {} + //~^ unnested_or_patterns if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {} + //~^ unnested_or_patterns struct S { x: u8, y: u8, } if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} + //~^ unnested_or_patterns if let S { x: 0, y, .. } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} } @@ -45,5 +55,5 @@ fn msrv_1_52() { #[clippy::msrv = "1.53"] fn msrv_1_53() { - if let [1] | [53] = [0] {} + if let [1] | [53] = [0] {} //~ unnested_or_patterns } diff --git a/tests/ui/unnested_or_patterns.stderr b/tests/ui/unnested_or_patterns.stderr index 98ca7e373567..79673792b19c 100644 --- a/tests/ui/unnested_or_patterns.stderr +++ b/tests/ui/unnested_or_patterns.stderr @@ -23,7 +23,7 @@ LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} | ~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:19:12 + --> $DIR/unnested_or_patterns.rs:20:12 | LL | if let Some(1) | C0 | Some(2) = None {} | ^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | if let Some(1 | 2) | C0 = None {} | ~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:20:12 + --> $DIR/unnested_or_patterns.rs:21:12 | LL | if let &mut 0 | &mut 2 = &mut 0 {} | ^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | if let &mut (0 | 2) = &mut 0 {} | ~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:21:12 + --> $DIR/unnested_or_patterns.rs:22:12 | LL | if let x @ 0 | x @ 2 = 0 {} | ^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | if let x @ (0 | 2) = 0 {} | ~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:22:12 + --> $DIR/unnested_or_patterns.rs:23:12 | LL | if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | if let (0, 1 | 2 | 3) = (0, 0) {} | ~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:23:12 + --> $DIR/unnested_or_patterns.rs:25:12 | LL | if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | if let (1 | 2 | 3, 0) = (0, 0) {} | ~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:24:12 + --> $DIR/unnested_or_patterns.rs:27:12 | LL | if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | if let (x, ..) | (x, 1 | 2) = (0, 1) {} | ~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:25:12 + --> $DIR/unnested_or_patterns.rs:29:12 | LL | if let [0] | [1] = [0] {} | ^^^^^^^^^ @@ -100,7 +100,7 @@ LL | if let [0 | 1] = [0] {} | ~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:26:12 + --> $DIR/unnested_or_patterns.rs:30:12 | LL | if let [x, 0] | [x, 1] = [0, 1] {} | ^^^^^^^^^^^^^^^ @@ -111,7 +111,7 @@ LL | if let [x, 0 | 1] = [0, 1] {} | ~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:27:12 + --> $DIR/unnested_or_patterns.rs:31:12 | LL | if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | if let [x, 0 | 1 | 2] = [0, 1] {} | ~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:28:12 + --> $DIR/unnested_or_patterns.rs:33:12 | LL | if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | if let [x, ..] | [x, 1 | 2] = [0, 1] {} | ~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:30:12 + --> $DIR/unnested_or_patterns.rs:36:12 | LL | if let TS(0, x) | TS(1, x) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | if let TS(0 | 1, x) = TS(0, 0) {} | ~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:31:12 + --> $DIR/unnested_or_patterns.rs:38:12 | LL | if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -155,7 +155,7 @@ LL | if let TS(1 | 2 | 3, 0) = TS(0, 0) {} | ~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:32:12 + --> $DIR/unnested_or_patterns.rs:40:12 | LL | if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -166,7 +166,7 @@ LL | if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {} | ~~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:37:12 + --> $DIR/unnested_or_patterns.rs:46:12 | LL | if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | if let S { x: 0 | 1, y } = (S { x: 0, y: 1 }) {} | ~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:48:12 + --> $DIR/unnested_or_patterns.rs:58:12 | LL | if let [1] | [53] = [0] {} | ^^^^^^^^^^ diff --git a/tests/ui/unnested_or_patterns2.fixed b/tests/ui/unnested_or_patterns2.fixed index b2a4e83dadc3..7d336d46745d 100644 --- a/tests/ui/unnested_or_patterns2.fixed +++ b/tests/ui/unnested_or_patterns2.fixed @@ -10,11 +10,18 @@ fn main() { if let Some(Some(0 | 1)) = None {} + //~^ unnested_or_patterns if let Some(Some(0 | 1 | 2)) = None {} + //~^ unnested_or_patterns if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {} + //~^ unnested_or_patterns if let Some(Some(0 | 1 | 2)) = None {} + //~^ unnested_or_patterns if let ((0 | 1 | 2,),) = ((0,),) {} - if let 0 | 1 | 2 = 0 {} + //~^ unnested_or_patterns + if let 0 | 1 | 2 = 0 {} //~ unnested_or_patterns if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} + //~^ unnested_or_patterns if let box box (0 | 2 | 4) = Box::new(Box::new(0)) {} + //~^ unnested_or_patterns } diff --git a/tests/ui/unnested_or_patterns2.rs b/tests/ui/unnested_or_patterns2.rs index 58435f8990d2..b2fbe39f3492 100644 --- a/tests/ui/unnested_or_patterns2.rs +++ b/tests/ui/unnested_or_patterns2.rs @@ -10,11 +10,18 @@ fn main() { if let Some(Some(0)) | Some(Some(1)) = None {} + //~^ unnested_or_patterns if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {} + //~^ unnested_or_patterns if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {} + //~^ unnested_or_patterns if let Some(Some(0) | Some(1 | 2)) = None {} + //~^ unnested_or_patterns if let ((0,),) | ((1,) | (2,),) = ((0,),) {} - if let 0 | (1 | 2) = 0 {} + //~^ unnested_or_patterns + if let 0 | (1 | 2) = 0 {} //~ unnested_or_patterns if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {} + //~^ unnested_or_patterns if let box box 0 | box (box 2 | box 4) = Box::new(Box::new(0)) {} + //~^ unnested_or_patterns } diff --git a/tests/ui/unnested_or_patterns2.stderr b/tests/ui/unnested_or_patterns2.stderr index 182ae00de220..bc888fd67c72 100644 --- a/tests/ui/unnested_or_patterns2.stderr +++ b/tests/ui/unnested_or_patterns2.stderr @@ -12,7 +12,7 @@ LL | if let Some(Some(0 | 1)) = None {} | ~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:13:12 + --> $DIR/unnested_or_patterns2.rs:14:12 | LL | if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | if let Some(Some(0 | 1 | 2)) = None {} | ~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:14:12 + --> $DIR/unnested_or_patterns2.rs:16:12 | LL | if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {} | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:15:12 + --> $DIR/unnested_or_patterns2.rs:18:12 | LL | if let Some(Some(0) | Some(1 | 2)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | if let Some(Some(0 | 1 | 2)) = None {} | ~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:16:12 + --> $DIR/unnested_or_patterns2.rs:20:12 | LL | if let ((0,),) | ((1,) | (2,),) = ((0,),) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | if let ((0 | 1 | 2,),) = ((0,),) {} | ~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:17:12 + --> $DIR/unnested_or_patterns2.rs:22:12 | LL | if let 0 | (1 | 2) = 0 {} | ^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | if let 0 | 1 | 2 = 0 {} | ~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:18:12 + --> $DIR/unnested_or_patterns2.rs:23:12 | LL | if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} | ~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:19:12 + --> $DIR/unnested_or_patterns2.rs:25:12 | LL | if let box box 0 | box (box 2 | box 4) = Box::new(Box::new(0)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unreadable_literal.fixed b/tests/ui/unreadable_literal.fixed index fb9c2672db82..7dc43e27a520 100644 --- a/tests/ui/unreadable_literal.fixed +++ b/tests/ui/unreadable_literal.fixed @@ -29,14 +29,18 @@ fn main() { 1.123_4_f32, ); let _bad = (0b11_0110_i64, 0x1234_5678_usize, 123_456_f32, 1.234_567_f32); + //~^ unreadable_literal + //~| unreadable_literal + //~| unreadable_literal + //~| unreadable_literal let _good_sci = 1.1234e1; - let _bad_sci = 1.123_456e1; + let _bad_sci = 1.123_456e1; //~ unreadable_literal - let _fail1 = 0x00ab_cdef; - let _fail2: u32 = 0xBAFE_BAFE; - let _fail3 = 0x0abc_deff; - let _fail4: i128 = 0x00ab_cabc_abca_bcab_cabc; - let _fail5 = 1.100_300_400; + let _fail1 = 0x00ab_cdef; //~ unreadable_literal + let _fail2: u32 = 0xBAFE_BAFE; //~ unreadable_literal + let _fail3 = 0x0abc_deff; //~ unreadable_literal + let _fail4: i128 = 0x00ab_cabc_abca_bcab_cabc; //~ unreadable_literal + let _fail5 = 1.100_300_400; //~ unreadable_literal let _ = foo!(); let _ = bar!(); diff --git a/tests/ui/unreadable_literal.rs b/tests/ui/unreadable_literal.rs index 0a24fa852546..5ab99d44fe3e 100644 --- a/tests/ui/unreadable_literal.rs +++ b/tests/ui/unreadable_literal.rs @@ -29,14 +29,18 @@ fn main() { 1.123_4_f32, ); let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); + //~^ unreadable_literal + //~| unreadable_literal + //~| unreadable_literal + //~| unreadable_literal let _good_sci = 1.1234e1; - let _bad_sci = 1.123456e1; + let _bad_sci = 1.123456e1; //~ unreadable_literal - let _fail1 = 0xabcdef; - let _fail2: u32 = 0xBAFEBAFE; - let _fail3 = 0xabcdeff; - let _fail4: i128 = 0xabcabcabcabcabcabc; - let _fail5 = 1.100300400; + let _fail1 = 0xabcdef; //~ unreadable_literal + let _fail2: u32 = 0xBAFEBAFE; //~ unreadable_literal + let _fail3 = 0xabcdeff; //~ unreadable_literal + let _fail4: i128 = 0xabcabcabcabcabcabc; //~ unreadable_literal + let _fail5 = 1.100300400; //~ unreadable_literal let _ = foo!(); let _ = bar!(); diff --git a/tests/ui/unreadable_literal.stderr b/tests/ui/unreadable_literal.stderr index 37f91acf82b9..9cdb02baabfb 100644 --- a/tests/ui/unreadable_literal.stderr +++ b/tests/ui/unreadable_literal.stderr @@ -26,37 +26,37 @@ LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^^^ help: consider: `1.234_567_f32` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:33:20 + --> $DIR/unreadable_literal.rs:37:20 | LL | let _bad_sci = 1.123456e1; | ^^^^^^^^^^ help: consider: `1.123_456e1` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:35:18 + --> $DIR/unreadable_literal.rs:39:18 | LL | let _fail1 = 0xabcdef; | ^^^^^^^^ help: consider: `0x00ab_cdef` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:36:23 + --> $DIR/unreadable_literal.rs:40:23 | LL | let _fail2: u32 = 0xBAFEBAFE; | ^^^^^^^^^^ help: consider: `0xBAFE_BAFE` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:37:18 + --> $DIR/unreadable_literal.rs:41:18 | LL | let _fail3 = 0xabcdeff; | ^^^^^^^^^ help: consider: `0x0abc_deff` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:38:24 + --> $DIR/unreadable_literal.rs:42:24 | LL | let _fail4: i128 = 0xabcabcabcabcabcabc; | ^^^^^^^^^^^^^^^^^^^^ help: consider: `0x00ab_cabc_abca_bcab_cabc` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:39:18 + --> $DIR/unreadable_literal.rs:43:18 | LL | let _fail5 = 1.100300400; | ^^^^^^^^^^^ help: consider: `1.100_300_400` diff --git a/tests/ui/unseparated_prefix_literals.fixed b/tests/ui/unseparated_prefix_literals.fixed index 93f7f747b7cd..a783ebf3d49d 100644 --- a/tests/ui/unseparated_prefix_literals.fixed +++ b/tests/ui/unseparated_prefix_literals.fixed @@ -12,7 +12,7 @@ struct Foo; macro_rules! lit_from_macro { () => { - 42_usize + 42_usize //~ unseparated_literal_suffix }; } @@ -20,16 +20,16 @@ fn main() { let _ok1 = 1234_i32; let _ok2 = 1234_isize; let _ok3 = 0x123_isize; - let _fail1 = 1234_i32; - let _fail2 = 1234_u32; - let _fail3 = 1234_isize; - let _fail4 = 1234_usize; - let _fail5 = 0x123_isize; + let _fail1 = 1234_i32; //~ unseparated_literal_suffix + let _fail2 = 1234_u32; //~ unseparated_literal_suffix + let _fail3 = 1234_isize; //~ unseparated_literal_suffix + let _fail4 = 1234_usize; //~ unseparated_literal_suffix + let _fail5 = 0x123_isize; //~ unseparated_literal_suffix let _okf1 = 1.5_f32; let _okf2 = 1_f32; - let _failf1 = 1.5_f32; - let _failf2 = 1_f32; + let _failf1 = 1.5_f32; //~ unseparated_literal_suffix + let _failf2 = 1_f32; //~ unseparated_literal_suffix // Test for macro let _ = lit_from_macro!(); @@ -37,5 +37,5 @@ fn main() { // Counter example let _ = line!(); // Because `assert!` contains `line!()` macro. - assert_eq!(4897_u32, 32223); + assert_eq!(4897_u32, 32223); //~ unseparated_literal_suffix } diff --git a/tests/ui/unseparated_prefix_literals.rs b/tests/ui/unseparated_prefix_literals.rs index c960ff6b5dcc..b17bbea414c3 100644 --- a/tests/ui/unseparated_prefix_literals.rs +++ b/tests/ui/unseparated_prefix_literals.rs @@ -12,7 +12,7 @@ struct Foo; macro_rules! lit_from_macro { () => { - 42usize + 42usize //~ unseparated_literal_suffix }; } @@ -20,16 +20,16 @@ fn main() { let _ok1 = 1234_i32; let _ok2 = 1234_isize; let _ok3 = 0x123_isize; - let _fail1 = 1234i32; - let _fail2 = 1234u32; - let _fail3 = 1234isize; - let _fail4 = 1234usize; - let _fail5 = 0x123isize; + let _fail1 = 1234i32; //~ unseparated_literal_suffix + let _fail2 = 1234u32; //~ unseparated_literal_suffix + let _fail3 = 1234isize; //~ unseparated_literal_suffix + let _fail4 = 1234usize; //~ unseparated_literal_suffix + let _fail5 = 0x123isize; //~ unseparated_literal_suffix let _okf1 = 1.5_f32; let _okf2 = 1_f32; - let _failf1 = 1.5f32; - let _failf2 = 1f32; + let _failf1 = 1.5f32; //~ unseparated_literal_suffix + let _failf2 = 1f32; //~ unseparated_literal_suffix // Test for macro let _ = lit_from_macro!(); @@ -37,5 +37,5 @@ fn main() { // Counter example let _ = line!(); // Because `assert!` contains `line!()` macro. - assert_eq!(4897u32, 32223); + assert_eq!(4897u32, 32223); //~ unseparated_literal_suffix } diff --git a/tests/ui/unused_enumerate_index.fixed b/tests/ui/unused_enumerate_index.fixed index d079807ab587..945c2e30b34e 100644 --- a/tests/ui/unused_enumerate_index.fixed +++ b/tests/ui/unused_enumerate_index.fixed @@ -5,6 +5,7 @@ use std::iter::Enumerate; fn main() { let v = [1, 2, 3]; + //~v unused_enumerate_index for x in v.iter() { println!("{x}"); } @@ -52,6 +53,7 @@ fn main() { } let dummy = Dummy3(vec![1, 2, 3].into_iter()); + //~v unused_enumerate_index for x in dummy { println!("{x}"); } diff --git a/tests/ui/unused_enumerate_index.rs b/tests/ui/unused_enumerate_index.rs index 2d524da76327..7efabcd702fb 100644 --- a/tests/ui/unused_enumerate_index.rs +++ b/tests/ui/unused_enumerate_index.rs @@ -5,6 +5,7 @@ use std::iter::Enumerate; fn main() { let v = [1, 2, 3]; + //~v unused_enumerate_index for (_, x) in v.iter().enumerate() { println!("{x}"); } @@ -52,6 +53,7 @@ fn main() { } let dummy = Dummy3(vec![1, 2, 3].into_iter()); + //~v unused_enumerate_index for (_, x) in dummy.enumerate() { println!("{x}"); } diff --git a/tests/ui/unused_enumerate_index.stderr b/tests/ui/unused_enumerate_index.stderr index b575fbbc4e61..d379656a5749 100644 --- a/tests/ui/unused_enumerate_index.stderr +++ b/tests/ui/unused_enumerate_index.stderr @@ -1,5 +1,5 @@ error: you seem to use `.enumerate()` and immediately discard the index - --> $DIR/unused_enumerate_index.rs:8:19 + --> $DIR/unused_enumerate_index.rs:9:19 | LL | for (_, x) in v.iter().enumerate() { | ^^^^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL | for x in v.iter() { | ~ ~~~~~~~~ error: you seem to use `.enumerate()` and immediately discard the index - --> $DIR/unused_enumerate_index.rs:55:19 + --> $DIR/unused_enumerate_index.rs:57:19 | LL | for (_, x) in dummy.enumerate() { | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unused_io_amount.rs b/tests/ui/unused_io_amount.rs index 7e5a10c911bf..8a6e8b91feee 100644 --- a/tests/ui/unused_io_amount.rs +++ b/tests/ui/unused_io_amount.rs @@ -101,7 +101,7 @@ async fn io_not_ignored_async_write(mut w: W) { // Here we're forgetting to await the future, so we should get a // warning about _that_ (or we would, if it were enabled), but we // won't get one about ignoring the return value. - w.write(b"hello world"); + w.write(b"hello world"); //~ unused_io_amount } fn bad_async_write_closure(w: W) -> impl futures::Future> { diff --git a/tests/ui/unused_rounding.fixed b/tests/ui/unused_rounding.fixed index 02f970f42a42..821c9f0afbfc 100644 --- a/tests/ui/unused_rounding.fixed +++ b/tests/ui/unused_rounding.fixed @@ -1,16 +1,16 @@ #![warn(clippy::unused_rounding)] fn main() { - let _ = 1f32; - let _ = 1.0f64; - let _ = 1.00f32; + let _ = 1f32; //~ unused_rounding + let _ = 1.0f64; //~ unused_rounding + let _ = 1.00f32; //~ unused_rounding let _ = 2e-54f64.floor(); // issue9866 let _ = 3.3_f32.round(); let _ = 3.3_f64.round(); - let _ = 3.0_f32; + let _ = 3.0_f32; //~ unused_rounding - let _ = 3_3.0_0_f32; + let _ = 3_3.0_0_f32; //~ unused_rounding let _ = 3_3.0_1_f64.round(); } diff --git a/tests/ui/unused_rounding.rs b/tests/ui/unused_rounding.rs index fd14c466f120..967b1780e770 100644 --- a/tests/ui/unused_rounding.rs +++ b/tests/ui/unused_rounding.rs @@ -1,16 +1,16 @@ #![warn(clippy::unused_rounding)] fn main() { - let _ = 1f32.ceil(); - let _ = 1.0f64.floor(); - let _ = 1.00f32.round(); + let _ = 1f32.ceil(); //~ unused_rounding + let _ = 1.0f64.floor(); //~ unused_rounding + let _ = 1.00f32.round(); //~ unused_rounding let _ = 2e-54f64.floor(); // issue9866 let _ = 3.3_f32.round(); let _ = 3.3_f64.round(); - let _ = 3.0_f32.round(); + let _ = 3.0_f32.round(); //~ unused_rounding - let _ = 3_3.0_0_f32.round(); + let _ = 3_3.0_0_f32.round(); //~ unused_rounding let _ = 3_3.0_1_f64.round(); } diff --git a/tests/ui/unused_unit.fixed b/tests/ui/unused_unit.fixed index 16da9a25b2aa..bc11d6da4c7c 100644 --- a/tests/ui/unused_unit.fixed +++ b/tests/ui/unused_unit.fixed @@ -18,34 +18,43 @@ struct Unitter; impl Unitter { #[allow(clippy::no_effect)] pub fn get_unit(&self, f: F, _g: G) + //~^ unused_unit + //~| unused_unit + + //~v unused_unit where G: Fn() { - let _y: &dyn Fn() = &f; + let _y: &dyn Fn() = &f; //~ unused_unit (); // this should not lint, as it's not in return type position } } impl Into<()> for Unitter { #[rustfmt::skip] + //~v unused_unit fn into(self) { - + //~ unused_unit } } trait Trait { fn redundant(&self, _f: F, _g: G, _h: H) + //~^ unused_unit where - G: FnMut(), - H: Fn(); + G: FnMut(), //~ unused_unit + H: Fn(); //~ unused_unit } impl Trait for Unitter { fn redundant(&self, _f: F, _g: G, _h: H) + //~^ unused_unit where - G: FnMut(), - H: Fn() {} + G: FnMut(), //~ unused_unit + H: Fn() {} //~ unused_unit } fn return_unit() { } +//~^ unused_unit +//~| unused_unit #[allow(clippy::needless_return)] #[allow(clippy::never_loop)] @@ -55,9 +64,9 @@ fn main() { assert_eq!(u.get_unit(|| {}, return_unit), u.into()); return_unit(); loop { - break; + break; //~ unused_unit } - return; + return; //~ unused_unit } // https://github.com/rust-lang/rust-clippy/issues/4076 @@ -74,13 +83,13 @@ fn foo() { } #[rustfmt::skip] -fn test(){} +fn test(){} //~ unused_unit #[rustfmt::skip] -fn test2(){} +fn test2(){} //~ unused_unit #[rustfmt::skip] -fn test3(){} +fn test3(){} //~ unused_unit fn macro_expr() { macro_rules! e { diff --git a/tests/ui/unused_unit.rs b/tests/ui/unused_unit.rs index e374031436d5..a43bfdd47afc 100644 --- a/tests/ui/unused_unit.rs +++ b/tests/ui/unused_unit.rs @@ -18,34 +18,43 @@ struct Unitter; impl Unitter { #[allow(clippy::no_effect)] pub fn get_unit (), G>(&self, f: F, _g: G) -> () + //~^ unused_unit + //~| unused_unit + + //~v unused_unit where G: Fn() -> () { - let _y: &dyn Fn() -> () = &f; + let _y: &dyn Fn() -> () = &f; //~ unused_unit (); // this should not lint, as it's not in return type position } } impl Into<()> for Unitter { #[rustfmt::skip] + //~v unused_unit fn into(self) -> () { - () + () //~ unused_unit } } trait Trait { fn redundant (), G, H>(&self, _f: F, _g: G, _h: H) + //~^ unused_unit where - G: FnMut() -> (), - H: Fn() -> (); + G: FnMut() -> (), //~ unused_unit + H: Fn() -> (); //~ unused_unit } impl Trait for Unitter { fn redundant (), G, H>(&self, _f: F, _g: G, _h: H) + //~^ unused_unit where - G: FnMut() -> (), - H: Fn() -> () {} + G: FnMut() -> (), //~ unused_unit + H: Fn() -> () {} //~ unused_unit } fn return_unit() -> () { () } +//~^ unused_unit +//~| unused_unit #[allow(clippy::needless_return)] #[allow(clippy::never_loop)] @@ -55,9 +64,9 @@ fn main() { assert_eq!(u.get_unit(|| {}, return_unit), u.into()); return_unit(); loop { - break(); + break(); //~ unused_unit } - return(); + return(); //~ unused_unit } // https://github.com/rust-lang/rust-clippy/issues/4076 @@ -74,13 +83,13 @@ fn foo() { } #[rustfmt::skip] -fn test()->(){} +fn test()->(){} //~ unused_unit #[rustfmt::skip] -fn test2() ->(){} +fn test2() ->(){} //~ unused_unit #[rustfmt::skip] -fn test3()-> (){} +fn test3()-> (){} //~ unused_unit fn macro_expr() { macro_rules! e { diff --git a/tests/ui/unused_unit.stderr b/tests/ui/unused_unit.stderr index ce06738cfe47..ba6a88c6d6aa 100644 --- a/tests/ui/unused_unit.stderr +++ b/tests/ui/unused_unit.stderr @@ -17,103 +17,103 @@ LL | pub fn get_unit (), G>(&self, f: F, _g: G) -> () | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> $DIR/unused_unit.rs:21:18 + --> $DIR/unused_unit.rs:25:18 | LL | where G: Fn() -> () { | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> $DIR/unused_unit.rs:22:26 + --> $DIR/unused_unit.rs:26:26 | LL | let _y: &dyn Fn() -> () = &f; | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> $DIR/unused_unit.rs:29:18 + --> $DIR/unused_unit.rs:34:18 | LL | fn into(self) -> () { | ^^^^^^ help: remove the `-> ()` error: unneeded unit expression - --> $DIR/unused_unit.rs:30:9 + --> $DIR/unused_unit.rs:35:9 | LL | () | ^^ help: remove the final `()` error: unneeded unit return type - --> $DIR/unused_unit.rs:35:29 + --> $DIR/unused_unit.rs:40:29 | LL | fn redundant (), G, H>(&self, _f: F, _g: G, _h: H) | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> $DIR/unused_unit.rs:37:19 + --> $DIR/unused_unit.rs:43:19 | LL | G: FnMut() -> (), | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> $DIR/unused_unit.rs:38:16 + --> $DIR/unused_unit.rs:44:16 | LL | H: Fn() -> (); | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> $DIR/unused_unit.rs:42:29 + --> $DIR/unused_unit.rs:48:29 | LL | fn redundant (), G, H>(&self, _f: F, _g: G, _h: H) | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> $DIR/unused_unit.rs:44:19 + --> $DIR/unused_unit.rs:51:19 | LL | G: FnMut() -> (), | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> $DIR/unused_unit.rs:45:16 + --> $DIR/unused_unit.rs:52:16 | LL | H: Fn() -> () {} | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> $DIR/unused_unit.rs:48:17 + --> $DIR/unused_unit.rs:55:17 | LL | fn return_unit() -> () { () } | ^^^^^^ help: remove the `-> ()` error: unneeded unit expression - --> $DIR/unused_unit.rs:48:26 + --> $DIR/unused_unit.rs:55:26 | LL | fn return_unit() -> () { () } | ^^ help: remove the final `()` error: unneeded `()` - --> $DIR/unused_unit.rs:58:14 + --> $DIR/unused_unit.rs:67:14 | LL | break(); | ^^ help: remove the `()` error: unneeded `()` - --> $DIR/unused_unit.rs:60:11 + --> $DIR/unused_unit.rs:69:11 | LL | return(); | ^^ help: remove the `()` error: unneeded unit return type - --> $DIR/unused_unit.rs:77:10 + --> $DIR/unused_unit.rs:86:10 | LL | fn test()->(){} | ^^^^ help: remove the `-> ()` error: unneeded unit return type - --> $DIR/unused_unit.rs:80:11 + --> $DIR/unused_unit.rs:89:11 | LL | fn test2() ->(){} | ^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> $DIR/unused_unit.rs:83:11 + --> $DIR/unused_unit.rs:92:11 | LL | fn test3()-> (){} | ^^^^^ help: remove the `-> ()` diff --git a/tests/ui/unwrap_or_else_default.fixed b/tests/ui/unwrap_or_else_default.fixed index 8d5d34175c52..525d9e520e66 100644 --- a/tests/ui/unwrap_or_else_default.fixed +++ b/tests/ui/unwrap_or_else_default.fixed @@ -43,7 +43,7 @@ fn unwrap_or_else_default() { with_enum.unwrap_or_else(Enum::A); let with_new = Some(vec![1]); - with_new.unwrap_or_default(); + with_new.unwrap_or_default(); //~ unwrap_or_default let with_err: Result<_, ()> = Ok(vec![1]); with_err.unwrap_or_else(make); @@ -58,43 +58,48 @@ fn unwrap_or_else_default() { let with_real_default = None::; with_real_default.unwrap_or_default(); + //~^ unwrap_or_default let with_default_trait = Some(1); with_default_trait.unwrap_or_default(); + //~^ unwrap_or_default let with_default_type = Some(1); with_default_type.unwrap_or_default(); + //~^ unwrap_or_default let with_default_type: Option> = None; with_default_type.unwrap_or_default(); + //~^ unwrap_or_default let empty_string = None::; empty_string.unwrap_or_default(); + //~^ unwrap_or_default } fn type_certainty(option: Option>) { - option.unwrap_or_default().push(1); + option.unwrap_or_default().push(1); //~ unwrap_or_default let option: std::option::Option> = None; - option.unwrap_or_default().push(1); + option.unwrap_or_default().push(1); //~ unwrap_or_default let option: Option> = None; - option.unwrap_or_default().push(1); + option.unwrap_or_default().push(1); //~ unwrap_or_default let option = std::option::Option::>::None; - option.unwrap_or_default().push(1); + option.unwrap_or_default().push(1); //~ unwrap_or_default let option = Option::>::None; - option.unwrap_or_default().push(1); + option.unwrap_or_default().push(1); //~ unwrap_or_default let option = std::option::Option::None::>; - option.unwrap_or_default().push(1); + option.unwrap_or_default().push(1); //~ unwrap_or_default let option = Option::None::>; - option.unwrap_or_default().push(1); + option.unwrap_or_default().push(1); //~ unwrap_or_default let option = None::>; - option.unwrap_or_default().push(1); + option.unwrap_or_default().push(1); //~ unwrap_or_default // should not be changed: type annotation with infer, unconcretized initializer let option: Option> = None; @@ -110,7 +115,7 @@ fn type_certainty(option: Option>) { type Alias = Option>; let option: Alias = Option::>::Some(Vec::new()); - option.unwrap_or_default().push(1); + option.unwrap_or_default().push(1); //~ unwrap_or_default } fn method_call_with_deref() { @@ -128,6 +133,7 @@ fn method_call_with_deref() { let inner_map = outer_map.get_mut(&option.unwrap()).unwrap(); let _ = inner_map.entry(0).or_default(); + //~^ unwrap_or_default } fn missing_suggested_method() { diff --git a/tests/ui/unwrap_or_else_default.rs b/tests/ui/unwrap_or_else_default.rs index adbcb4b44659..a071891ba642 100644 --- a/tests/ui/unwrap_or_else_default.rs +++ b/tests/ui/unwrap_or_else_default.rs @@ -43,7 +43,7 @@ fn unwrap_or_else_default() { with_enum.unwrap_or_else(Enum::A); let with_new = Some(vec![1]); - with_new.unwrap_or_else(Vec::new); + with_new.unwrap_or_else(Vec::new); //~ unwrap_or_default let with_err: Result<_, ()> = Ok(vec![1]); with_err.unwrap_or_else(make); @@ -58,43 +58,48 @@ fn unwrap_or_else_default() { let with_real_default = None::; with_real_default.unwrap_or_else(::default); + //~^ unwrap_or_default let with_default_trait = Some(1); with_default_trait.unwrap_or_else(Default::default); + //~^ unwrap_or_default let with_default_type = Some(1); with_default_type.unwrap_or_else(u64::default); + //~^ unwrap_or_default let with_default_type: Option> = None; with_default_type.unwrap_or_else(Vec::new); + //~^ unwrap_or_default let empty_string = None::; empty_string.unwrap_or_else(|| "".to_string()); + //~^ unwrap_or_default } fn type_certainty(option: Option>) { - option.unwrap_or_else(Vec::new).push(1); + option.unwrap_or_else(Vec::new).push(1); //~ unwrap_or_default let option: std::option::Option> = None; - option.unwrap_or_else(Vec::new).push(1); + option.unwrap_or_else(Vec::new).push(1); //~ unwrap_or_default let option: Option> = None; - option.unwrap_or_else(Vec::new).push(1); + option.unwrap_or_else(Vec::new).push(1); //~ unwrap_or_default let option = std::option::Option::>::None; - option.unwrap_or_else(Vec::new).push(1); + option.unwrap_or_else(Vec::new).push(1); //~ unwrap_or_default let option = Option::>::None; - option.unwrap_or_else(Vec::new).push(1); + option.unwrap_or_else(Vec::new).push(1); //~ unwrap_or_default let option = std::option::Option::None::>; - option.unwrap_or_else(Vec::new).push(1); + option.unwrap_or_else(Vec::new).push(1); //~ unwrap_or_default let option = Option::None::>; - option.unwrap_or_else(Vec::new).push(1); + option.unwrap_or_else(Vec::new).push(1); //~ unwrap_or_default let option = None::>; - option.unwrap_or_else(Vec::new).push(1); + option.unwrap_or_else(Vec::new).push(1); //~ unwrap_or_default // should not be changed: type annotation with infer, unconcretized initializer let option: Option> = None; @@ -110,7 +115,7 @@ fn type_certainty(option: Option>) { type Alias = Option>; let option: Alias = Option::>::Some(Vec::new()); - option.unwrap_or_else(Vec::new).push(1); + option.unwrap_or_else(Vec::new).push(1); //~ unwrap_or_default } fn method_call_with_deref() { @@ -128,6 +133,7 @@ fn method_call_with_deref() { let inner_map = outer_map.get_mut(&option.unwrap()).unwrap(); let _ = inner_map.entry(0).or_insert_with(Default::default); + //~^ unwrap_or_default } fn missing_suggested_method() { diff --git a/tests/ui/unwrap_or_else_default.stderr b/tests/ui/unwrap_or_else_default.stderr index 3119aba19e8f..96adac96888f 100644 --- a/tests/ui/unwrap_or_else_default.stderr +++ b/tests/ui/unwrap_or_else_default.stderr @@ -14,85 +14,85 @@ LL | with_real_default.unwrap_or_else(::d | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:63:24 + --> $DIR/unwrap_or_else_default.rs:64:24 | LL | with_default_trait.unwrap_or_else(Default::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:66:23 + --> $DIR/unwrap_or_else_default.rs:68:23 | LL | with_default_type.unwrap_or_else(u64::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:69:23 + --> $DIR/unwrap_or_else_default.rs:72:23 | LL | with_default_type.unwrap_or_else(Vec::new); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:72:18 + --> $DIR/unwrap_or_else_default.rs:76:18 | LL | empty_string.unwrap_or_else(|| "".to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:76:12 + --> $DIR/unwrap_or_else_default.rs:81:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:79:12 + --> $DIR/unwrap_or_else_default.rs:84:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:82:12 + --> $DIR/unwrap_or_else_default.rs:87:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:85:12 + --> $DIR/unwrap_or_else_default.rs:90:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:88:12 + --> $DIR/unwrap_or_else_default.rs:93:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:91:12 + --> $DIR/unwrap_or_else_default.rs:96:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:94:12 + --> $DIR/unwrap_or_else_default.rs:99:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:97:12 + --> $DIR/unwrap_or_else_default.rs:102:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:113:12 + --> $DIR/unwrap_or_else_default.rs:118:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `or_insert_with` to construct default value - --> $DIR/unwrap_or_else_default.rs:130:32 + --> $DIR/unwrap_or_else_default.rs:135:32 | LL | let _ = inner_map.entry(0).or_insert_with(Default::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` diff --git a/tests/ui/use_self.fixed b/tests/ui/use_self.fixed index 787dd3ec7e68..c5282d2ea367 100644 --- a/tests/ui/use_self.fixed +++ b/tests/ui/use_self.fixed @@ -18,17 +18,20 @@ mod use_self { struct Foo; impl Foo { + //~v use_self fn new() -> Self { - Self {} + Self {} //~ use_self } + //~v use_self fn test() -> Self { - Self::new() + Self::new() //~ use_self } } impl Default for Foo { + //~v use_self fn default() -> Self { - Self::new() + Self::new() //~ use_self } } } @@ -93,6 +96,8 @@ mod existential { struct Foo; impl Foo { + //~| use_self + //~v use_self fn bad(foos: &[Self]) -> impl Iterator { foos.iter() } @@ -108,7 +113,7 @@ mod tuple_structs { impl TS { pub fn ts() -> Self { - Self(0) + Self(0) //~ use_self } } } @@ -143,8 +148,9 @@ mod nesting { } impl Bar { + //~v use_self fn bar() -> Self { - Self { foo: Foo {} } + Self { foo: Foo {} } //~ use_self } } @@ -155,8 +161,9 @@ mod nesting { } // Should lint here + //~v use_self fn baz() -> Self { - Self {} + Self {} //~ use_self } } @@ -173,9 +180,9 @@ mod nesting { } fn method2() { - let _ = Self::B(42); - let _ = Self::C { field: true }; - let _ = Self::A; + let _ = Self::B(42); //~ use_self + let _ = Self::C { field: true }; //~ use_self + let _ = Self::A; //~ use_self } } } @@ -217,10 +224,10 @@ mod rustfix { fn fun_1() {} fn fun_2() { - Self::fun_1(); - Self::A; + Self::fun_1(); //~ use_self + Self::A; //~ use_self - Self {}; + Self {}; //~ use_self } } } @@ -239,7 +246,7 @@ mod issue3567 { impl Test for TestStruct { fn test() -> TestStruct { - Self::from_something() + Self::from_something() //~ use_self } } } @@ -253,12 +260,15 @@ mod paths_created_by_lowering { const A: usize = 0; const B: usize = 1; + //~v use_self async fn g() -> Self { - Self {} + Self {} //~ use_self } fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] { &p[Self::A..Self::B] + //~^ use_self + //~| use_self } } @@ -281,8 +291,9 @@ mod generics { impl Foo { // `Self` is applicable here + //~v use_self fn foo(value: T) -> Self { - Self { value } + Self { value } //~ use_self } // `Cannot` use `Self` as a return type as the generic types are different @@ -454,7 +465,7 @@ mod nested_paths { impl A { fn test() -> Self { - Self::new::(submod::B {}) + Self::new::(submod::B {}) //~ use_self } } } @@ -491,7 +502,7 @@ mod issue7206 { impl<'a> S2> { fn new_again() -> Self { - Self::new() + Self::new() //~ use_self } } } @@ -528,13 +539,14 @@ mod use_self_in_pat { impl Foo { fn do_stuff(self) { match self { - Self::Bar => unimplemented!(), - Self::Baz => unimplemented!(), + Self::Bar => unimplemented!(), //~ use_self + Self::Baz => unimplemented!(), //~ use_self } match Some(1) { Some(_) => unimplemented!(), None => unimplemented!(), } + //~v use_self if let Self::Bar = self { unimplemented!() } @@ -559,17 +571,21 @@ mod issue8845 { impl Something { fn get_value(&self) -> u8 { match self { - Self::Num(n) => *n, - Self::TupleNums(n, _m) => *n, + Self::Num(n) => *n, //~ use_self + Self::TupleNums(n, _m) => *n, //~ use_self Self::StructNums { one, two: _ } => *one, + //~^ use_self } } fn use_crate(&self) -> u8 { match self { Self::Num(n) => *n, + //~^ use_self Self::TupleNums(n, _m) => *n, + //~^ use_self Self::StructNums { one, two: _ } => *one, + //~^ use_self } } @@ -585,24 +601,24 @@ mod issue8845 { impl Foo { fn get_value(&self) -> u8 { - let Self(x) = self; + let Self(x) = self; //~ use_self *x } fn use_crate(&self) -> u8 { - let Self(x) = self; + let Self(x) = self; //~ use_self *x } } impl Bar { fn get_value(&self) -> u8 { - let Self { x, .. } = self; + let Self { x, .. } = self; //~ use_self *x } fn use_crate(&self) -> u8 { - let Self { x, .. } = self; + let Self { x, .. } = self; //~ use_self *x } } @@ -641,7 +657,7 @@ fn msrv_1_37() { impl E { fn foo(self) { match self { - Self::A => {}, + Self::A => {}, //~ use_self } } } diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs index 39e182faea67..041fc4137240 100644 --- a/tests/ui/use_self.rs +++ b/tests/ui/use_self.rs @@ -18,17 +18,20 @@ mod use_self { struct Foo; impl Foo { + //~v use_self fn new() -> Foo { - Foo {} + Foo {} //~ use_self } + //~v use_self fn test() -> Foo { - Foo::new() + Foo::new() //~ use_self } } impl Default for Foo { + //~v use_self fn default() -> Foo { - Foo::new() + Foo::new() //~ use_self } } } @@ -93,6 +96,8 @@ mod existential { struct Foo; impl Foo { + //~| use_self + //~v use_self fn bad(foos: &[Foo]) -> impl Iterator { foos.iter() } @@ -108,7 +113,7 @@ mod tuple_structs { impl TS { pub fn ts() -> Self { - TS(0) + TS(0) //~ use_self } } } @@ -143,8 +148,9 @@ mod nesting { } impl Bar { + //~v use_self fn bar() -> Bar { - Bar { foo: Foo {} } + Bar { foo: Foo {} } //~ use_self } } @@ -155,8 +161,9 @@ mod nesting { } // Should lint here + //~v use_self fn baz() -> Foo { - Foo {} + Foo {} //~ use_self } } @@ -173,9 +180,9 @@ mod nesting { } fn method2() { - let _ = Enum::B(42); - let _ = Enum::C { field: true }; - let _ = Enum::A; + let _ = Enum::B(42); //~ use_self + let _ = Enum::C { field: true }; //~ use_self + let _ = Enum::A; //~ use_self } } } @@ -217,10 +224,10 @@ mod rustfix { fn fun_1() {} fn fun_2() { - nested::A::fun_1(); - nested::A::A; + nested::A::fun_1(); //~ use_self + nested::A::A; //~ use_self - nested::A {}; + nested::A {}; //~ use_self } } } @@ -239,7 +246,7 @@ mod issue3567 { impl Test for TestStruct { fn test() -> TestStruct { - TestStruct::from_something() + TestStruct::from_something() //~ use_self } } } @@ -253,12 +260,15 @@ mod paths_created_by_lowering { const A: usize = 0; const B: usize = 1; + //~v use_self async fn g() -> S { - S {} + S {} //~ use_self } fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] { &p[S::A..S::B] + //~^ use_self + //~| use_self } } @@ -281,8 +291,9 @@ mod generics { impl Foo { // `Self` is applicable here + //~v use_self fn foo(value: T) -> Foo { - Foo:: { value } + Foo:: { value } //~ use_self } // `Cannot` use `Self` as a return type as the generic types are different @@ -454,7 +465,7 @@ mod nested_paths { impl A { fn test() -> Self { - A::new::(submod::B {}) + A::new::(submod::B {}) //~ use_self } } } @@ -491,7 +502,7 @@ mod issue7206 { impl<'a> S2> { fn new_again() -> Self { - S2::new() + S2::new() //~ use_self } } } @@ -528,13 +539,14 @@ mod use_self_in_pat { impl Foo { fn do_stuff(self) { match self { - Foo::Bar => unimplemented!(), - Foo::Baz => unimplemented!(), + Foo::Bar => unimplemented!(), //~ use_self + Foo::Baz => unimplemented!(), //~ use_self } match Some(1) { Some(_) => unimplemented!(), None => unimplemented!(), } + //~v use_self if let Foo::Bar = self { unimplemented!() } @@ -559,17 +571,21 @@ mod issue8845 { impl Something { fn get_value(&self) -> u8 { match self { - Something::Num(n) => *n, - Something::TupleNums(n, _m) => *n, + Something::Num(n) => *n, //~ use_self + Something::TupleNums(n, _m) => *n, //~ use_self Something::StructNums { one, two: _ } => *one, + //~^ use_self } } fn use_crate(&self) -> u8 { match self { crate::issue8845::Something::Num(n) => *n, + //~^ use_self crate::issue8845::Something::TupleNums(n, _m) => *n, + //~^ use_self crate::issue8845::Something::StructNums { one, two: _ } => *one, + //~^ use_self } } @@ -585,24 +601,24 @@ mod issue8845 { impl Foo { fn get_value(&self) -> u8 { - let Foo(x) = self; + let Foo(x) = self; //~ use_self *x } fn use_crate(&self) -> u8 { - let crate::issue8845::Foo(x) = self; + let crate::issue8845::Foo(x) = self; //~ use_self *x } } impl Bar { fn get_value(&self) -> u8 { - let Bar { x, .. } = self; + let Bar { x, .. } = self; //~ use_self *x } fn use_crate(&self) -> u8 { - let crate::issue8845::Bar { x, .. } = self; + let crate::issue8845::Bar { x, .. } = self; //~ use_self *x } } @@ -641,7 +657,7 @@ fn msrv_1_37() { impl E { fn foo(self) { match self { - E::A => {}, + E::A => {}, //~ use_self } } } diff --git a/tests/ui/use_self.stderr b/tests/ui/use_self.stderr index a1d4eac5dc09..c58c3fb094eb 100644 --- a/tests/ui/use_self.stderr +++ b/tests/ui/use_self.stderr @@ -1,5 +1,5 @@ error: unnecessary structure name repetition - --> $DIR/use_self.rs:21:21 + --> $DIR/use_self.rs:22:21 | LL | fn new() -> Foo { | ^^^ help: use the applicable keyword: `Self` @@ -8,247 +8,247 @@ LL | fn new() -> Foo { = help: to override `-D warnings` add `#[allow(clippy::use_self)]` error: unnecessary structure name repetition - --> $DIR/use_self.rs:22:13 + --> $DIR/use_self.rs:23:13 | LL | Foo {} | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:24:22 + --> $DIR/use_self.rs:26:22 | LL | fn test() -> Foo { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:25:13 + --> $DIR/use_self.rs:27:13 | LL | Foo::new() | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:30:25 + --> $DIR/use_self.rs:33:25 | LL | fn default() -> Foo { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:31:13 + --> $DIR/use_self.rs:34:13 | LL | Foo::new() | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:96:24 + --> $DIR/use_self.rs:101:24 | LL | fn bad(foos: &[Foo]) -> impl Iterator { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:96:55 + --> $DIR/use_self.rs:101:55 | LL | fn bad(foos: &[Foo]) -> impl Iterator { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:111:13 + --> $DIR/use_self.rs:116:13 | LL | TS(0) | ^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:146:29 + --> $DIR/use_self.rs:152:29 | LL | fn bar() -> Bar { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:147:21 + --> $DIR/use_self.rs:153:21 | LL | Bar { foo: Foo {} } | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:158:21 + --> $DIR/use_self.rs:165:21 | LL | fn baz() -> Foo { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:159:13 + --> $DIR/use_self.rs:166:13 | LL | Foo {} | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:176:21 + --> $DIR/use_self.rs:183:21 | LL | let _ = Enum::B(42); | ^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:177:21 + --> $DIR/use_self.rs:184:21 | LL | let _ = Enum::C { field: true }; | ^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:178:21 + --> $DIR/use_self.rs:185:21 | LL | let _ = Enum::A; | ^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:220:13 + --> $DIR/use_self.rs:227:13 | LL | nested::A::fun_1(); | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:221:13 + --> $DIR/use_self.rs:228:13 | LL | nested::A::A; | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:223:13 + --> $DIR/use_self.rs:230:13 | LL | nested::A {}; | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:242:13 + --> $DIR/use_self.rs:249:13 | LL | TestStruct::from_something() | ^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:256:25 + --> $DIR/use_self.rs:264:25 | LL | async fn g() -> S { | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:257:13 + --> $DIR/use_self.rs:265:13 | LL | S {} | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:261:16 + --> $DIR/use_self.rs:269:16 | LL | &p[S::A..S::B] | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:261:22 + --> $DIR/use_self.rs:269:22 | LL | &p[S::A..S::B] | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:284:29 + --> $DIR/use_self.rs:295:29 | LL | fn foo(value: T) -> Foo { | ^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:285:13 + --> $DIR/use_self.rs:296:13 | LL | Foo:: { value } | ^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:457:13 + --> $DIR/use_self.rs:468:13 | LL | A::new::(submod::B {}) | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:494:13 + --> $DIR/use_self.rs:505:13 | LL | S2::new() | ^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:531:17 + --> $DIR/use_self.rs:542:17 | LL | Foo::Bar => unimplemented!(), | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:532:17 + --> $DIR/use_self.rs:543:17 | LL | Foo::Baz => unimplemented!(), | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:538:20 + --> $DIR/use_self.rs:550:20 | LL | if let Foo::Bar = self { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:562:17 + --> $DIR/use_self.rs:574:17 | LL | Something::Num(n) => *n, | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:563:17 + --> $DIR/use_self.rs:575:17 | LL | Something::TupleNums(n, _m) => *n, | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:564:17 + --> $DIR/use_self.rs:576:17 | LL | Something::StructNums { one, two: _ } => *one, | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:570:17 + --> $DIR/use_self.rs:583:17 | LL | crate::issue8845::Something::Num(n) => *n, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:571:17 + --> $DIR/use_self.rs:585:17 | LL | crate::issue8845::Something::TupleNums(n, _m) => *n, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:572:17 + --> $DIR/use_self.rs:587:17 | LL | crate::issue8845::Something::StructNums { one, two: _ } => *one, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:588:17 + --> $DIR/use_self.rs:604:17 | LL | let Foo(x) = self; | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:593:17 + --> $DIR/use_self.rs:609:17 | LL | let crate::issue8845::Foo(x) = self; | ^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:600:17 + --> $DIR/use_self.rs:616:17 | LL | let Bar { x, .. } = self; | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:605:17 + --> $DIR/use_self.rs:621:17 | LL | let crate::issue8845::Bar { x, .. } = self; | ^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:644:17 + --> $DIR/use_self.rs:660:17 | LL | E::A => {}, | ^ help: use the applicable keyword: `Self` diff --git a/tests/ui/use_self_trait.fixed b/tests/ui/use_self_trait.fixed index 2758ec7aca1f..8912b3db0a7b 100644 --- a/tests/ui/use_self_trait.fixed +++ b/tests/ui/use_self_trait.fixed @@ -16,28 +16,40 @@ trait SelfTrait { struct Bad; impl SelfTrait for Bad { + //~| use_self + //~v use_self fn refs(p1: &Self) -> &Self { p1 } + //~| use_self + //~v use_self fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self { p1 } + //~| use_self + //~v use_self fn mut_refs(p1: &mut Self) -> &mut Self { p1 } fn nested(_p1: Box, _p2: (&u8, &Self)) {} + //~^ use_self + //~| use_self + //~| use_self + //~v use_self fn vals(_: Self) -> Self { - Self + Self //~ use_self } } impl Mul for Bad { - type Output = Self; + type Output = Self; //~ use_self + //~| use_self + //~v use_self fn mul(self, rhs: Self) -> Self { rhs } @@ -45,7 +57,7 @@ impl Mul for Bad { impl Clone for Bad { fn clone(&self) -> Self { - Self + Self //~ use_self } } @@ -142,6 +154,7 @@ mod full_path_replacement { impl Error for std::fmt::Error { fn custom(_msg: T) -> Self { + //~v use_self Self // Should lint } } diff --git a/tests/ui/use_self_trait.rs b/tests/ui/use_self_trait.rs index 31031e8f50b2..4c1cb24479bc 100644 --- a/tests/ui/use_self_trait.rs +++ b/tests/ui/use_self_trait.rs @@ -16,28 +16,40 @@ trait SelfTrait { struct Bad; impl SelfTrait for Bad { + //~| use_self + //~v use_self fn refs(p1: &Bad) -> &Bad { p1 } + //~| use_self + //~v use_self fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad { p1 } + //~| use_self + //~v use_self fn mut_refs(p1: &mut Bad) -> &mut Bad { p1 } fn nested(_p1: Box, _p2: (&u8, &Bad)) {} + //~^ use_self + //~| use_self + //~| use_self + //~v use_self fn vals(_: Bad) -> Bad { - Bad + Bad //~ use_self } } impl Mul for Bad { - type Output = Bad; + type Output = Bad; //~ use_self + //~| use_self + //~v use_self fn mul(self, rhs: Bad) -> Bad { rhs } @@ -45,7 +57,7 @@ impl Mul for Bad { impl Clone for Bad { fn clone(&self) -> Self { - Bad + Bad //~ use_self } } @@ -142,6 +154,7 @@ mod full_path_replacement { impl Error for std::fmt::Error { fn custom(_msg: T) -> Self { + //~v use_self std::fmt::Error // Should lint } } diff --git a/tests/ui/use_self_trait.stderr b/tests/ui/use_self_trait.stderr index 71a227174eaf..a34621a2eb36 100644 --- a/tests/ui/use_self_trait.stderr +++ b/tests/ui/use_self_trait.stderr @@ -1,5 +1,5 @@ error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:19:18 + --> $DIR/use_self_trait.rs:21:18 | LL | fn refs(p1: &Bad) -> &Bad { | ^^^ help: use the applicable keyword: `Self` @@ -8,91 +8,91 @@ LL | fn refs(p1: &Bad) -> &Bad { = help: to override `-D warnings` add `#[allow(clippy::use_self)]` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:19:27 + --> $DIR/use_self_trait.rs:21:27 | LL | fn refs(p1: &Bad) -> &Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:23:33 + --> $DIR/use_self_trait.rs:27:33 | LL | fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:23:49 + --> $DIR/use_self_trait.rs:27:49 | LL | fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:27:26 + --> $DIR/use_self_trait.rs:33:26 | LL | fn mut_refs(p1: &mut Bad) -> &mut Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:27:39 + --> $DIR/use_self_trait.rs:33:39 | LL | fn mut_refs(p1: &mut Bad) -> &mut Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:31:24 + --> $DIR/use_self_trait.rs:37:24 | LL | fn nested(_p1: Box, _p2: (&u8, &Bad)) {} | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:31:42 + --> $DIR/use_self_trait.rs:37:42 | LL | fn nested(_p1: Box, _p2: (&u8, &Bad)) {} | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:33:16 + --> $DIR/use_self_trait.rs:43:16 | LL | fn vals(_: Bad) -> Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:33:24 + --> $DIR/use_self_trait.rs:43:24 | LL | fn vals(_: Bad) -> Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:34:9 + --> $DIR/use_self_trait.rs:44:9 | LL | Bad | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:39:19 + --> $DIR/use_self_trait.rs:49:19 | LL | type Output = Bad; | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:41:23 + --> $DIR/use_self_trait.rs:53:23 | LL | fn mul(self, rhs: Bad) -> Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:41:31 + --> $DIR/use_self_trait.rs:53:31 | LL | fn mul(self, rhs: Bad) -> Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:48:9 + --> $DIR/use_self_trait.rs:60:9 | LL | Bad | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:145:13 + --> $DIR/use_self_trait.rs:158:13 | LL | std::fmt::Error // Should lint | ^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` diff --git a/tests/ui/used_underscore_binding.rs b/tests/ui/used_underscore_binding.rs index a8f404b1400c..33852c6b351a 100644 --- a/tests/ui/used_underscore_binding.rs +++ b/tests/ui/used_underscore_binding.rs @@ -20,13 +20,15 @@ macro_rules! test_macro { /// Tests that we lint if we use a binding with a single leading underscore fn prefix_underscore(_foo: u32) -> u32 { - _foo + 1 + _foo + 1 //~ used_underscore_binding } /// Tests that we lint if we use a `_`-variable defined outside within a macro expansion fn in_macro_or_desugar(_foo: u32) { - println!("{}", _foo); + println!("{}", _foo); //~ used_underscore_binding assert_eq!(_foo, _foo); + //~^ used_underscore_binding + //~| used_underscore_binding test_macro!() + 1; } @@ -39,7 +41,7 @@ struct StructFieldTest { /// Tests that we lint the use of a struct field which is prefixed with an underscore fn in_struct_field() { let mut s = StructFieldTest { _underscore_field: 0 }; - s._underscore_field += 1; + s._underscore_field += 1; //~ used_underscore_binding } /// Tests that we do not lint if the struct field is used in code created with derive. @@ -100,7 +102,7 @@ async fn await_desugaring() { foo().await; ({ let _i = 5; - uses_i(_i); + uses_i(_i); //~ used_underscore_binding foo() }) .await diff --git a/tests/ui/used_underscore_binding.stderr b/tests/ui/used_underscore_binding.stderr index 78d8279810c1..060a09385486 100644 --- a/tests/ui/used_underscore_binding.stderr +++ b/tests/ui/used_underscore_binding.stderr @@ -49,25 +49,25 @@ LL | fn in_macro_or_desugar(_foo: u32) { | ^^^^ error: used binding `_underscore_field` which is prefixed with an underscore. A leading underscore signals that a binding will not be used - --> $DIR/used_underscore_binding.rs:42:5 + --> $DIR/used_underscore_binding.rs:44:5 | LL | s._underscore_field += 1; | ^^^^^^^^^^^^^^^^^^^ | note: `_underscore_field` is defined here - --> $DIR/used_underscore_binding.rs:36:5 + --> $DIR/used_underscore_binding.rs:38:5 | LL | _underscore_field: u32, | ^^^^^^^^^^^^^^^^^^^^^^ error: used binding `_i` which is prefixed with an underscore. A leading underscore signals that a binding will not be used - --> $DIR/used_underscore_binding.rs:103:16 + --> $DIR/used_underscore_binding.rs:105:16 | LL | uses_i(_i); | ^^ | note: `_i` is defined here - --> $DIR/used_underscore_binding.rs:102:13 + --> $DIR/used_underscore_binding.rs:104:13 | LL | let _i = 5; | ^^ diff --git a/tests/ui/useless_asref.fixed b/tests/ui/useless_asref.fixed index c98f2928e03c..27d1ab118689 100644 --- a/tests/ui/useless_asref.fixed +++ b/tests/ui/useless_asref.fixed @@ -45,35 +45,35 @@ fn not_ok() { { let rslice: &[i32] = &*mrslice; + foo_rstr(rstr); //~ useless_asref foo_rstr(rstr); - foo_rstr(rstr); - foo_rslice(rslice); + foo_rslice(rslice); //~ useless_asref foo_rslice(rslice); } { + foo_mrslice(mrslice); //~ useless_asref foo_mrslice(mrslice); - foo_mrslice(mrslice); - foo_rslice(mrslice); + foo_rslice(mrslice); //~ useless_asref foo_rslice(mrslice); } { let rrrrrstr = &&&&rstr; let rrrrrslice = &&&&&*mrslice; + foo_rslice(rrrrrslice); //~ useless_asref foo_rslice(rrrrrslice); - foo_rslice(rrrrrslice); - foo_rstr(rrrrrstr); + foo_rstr(rrrrrstr); //~ useless_asref foo_rstr(rrrrrstr); } { let mrrrrrslice = &mut &mut &mut &mut mrslice; + foo_mrslice(mrrrrrslice); //~ useless_asref foo_mrslice(mrrrrrslice); - foo_mrslice(mrrrrrslice); - foo_rslice(mrrrrrslice); + foo_rslice(mrrrrrslice); //~ useless_asref foo_rslice(mrrrrrslice); } #[allow(unused_parens, clippy::double_parens, clippy::needless_borrow)] - foo_rrrrmr((&&&&MoreRef)); + foo_rrrrmr((&&&&MoreRef)); //~ useless_asref generic_not_ok(mrslice); generic_ok(mrslice); @@ -123,9 +123,9 @@ fn foo_rt(t: &T) { } fn generic_not_ok + AsRef + Debug + ?Sized>(mrt: &mut T) { + foo_mrt(mrt); //~ useless_asref foo_mrt(mrt); - foo_mrt(mrt); - foo_rt(mrt); + foo_rt(mrt); //~ useless_asref foo_rt(mrt); } diff --git a/tests/ui/useless_asref.rs b/tests/ui/useless_asref.rs index f9d603f116de..112640f1f34e 100644 --- a/tests/ui/useless_asref.rs +++ b/tests/ui/useless_asref.rs @@ -45,35 +45,35 @@ fn not_ok() { { let rslice: &[i32] = &*mrslice; - foo_rstr(rstr.as_ref()); + foo_rstr(rstr.as_ref()); //~ useless_asref foo_rstr(rstr); - foo_rslice(rslice.as_ref()); + foo_rslice(rslice.as_ref()); //~ useless_asref foo_rslice(rslice); } { - foo_mrslice(mrslice.as_mut()); + foo_mrslice(mrslice.as_mut()); //~ useless_asref foo_mrslice(mrslice); - foo_rslice(mrslice.as_ref()); + foo_rslice(mrslice.as_ref()); //~ useless_asref foo_rslice(mrslice); } { let rrrrrstr = &&&&rstr; let rrrrrslice = &&&&&*mrslice; - foo_rslice(rrrrrslice.as_ref()); + foo_rslice(rrrrrslice.as_ref()); //~ useless_asref foo_rslice(rrrrrslice); - foo_rstr(rrrrrstr.as_ref()); + foo_rstr(rrrrrstr.as_ref()); //~ useless_asref foo_rstr(rrrrrstr); } { let mrrrrrslice = &mut &mut &mut &mut mrslice; - foo_mrslice(mrrrrrslice.as_mut()); + foo_mrslice(mrrrrrslice.as_mut()); //~ useless_asref foo_mrslice(mrrrrrslice); - foo_rslice(mrrrrrslice.as_ref()); + foo_rslice(mrrrrrslice.as_ref()); //~ useless_asref foo_rslice(mrrrrrslice); } #[allow(unused_parens, clippy::double_parens, clippy::needless_borrow)] - foo_rrrrmr((&&&&MoreRef).as_ref()); + foo_rrrrmr((&&&&MoreRef).as_ref()); //~ useless_asref generic_not_ok(mrslice); generic_ok(mrslice); @@ -123,9 +123,9 @@ fn foo_rt(t: &T) { } fn generic_not_ok + AsRef + Debug + ?Sized>(mrt: &mut T) { - foo_mrt(mrt.as_mut()); + foo_mrt(mrt.as_mut()); //~ useless_asref foo_mrt(mrt); - foo_rt(mrt.as_ref()); + foo_rt(mrt.as_ref()); //~ useless_asref foo_rt(mrt); } diff --git a/tests/ui/useless_attribute.fixed b/tests/ui/useless_attribute.fixed index c7d611f36cf8..d99a1c23f5b6 100644 --- a/tests/ui/useless_attribute.fixed +++ b/tests/ui/useless_attribute.fixed @@ -5,8 +5,8 @@ #![warn(unreachable_pub)] #![feature(rustc_private)] -#![allow(dead_code)] -#![cfg_attr(clippy, allow(dead_code))] +#![allow(dead_code)] //~ useless_attribute +#![cfg_attr(clippy, allow(dead_code))] //~ useless_attribute #[rustfmt::skip] #[allow(unused_imports)] #[allow(unused_extern_crates)] @@ -17,7 +17,7 @@ extern crate rustc_middle; extern crate proc_macro_derive; fn test_indented_attr() { - #![allow(clippy::almost_swapped)] + #![allow(clippy::almost_swapped)] //~ useless_attribute use std::collections::HashSet; let _ = HashSet::::default(); diff --git a/tests/ui/useless_attribute.rs b/tests/ui/useless_attribute.rs index 00cfa8f5d54f..85e15b9cbf7c 100644 --- a/tests/ui/useless_attribute.rs +++ b/tests/ui/useless_attribute.rs @@ -5,8 +5,8 @@ #![warn(unreachable_pub)] #![feature(rustc_private)] -#[allow(dead_code)] -#[cfg_attr(clippy, allow(dead_code))] +#[allow(dead_code)] //~ useless_attribute +#[cfg_attr(clippy, allow(dead_code))] //~ useless_attribute #[rustfmt::skip] #[allow(unused_imports)] #[allow(unused_extern_crates)] @@ -17,7 +17,7 @@ extern crate rustc_middle; extern crate proc_macro_derive; fn test_indented_attr() { - #[allow(clippy::almost_swapped)] + #[allow(clippy::almost_swapped)] //~ useless_attribute use std::collections::HashSet; let _ = HashSet::::default(); diff --git a/tests/ui/useless_conversion.fixed b/tests/ui/useless_conversion.fixed index ce00fde2f993..7ec3cc3805da 100644 --- a/tests/ui/useless_conversion.fixed +++ b/tests/ui/useless_conversion.fixed @@ -2,8 +2,8 @@ #![allow(clippy::needless_if, clippy::unnecessary_wraps)] fn test_generic(val: T) -> T { - let _ = val; - val + let _ = val; //~ useless_conversion + val //~ useless_conversion } fn test_generic2 + Into, U: From>(val: T) { @@ -15,7 +15,7 @@ fn test_generic2 + Into, U: From>(val: T) { fn test_questionmark() -> Result<(), ()> { { - let _: i32 = 0i32; + let _: i32 = 0i32; //~ useless_conversion Ok(Ok(())) }??; Ok(()) @@ -46,28 +46,30 @@ fn lint_into_iter_on_mutable_local_implementing_iterator_in_expr() { let text = "foo\r\nbar\n\nbaz\n"; let mut lines = text.lines(); if Some("ok") == lines.next() {} + //~^ useless_conversion } fn lint_into_iter_on_expr_implementing_iterator() { let text = "foo\r\nbar\n\nbaz\n"; - let mut lines = text.lines(); + let mut lines = text.lines(); //~ useless_conversion if Some("ok") == lines.next() {} } fn lint_into_iter_on_expr_implementing_iterator_2() { let text = "foo\r\nbar\n\nbaz\n"; if Some("ok") == text.lines().next() {} + //~^ useless_conversion } #[allow(const_item_mutation)] fn lint_into_iter_on_const_implementing_iterator() { const NUMBERS: std::ops::Range = 0..10; - let _ = NUMBERS.next(); + let _ = NUMBERS.next(); //~ useless_conversion } fn lint_into_iter_on_const_implementing_iterator_2() { const NUMBERS: std::ops::Range = 0..10; - let mut n = NUMBERS; + let mut n = NUMBERS; //~ useless_conversion n.next(); } @@ -129,28 +131,33 @@ fn main() { let _ = "".lines().into_iter(); } + let _: String = "foo".to_string(); //~ useless_conversion let _: String = "foo".to_string(); - let _: String = "foo".to_string(); - let _ = "foo".to_string(); + //~^ useless_conversion + let _ = "foo".to_string(); //~ useless_conversion let _ = format!("A: {:04}", 123); - let _ = "".lines(); + //~^ useless_conversion + let _ = "".lines(); //~ useless_conversion let _ = vec![1, 2, 3].into_iter(); + //~^ useless_conversion let _: String = format!("Hello {}", "world"); + //~^ useless_conversion // keep parentheses around `a + b` for suggestion (see #4750) let a: i32 = 1; let b: i32 = 1; - let _ = (a + b) * 3; + let _ = (a + b) * 3; //~ useless_conversion // see #7205 let s: Foo<'a'> = Foo; let _: Foo<'b'> = s.into(); let s2: Foo<'a'> = Foo; - let _: Foo<'a'> = s2; + let _: Foo<'a'> = s2; //~ useless_conversion let s3: Foo<'a'> = Foo; - let _ = s3; + let _ = s3; //~ useless_conversion let s4: Foo<'a'> = Foo; let _ = vec![s4, s4, s4].into_iter(); + //~^ useless_conversion issue11300::bar(); } @@ -182,13 +189,14 @@ fn explicit_into_iter_fn_arg() { fn f(_: std::vec::IntoIter) {} a(vec![1, 2].into_iter()); - b(vec![1, 2]); - c(vec![1, 2]); - d(vec![1, 2]); + b(vec![1, 2]); //~ useless_conversion + c(vec![1, 2]); //~ useless_conversion + d(vec![1, 2]); //~ useless_conversion b([&1, &2, &3].into_iter().cloned()); + b(vec![1, 2]); //~ useless_conversion b(vec![1, 2]); - b(vec![1, 2]); + //~^ useless_conversion macro_rules! macro_generated { () => { @@ -235,6 +243,7 @@ mod issue11300 { // This should trigger the lint, receiver type [i32; 3] also implements `Helper` foo2::([1, 2, 3]); + //~^ useless_conversion // This again should *not* lint, since X = () and I = std::array::IntoIter, // and `[i32; 3]: Helper<()>` is not true (only `std::array::IntoIter: Helper<()>` is). @@ -242,7 +251,7 @@ mod issue11300 { // This should lint. Removing the `.into_iter()` means that `I` gets substituted with `[i32; 3]`, // and `i32: Helper2<[i32, 3]>` is true, so this call is indeed unnecessary. - foo3([1, 2, 3]); + foo3([1, 2, 3]); //~ useless_conversion } fn ice() { @@ -251,7 +260,7 @@ mod issue11300 { pub fn foo(&self, _: I) {} } - S1.foo([1, 2]); + S1.foo([1, 2]); //~ useless_conversion // ICE that occurred in itertools trait Itertools { @@ -271,6 +280,7 @@ mod issue11300 { let v0: Vec = vec![0, 2, 4]; let v1: Vec = vec![1, 3, 5, 7]; v0.into_iter().interleave_shortest(v1); + //~^ useless_conversion trait TraitWithLifetime<'a> {} impl<'a> TraitWithLifetime<'a> for std::array::IntoIter<&'a i32, 2> {} diff --git a/tests/ui/useless_conversion.rs b/tests/ui/useless_conversion.rs index 399796195868..f70ca25af3e2 100644 --- a/tests/ui/useless_conversion.rs +++ b/tests/ui/useless_conversion.rs @@ -2,8 +2,8 @@ #![allow(clippy::needless_if, clippy::unnecessary_wraps)] fn test_generic(val: T) -> T { - let _ = T::from(val); - val.into() + let _ = T::from(val); //~ useless_conversion + val.into() //~ useless_conversion } fn test_generic2 + Into, U: From>(val: T) { @@ -15,7 +15,7 @@ fn test_generic2 + Into, U: From>(val: T) { fn test_questionmark() -> Result<(), ()> { { - let _: i32 = 0i32.into(); + let _: i32 = 0i32.into(); //~ useless_conversion Ok(Ok(())) }??; Ok(()) @@ -46,28 +46,30 @@ fn lint_into_iter_on_mutable_local_implementing_iterator_in_expr() { let text = "foo\r\nbar\n\nbaz\n"; let mut lines = text.lines(); if Some("ok") == lines.into_iter().next() {} + //~^ useless_conversion } fn lint_into_iter_on_expr_implementing_iterator() { let text = "foo\r\nbar\n\nbaz\n"; - let mut lines = text.lines().into_iter(); + let mut lines = text.lines().into_iter(); //~ useless_conversion if Some("ok") == lines.next() {} } fn lint_into_iter_on_expr_implementing_iterator_2() { let text = "foo\r\nbar\n\nbaz\n"; if Some("ok") == text.lines().into_iter().next() {} + //~^ useless_conversion } #[allow(const_item_mutation)] fn lint_into_iter_on_const_implementing_iterator() { const NUMBERS: std::ops::Range = 0..10; - let _ = NUMBERS.into_iter().next(); + let _ = NUMBERS.into_iter().next(); //~ useless_conversion } fn lint_into_iter_on_const_implementing_iterator_2() { const NUMBERS: std::ops::Range = 0..10; - let mut n = NUMBERS.into_iter(); + let mut n = NUMBERS.into_iter(); //~ useless_conversion n.next(); } @@ -129,28 +131,33 @@ fn main() { let _ = "".lines().into_iter(); } - let _: String = "foo".to_string().into(); + let _: String = "foo".to_string().into(); //~ useless_conversion let _: String = From::from("foo".to_string()); - let _ = String::from("foo".to_string()); + //~^ useless_conversion + let _ = String::from("foo".to_string()); //~ useless_conversion let _ = String::from(format!("A: {:04}", 123)); - let _ = "".lines().into_iter(); + //~^ useless_conversion + let _ = "".lines().into_iter(); //~ useless_conversion let _ = vec![1, 2, 3].into_iter().into_iter(); + //~^ useless_conversion let _: String = format!("Hello {}", "world").into(); + //~^ useless_conversion // keep parentheses around `a + b` for suggestion (see #4750) let a: i32 = 1; let b: i32 = 1; - let _ = i32::from(a + b) * 3; + let _ = i32::from(a + b) * 3; //~ useless_conversion // see #7205 let s: Foo<'a'> = Foo; let _: Foo<'b'> = s.into(); let s2: Foo<'a'> = Foo; - let _: Foo<'a'> = s2.into(); + let _: Foo<'a'> = s2.into(); //~ useless_conversion let s3: Foo<'a'> = Foo; - let _ = Foo::<'a'>::from(s3); + let _ = Foo::<'a'>::from(s3); //~ useless_conversion let s4: Foo<'a'> = Foo; let _ = vec![s4, s4, s4].into_iter().into_iter(); + //~^ useless_conversion issue11300::bar(); } @@ -182,13 +189,14 @@ fn explicit_into_iter_fn_arg() { fn f(_: std::vec::IntoIter) {} a(vec![1, 2].into_iter()); - b(vec![1, 2].into_iter()); - c(vec![1, 2].into_iter()); - d(vec![1, 2].into_iter()); + b(vec![1, 2].into_iter()); //~ useless_conversion + c(vec![1, 2].into_iter()); //~ useless_conversion + d(vec![1, 2].into_iter()); //~ useless_conversion b([&1, &2, &3].into_iter().cloned()); - b(vec![1, 2].into_iter().into_iter()); + b(vec![1, 2].into_iter().into_iter()); //~ useless_conversion b(vec![1, 2].into_iter().into_iter().into_iter()); + //~^ useless_conversion macro_rules! macro_generated { () => { @@ -235,6 +243,7 @@ mod issue11300 { // This should trigger the lint, receiver type [i32; 3] also implements `Helper` foo2::([1, 2, 3].into_iter()); + //~^ useless_conversion // This again should *not* lint, since X = () and I = std::array::IntoIter, // and `[i32; 3]: Helper<()>` is not true (only `std::array::IntoIter: Helper<()>` is). @@ -242,7 +251,7 @@ mod issue11300 { // This should lint. Removing the `.into_iter()` means that `I` gets substituted with `[i32; 3]`, // and `i32: Helper2<[i32, 3]>` is true, so this call is indeed unnecessary. - foo3([1, 2, 3].into_iter()); + foo3([1, 2, 3].into_iter()); //~ useless_conversion } fn ice() { @@ -251,7 +260,7 @@ mod issue11300 { pub fn foo(&self, _: I) {} } - S1.foo([1, 2].into_iter()); + S1.foo([1, 2].into_iter()); //~ useless_conversion // ICE that occurred in itertools trait Itertools { @@ -271,6 +280,7 @@ mod issue11300 { let v0: Vec = vec![0, 2, 4]; let v1: Vec = vec![1, 3, 5, 7]; v0.into_iter().interleave_shortest(v1.into_iter()); + //~^ useless_conversion trait TraitWithLifetime<'a> {} impl<'a> TraitWithLifetime<'a> for std::array::IntoIter<&'a i32, 2> {} diff --git a/tests/ui/useless_conversion.stderr b/tests/ui/useless_conversion.stderr index c1f8b6b4aa96..df938368d78c 100644 --- a/tests/ui/useless_conversion.stderr +++ b/tests/ui/useless_conversion.stderr @@ -29,199 +29,199 @@ LL | if Some("ok") == lines.into_iter().next() {} | ^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `lines` error: useless conversion to the same type: `std::str::Lines<'_>` - --> $DIR/useless_conversion.rs:53:21 + --> $DIR/useless_conversion.rs:54:21 | LL | let mut lines = text.lines().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `text.lines()` error: useless conversion to the same type: `std::str::Lines<'_>` - --> $DIR/useless_conversion.rs:59:22 + --> $DIR/useless_conversion.rs:60:22 | LL | if Some("ok") == text.lines().into_iter().next() {} | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `text.lines()` error: useless conversion to the same type: `std::ops::Range` - --> $DIR/useless_conversion.rs:65:13 + --> $DIR/useless_conversion.rs:67:13 | LL | let _ = NUMBERS.into_iter().next(); | ^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `NUMBERS` error: useless conversion to the same type: `std::ops::Range` - --> $DIR/useless_conversion.rs:70:17 + --> $DIR/useless_conversion.rs:72:17 | LL | let mut n = NUMBERS.into_iter(); | ^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `NUMBERS` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion.rs:132:21 + --> $DIR/useless_conversion.rs:134:21 | LL | let _: String = "foo".to_string().into(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `"foo".to_string()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion.rs:133:21 + --> $DIR/useless_conversion.rs:135:21 | LL | let _: String = From::from("foo".to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `From::from()`: `"foo".to_string()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion.rs:134:13 + --> $DIR/useless_conversion.rs:137:13 | LL | let _ = String::from("foo".to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `"foo".to_string()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion.rs:135:13 + --> $DIR/useless_conversion.rs:138:13 | LL | let _ = String::from(format!("A: {:04}", 123)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `format!("A: {:04}", 123)` error: useless conversion to the same type: `std::str::Lines<'_>` - --> $DIR/useless_conversion.rs:136:13 + --> $DIR/useless_conversion.rs:140:13 | LL | let _ = "".lines().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `"".lines()` error: useless conversion to the same type: `std::vec::IntoIter` - --> $DIR/useless_conversion.rs:137:13 + --> $DIR/useless_conversion.rs:141:13 | LL | let _ = vec![1, 2, 3].into_iter().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![1, 2, 3].into_iter()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion.rs:138:21 + --> $DIR/useless_conversion.rs:143:21 | LL | let _: String = format!("Hello {}", "world").into(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `format!("Hello {}", "world")` error: useless conversion to the same type: `i32` - --> $DIR/useless_conversion.rs:143:13 + --> $DIR/useless_conversion.rs:149:13 | LL | let _ = i32::from(a + b) * 3; | ^^^^^^^^^^^^^^^^ help: consider removing `i32::from()`: `(a + b)` error: useless conversion to the same type: `Foo<'a'>` - --> $DIR/useless_conversion.rs:149:23 + --> $DIR/useless_conversion.rs:155:23 | LL | let _: Foo<'a'> = s2.into(); | ^^^^^^^^^ help: consider removing `.into()`: `s2` error: useless conversion to the same type: `Foo<'a'>` - --> $DIR/useless_conversion.rs:151:13 + --> $DIR/useless_conversion.rs:157:13 | LL | let _ = Foo::<'a'>::from(s3); | ^^^^^^^^^^^^^^^^^^^^ help: consider removing `Foo::<'a'>::from()`: `s3` error: useless conversion to the same type: `std::vec::IntoIter>` - --> $DIR/useless_conversion.rs:153:13 + --> $DIR/useless_conversion.rs:159:13 | LL | let _ = vec![s4, s4, s4].into_iter().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![s4, s4, s4].into_iter()` error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:185:7 + --> $DIR/useless_conversion.rs:192:7 | LL | b(vec![1, 2].into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:175:13 + --> $DIR/useless_conversion.rs:182:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:186:7 + --> $DIR/useless_conversion.rs:193:7 | LL | c(vec![1, 2].into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:176:18 + --> $DIR/useless_conversion.rs:183:18 | LL | fn c(_: impl IntoIterator) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:187:7 + --> $DIR/useless_conversion.rs:194:7 | LL | d(vec![1, 2].into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:179:12 + --> $DIR/useless_conversion.rs:186:12 | LL | T: IntoIterator, | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:190:7 + --> $DIR/useless_conversion.rs:197:7 | LL | b(vec![1, 2].into_iter().into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:175:13 + --> $DIR/useless_conversion.rs:182:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:191:7 + --> $DIR/useless_conversion.rs:198:7 | LL | b(vec![1, 2].into_iter().into_iter().into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:175:13 + --> $DIR/useless_conversion.rs:182:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:237:24 + --> $DIR/useless_conversion.rs:245:24 | LL | foo2::([1, 2, 3].into_iter()); | ^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `[1, 2, 3]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:216:12 + --> $DIR/useless_conversion.rs:224:12 | LL | I: IntoIterator + Helper, | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:245:14 + --> $DIR/useless_conversion.rs:254:14 | LL | foo3([1, 2, 3].into_iter()); | ^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `[1, 2, 3]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:225:12 + --> $DIR/useless_conversion.rs:233:12 | LL | I: IntoIterator, | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:254:16 + --> $DIR/useless_conversion.rs:263:16 | LL | S1.foo([1, 2].into_iter()); | ^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `[1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:251:27 + --> $DIR/useless_conversion.rs:260:27 | LL | pub fn foo(&self, _: I) {} | ^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:273:44 + --> $DIR/useless_conversion.rs:282:44 | LL | v0.into_iter().interleave_shortest(v1.into_iter()); | ^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `v1` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:260:20 + --> $DIR/useless_conversion.rs:269:20 | LL | J: IntoIterator, | ^^^^^^^^^^^^ diff --git a/tests/ui/vec.fixed b/tests/ui/vec.fixed index b318fd42f7ca..ef4aacc8c34a 100644 --- a/tests/ui/vec.fixed +++ b/tests/ui/vec.fixed @@ -27,25 +27,25 @@ impl Line { } fn main() { + on_slice(&[]); //~ useless_vec on_slice(&[]); - on_slice(&[]); - on_mut_slice(&mut []); + on_mut_slice(&mut []); //~ useless_vec + on_slice(&[1, 2]); //~ useless_vec on_slice(&[1, 2]); - on_slice(&[1, 2]); - on_mut_slice(&mut [1, 2]); + on_mut_slice(&mut [1, 2]); //~ useless_vec + on_slice(&[1, 2]); //~ useless_vec on_slice(&[1, 2]); - on_slice(&[1, 2]); - on_mut_slice(&mut [1, 2]); + on_mut_slice(&mut [1, 2]); //~ useless_vec #[rustfmt::skip] + on_slice(&[1, 2]); //~ useless_vec on_slice(&[1, 2]); - on_slice(&[1, 2]); - on_mut_slice(&mut [1, 2]); + on_mut_slice(&mut [1, 2]); //~ useless_vec + on_slice(&[1; 2]); //~ useless_vec on_slice(&[1; 2]); - on_slice(&[1; 2]); - on_mut_slice(&mut [1; 2]); + on_mut_slice(&mut [1; 2]); //~ useless_vec on_vec(&vec![]); on_vec(&vec![1, 2]); @@ -71,18 +71,18 @@ fn main() { } // https://github.com/rust-lang/rust-clippy/issues/2262#issuecomment-783979246 - let _x: i32 = [1, 2, 3].iter().sum(); + let _x: i32 = [1, 2, 3].iter().sum(); //~ useless_vec // Do lint - let mut x = [1, 2, 3]; + let mut x = [1, 2, 3]; //~ useless_vec x.fill(123); dbg!(x[0]); dbg!(x.len()); dbg!(x.iter().sum::()); - let _x: &[i32] = &[1, 2, 3]; + let _x: &[i32] = &[1, 2, 3]; //~ useless_vec - for _ in [1, 2, 3] {} + for _ in [1, 2, 3] {} //~ useless_vec // Don't lint let x = vec![1, 2, 3]; @@ -121,6 +121,7 @@ fn issue11075() { }; } #[allow(clippy::never_loop)] + //~v useless_vec for _string in [repro!(true), repro!(null)] { unimplemented!(); } @@ -139,6 +140,8 @@ fn issue11075() { } in_macro!(1, [1, 2], [1; 2]); + //~^ useless_vec + //~| useless_vec macro_rules! from_macro { () => { @@ -157,10 +160,12 @@ fn issue11075() { #[clippy::msrv = "1.53"] fn above() { + //~v useless_vec for a in [1, 2, 3] { let _: usize = a; } + //~v useless_vec for a in [String::new(), String::new()] { let _: String = a; } diff --git a/tests/ui/vec.rs b/tests/ui/vec.rs index 08ad6efa37f2..3ed66b612a7a 100644 --- a/tests/ui/vec.rs +++ b/tests/ui/vec.rs @@ -27,25 +27,25 @@ impl Line { } fn main() { - on_slice(&vec![]); + on_slice(&vec![]); //~ useless_vec on_slice(&[]); - on_mut_slice(&mut vec![]); + on_mut_slice(&mut vec![]); //~ useless_vec - on_slice(&vec![1, 2]); + on_slice(&vec![1, 2]); //~ useless_vec on_slice(&[1, 2]); - on_mut_slice(&mut vec![1, 2]); + on_mut_slice(&mut vec![1, 2]); //~ useless_vec - on_slice(&vec![1, 2]); + on_slice(&vec![1, 2]); //~ useless_vec on_slice(&[1, 2]); - on_mut_slice(&mut vec![1, 2]); + on_mut_slice(&mut vec![1, 2]); //~ useless_vec #[rustfmt::skip] - on_slice(&vec!(1, 2)); + on_slice(&vec!(1, 2)); //~ useless_vec on_slice(&[1, 2]); - on_mut_slice(&mut vec![1, 2]); + on_mut_slice(&mut vec![1, 2]); //~ useless_vec - on_slice(&vec![1; 2]); + on_slice(&vec![1; 2]); //~ useless_vec on_slice(&[1; 2]); - on_mut_slice(&mut vec![1; 2]); + on_mut_slice(&mut vec![1; 2]); //~ useless_vec on_vec(&vec![]); on_vec(&vec![1, 2]); @@ -71,18 +71,18 @@ fn main() { } // https://github.com/rust-lang/rust-clippy/issues/2262#issuecomment-783979246 - let _x: i32 = vec![1, 2, 3].iter().sum(); + let _x: i32 = vec![1, 2, 3].iter().sum(); //~ useless_vec // Do lint - let mut x = vec![1, 2, 3]; + let mut x = vec![1, 2, 3]; //~ useless_vec x.fill(123); dbg!(x[0]); dbg!(x.len()); dbg!(x.iter().sum::()); - let _x: &[i32] = &vec![1, 2, 3]; + let _x: &[i32] = &vec![1, 2, 3]; //~ useless_vec - for _ in vec![1, 2, 3] {} + for _ in vec![1, 2, 3] {} //~ useless_vec // Don't lint let x = vec![1, 2, 3]; @@ -121,6 +121,7 @@ fn issue11075() { }; } #[allow(clippy::never_loop)] + //~v useless_vec for _string in vec![repro!(true), repro!(null)] { unimplemented!(); } @@ -139,6 +140,8 @@ fn issue11075() { } in_macro!(1, vec![1, 2], vec![1; 2]); + //~^ useless_vec + //~| useless_vec macro_rules! from_macro { () => { @@ -157,10 +160,12 @@ fn issue11075() { #[clippy::msrv = "1.53"] fn above() { + //~v useless_vec for a in vec![1, 2, 3] { let _: usize = a; } + //~v useless_vec for a in vec![String::new(), String::new()] { let _: String = a; } diff --git a/tests/ui/vec.stderr b/tests/ui/vec.stderr index c9018f94f9d1..8f4cd7c09c94 100644 --- a/tests/ui/vec.stderr +++ b/tests/ui/vec.stderr @@ -86,37 +86,37 @@ LL | for _ in vec![1, 2, 3] {} | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> $DIR/vec.rs:124:20 + --> $DIR/vec.rs:125:20 | LL | for _string in vec![repro!(true), repro!(null)] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[repro!(true), repro!(null)]` error: useless use of `vec!` - --> $DIR/vec.rs:141:18 + --> $DIR/vec.rs:142:18 | LL | in_macro!(1, vec![1, 2], vec![1; 2]); | ^^^^^^^^^^ help: you can use an array directly: `[1, 2]` error: useless use of `vec!` - --> $DIR/vec.rs:141:30 + --> $DIR/vec.rs:142:30 | LL | in_macro!(1, vec![1, 2], vec![1; 2]); | ^^^^^^^^^^ help: you can use an array directly: `[1; 2]` error: useless use of `vec!` - --> $DIR/vec.rs:160:14 + --> $DIR/vec.rs:164:14 | LL | for a in vec![1, 2, 3] { | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> $DIR/vec.rs:164:14 + --> $DIR/vec.rs:169:14 | LL | for a in vec![String::new(), String::new()] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[String::new(), String::new()]` error: useless use of `vec!` - --> $DIR/vec.rs:196:33 + --> $DIR/vec.rs:201:33 | LL | this_macro_doesnt_need_vec!(vec![1]); | ^^^^^^^ help: you can use an array directly: `[1]` diff --git a/tests/ui/vec_box_sized.rs b/tests/ui/vec_box_sized.rs index 49eaf8e062af..ee6d296de560 100644 --- a/tests/ui/vec_box_sized.rs +++ b/tests/ui/vec_box_sized.rs @@ -23,22 +23,25 @@ unsafe impl Allocator for DummyAllocator { /// The following should trigger the lint mod should_trigger { use super::{DummyAllocator, SizedStruct}; - const C: Vec> = Vec::new(); - static S: Vec> = Vec::new(); + const C: Vec> = Vec::new(); //~ vec_box + static S: Vec> = Vec::new(); //~ vec_box struct StructWithVecBox { - sized_type: Vec>, + sized_type: Vec>, //~ vec_box } - struct A(Vec>); - struct B(Vec>>); + struct A(Vec>); //~ vec_box + struct B(Vec>>); //~ vec_box + //~v vec_box fn allocator_global_defined_vec() -> Vec, std::alloc::Global> { Vec::new() } + //~v vec_box fn allocator_global_defined_box() -> Vec> { Vec::new() } + //~v vec_box fn allocator_match() -> Vec, DummyAllocator> { Vec::new_in(DummyAllocator) } @@ -76,6 +79,7 @@ mod inner_mod { mod inner2 { use super::inner::S; + //~v vec_box pub fn f() -> Vec> { vec![] } diff --git a/tests/ui/vec_box_sized.stderr b/tests/ui/vec_box_sized.stderr index d6479271fa63..5c4abd36d253 100644 --- a/tests/ui/vec_box_sized.stderr +++ b/tests/ui/vec_box_sized.stderr @@ -32,25 +32,25 @@ LL | struct B(Vec>>); | ^^^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> $DIR/vec_box_sized.rs:36:42 + --> $DIR/vec_box_sized.rs:37:42 | LL | fn allocator_global_defined_vec() -> Vec, std::alloc::Global> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> $DIR/vec_box_sized.rs:39:42 + --> $DIR/vec_box_sized.rs:41:42 | LL | fn allocator_global_defined_box() -> Vec> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> $DIR/vec_box_sized.rs:42:29 + --> $DIR/vec_box_sized.rs:45:29 | LL | fn allocator_match() -> Vec, DummyAllocator> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> $DIR/vec_box_sized.rs:79:23 + --> $DIR/vec_box_sized.rs:83:23 | LL | pub fn f() -> Vec> { | ^^^^^^^^^^^ help: try: `Vec` diff --git a/tests/ui/waker_clone_wake.fixed b/tests/ui/waker_clone_wake.fixed index 9c02b9a90fdd..bc47ff74a5e1 100644 --- a/tests/ui/waker_clone_wake.fixed +++ b/tests/ui/waker_clone_wake.fixed @@ -12,9 +12,9 @@ macro_rules! mac { } pub fn wake(cx: &mut std::task::Context) { - cx.waker().wake_by_ref(); + cx.waker().wake_by_ref(); //~ waker_clone_wake - mac!(cx).wake_by_ref(); + mac!(cx).wake_by_ref(); //~ waker_clone_wake } pub fn no_lint(cx: &mut std::task::Context, c: &Custom) { diff --git a/tests/ui/waker_clone_wake.rs b/tests/ui/waker_clone_wake.rs index edc3bbd8fc08..32374f2c46ac 100644 --- a/tests/ui/waker_clone_wake.rs +++ b/tests/ui/waker_clone_wake.rs @@ -12,9 +12,9 @@ macro_rules! mac { } pub fn wake(cx: &mut std::task::Context) { - cx.waker().clone().wake(); + cx.waker().clone().wake(); //~ waker_clone_wake - mac!(cx).clone().wake(); + mac!(cx).clone().wake(); //~ waker_clone_wake } pub fn no_lint(cx: &mut std::task::Context, c: &Custom) { diff --git a/tests/ui/while_let_on_iterator.fixed b/tests/ui/while_let_on_iterator.fixed index 59b5c858d046..293ffaef3335 100644 --- a/tests/ui/while_let_on_iterator.fixed +++ b/tests/ui/while_let_on_iterator.fixed @@ -12,17 +12,19 @@ fn base() { let mut iter = 1..20; + //~v while_let_on_iterator for x in iter { println!("{}", x); } let mut iter = 1..20; + //~v while_let_on_iterator for x in iter { println!("{}", x); } let mut iter = 1..20; - for _ in iter {} + for _ in iter {} //~ while_let_on_iterator let mut iter = 1..20; while let None = iter.next() {} // this is fine (if nonsensical) @@ -99,6 +101,7 @@ fn refutable2() { let mut it = v.windows(2); for [..] in it {} + //~^ while_let_on_iterator let v = vec![[1], [2], [3]]; let mut it = v.iter(); @@ -106,6 +109,7 @@ fn refutable2() { let mut it = v.iter(); for [_x] in it {} + //~^ while_let_on_iterator } // binding @@ -118,6 +122,7 @@ fn refutable2() { let v = vec![[1], [2], [3]]; let mut it = v.iter(); + //~v while_let_on_iterator for x @ [_] in it { println!("{:?}", x); } @@ -138,6 +143,7 @@ fn nested_loops() { loop { let mut y = a.iter(); + //~v while_let_on_iterator for _ in y { // use a for loop here } @@ -195,6 +201,7 @@ fn issue6491() { // Used in outer loop, needs &mut let mut it = 1..40; while let Some(n) = it.next() { + //~v while_let_on_iterator for m in it.by_ref() { if m % 10 == 0 { break; @@ -206,8 +213,10 @@ fn issue6491() { // This is fine, inner loop uses a new iterator. let mut it = 1..40; + //~v while_let_on_iterator for n in it { let mut it = 1..40; + //~v while_let_on_iterator for m in it { if m % 10 == 0 { break; @@ -217,6 +226,7 @@ fn issue6491() { // Weird binding shouldn't change anything. let (mut it, _) = (1..40, 0); + //~v while_let_on_iterator for m in it { if m % 10 == 0 { break; @@ -226,6 +236,7 @@ fn issue6491() { // Used after the loop, needs &mut. let mut it = 1..40; + //~v while_let_on_iterator for m in it.by_ref() { if m % 10 == 0 { break; @@ -243,6 +254,7 @@ fn issue6231() { let mut it = 1..40; let mut opt = Some(0); while let Some(n) = opt.take().or_else(|| it.next()) { + //~v while_let_on_iterator for m in it.by_ref() { if n % 10 == 0 { break; @@ -258,6 +270,7 @@ fn issue1924() { impl> S { fn f(&mut self) -> Option { // Used as a field. + //~v while_let_on_iterator for i in self.0.by_ref() { if !(3..8).contains(&i) { return Some(i); @@ -290,6 +303,7 @@ fn issue1924() { } } // This one is fine, a different field is borrowed + //~v while_let_on_iterator for i in self.0.0.0.by_ref() { if i == 1 { return self.0.1.take(); @@ -319,6 +333,7 @@ fn issue1924() { // Needs &mut, field of the iterator is accessed after the loop let mut it = S2(1..40, 0); + //~v while_let_on_iterator for n in it.by_ref() { if n == 0 { break; @@ -331,6 +346,7 @@ fn issue7249() { let mut it = 0..10; let mut x = || { // Needs &mut, the closure can be called multiple times + //~v while_let_on_iterator for x in it.by_ref() { if x % 2 == 0 { break; @@ -345,6 +361,7 @@ fn issue7510() { let mut it = 0..10; let it = &mut it; // Needs to reborrow `it` as the binding isn't mutable + //~v while_let_on_iterator for x in it.by_ref() { if x % 2 == 0 { break; @@ -356,6 +373,7 @@ fn issue7510() { let mut it = 0..10; let it = S(&mut it); // Needs to reborrow `it.0` as the binding isn't mutable + //~v while_let_on_iterator for x in it.0.by_ref() { if x % 2 == 0 { break; @@ -391,6 +409,7 @@ fn custom_deref() { } let mut s = S2(S1 { x: 0..10 }); + //~v while_let_on_iterator for x in s.x.by_ref() { println!("{}", x); } @@ -398,6 +417,7 @@ fn custom_deref() { fn issue_8113() { let mut x = [0..10]; + //~v while_let_on_iterator for x in x[0].by_ref() { println!("{}", x); } @@ -406,6 +426,7 @@ fn issue_8113() { fn fn_once_closure() { let mut it = 0..10; (|| { + //~v while_let_on_iterator for x in it.by_ref() { if x % 2 == 0 { break; @@ -416,6 +437,7 @@ fn fn_once_closure() { fn f(_: impl FnOnce()) {} let mut it = 0..10; f(|| { + //~v while_let_on_iterator for x in it { if x % 2 == 0 { break; @@ -426,6 +448,7 @@ fn fn_once_closure() { fn f2(_: impl FnMut()) {} let mut it = 0..10; f2(|| { + //~v while_let_on_iterator for x in it.by_ref() { if x % 2 == 0 { break; @@ -436,6 +459,7 @@ fn fn_once_closure() { fn f3(_: fn()) {} f3(|| { let mut it = 0..10; + //~v while_let_on_iterator for x in it { if x % 2 == 0 { break; @@ -448,6 +472,7 @@ fn fn_once_closure() { fn f4(_: impl MySpecialFnMut) {} let mut it = 0..10; f4(|| { + //~v while_let_on_iterator for x in it { if x % 2 == 0 { break; @@ -458,6 +483,7 @@ fn fn_once_closure() { fn main() { let mut it = 0..20; + //~v while_let_on_iterator for _ in it { println!("test"); } diff --git a/tests/ui/while_let_on_iterator.rs b/tests/ui/while_let_on_iterator.rs index 559513d56946..380cc1716317 100644 --- a/tests/ui/while_let_on_iterator.rs +++ b/tests/ui/while_let_on_iterator.rs @@ -12,17 +12,19 @@ fn base() { let mut iter = 1..20; + //~v while_let_on_iterator while let Option::Some(x) = iter.next() { println!("{}", x); } let mut iter = 1..20; + //~v while_let_on_iterator while let Some(x) = iter.next() { println!("{}", x); } let mut iter = 1..20; - while let Some(_) = iter.next() {} + while let Some(_) = iter.next() {} //~ while_let_on_iterator let mut iter = 1..20; while let None = iter.next() {} // this is fine (if nonsensical) @@ -99,6 +101,7 @@ fn refutable2() { let mut it = v.windows(2); while let Some([..]) = it.next() {} + //~^ while_let_on_iterator let v = vec![[1], [2], [3]]; let mut it = v.iter(); @@ -106,6 +109,7 @@ fn refutable2() { let mut it = v.iter(); while let Some([_x]) = it.next() {} + //~^ while_let_on_iterator } // binding @@ -118,6 +122,7 @@ fn refutable2() { let v = vec![[1], [2], [3]]; let mut it = v.iter(); + //~v while_let_on_iterator while let Some(x @ [_]) = it.next() { println!("{:?}", x); } @@ -138,6 +143,7 @@ fn nested_loops() { loop { let mut y = a.iter(); + //~v while_let_on_iterator while let Some(_) = y.next() { // use a for loop here } @@ -195,6 +201,7 @@ fn issue6491() { // Used in outer loop, needs &mut let mut it = 1..40; while let Some(n) = it.next() { + //~v while_let_on_iterator while let Some(m) = it.next() { if m % 10 == 0 { break; @@ -206,8 +213,10 @@ fn issue6491() { // This is fine, inner loop uses a new iterator. let mut it = 1..40; + //~v while_let_on_iterator while let Some(n) = it.next() { let mut it = 1..40; + //~v while_let_on_iterator while let Some(m) = it.next() { if m % 10 == 0 { break; @@ -217,6 +226,7 @@ fn issue6491() { // Weird binding shouldn't change anything. let (mut it, _) = (1..40, 0); + //~v while_let_on_iterator while let Some(m) = it.next() { if m % 10 == 0 { break; @@ -226,6 +236,7 @@ fn issue6491() { // Used after the loop, needs &mut. let mut it = 1..40; + //~v while_let_on_iterator while let Some(m) = it.next() { if m % 10 == 0 { break; @@ -243,6 +254,7 @@ fn issue6231() { let mut it = 1..40; let mut opt = Some(0); while let Some(n) = opt.take().or_else(|| it.next()) { + //~v while_let_on_iterator while let Some(m) = it.next() { if n % 10 == 0 { break; @@ -258,6 +270,7 @@ fn issue1924() { impl> S { fn f(&mut self) -> Option { // Used as a field. + //~v while_let_on_iterator while let Some(i) = self.0.next() { if !(3..8).contains(&i) { return Some(i); @@ -290,6 +303,7 @@ fn issue1924() { } } // This one is fine, a different field is borrowed + //~v while_let_on_iterator while let Some(i) = self.0.0.0.next() { if i == 1 { return self.0.1.take(); @@ -319,6 +333,7 @@ fn issue1924() { // Needs &mut, field of the iterator is accessed after the loop let mut it = S2(1..40, 0); + //~v while_let_on_iterator while let Some(n) = it.next() { if n == 0 { break; @@ -331,6 +346,7 @@ fn issue7249() { let mut it = 0..10; let mut x = || { // Needs &mut, the closure can be called multiple times + //~v while_let_on_iterator while let Some(x) = it.next() { if x % 2 == 0 { break; @@ -345,6 +361,7 @@ fn issue7510() { let mut it = 0..10; let it = &mut it; // Needs to reborrow `it` as the binding isn't mutable + //~v while_let_on_iterator while let Some(x) = it.next() { if x % 2 == 0 { break; @@ -356,6 +373,7 @@ fn issue7510() { let mut it = 0..10; let it = S(&mut it); // Needs to reborrow `it.0` as the binding isn't mutable + //~v while_let_on_iterator while let Some(x) = it.0.next() { if x % 2 == 0 { break; @@ -391,6 +409,7 @@ fn custom_deref() { } let mut s = S2(S1 { x: 0..10 }); + //~v while_let_on_iterator while let Some(x) = s.x.next() { println!("{}", x); } @@ -398,6 +417,7 @@ fn custom_deref() { fn issue_8113() { let mut x = [0..10]; + //~v while_let_on_iterator while let Some(x) = x[0].next() { println!("{}", x); } @@ -406,6 +426,7 @@ fn issue_8113() { fn fn_once_closure() { let mut it = 0..10; (|| { + //~v while_let_on_iterator while let Some(x) = it.next() { if x % 2 == 0 { break; @@ -416,6 +437,7 @@ fn fn_once_closure() { fn f(_: impl FnOnce()) {} let mut it = 0..10; f(|| { + //~v while_let_on_iterator while let Some(x) = it.next() { if x % 2 == 0 { break; @@ -426,6 +448,7 @@ fn fn_once_closure() { fn f2(_: impl FnMut()) {} let mut it = 0..10; f2(|| { + //~v while_let_on_iterator while let Some(x) = it.next() { if x % 2 == 0 { break; @@ -436,6 +459,7 @@ fn fn_once_closure() { fn f3(_: fn()) {} f3(|| { let mut it = 0..10; + //~v while_let_on_iterator while let Some(x) = it.next() { if x % 2 == 0 { break; @@ -448,6 +472,7 @@ fn fn_once_closure() { fn f4(_: impl MySpecialFnMut) {} let mut it = 0..10; f4(|| { + //~v while_let_on_iterator while let Some(x) = it.next() { if x % 2 == 0 { break; @@ -458,6 +483,7 @@ fn fn_once_closure() { fn main() { let mut it = 0..20; + //~v while_let_on_iterator while let Some(..) = it.next() { println!("test"); } diff --git a/tests/ui/while_let_on_iterator.stderr b/tests/ui/while_let_on_iterator.stderr index 7b9a9dc049a2..d9c3fd2161f6 100644 --- a/tests/ui/while_let_on_iterator.stderr +++ b/tests/ui/while_let_on_iterator.stderr @@ -1,5 +1,5 @@ error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:15:5 + --> $DIR/while_let_on_iterator.rs:16:5 | LL | while let Option::Some(x) = iter.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter` @@ -8,157 +8,157 @@ LL | while let Option::Some(x) = iter.next() { = help: to override `-D warnings` add `#[allow(clippy::while_let_on_iterator)]` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:20:5 + --> $DIR/while_let_on_iterator.rs:22:5 | LL | while let Some(x) = iter.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:25:5 + --> $DIR/while_let_on_iterator.rs:27:5 | LL | while let Some(_) = iter.next() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in iter` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:101:9 + --> $DIR/while_let_on_iterator.rs:103:9 | LL | while let Some([..]) = it.next() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for [..] in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:108:9 + --> $DIR/while_let_on_iterator.rs:111:9 | LL | while let Some([_x]) = it.next() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for [_x] in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:121:9 + --> $DIR/while_let_on_iterator.rs:126:9 | LL | while let Some(x @ [_]) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x @ [_] in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:141:9 + --> $DIR/while_let_on_iterator.rs:147:9 | LL | while let Some(_) = y.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in y` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:198:9 + --> $DIR/while_let_on_iterator.rs:205:9 | LL | while let Some(m) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for m in it.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:209:5 + --> $DIR/while_let_on_iterator.rs:217:5 | LL | while let Some(n) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for n in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:211:9 + --> $DIR/while_let_on_iterator.rs:220:9 | LL | while let Some(m) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for m in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:220:9 + --> $DIR/while_let_on_iterator.rs:230:9 | LL | while let Some(m) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for m in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:229:9 + --> $DIR/while_let_on_iterator.rs:240:9 | LL | while let Some(m) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for m in it.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:246:9 + --> $DIR/while_let_on_iterator.rs:258:9 | LL | while let Some(m) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for m in it.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:261:13 + --> $DIR/while_let_on_iterator.rs:274:13 | LL | while let Some(i) = self.0.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for i in self.0.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:293:13 + --> $DIR/while_let_on_iterator.rs:307:13 | LL | while let Some(i) = self.0.0.0.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for i in self.0.0.0.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:322:5 + --> $DIR/while_let_on_iterator.rs:337:5 | LL | while let Some(n) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for n in it.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:334:9 + --> $DIR/while_let_on_iterator.rs:350:9 | LL | while let Some(x) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:348:5 + --> $DIR/while_let_on_iterator.rs:365:5 | LL | while let Some(x) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:359:5 + --> $DIR/while_let_on_iterator.rs:377:5 | LL | while let Some(x) = it.0.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it.0.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:394:5 + --> $DIR/while_let_on_iterator.rs:413:5 | LL | while let Some(x) = s.x.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in s.x.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:401:5 + --> $DIR/while_let_on_iterator.rs:421:5 | LL | while let Some(x) = x[0].next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in x[0].by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:409:9 + --> $DIR/while_let_on_iterator.rs:430:9 | LL | while let Some(x) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:419:9 + --> $DIR/while_let_on_iterator.rs:441:9 | LL | while let Some(x) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:429:9 + --> $DIR/while_let_on_iterator.rs:452:9 | LL | while let Some(x) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:439:9 + --> $DIR/while_let_on_iterator.rs:463:9 | LL | while let Some(x) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:451:9 + --> $DIR/while_let_on_iterator.rs:476:9 | LL | while let Some(x) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:461:5 + --> $DIR/while_let_on_iterator.rs:487:5 | LL | while let Some(..) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in it` diff --git a/tests/ui/wildcard_enum_match_arm.fixed b/tests/ui/wildcard_enum_match_arm.fixed index 1089415733a9..9646c0dd180b 100644 --- a/tests/ui/wildcard_enum_match_arm.fixed +++ b/tests/ui/wildcard_enum_match_arm.fixed @@ -36,15 +36,17 @@ fn main() { let color = Color::Rgb(0, 0, 127); match color { Color::Red => println!("Red"), - Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan => eprintln!("Not red"), + Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan => eprintln!("Not red"), //~ wildcard_enum_match_arm }; match color { Color::Red => println!("Red"), _not_red @ Color::Green | _not_red @ Color::Blue | _not_red @ Color::Rgb(..) | _not_red @ Color::Cyan => eprintln!("Not red"), + //~^ wildcard_enum_match_arm }; let _str = match color { Color::Red => "Red".to_owned(), not_red @ Color::Green | not_red @ Color::Blue | not_red @ Color::Rgb(..) | not_red @ Color::Cyan => format!("{:?}", not_red), + //~^ wildcard_enum_match_arm }; match color { Color::Red => {}, @@ -60,7 +62,7 @@ fn main() { }; match color { Color::Rgb(r, _, _) if r > 0 => "Some red", - Color::Red | Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan => "No red", + Color::Red | Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan => "No red", //~ wildcard_enum_match_arm }; match color { Color::Red | Color::Green | Color::Blue | Color::Cyan => {}, @@ -77,7 +79,7 @@ fn main() { let error_kind = ErrorKind::NotFound; match error_kind { ErrorKind::NotFound => {}, - ErrorKind::PermissionDenied | _ => {}, + ErrorKind::PermissionDenied | _ => {}, //~ wildcard_enum_match_arm } match error_kind { ErrorKind::NotFound => {}, @@ -95,7 +97,7 @@ fn main() { } match Enum::A { Enum::A => (), - Enum::B | Enum::__Private => (), + Enum::B | Enum::__Private => (), //~ wildcard_enum_match_arm } } } diff --git a/tests/ui/wildcard_enum_match_arm.rs b/tests/ui/wildcard_enum_match_arm.rs index d9285c56f3ef..a4e4f46077f2 100644 --- a/tests/ui/wildcard_enum_match_arm.rs +++ b/tests/ui/wildcard_enum_match_arm.rs @@ -36,15 +36,17 @@ fn main() { let color = Color::Rgb(0, 0, 127); match color { Color::Red => println!("Red"), - _ => eprintln!("Not red"), + _ => eprintln!("Not red"), //~ wildcard_enum_match_arm }; match color { Color::Red => println!("Red"), _not_red => eprintln!("Not red"), + //~^ wildcard_enum_match_arm }; let _str = match color { Color::Red => "Red".to_owned(), not_red => format!("{:?}", not_red), + //~^ wildcard_enum_match_arm }; match color { Color::Red => {}, @@ -60,7 +62,7 @@ fn main() { }; match color { Color::Rgb(r, _, _) if r > 0 => "Some red", - _ => "No red", + _ => "No red", //~ wildcard_enum_match_arm }; match color { Color::Red | Color::Green | Color::Blue | Color::Cyan => {}, @@ -77,7 +79,7 @@ fn main() { let error_kind = ErrorKind::NotFound; match error_kind { ErrorKind::NotFound => {}, - _ => {}, + _ => {}, //~ wildcard_enum_match_arm } match error_kind { ErrorKind::NotFound => {}, @@ -95,7 +97,7 @@ fn main() { } match Enum::A { Enum::A => (), - _ => (), + _ => (), //~ wildcard_enum_match_arm } } } diff --git a/tests/ui/wildcard_enum_match_arm.stderr b/tests/ui/wildcard_enum_match_arm.stderr index 7fbb16e69e4c..1516ae018b60 100644 --- a/tests/ui/wildcard_enum_match_arm.stderr +++ b/tests/ui/wildcard_enum_match_arm.stderr @@ -17,25 +17,25 @@ LL | _not_red => eprintln!("Not red"), | ^^^^^^^^ help: try: `_not_red @ Color::Green | _not_red @ Color::Blue | _not_red @ Color::Rgb(..) | _not_red @ Color::Cyan` error: wildcard match will also match any future added variants - --> $DIR/wildcard_enum_match_arm.rs:47:9 + --> $DIR/wildcard_enum_match_arm.rs:48:9 | LL | not_red => format!("{:?}", not_red), | ^^^^^^^ help: try: `not_red @ Color::Green | not_red @ Color::Blue | not_red @ Color::Rgb(..) | not_red @ Color::Cyan` error: wildcard match will also match any future added variants - --> $DIR/wildcard_enum_match_arm.rs:63:9 + --> $DIR/wildcard_enum_match_arm.rs:65:9 | LL | _ => "No red", | ^ help: try: `Color::Red | Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan` error: wildcard matches known variants and will also match future added variants - --> $DIR/wildcard_enum_match_arm.rs:80:9 + --> $DIR/wildcard_enum_match_arm.rs:82:9 | LL | _ => {}, | ^ help: try: `ErrorKind::PermissionDenied | _` error: wildcard match will also match any future added variants - --> $DIR/wildcard_enum_match_arm.rs:98:13 + --> $DIR/wildcard_enum_match_arm.rs:100:13 | LL | _ => (), | ^ help: try: `Enum::B | Enum::__Private` diff --git a/tests/ui/wildcard_imports.fixed b/tests/ui/wildcard_imports.fixed index 6fdd728b9b72..cf732f84be3e 100644 --- a/tests/ui/wildcard_imports.fixed +++ b/tests/ui/wildcard_imports.fixed @@ -12,16 +12,17 @@ extern crate wildcard_imports_helper; -use crate::fn_mod::foo; -use crate::mod_mod::inner_mod; -use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}; +use crate::fn_mod::foo; //~ wildcard_imports +use crate::mod_mod::inner_mod; //~ wildcard_imports +use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}; //~ wildcard_imports #[macro_use] -use crate::struct_mod::{A, inner_struct_mod}; +use crate::struct_mod::{A, inner_struct_mod}; //~ wildcard_imports #[allow(unused_imports)] use wildcard_imports_helper::inner::inner_for_self_import; use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar; -use wildcard_imports_helper::{ExternA, extern_foo}; +//~^ wildcard_imports +use wildcard_imports_helper::{ExternA, extern_foo}; //~ wildcard_imports use std::io::prelude::*; use wildcard_imports_helper::extern_prelude::v1::*; @@ -91,7 +92,7 @@ mod underscore_mod { } fn does_lint() { - use self::exports_underscore_ish::{_Deref, dummy}; + use self::exports_underscore_ish::{_Deref, dummy}; //~ wildcard_imports let _ = (&0).deref(); dummy(); } @@ -122,14 +123,15 @@ mod in_fn_test { pub(crate) use self::inner_exported2::*; fn test_intern() { - use crate::fn_mod::foo; + use crate::fn_mod::foo; //~ wildcard_imports foo(); } fn test_extern() { use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo}; - use wildcard_imports_helper::{ExternA, extern_foo}; + //~^ wildcard_imports + use wildcard_imports_helper::{ExternA, extern_foo}; //~ wildcard_imports inner_for_self_import::inner_extern_foo(); inner_extern_foo(); @@ -142,13 +144,15 @@ mod in_fn_test { fn test_inner_nested() { #[rustfmt::skip] use self::{inner::inner_foo, inner2::inner_bar}; + //~^ wildcard_imports + //~| wildcard_imports inner_foo(); inner_bar(); } fn test_extern_reexported() { - use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}; + use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}; //~ wildcard_imports extern_exported(); let _ = ExternExportedStruct; @@ -177,7 +181,7 @@ mod in_fn_test { } fn test_reexported() { - use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}; + use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}; //~ wildcard_imports exported(); let _ = ExportedStruct; @@ -186,7 +190,9 @@ fn test_reexported() { #[rustfmt::skip] fn test_weird_formatting() { - use crate:: in_fn_test::exported; + use crate:: in_fn_test::exported; //~ wildcard_imports + + //~v wildcard_imports use crate:: fn_mod::foo; exported(); @@ -197,7 +203,7 @@ mod super_imports { fn foofoo() {} mod should_be_replaced { - use super::foofoo; + use super::foofoo; //~ wildcard_imports fn with_super() { let _ = foofoo(); @@ -232,7 +238,7 @@ mod super_imports { mod should_be_replaced_further_inside { fn insidefoo() {} mod inner { - use super::insidefoo; + use super::insidefoo; //~ wildcard_imports fn with_super() { let _ = insidefoo(); } @@ -240,7 +246,7 @@ mod super_imports { } mod use_explicit_should_be_replaced { - use crate::super_imports::foofoo; + use crate::super_imports::foofoo; //~ wildcard_imports fn with_explicit() { let _ = foofoo(); @@ -249,7 +255,7 @@ mod super_imports { mod use_double_super_should_be_replaced { mod inner { - use super::super::foofoo; + use super::super::foofoo; //~ wildcard_imports fn with_double_super() { let _ = foofoo(); @@ -258,7 +264,7 @@ mod super_imports { } mod use_super_explicit_should_be_replaced { - use super::super::super_imports::foofoo; + use super::super::super_imports::foofoo; //~ wildcard_imports fn with_super_explicit() { let _ = foofoo(); @@ -266,7 +272,7 @@ mod super_imports { } mod attestation_should_be_replaced { - use super::foofoo; + use super::foofoo; //~ wildcard_imports fn with_explicit() { let _ = foofoo(); diff --git a/tests/ui/wildcard_imports.rs b/tests/ui/wildcard_imports.rs index 20e06d4b3664..06767e6a5990 100644 --- a/tests/ui/wildcard_imports.rs +++ b/tests/ui/wildcard_imports.rs @@ -12,16 +12,17 @@ extern crate wildcard_imports_helper; -use crate::fn_mod::*; -use crate::mod_mod::*; -use crate::multi_fn_mod::*; +use crate::fn_mod::*; //~ wildcard_imports +use crate::mod_mod::*; //~ wildcard_imports +use crate::multi_fn_mod::*; //~ wildcard_imports #[macro_use] -use crate::struct_mod::*; +use crate::struct_mod::*; //~ wildcard_imports #[allow(unused_imports)] use wildcard_imports_helper::inner::inner_for_self_import; use wildcard_imports_helper::inner::inner_for_self_import::*; -use wildcard_imports_helper::*; +//~^ wildcard_imports +use wildcard_imports_helper::*; //~ wildcard_imports use std::io::prelude::*; use wildcard_imports_helper::extern_prelude::v1::*; @@ -91,7 +92,7 @@ mod underscore_mod { } fn does_lint() { - use self::exports_underscore_ish::*; + use self::exports_underscore_ish::*; //~ wildcard_imports let _ = (&0).deref(); dummy(); } @@ -122,14 +123,15 @@ mod in_fn_test { pub(crate) use self::inner_exported2::*; fn test_intern() { - use crate::fn_mod::*; + use crate::fn_mod::*; //~ wildcard_imports foo(); } fn test_extern() { use wildcard_imports_helper::inner::inner_for_self_import::{self, *}; - use wildcard_imports_helper::*; + //~^ wildcard_imports + use wildcard_imports_helper::*; //~ wildcard_imports inner_for_self_import::inner_extern_foo(); inner_extern_foo(); @@ -142,13 +144,15 @@ mod in_fn_test { fn test_inner_nested() { #[rustfmt::skip] use self::{inner::*, inner2::*}; + //~^ wildcard_imports + //~| wildcard_imports inner_foo(); inner_bar(); } fn test_extern_reexported() { - use wildcard_imports_helper::*; + use wildcard_imports_helper::*; //~ wildcard_imports extern_exported(); let _ = ExternExportedStruct; @@ -177,7 +181,7 @@ mod in_fn_test { } fn test_reexported() { - use crate::in_fn_test::*; + use crate::in_fn_test::*; //~ wildcard_imports exported(); let _ = ExportedStruct; @@ -186,7 +190,9 @@ fn test_reexported() { #[rustfmt::skip] fn test_weird_formatting() { - use crate:: in_fn_test:: * ; + use crate:: in_fn_test:: * ; //~ wildcard_imports + + //~v wildcard_imports use crate:: fn_mod:: *; @@ -198,7 +204,7 @@ mod super_imports { fn foofoo() {} mod should_be_replaced { - use super::*; + use super::*; //~ wildcard_imports fn with_super() { let _ = foofoo(); @@ -233,7 +239,7 @@ mod super_imports { mod should_be_replaced_further_inside { fn insidefoo() {} mod inner { - use super::*; + use super::*; //~ wildcard_imports fn with_super() { let _ = insidefoo(); } @@ -241,7 +247,7 @@ mod super_imports { } mod use_explicit_should_be_replaced { - use crate::super_imports::*; + use crate::super_imports::*; //~ wildcard_imports fn with_explicit() { let _ = foofoo(); @@ -250,7 +256,7 @@ mod super_imports { mod use_double_super_should_be_replaced { mod inner { - use super::super::*; + use super::super::*; //~ wildcard_imports fn with_double_super() { let _ = foofoo(); @@ -259,7 +265,7 @@ mod super_imports { } mod use_super_explicit_should_be_replaced { - use super::super::super_imports::*; + use super::super::super_imports::*; //~ wildcard_imports fn with_super_explicit() { let _ = foofoo(); @@ -267,7 +273,7 @@ mod super_imports { } mod attestation_should_be_replaced { - use super::*; + use super::*; //~ wildcard_imports fn with_explicit() { let _ = foofoo(); diff --git a/tests/ui/wildcard_imports.stderr b/tests/ui/wildcard_imports.stderr index 01a5414778c1..0880d40c7f7c 100644 --- a/tests/ui/wildcard_imports.stderr +++ b/tests/ui/wildcard_imports.stderr @@ -32,67 +32,67 @@ LL | use wildcard_imports_helper::inner::inner_for_self_import::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:24:5 + --> $DIR/wildcard_imports.rs:25:5 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:94:13 + --> $DIR/wildcard_imports.rs:95:13 | LL | use self::exports_underscore_ish::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `self::exports_underscore_ish::{_Deref, dummy}` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:125:13 + --> $DIR/wildcard_imports.rs:126:13 | LL | use crate::fn_mod::*; | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:131:75 + --> $DIR/wildcard_imports.rs:132:75 | LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *}; | ^ help: try: `inner_extern_foo` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:132:13 + --> $DIR/wildcard_imports.rs:134:13 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:144:20 + --> $DIR/wildcard_imports.rs:146:20 | LL | use self::{inner::*, inner2::*}; | ^^^^^^^^ help: try: `inner::inner_foo` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:144:30 + --> $DIR/wildcard_imports.rs:146:30 | LL | use self::{inner::*, inner2::*}; | ^^^^^^^^^ help: try: `inner2::inner_bar` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:151:13 + --> $DIR/wildcard_imports.rs:155:13 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:180:9 + --> $DIR/wildcard_imports.rs:184:9 | LL | use crate::in_fn_test::*; | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:189:9 + --> $DIR/wildcard_imports.rs:193:9 | LL | use crate:: in_fn_test:: * ; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:190:9 + --> $DIR/wildcard_imports.rs:196:9 | LL | use crate:: fn_mod:: | _________^ @@ -100,37 +100,37 @@ LL | | *; | |_________^ help: try: `crate:: fn_mod::foo` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:201:13 + --> $DIR/wildcard_imports.rs:207:13 | LL | use super::*; | ^^^^^^^^ help: try: `super::foofoo` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:236:17 + --> $DIR/wildcard_imports.rs:242:17 | LL | use super::*; | ^^^^^^^^ help: try: `super::insidefoo` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:244:13 + --> $DIR/wildcard_imports.rs:250:13 | LL | use crate::super_imports::*; | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:253:17 + --> $DIR/wildcard_imports.rs:259:17 | LL | use super::super::*; | ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:262:13 + --> $DIR/wildcard_imports.rs:268:13 | LL | use super::super::super_imports::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:270:13 + --> $DIR/wildcard_imports.rs:276:13 | LL | use super::*; | ^^^^^^^^ help: try: `super::foofoo` diff --git a/tests/ui/wildcard_imports_2021.edition2018.fixed b/tests/ui/wildcard_imports_2021.edition2018.fixed index 6a9fe007d654..e30c1d4e7446 100644 --- a/tests/ui/wildcard_imports_2021.edition2018.fixed +++ b/tests/ui/wildcard_imports_2021.edition2018.fixed @@ -10,15 +10,16 @@ extern crate wildcard_imports_helper; -use crate::fn_mod::foo; -use crate::mod_mod::inner_mod; -use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}; -use crate::struct_mod::{A, inner_struct_mod}; +use crate::fn_mod::foo; //~ wildcard_imports +use crate::mod_mod::inner_mod; //~ wildcard_imports +use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}; //~ wildcard_imports +use crate::struct_mod::{A, inner_struct_mod}; //~ wildcard_imports #[allow(unused_imports)] use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar; +//~^ wildcard_imports use wildcard_imports_helper::prelude::v1::*; -use wildcard_imports_helper::{ExternA, extern_foo}; +use wildcard_imports_helper::{ExternA, extern_foo}; //~ wildcard_imports use std::io::prelude::*; @@ -86,7 +87,7 @@ mod underscore_mod { } fn does_lint() { - use exports_underscore_ish::{_Deref, dummy}; + use exports_underscore_ish::{_Deref, dummy}; //~ wildcard_imports let _ = (&0).deref(); dummy(); } @@ -116,14 +117,15 @@ mod in_fn_test { pub(crate) use self::inner_exported2::*; fn test_intern() { - use crate::fn_mod::foo; + use crate::fn_mod::foo; //~ wildcard_imports foo(); } fn test_extern() { use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo}; - use wildcard_imports_helper::{ExternA, extern_foo}; + //~^ wildcard_imports + use wildcard_imports_helper::{ExternA, extern_foo}; //~ wildcard_imports inner_for_self_import::inner_extern_foo(); inner_extern_foo(); @@ -136,13 +138,15 @@ mod in_fn_test { fn test_inner_nested() { #[rustfmt::skip] use self::{inner::inner_foo, inner2::inner_bar}; + //~^ wildcard_imports + //~| wildcard_imports inner_foo(); inner_bar(); } fn test_extern_reexported() { - use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}; + use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}; //~ wildcard_imports extern_exported(); let _ = ExternExportedStruct; @@ -171,7 +175,7 @@ mod in_fn_test { } fn test_reexported() { - use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}; + use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}; //~ wildcard_imports exported(); let _ = ExportedStruct; @@ -180,7 +184,9 @@ fn test_reexported() { #[rustfmt::skip] fn test_weird_formatting() { - use crate:: in_fn_test::exported; + use crate:: in_fn_test::exported; //~ wildcard_imports + + //~v wildcard_imports use crate:: fn_mod::foo; exported(); @@ -191,7 +197,7 @@ mod super_imports { fn foofoo() {} mod should_be_replaced { - use super::foofoo; + use super::foofoo; //~ wildcard_imports fn with_super() { let _ = foofoo(); @@ -226,7 +232,7 @@ mod super_imports { mod should_be_replaced_further_inside { fn insidefoo() {} mod inner { - use super::insidefoo; + use super::insidefoo; //~ wildcard_imports fn with_super() { let _ = insidefoo(); } @@ -234,7 +240,7 @@ mod super_imports { } mod use_explicit_should_be_replaced { - use crate::super_imports::foofoo; + use crate::super_imports::foofoo; //~ wildcard_imports fn with_explicit() { let _ = foofoo(); @@ -243,7 +249,7 @@ mod super_imports { mod use_double_super_should_be_replaced { mod inner { - use super::super::foofoo; + use super::super::foofoo; //~ wildcard_imports fn with_double_super() { let _ = foofoo(); @@ -252,7 +258,7 @@ mod super_imports { } mod use_super_explicit_should_be_replaced { - use super::super::super_imports::foofoo; + use super::super::super_imports::foofoo; //~ wildcard_imports fn with_super_explicit() { let _ = foofoo(); @@ -260,7 +266,7 @@ mod super_imports { } mod attestation_should_be_replaced { - use super::foofoo; + use super::foofoo; //~ wildcard_imports fn with_explicit() { let _ = foofoo(); diff --git a/tests/ui/wildcard_imports_2021.edition2018.stderr b/tests/ui/wildcard_imports_2021.edition2018.stderr index e39f240a4aa2..d88e2ca967fd 100644 --- a/tests/ui/wildcard_imports_2021.edition2018.stderr +++ b/tests/ui/wildcard_imports_2021.edition2018.stderr @@ -32,67 +32,67 @@ LL | use wildcard_imports_helper::inner::inner_for_self_import::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:21:5 + --> $DIR/wildcard_imports_2021.rs:22:5 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:89:13 + --> $DIR/wildcard_imports_2021.rs:90:13 | LL | use exports_underscore_ish::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `exports_underscore_ish::{_Deref, dummy}` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:119:13 + --> $DIR/wildcard_imports_2021.rs:120:13 | LL | use crate::fn_mod::*; | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:125:75 + --> $DIR/wildcard_imports_2021.rs:126:75 | LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *}; | ^ help: try: `inner_extern_foo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:126:13 + --> $DIR/wildcard_imports_2021.rs:128:13 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:138:20 + --> $DIR/wildcard_imports_2021.rs:140:20 | LL | use self::{inner::*, inner2::*}; | ^^^^^^^^ help: try: `inner::inner_foo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:138:30 + --> $DIR/wildcard_imports_2021.rs:140:30 | LL | use self::{inner::*, inner2::*}; | ^^^^^^^^^ help: try: `inner2::inner_bar` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:145:13 + --> $DIR/wildcard_imports_2021.rs:149:13 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:174:9 + --> $DIR/wildcard_imports_2021.rs:178:9 | LL | use crate::in_fn_test::*; | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:183:9 + --> $DIR/wildcard_imports_2021.rs:187:9 | LL | use crate:: in_fn_test:: * ; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:184:9 + --> $DIR/wildcard_imports_2021.rs:190:9 | LL | use crate:: fn_mod:: | _________^ @@ -100,37 +100,37 @@ LL | | *; | |_________^ help: try: `crate:: fn_mod::foo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:195:13 + --> $DIR/wildcard_imports_2021.rs:201:13 | LL | use super::*; | ^^^^^^^^ help: try: `super::foofoo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:230:17 + --> $DIR/wildcard_imports_2021.rs:236:17 | LL | use super::*; | ^^^^^^^^ help: try: `super::insidefoo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:238:13 + --> $DIR/wildcard_imports_2021.rs:244:13 | LL | use crate::super_imports::*; | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:247:17 + --> $DIR/wildcard_imports_2021.rs:253:17 | LL | use super::super::*; | ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:256:13 + --> $DIR/wildcard_imports_2021.rs:262:13 | LL | use super::super::super_imports::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:264:13 + --> $DIR/wildcard_imports_2021.rs:270:13 | LL | use super::*; | ^^^^^^^^ help: try: `super::foofoo` diff --git a/tests/ui/wildcard_imports_2021.edition2021.fixed b/tests/ui/wildcard_imports_2021.edition2021.fixed index 6a9fe007d654..e30c1d4e7446 100644 --- a/tests/ui/wildcard_imports_2021.edition2021.fixed +++ b/tests/ui/wildcard_imports_2021.edition2021.fixed @@ -10,15 +10,16 @@ extern crate wildcard_imports_helper; -use crate::fn_mod::foo; -use crate::mod_mod::inner_mod; -use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}; -use crate::struct_mod::{A, inner_struct_mod}; +use crate::fn_mod::foo; //~ wildcard_imports +use crate::mod_mod::inner_mod; //~ wildcard_imports +use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}; //~ wildcard_imports +use crate::struct_mod::{A, inner_struct_mod}; //~ wildcard_imports #[allow(unused_imports)] use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar; +//~^ wildcard_imports use wildcard_imports_helper::prelude::v1::*; -use wildcard_imports_helper::{ExternA, extern_foo}; +use wildcard_imports_helper::{ExternA, extern_foo}; //~ wildcard_imports use std::io::prelude::*; @@ -86,7 +87,7 @@ mod underscore_mod { } fn does_lint() { - use exports_underscore_ish::{_Deref, dummy}; + use exports_underscore_ish::{_Deref, dummy}; //~ wildcard_imports let _ = (&0).deref(); dummy(); } @@ -116,14 +117,15 @@ mod in_fn_test { pub(crate) use self::inner_exported2::*; fn test_intern() { - use crate::fn_mod::foo; + use crate::fn_mod::foo; //~ wildcard_imports foo(); } fn test_extern() { use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo}; - use wildcard_imports_helper::{ExternA, extern_foo}; + //~^ wildcard_imports + use wildcard_imports_helper::{ExternA, extern_foo}; //~ wildcard_imports inner_for_self_import::inner_extern_foo(); inner_extern_foo(); @@ -136,13 +138,15 @@ mod in_fn_test { fn test_inner_nested() { #[rustfmt::skip] use self::{inner::inner_foo, inner2::inner_bar}; + //~^ wildcard_imports + //~| wildcard_imports inner_foo(); inner_bar(); } fn test_extern_reexported() { - use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}; + use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}; //~ wildcard_imports extern_exported(); let _ = ExternExportedStruct; @@ -171,7 +175,7 @@ mod in_fn_test { } fn test_reexported() { - use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}; + use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}; //~ wildcard_imports exported(); let _ = ExportedStruct; @@ -180,7 +184,9 @@ fn test_reexported() { #[rustfmt::skip] fn test_weird_formatting() { - use crate:: in_fn_test::exported; + use crate:: in_fn_test::exported; //~ wildcard_imports + + //~v wildcard_imports use crate:: fn_mod::foo; exported(); @@ -191,7 +197,7 @@ mod super_imports { fn foofoo() {} mod should_be_replaced { - use super::foofoo; + use super::foofoo; //~ wildcard_imports fn with_super() { let _ = foofoo(); @@ -226,7 +232,7 @@ mod super_imports { mod should_be_replaced_further_inside { fn insidefoo() {} mod inner { - use super::insidefoo; + use super::insidefoo; //~ wildcard_imports fn with_super() { let _ = insidefoo(); } @@ -234,7 +240,7 @@ mod super_imports { } mod use_explicit_should_be_replaced { - use crate::super_imports::foofoo; + use crate::super_imports::foofoo; //~ wildcard_imports fn with_explicit() { let _ = foofoo(); @@ -243,7 +249,7 @@ mod super_imports { mod use_double_super_should_be_replaced { mod inner { - use super::super::foofoo; + use super::super::foofoo; //~ wildcard_imports fn with_double_super() { let _ = foofoo(); @@ -252,7 +258,7 @@ mod super_imports { } mod use_super_explicit_should_be_replaced { - use super::super::super_imports::foofoo; + use super::super::super_imports::foofoo; //~ wildcard_imports fn with_super_explicit() { let _ = foofoo(); @@ -260,7 +266,7 @@ mod super_imports { } mod attestation_should_be_replaced { - use super::foofoo; + use super::foofoo; //~ wildcard_imports fn with_explicit() { let _ = foofoo(); diff --git a/tests/ui/wildcard_imports_2021.edition2021.stderr b/tests/ui/wildcard_imports_2021.edition2021.stderr index e39f240a4aa2..d88e2ca967fd 100644 --- a/tests/ui/wildcard_imports_2021.edition2021.stderr +++ b/tests/ui/wildcard_imports_2021.edition2021.stderr @@ -32,67 +32,67 @@ LL | use wildcard_imports_helper::inner::inner_for_self_import::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:21:5 + --> $DIR/wildcard_imports_2021.rs:22:5 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:89:13 + --> $DIR/wildcard_imports_2021.rs:90:13 | LL | use exports_underscore_ish::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `exports_underscore_ish::{_Deref, dummy}` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:119:13 + --> $DIR/wildcard_imports_2021.rs:120:13 | LL | use crate::fn_mod::*; | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:125:75 + --> $DIR/wildcard_imports_2021.rs:126:75 | LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *}; | ^ help: try: `inner_extern_foo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:126:13 + --> $DIR/wildcard_imports_2021.rs:128:13 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:138:20 + --> $DIR/wildcard_imports_2021.rs:140:20 | LL | use self::{inner::*, inner2::*}; | ^^^^^^^^ help: try: `inner::inner_foo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:138:30 + --> $DIR/wildcard_imports_2021.rs:140:30 | LL | use self::{inner::*, inner2::*}; | ^^^^^^^^^ help: try: `inner2::inner_bar` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:145:13 + --> $DIR/wildcard_imports_2021.rs:149:13 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:174:9 + --> $DIR/wildcard_imports_2021.rs:178:9 | LL | use crate::in_fn_test::*; | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:183:9 + --> $DIR/wildcard_imports_2021.rs:187:9 | LL | use crate:: in_fn_test:: * ; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:184:9 + --> $DIR/wildcard_imports_2021.rs:190:9 | LL | use crate:: fn_mod:: | _________^ @@ -100,37 +100,37 @@ LL | | *; | |_________^ help: try: `crate:: fn_mod::foo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:195:13 + --> $DIR/wildcard_imports_2021.rs:201:13 | LL | use super::*; | ^^^^^^^^ help: try: `super::foofoo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:230:17 + --> $DIR/wildcard_imports_2021.rs:236:17 | LL | use super::*; | ^^^^^^^^ help: try: `super::insidefoo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:238:13 + --> $DIR/wildcard_imports_2021.rs:244:13 | LL | use crate::super_imports::*; | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:247:17 + --> $DIR/wildcard_imports_2021.rs:253:17 | LL | use super::super::*; | ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:256:13 + --> $DIR/wildcard_imports_2021.rs:262:13 | LL | use super::super::super_imports::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo` error: usage of wildcard import - --> $DIR/wildcard_imports_2021.rs:264:13 + --> $DIR/wildcard_imports_2021.rs:270:13 | LL | use super::*; | ^^^^^^^^ help: try: `super::foofoo` diff --git a/tests/ui/wildcard_imports_2021.rs b/tests/ui/wildcard_imports_2021.rs index 18ebc0f51274..70010b83aee9 100644 --- a/tests/ui/wildcard_imports_2021.rs +++ b/tests/ui/wildcard_imports_2021.rs @@ -10,15 +10,16 @@ extern crate wildcard_imports_helper; -use crate::fn_mod::*; -use crate::mod_mod::*; -use crate::multi_fn_mod::*; -use crate::struct_mod::*; +use crate::fn_mod::*; //~ wildcard_imports +use crate::mod_mod::*; //~ wildcard_imports +use crate::multi_fn_mod::*; //~ wildcard_imports +use crate::struct_mod::*; //~ wildcard_imports #[allow(unused_imports)] use wildcard_imports_helper::inner::inner_for_self_import::*; +//~^ wildcard_imports use wildcard_imports_helper::prelude::v1::*; -use wildcard_imports_helper::*; +use wildcard_imports_helper::*; //~ wildcard_imports use std::io::prelude::*; @@ -86,7 +87,7 @@ mod underscore_mod { } fn does_lint() { - use exports_underscore_ish::*; + use exports_underscore_ish::*; //~ wildcard_imports let _ = (&0).deref(); dummy(); } @@ -116,14 +117,15 @@ mod in_fn_test { pub(crate) use self::inner_exported2::*; fn test_intern() { - use crate::fn_mod::*; + use crate::fn_mod::*; //~ wildcard_imports foo(); } fn test_extern() { use wildcard_imports_helper::inner::inner_for_self_import::{self, *}; - use wildcard_imports_helper::*; + //~^ wildcard_imports + use wildcard_imports_helper::*; //~ wildcard_imports inner_for_self_import::inner_extern_foo(); inner_extern_foo(); @@ -136,13 +138,15 @@ mod in_fn_test { fn test_inner_nested() { #[rustfmt::skip] use self::{inner::*, inner2::*}; + //~^ wildcard_imports + //~| wildcard_imports inner_foo(); inner_bar(); } fn test_extern_reexported() { - use wildcard_imports_helper::*; + use wildcard_imports_helper::*; //~ wildcard_imports extern_exported(); let _ = ExternExportedStruct; @@ -171,7 +175,7 @@ mod in_fn_test { } fn test_reexported() { - use crate::in_fn_test::*; + use crate::in_fn_test::*; //~ wildcard_imports exported(); let _ = ExportedStruct; @@ -180,7 +184,9 @@ fn test_reexported() { #[rustfmt::skip] fn test_weird_formatting() { - use crate:: in_fn_test:: * ; + use crate:: in_fn_test:: * ; //~ wildcard_imports + + //~v wildcard_imports use crate:: fn_mod:: *; @@ -192,7 +198,7 @@ mod super_imports { fn foofoo() {} mod should_be_replaced { - use super::*; + use super::*; //~ wildcard_imports fn with_super() { let _ = foofoo(); @@ -227,7 +233,7 @@ mod super_imports { mod should_be_replaced_further_inside { fn insidefoo() {} mod inner { - use super::*; + use super::*; //~ wildcard_imports fn with_super() { let _ = insidefoo(); } @@ -235,7 +241,7 @@ mod super_imports { } mod use_explicit_should_be_replaced { - use crate::super_imports::*; + use crate::super_imports::*; //~ wildcard_imports fn with_explicit() { let _ = foofoo(); @@ -244,7 +250,7 @@ mod super_imports { mod use_double_super_should_be_replaced { mod inner { - use super::super::*; + use super::super::*; //~ wildcard_imports fn with_double_super() { let _ = foofoo(); @@ -253,7 +259,7 @@ mod super_imports { } mod use_super_explicit_should_be_replaced { - use super::super::super_imports::*; + use super::super::super_imports::*; //~ wildcard_imports fn with_super_explicit() { let _ = foofoo(); @@ -261,7 +267,7 @@ mod super_imports { } mod attestation_should_be_replaced { - use super::*; + use super::*; //~ wildcard_imports fn with_explicit() { let _ = foofoo(); diff --git a/tests/ui/write_literal_2.rs b/tests/ui/write_literal_2.rs index b2ed552d46bc..1e37700d1bff 100644 --- a/tests/ui/write_literal_2.rs +++ b/tests/ui/write_literal_2.rs @@ -31,7 +31,10 @@ fn main() { v, "some {}\ {} \\ {}", - "1", "2", "3", + //~v write_literal + "1", + "2", + "3", ); writeln!(v, "{}", "\\"); //~^ ERROR: literal with an empty format string diff --git a/tests/ui/write_literal_2.stderr b/tests/ui/write_literal_2.stderr index 81ef49de082e..d2917f32f7fe 100644 --- a/tests/ui/write_literal_2.stderr +++ b/tests/ui/write_literal_2.stderr @@ -80,10 +80,12 @@ LL ~ world!", | error: literal with an empty format string - --> $DIR/write_literal_2.rs:34:9 + --> $DIR/write_literal_2.rs:35:9 | -LL | "1", "2", "3", - | ^^^^^^^^^^^^^ +LL | / "1", +LL | | "2", +LL | | "3", + | |___________^ | help: try | @@ -92,7 +94,7 @@ LL ~ 2 \\ 3", | error: literal with an empty format string - --> $DIR/write_literal_2.rs:36:23 + --> $DIR/write_literal_2.rs:39:23 | LL | writeln!(v, "{}", "\\"); | ^^^^ @@ -104,7 +106,7 @@ LL + writeln!(v, "\\"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:38:24 + --> $DIR/write_literal_2.rs:41:24 | LL | writeln!(v, r"{}", "\\"); | ^^^^ @@ -116,7 +118,7 @@ LL + writeln!(v, r"\"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:40:26 + --> $DIR/write_literal_2.rs:43:26 | LL | writeln!(v, r#"{}"#, "\\"); | ^^^^ @@ -128,7 +130,7 @@ LL + writeln!(v, r#"\"#); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:42:23 + --> $DIR/write_literal_2.rs:45:23 | LL | writeln!(v, "{}", r"\"); | ^^^^ @@ -140,7 +142,7 @@ LL + writeln!(v, "\\"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:44:23 + --> $DIR/write_literal_2.rs:47:23 | LL | writeln!(v, "{}", "\r"); | ^^^^ @@ -152,7 +154,7 @@ LL + writeln!(v, "\r"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:47:28 + --> $DIR/write_literal_2.rs:50:28 | LL | writeln!(v, r#"{}{}"#, '#', '"'); | ^^^^^^^^ diff --git a/tests/ui/writeln_empty_string.fixed b/tests/ui/writeln_empty_string.fixed index f6a7481f6422..e8341ff7483f 100644 --- a/tests/ui/writeln_empty_string.fixed +++ b/tests/ui/writeln_empty_string.fixed @@ -6,10 +6,10 @@ fn main() { let mut v = Vec::new(); // These should fail - writeln!(v); + writeln!(v); //~ writeln_empty_string let mut suggestion = Vec::new(); - writeln!(suggestion); + writeln!(suggestion); //~ writeln_empty_string // These should be fine writeln!(v); diff --git a/tests/ui/writeln_empty_string.rs b/tests/ui/writeln_empty_string.rs index 0297dba8c45d..545e0b88c40f 100644 --- a/tests/ui/writeln_empty_string.rs +++ b/tests/ui/writeln_empty_string.rs @@ -6,10 +6,10 @@ fn main() { let mut v = Vec::new(); // These should fail - writeln!(v, ""); + writeln!(v, ""); //~ writeln_empty_string let mut suggestion = Vec::new(); - writeln!(suggestion, ""); + writeln!(suggestion, ""); //~ writeln_empty_string // These should be fine writeln!(v); diff --git a/tests/ui/zero_ptr.fixed b/tests/ui/zero_ptr.fixed index 5d99bc9b757d..1d44586c14af 100644 --- a/tests/ui/zero_ptr.fixed +++ b/tests/ui/zero_ptr.fixed @@ -1,12 +1,14 @@ pub fn foo(_const: *const f32, _mut: *mut i64) {} fn main() { - let _ = std::ptr::null::(); - let _ = std::ptr::null_mut::(); - let _: *const u8 = std::ptr::null(); + let _ = std::ptr::null::(); //~ zero_ptr + let _ = std::ptr::null_mut::(); //~ zero_ptr + let _: *const u8 = std::ptr::null(); //~ zero_ptr foo(0 as _, 0 as _); foo(std::ptr::null(), std::ptr::null_mut()); + //~^ zero_ptr + //~| zero_ptr let z = 0; let _ = z as *const usize; // this is currently not caught diff --git a/tests/ui/zero_ptr.rs b/tests/ui/zero_ptr.rs index 09d321c7a18d..f6bc31b322d1 100644 --- a/tests/ui/zero_ptr.rs +++ b/tests/ui/zero_ptr.rs @@ -1,12 +1,14 @@ pub fn foo(_const: *const f32, _mut: *mut i64) {} fn main() { - let _ = 0 as *const usize; - let _ = 0 as *mut f64; - let _: *const u8 = 0 as *const _; + let _ = 0 as *const usize; //~ zero_ptr + let _ = 0 as *mut f64; //~ zero_ptr + let _: *const u8 = 0 as *const _; //~ zero_ptr foo(0 as _, 0 as _); foo(0 as *const _, 0 as *mut _); + //~^ zero_ptr + //~| zero_ptr let z = 0; let _ = z as *const usize; // this is currently not caught diff --git a/tests/ui/zero_ptr_no_std.fixed b/tests/ui/zero_ptr_no_std.fixed index 4f4d19e883d1..53185d013410 100644 --- a/tests/ui/zero_ptr_no_std.fixed +++ b/tests/ui/zero_ptr_no_std.fixed @@ -4,9 +4,9 @@ #[start] fn main(_argc: isize, _argv: *const *const u8) -> isize { - let _ = core::ptr::null::(); - let _ = core::ptr::null_mut::(); - let _: *const u8 = core::ptr::null(); + let _ = core::ptr::null::(); //~ zero_ptr + let _ = core::ptr::null_mut::(); //~ zero_ptr + let _: *const u8 = core::ptr::null(); //~ zero_ptr 0 } diff --git a/tests/ui/zero_ptr_no_std.rs b/tests/ui/zero_ptr_no_std.rs index 54954d8d13fe..0154b2c9f6b1 100644 --- a/tests/ui/zero_ptr_no_std.rs +++ b/tests/ui/zero_ptr_no_std.rs @@ -4,9 +4,9 @@ #[start] fn main(_argc: isize, _argv: *const *const u8) -> isize { - let _ = 0 as *const usize; - let _ = 0 as *mut f64; - let _: *const u8 = 0 as *const _; + let _ = 0 as *const usize; //~ zero_ptr + let _ = 0 as *mut f64; //~ zero_ptr + let _: *const u8 = 0 as *const _; //~ zero_ptr 0 }